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