]> Dogcows Code - chaz/tint2/blob - src/panel.c
87bab8d42c9bef723c27571d038685cf3d4dd48e
[chaz/tint2] / src / panel.c
1 /**************************************************************************
2 *
3 * Copyright (C) 2008 Pål Staurland (staura@gmail.com)
4 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 **************************************************************************/
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #include <cairo.h>
26 #include <cairo-xlib.h>
27 #include <pango/pangocairo.h>
28
29 #include "server.h"
30 #include "config.h"
31 #include "window.h"
32 #include "task.h"
33 #include "panel.h"
34 #include "tooltip.h"
35
36
37 int signal_pending;
38 // --------------------------------------------------
39 // mouse events
40 int mouse_middle;
41 int mouse_right;
42 int mouse_scroll_up;
43 int mouse_scroll_down;
44 int mouse_tilt_left;
45 int mouse_tilt_right;
46
47 int panel_mode;
48 int wm_menu;
49 int panel_dock;
50 int panel_layer;
51 int panel_position;
52 int panel_horizontal;
53 int panel_refresh;
54 int task_dragged;
55
56 int panel_autohide;
57 int panel_autohide_show_timeout;
58 int panel_autohide_hide_timeout;
59 int panel_autohide_height;
60 int panel_strut_policy;
61
62 Task *task_active;
63 Task *task_drag;
64 int max_tick_urgent;
65
66 // panel's initial config
67 Panel panel_config;
68 // panels (one panel per monitor)
69 Panel *panel1;
70 int nb_panel;
71
72 GArray* backgrounds;
73
74 Imlib_Image default_icon;
75
76
77 void autohide_hide(void* p);
78 void autohide_show(void* p);
79
80
81 void default_panel()
82 {
83 panel1 = 0;
84 nb_panel = 0;
85 default_icon = NULL;
86 task_active = 0;
87 task_drag = 0;
88 task_dragged = 0;
89 panel_horizontal = 1;
90 panel_position = CENTER;
91 panel_autohide = 0;
92 panel_autohide_show_timeout = 0;
93 panel_autohide_hide_timeout = 0;
94 panel_autohide_height = 5; // for vertical panels this is of course the width
95 panel_strut_policy = STRUT_MINIMUM;
96 panel_dock = 0; // default not in the dock
97 panel_layer = BOTTOM_LAYER; // default is bottom layer
98 wm_menu = 0;
99 max_tick_urgent = 7;
100 memset(&panel_config, 0, sizeof(Panel));
101 backgrounds = g_array_new(0, 0, sizeof(Background));
102
103 // append full transparency background
104 Background transparent_bg;
105 memset(&transparent_bg, 0, sizeof(Background));
106 g_array_append_val(backgrounds, transparent_bg);
107 }
108
109 void cleanup_panel()
110 {
111 if (!panel1) return;
112
113 cleanup_taskbar();
114
115 int i;
116 Panel *p;
117 for (i=0 ; i < nb_panel ; i++) {
118 p = &panel1[i];
119
120 free_area(&p->area);
121 if (p->temp_pmap) XFreePixmap(server.dsp, p->temp_pmap);
122 if (p->hidden_pixmap) XFreePixmap(server.dsp, p->hidden_pixmap);
123 if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
124 }
125
126 if (panel1) free(panel1);
127 if (backgrounds) g_array_free(backgrounds, 1);
128 if (panel_config.g_task.font_desc) pango_font_description_free(panel_config.g_task.font_desc);
129 }
130
131 void init_panel()
132 {
133 int i, old_nb_panel;
134 Panel *new_panel, *p;
135
136 if (panel_config.monitor > (server.nb_monitor-1)) {
137 // server.nb_monitor minimum value is 1 (see get_monitors())
138 fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n");
139 panel_config.monitor = 0;
140 }
141
142 init_tooltip();
143 init_systray();
144 init_clock();
145 #ifdef ENABLE_BATTERY
146 init_battery();
147 #endif
148
149 cleanup_taskbar();
150 for (i=0 ; i < nb_panel ; i++) {
151 autohide_show(&panel1[i]);
152 free_area(&panel1[i].area);
153 if (panel1[i].temp_pmap) {
154 XFreePixmap(server.dsp, panel1[i].temp_pmap);
155 panel1[i].temp_pmap = 0;
156 }
157 }
158
159 // number of panels
160 old_nb_panel = nb_panel;
161 if (panel_config.monitor >= 0)
162 nb_panel = 1;
163 else
164 nb_panel = server.nb_monitor;
165
166 // freed old panels
167 for (i=nb_panel ; i < old_nb_panel ; i++) {
168 if (panel1[i].main_win) {
169 XDestroyWindow(server.dsp, panel1[i].main_win);
170 panel1[i].main_win = 0;
171 }
172 }
173
174 // alloc & init new panel
175 Window old_win;
176 if (nb_panel != old_nb_panel)
177 new_panel = realloc(panel1, nb_panel * sizeof(Panel));
178 else
179 new_panel = panel1;
180 for (i=0 ; i < nb_panel ; i++) {
181 old_win = new_panel[i].main_win;
182 memcpy(&new_panel[i], &panel_config, sizeof(Panel));
183 new_panel[i].main_win = old_win;
184 }
185
186 fprintf(stderr, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server.nb_monitor, nb_panel, server.nb_desktop);
187 for (i=0 ; i < nb_panel ; i++) {
188 p = &new_panel[i];
189
190 if (panel_config.monitor < 0)
191 p->monitor = i;
192 p->area.parent = p;
193 p->area.panel = p;
194 p->area.on_screen = 1;
195 p->area.resize = 1;
196 p->area._resize = resize_panel;
197 p->g_taskbar.area.parent = p;
198 p->g_taskbar.area.panel = p;
199 p->g_task.area.panel = p;
200 init_panel_size_and_position(p);
201 // add childs
202 if (clock_enabled) {
203 init_clock_panel(p);
204 p->area.list = g_slist_append(p->area.list, &p->clock);
205 }
206 #ifdef ENABLE_BATTERY
207 if (battery_enabled) {
208 init_battery_panel(p);
209 p->area.list = g_slist_append(p->area.list, &p->battery);
210 }
211 #endif
212 // systray only on first panel
213 if (systray.area.on_screen && i == 0) {
214 init_systray_panel(p);
215 p->area.list = g_slist_append(p->area.list, &systray);
216 refresh_systray = 1;
217 }
218
219 if (i >= old_nb_panel) {
220 // new panel : catch some events
221 XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
222 unsigned long mask = CWEventMask|CWColormap|CWBackPixel|CWBorderPixel;
223 p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, server.visual, mask, &att);
224 }
225 else {
226 // old panel
227 XMoveResizeWindow(server.dsp, p->main_win, p->posx, p->posy, p->area.width, p->area.height);
228 }
229
230 long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask;
231 if (g_tooltip.enabled)
232 event_mask |= PointerMotionMask|LeaveWindowMask;
233 if (panel_autohide)
234 event_mask |= LeaveWindowMask|EnterWindowMask;
235 XChangeWindowAttributes(server.dsp, p->main_win, CWEventMask, &(XSetWindowAttributes){.event_mask=event_mask});
236
237 if (!server.gc) {
238 XGCValues gcv;
239 server.gc = XCreateGC(server.dsp, p->main_win, 0, &gcv);
240 }
241 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
242 set_panel_properties(p);
243 set_panel_background(p);
244 if (i >= old_nb_panel && snapshot_path == 0) {
245 // if we are not in 'snapshot' mode then map new panel
246 XMapWindow (server.dsp, p->main_win);
247 }
248
249 if (panel_autohide)
250 add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p);
251 }
252
253 panel1 = new_panel;
254 panel_refresh = 1;
255 init_taskbar();
256 visible_object();
257 task_refresh_tasklist();
258 active_task();
259 }
260
261
262 void init_panel_size_and_position(Panel *panel)
263 {
264 // detect panel size
265 if (panel_horizontal) {
266 if (panel->pourcentx)
267 panel->area.width = (float)server.monitor[panel->monitor].width * panel->area.width / 100;
268 if (panel->pourcenty)
269 panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.height / 100;
270 if (panel->area.bg->border.rounded > panel->area.height/2) {
271 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
272 g_array_append_val(backgrounds, *panel->area.bg);
273 panel->area.bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
274 panel->area.bg->border.rounded = panel->area.height/2;
275 }
276 }
277 else {
278 int old_panel_height = panel->area.height;
279 if (panel->pourcentx)
280 panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.width / 100;
281 else
282 panel->area.height = panel->area.width;
283 if (panel->pourcenty)
284 panel->area.width = (float)server.monitor[panel->monitor].width * old_panel_height / 100;
285 else
286 panel->area.width = old_panel_height;
287 if (panel->area.bg->border.rounded > panel->area.width/2) {
288 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
289 g_array_append_val(backgrounds, *panel->area.bg);
290 panel->area.bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
291 panel->area.bg->border.rounded = panel->area.width/2;
292 }
293 }
294
295 // panel position determined here
296 if (panel_position & LEFT) {
297 panel->posx = server.monitor[panel->monitor].x + panel->marginx;
298 }
299 else {
300 if (panel_position & RIGHT) {
301 panel->posx = server.monitor[panel->monitor].x + server.monitor[panel->monitor].width - panel->area.width - panel->marginx;
302 }
303 else {
304 if (panel_horizontal)
305 panel->posx = server.monitor[panel->monitor].x + ((server.monitor[panel->monitor].width - panel->area.width) / 2);
306 else
307 panel->posx = server.monitor[panel->monitor].x + panel->marginx;
308 }
309 }
310 if (panel_position & TOP) {
311 panel->posy = server.monitor[panel->monitor].y + panel->marginy;
312 }
313 else {
314 if (panel_position & BOTTOM) {
315 panel->posy = server.monitor[panel->monitor].y + server.monitor[panel->monitor].height - panel->area.height - panel->marginy;
316 }
317 else {
318 panel->posy = server.monitor[panel->monitor].y + ((server.monitor[panel->monitor].height - panel->area.height) / 2);
319 }
320 }
321
322 if (panel_autohide) {
323 int diff = (panel_horizontal ? panel->area.height : panel->area.width) - panel_autohide_height;
324 if (panel_horizontal) {
325 panel->hidden_width = panel->area.width;
326 panel->hidden_height = panel->area.height - diff;
327 }
328 else {
329 panel->hidden_width = panel->area.width - diff;
330 panel->hidden_height = panel->area.height;
331 }
332 }
333 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
334 }
335
336
337 void resize_panel(void *obj)
338 {
339 Panel *panel = (Panel*)obj;
340
341 if (panel_horizontal) {
342 int taskbar_width, modulo_width = 0;
343
344 taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.bg->border.width);
345 if (panel->clock.area.on_screen && panel->clock.area.width)
346 taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
347 #ifdef ENABLE_BATTERY
348 if (panel->battery.area.on_screen && panel->battery.area.width)
349 taskbar_width -= (panel->battery.area.width + panel->area.paddingx);
350 #endif
351 // TODO : systray only on first panel. search better implementation !
352 if (systray.area.on_screen && systray.area.width && panel == &panel1[0])
353 taskbar_width -= (systray.area.width + panel->area.paddingx);
354
355 if (panel_mode == MULTI_DESKTOP) {
356 int width = taskbar_width - ((panel->nb_desktop-1) * panel->area.paddingx);
357 taskbar_width = width / panel->nb_desktop;
358 modulo_width = width % panel->nb_desktop;
359 }
360
361 // change posx and width for all taskbar
362 int i, posx;
363 posx = panel->area.bg->border.width + panel->area.paddingxlr;
364 for (i=0 ; i < panel->nb_desktop ; i++) {
365 panel->taskbar[i].area.posx = posx;
366 panel->taskbar[i].area.width = taskbar_width;
367 panel->taskbar[i].area.resize = 1;
368 if (modulo_width) {
369 panel->taskbar[i].area.width++;
370 modulo_width--;
371 }
372 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
373 if (panel_mode == MULTI_DESKTOP)
374 posx += panel->taskbar[i].area.width + panel->area.paddingx;
375 }
376 }
377 else {
378 int taskbar_height, modulo_height = 0;
379 int i, posy;
380
381 taskbar_height = panel->area.height - (2 * panel->area.paddingxlr) - (2 * panel->area.bg->border.width);
382 if (panel->clock.area.on_screen && panel->clock.area.height)
383 taskbar_height -= (panel->clock.area.height + panel->area.paddingx);
384 #ifdef ENABLE_BATTERY
385 if (panel->battery.area.on_screen && panel->battery.area.height)
386 taskbar_height -= (panel->battery.area.height + panel->area.paddingx);
387 #endif
388 // TODO : systray only on first panel. search better implementation !
389 if (systray.area.on_screen && systray.area.height && panel == &panel1[0])
390 taskbar_height -= (systray.area.height + panel->area.paddingx);
391
392 posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - taskbar_height;
393 if (panel_mode == MULTI_DESKTOP) {
394 int height = taskbar_height - ((panel->nb_desktop-1) * panel->area.paddingx);
395 taskbar_height = height / panel->nb_desktop;
396 modulo_height = height % panel->nb_desktop;
397 }
398
399 // change posy and height for all taskbar
400 for (i=0 ; i < panel->nb_desktop ; i++) {
401 panel->taskbar[i].area.posy = posy;
402 panel->taskbar[i].area.height = taskbar_height;
403 panel->taskbar[i].area.resize = 1;
404 if (modulo_height) {
405 panel->taskbar[i].area.height++;
406 modulo_height--;
407 }
408 if (panel_mode == MULTI_DESKTOP)
409 posy += panel->taskbar[i].area.height + panel->area.paddingx;
410 }
411 }
412 }
413
414
415 void visible_object()
416 {
417 Panel *panel;
418 int i, j;
419
420 for (i=0 ; i < nb_panel ; i++) {
421 panel = &panel1[i];
422
423 Taskbar *taskbar;
424 for (j=0 ; j < panel->nb_desktop ; j++) {
425 taskbar = &panel->taskbar[j];
426 if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
427 // SINGLE_DESKTOP and not current desktop
428 taskbar->area.on_screen = 0;
429 }
430 else {
431 taskbar->area.on_screen = 1;
432 }
433 }
434 }
435 panel_refresh = 1;
436 }
437
438 void update_strut(Panel* p)
439 {
440 if (panel_strut_policy == STRUT_NONE) {
441 XDeleteProperty(server.dsp, p->main_win, server.atom._NET_WM_STRUT);
442 XDeleteProperty(server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL);
443 return;
444 }
445
446 // Reserved space
447 unsigned int d1, screen_width, screen_height;
448 Window d2;
449 int d3;
450 XGetGeometry(server.dsp, server.root_win, &d2, &d3, &d3, &screen_width, &screen_height, &d1, &d1);
451 Monitor monitor = server.monitor[p->monitor];
452 long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
453 if (panel_horizontal) {
454 int height = p->area.height + p->marginy;
455 if (panel_autohide && (panel_strut_policy == STRUT_MINIMUM || (panel_strut_policy == STRUT_FOLLOW_SIZE && p->is_hidden)) )
456 height = p->hidden_height;
457 if (panel_position & TOP) {
458 struts[2] = height + monitor.y;
459 struts[8] = p->posx;
460 // p->area.width - 1 allowed full screen on monitor 2
461 struts[9] = p->posx + p->area.width - 1;
462 }
463 else {
464 struts[3] = height + screen_height - monitor.y - monitor.height;
465 struts[10] = p->posx;
466 // p->area.width - 1 allowed full screen on monitor 2
467 struts[11] = p->posx + p->area.width - 1;
468 }
469 }
470 else {
471 int width = p->area.width + p->marginx;
472 if (panel_autohide && (panel_strut_policy == STRUT_MINIMUM || (panel_strut_policy == STRUT_FOLLOW_SIZE && p->is_hidden)) )
473 width = p->hidden_width;
474 if (panel_position & LEFT) {
475 struts[0] = width + monitor.x;
476 struts[4] = p->posy;
477 // p->area.width - 1 allowed full screen on monitor 2
478 struts[5] = p->posy + p->area.height - 1;
479 }
480 else {
481 struts[1] = width + screen_width - monitor.x - monitor.width;
482 struts[6] = p->posy;
483 // p->area.width - 1 allowed full screen on monitor 2
484 struts[7] = p->posy + p->area.height - 1;
485 }
486 }
487 // Old specification : fluxbox need _NET_WM_STRUT.
488 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
489 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
490 }
491
492
493 void set_panel_properties(Panel *p)
494 {
495 XStoreName (server.dsp, p->main_win, "tint2");
496
497 gsize len;
498 gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL);
499 if (name != NULL) {
500 XChangeProperty(server.dsp, p->main_win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len);
501 g_free(name);
502 }
503
504 // Dock
505 long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
506 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
507
508 // Sticky and below other window
509 val = ALLDESKTOP;
510 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
511 Atom state[4];
512 state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
513 state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
514 state[2] = server.atom._NET_WM_STATE_STICKY;
515 state[3] = panel_layer == BOTTOM_LAYER ? server.atom._NET_WM_STATE_BELOW : server.atom._NET_WM_STATE_ABOVE;
516 int nb_atoms = panel_layer == NORMAL_LAYER ? 3 : 4;
517 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, nb_atoms);
518
519 // Unfocusable
520 XWMHints wmhints;
521 if (panel_dock) {
522 wmhints.icon_window = wmhints.window_group = p->main_win;
523 wmhints.flags = StateHint | IconWindowHint;
524 wmhints.initial_state = WithdrawnState;
525 }
526 else {
527 wmhints.flags = InputHint;
528 wmhints.input = False;
529 }
530 XSetWMHints(server.dsp, p->main_win, &wmhints);
531
532 // Undecorated
533 long prop[5] = { 2, 0, 0, 0, 0 };
534 XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
535
536 // XdndAware - Register for Xdnd events
537 int version=5;
538 XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
539
540 update_strut(p);
541
542 // Fixed position and non-resizable window
543 // Allow panel move and resize when tint2 reload config file
544 int minwidth = panel_autohide ? p->hidden_width : p->area.width;
545 int minheight = panel_autohide ? p->hidden_height : p->area.height;
546 XSizeHints size_hints;
547 size_hints.flags = PPosition|PMinSize|PMaxSize;
548 size_hints.min_width = minwidth;
549 size_hints.max_width = p->area.width;
550 size_hints.min_height = minheight;
551 size_hints.max_height = p->area.height;
552 XSetWMNormalHints(server.dsp, p->main_win, &size_hints);
553
554 // Set WM_CLASS
555 XClassHint* classhint = XAllocClassHint();
556 classhint->res_name = "tint2";
557 classhint->res_class = "Tint2";
558 XSetClassHint(server.dsp, p->main_win, classhint);
559 XFree(classhint);
560 }
561
562
563 void set_panel_background(Panel *p)
564 {
565 if (p->area.pix) XFreePixmap (server.dsp, p->area.pix);
566 p->area.pix = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
567
568 int xoff=0, yoff=0;
569 if (panel_horizontal && panel_position & BOTTOM)
570 yoff = p->area.height-p->hidden_height;
571 else if (!panel_horizontal && panel_position & RIGHT)
572 xoff = p->area.width-p->hidden_width;
573
574 if (server.real_transparency) {
575 clear_pixmap(p->area.pix, 0, 0, p->area.width, p->area.height);
576 }
577 else {
578 get_root_pixmap();
579 // copy background (server.root_pmap) in panel.area.pix
580 Window dummy;
581 int x, y;
582 XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
583 if (panel_autohide && p->is_hidden) {
584 x -= xoff;
585 y -= yoff;
586 }
587 XSetTSOrigin(server.dsp, server.gc, -x, -y);
588 XFillRectangle(server.dsp, p->area.pix, server.gc, 0, 0, p->area.width, p->area.height);
589 }
590
591 // draw background panel
592 cairo_surface_t *cs;
593 cairo_t *c;
594 cs = cairo_xlib_surface_create (server.dsp, p->area.pix, server.visual, p->area.width, p->area.height);
595 c = cairo_create (cs);
596 draw_background(&p->area, c);
597 cairo_destroy (c);
598 cairo_surface_destroy (cs);
599
600 if (panel_autohide) {
601 if (p->hidden_pixmap) XFreePixmap(server.dsp, p->hidden_pixmap);
602 p->hidden_pixmap = XCreatePixmap(server.dsp, server.root_win, p->hidden_width, p->hidden_height, server.depth);
603 XCopyArea(server.dsp, p->area.pix, p->hidden_pixmap, server.gc, xoff, yoff, p->hidden_width, p->hidden_height, 0, 0);
604 }
605
606 // redraw panel's object
607 GSList *l0;
608 Area *a;
609 for (l0 = p->area.list; l0 ; l0 = l0->next) {
610 a = l0->data;
611 set_redraw(a);
612 }
613 // reset task 'state_pix'
614 int i;
615 Taskbar *tskbar;
616 for (i=0 ; i < p->nb_desktop ; i++) {
617 tskbar = &p->taskbar[i];
618 for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
619 set_task_redraw((Task *)l0->data);
620 }
621 }
622 }
623
624
625 Panel *get_panel(Window win)
626 {
627 int i;
628 for (i=0 ; i < nb_panel ; i++) {
629 if (panel1[i].main_win == win) {
630 return &panel1[i];
631 }
632 }
633 return 0;
634 }
635
636
637 Taskbar *click_taskbar (Panel *panel, int x, int y)
638 {
639 Taskbar *tskbar;
640 int i;
641
642 if (panel_horizontal) {
643 for (i=0; i < panel->nb_desktop ; i++) {
644 tskbar = &panel->taskbar[i];
645 if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
646 return tskbar;
647 }
648 }
649 else {
650 for (i=0; i < panel->nb_desktop ; i++) {
651 tskbar = &panel->taskbar[i];
652 if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
653 return tskbar;
654 }
655 }
656 return NULL;
657 }
658
659
660 Task *click_task (Panel *panel, int x, int y)
661 {
662 GSList *l0;
663 Taskbar *tskbar;
664
665 if ( (tskbar = click_taskbar(panel, x, y)) ) {
666 if (panel_horizontal) {
667 Task *tsk;
668 for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
669 tsk = l0->data;
670 if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
671 return tsk;
672 }
673 }
674 }
675 else {
676 Task *tsk;
677 for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
678 tsk = l0->data;
679 if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
680 return tsk;
681 }
682 }
683 }
684 }
685 return NULL;
686 }
687
688
689 int click_padding(Panel *panel, int x, int y)
690 {
691 if (panel_horizontal) {
692 if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
693 return 1;
694 }
695 else {
696 if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
697 return 1;
698 }
699 return 0;
700 }
701
702
703 int click_clock(Panel *panel, int x, int y)
704 {
705 Clock clk = panel->clock;
706 if (panel_horizontal) {
707 if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
708 return TRUE;
709 } else {
710 if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
711 return TRUE;
712 }
713 return FALSE;
714 }
715
716
717 Area* click_area(Panel *panel, int x, int y)
718 {
719 Area* result = &panel->area;
720 Area* new_result = result;
721 do {
722 result = new_result;
723 GSList* it = result->list;
724 while (it) {
725 Area* a = it->data;
726 if (panel_horizontal) {
727 if (a->on_screen && x >= a->posx && x <= (a->posx + a->width)) {
728 new_result = a;
729 break;
730 }
731 } else {
732 if (a->on_screen && y >= a->posy && y <= (a->posy + a->height)) {
733 new_result = a;
734 break;
735 }
736 }
737 it = it->next;
738 }
739 } while (new_result != result);
740 return result;
741 }
742
743
744 void stop_autohide_timeout(Panel* p)
745 {
746 if (p->autohide_timeout) {
747 stop_timeout(p->autohide_timeout);
748 p->autohide_timeout = 0;
749 }
750 }
751
752
753 void autohide_show(void* p)
754 {
755 Panel* panel = p;
756 stop_autohide_timeout(panel);
757 panel->is_hidden = 0;
758 if (panel_strut_policy == STRUT_FOLLOW_SIZE)
759 update_strut(p);
760
761 XMapSubwindows(server.dsp, panel->main_win); // systray windows
762 if (panel_horizontal) {
763 if (panel_position & TOP)
764 XResizeWindow(server.dsp, panel->main_win, panel->area.width, panel->area.height);
765 else
766 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
767 }
768 else {
769 if (panel_position & LEFT)
770 XResizeWindow(server.dsp, panel->main_win, panel->area.width, panel->area.height);
771 else
772 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
773 }
774 refresh_systray = 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
775 panel_refresh = 1;
776 }
777
778
779 void autohide_hide(void* p)
780 {
781 Panel* panel = p;
782 stop_autohide_timeout(panel);
783 panel->is_hidden = 1;
784 if (panel_strut_policy == STRUT_FOLLOW_SIZE)
785 update_strut(p);
786
787 XUnmapSubwindows(server.dsp, panel->main_win); // systray windows
788 int diff = (panel_horizontal ? panel->area.height : panel->area.width) - panel_autohide_height;
789 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
790 if (panel_horizontal) {
791 if (panel_position & TOP)
792 XResizeWindow(server.dsp, panel->main_win, panel->hidden_width, panel->hidden_height);
793 else
794 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy+diff, panel->hidden_width, panel->hidden_height);
795 }
796 else {
797 if (panel_position & LEFT)
798 XResizeWindow(server.dsp, panel->main_win, panel->hidden_width, panel->hidden_height);
799 else
800 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx+diff, panel->posy, panel->hidden_width, panel->hidden_height);
801 }
802 panel_refresh = 1;
803 }
804
805
806 void autohide_trigger_show(Panel* p)
807 {
808 if (!p)
809 return;
810 if (p->autohide_timeout)
811 change_timeout(p->autohide_timeout, panel_autohide_show_timeout, 0, autohide_show, p);
812 else
813 p->autohide_timeout = add_timeout(panel_autohide_show_timeout, 0, autohide_show, p);
814 }
815
816
817 void autohide_trigger_hide(Panel* p)
818 {
819 if (!p)
820 return;
821
822 Window root, child;
823 int xr, yr, xw, yw;
824 unsigned int mask;
825 if (XQueryPointer(server.dsp, p->main_win, &root, &child, &xr, &yr, &xw, &yw, &mask))
826 if (child) return; // mouse over one of the system tray icons
827
828 if (p->autohide_timeout)
829 change_timeout(p->autohide_timeout, panel_autohide_hide_timeout, 0, autohide_hide, p);
830 else
831 p->autohide_timeout = add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p);
832 }
This page took 0.075546 seconds and 4 git commands to generate.