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