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