]> Dogcows Code - chaz/tint2/blob - src/panel.c
*add* remove of tooltip = En/Disabled. it's renamed to task_tooltip to enable/disable...
[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') {
186 // TODO : check systray is only on 1 panel
187 init_systray_panel(p);
188 refresh_systray = 1;
189 }
190 if (panel_items_order[k] == 'C')
191 init_clock_panel(p);
192 }
193 set_panel_items_order(p);
194
195 // catch some events
196 XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
197 unsigned long mask = CWEventMask|CWColormap|CWBackPixel|CWBorderPixel;
198 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);
199
200 long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask;
201 if (p->g_task.tooltip_enabled || p->clock.area._get_tooltip_text)
202 event_mask |= PointerMotionMask|LeaveWindowMask;
203 if (panel_autohide)
204 event_mask |= LeaveWindowMask|EnterWindowMask;
205 XChangeWindowAttributes(server.dsp, p->main_win, CWEventMask, &(XSetWindowAttributes){.event_mask=event_mask});
206
207 if (!server.gc) {
208 XGCValues gcv;
209 server.gc = XCreateGC(server.dsp, p->main_win, 0, &gcv);
210 }
211 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
212 set_panel_properties(p);
213 set_panel_background(p);
214 if (snapshot_path == 0) {
215 // if we are not in 'snapshot' mode then map new panel
216 XMapWindow (server.dsp, p->main_win);
217 }
218
219 if (panel_autohide)
220 add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p);
221
222 visible_taskbar(p);
223 }
224
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 resize_by_layout(obj, 0);
307
308 //printf("resize_panel\n");
309 if (panel_mode != MULTI_DESKTOP && taskbar_enabled) {
310 // propagate width/height on hidden taskbar
311 int i, width, height;
312 Panel *panel = (Panel*)obj;
313 width = panel->taskbar[server.desktop].area.width;
314 height = panel->taskbar[server.desktop].area.height;
315 for (i=0 ; i < panel->nb_desktop ; i++) {
316 panel->taskbar[i].area.width = width;
317 panel->taskbar[i].area.height = height;
318 panel->taskbar[i].area.resize = 1;
319 }
320 }
321 return 0;
322 }
323
324
325 void update_strut(Panel* p)
326 {
327 if (panel_strut_policy == STRUT_NONE) {
328 XDeleteProperty(server.dsp, p->main_win, server.atom._NET_WM_STRUT);
329 XDeleteProperty(server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL);
330 return;
331 }
332
333 // Reserved space
334 unsigned int d1, screen_width, screen_height;
335 Window d2;
336 int d3;
337 XGetGeometry(server.dsp, server.root_win, &d2, &d3, &d3, &screen_width, &screen_height, &d1, &d1);
338 Monitor monitor = server.monitor[p->monitor];
339 long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
340 if (panel_horizontal) {
341 int height = p->area.height + p->marginy;
342 if (panel_strut_policy == STRUT_MINIMUM || (panel_strut_policy == STRUT_FOLLOW_SIZE && p->is_hidden))
343 height = p->hidden_height;
344 if (panel_position & TOP) {
345 struts[2] = height + monitor.y;
346 struts[8] = p->posx;
347 // p->area.width - 1 allowed full screen on monitor 2
348 struts[9] = p->posx + p->area.width - 1;
349 }
350 else {
351 struts[3] = height + screen_height - monitor.y - monitor.height;
352 struts[10] = p->posx;
353 // p->area.width - 1 allowed full screen on monitor 2
354 struts[11] = p->posx + p->area.width - 1;
355 }
356 }
357 else {
358 int width = p->area.width + p->marginx;
359 if (panel_strut_policy == STRUT_MINIMUM || (panel_strut_policy == STRUT_FOLLOW_SIZE && p->is_hidden))
360 width = p->hidden_width;
361 if (panel_position & LEFT) {
362 struts[0] = width + monitor.x;
363 struts[4] = p->posy;
364 // p->area.width - 1 allowed full screen on monitor 2
365 struts[5] = p->posy + p->area.height - 1;
366 }
367 else {
368 struts[1] = width + screen_width - monitor.x - monitor.width;
369 struts[6] = p->posy;
370 // p->area.width - 1 allowed full screen on monitor 2
371 struts[7] = p->posy + p->area.height - 1;
372 }
373 }
374 // Old specification : fluxbox need _NET_WM_STRUT.
375 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
376 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
377 }
378
379
380 void set_panel_items_order(Panel *p)
381 {
382 int k, j;
383
384 if (p->area.list) {
385 g_slist_free(p->area.list);
386 p->area.list = 0;
387 }
388
389 for (k=0 ; k < strlen(panel_items_order) ; k++) {
390 if (panel_items_order[k] == 'L')
391 p->area.list = g_slist_append(p->area.list, &p->launcher);
392 if (panel_items_order[k] == 'T') {
393 for (j=0 ; j < p->nb_desktop ; j++)
394 p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
395 }
396 #ifdef ENABLE_BATTERY
397 if (panel_items_order[k] == 'B')
398 p->area.list = g_slist_append(p->area.list, &p->battery);
399 #endif
400 if (panel_items_order[k] == 'S') {
401 // TODO : check systray is only on 1 panel
402 p->area.list = g_slist_append(p->area.list, &systray);
403 }
404 if (panel_items_order[k] == 'C')
405 p->area.list = g_slist_append(p->area.list, &p->clock);
406 }
407 init_rendering(&p->area, 0);
408 }
409
410
411 void set_panel_properties(Panel *p)
412 {
413 XStoreName (server.dsp, p->main_win, "tint2");
414
415 gsize len;
416 gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL);
417 if (name != NULL) {
418 XChangeProperty(server.dsp, p->main_win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len);
419 g_free(name);
420 }
421
422 // Dock
423 long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
424 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
425
426 // Sticky and below other window
427 val = ALLDESKTOP;
428 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
429 Atom state[4];
430 state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
431 state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
432 state[2] = server.atom._NET_WM_STATE_STICKY;
433 state[3] = panel_layer == BOTTOM_LAYER ? server.atom._NET_WM_STATE_BELOW : server.atom._NET_WM_STATE_ABOVE;
434 int nb_atoms = panel_layer == NORMAL_LAYER ? 3 : 4;
435 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, nb_atoms);
436
437 // Unfocusable
438 XWMHints wmhints;
439 if (panel_dock) {
440 wmhints.icon_window = wmhints.window_group = p->main_win;
441 wmhints.flags = StateHint | IconWindowHint;
442 wmhints.initial_state = WithdrawnState;
443 }
444 else {
445 wmhints.flags = InputHint;
446 wmhints.input = False;
447 }
448 XSetWMHints(server.dsp, p->main_win, &wmhints);
449
450 // Undecorated
451 long prop[5] = { 2, 0, 0, 0, 0 };
452 XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
453
454 // XdndAware - Register for Xdnd events
455 Atom version=4;
456 XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
457
458 update_strut(p);
459
460 // Fixed position and non-resizable window
461 // Allow panel move and resize when tint2 reload config file
462 int minwidth = panel_autohide ? p->hidden_width : p->area.width;
463 int minheight = panel_autohide ? p->hidden_height : p->area.height;
464 XSizeHints size_hints;
465 size_hints.flags = PPosition|PMinSize|PMaxSize;
466 size_hints.min_width = minwidth;
467 size_hints.max_width = p->area.width;
468 size_hints.min_height = minheight;
469 size_hints.max_height = p->area.height;
470 XSetWMNormalHints(server.dsp, p->main_win, &size_hints);
471
472 // Set WM_CLASS
473 XClassHint* classhint = XAllocClassHint();
474 classhint->res_name = "tint2";
475 classhint->res_class = "Tint2";
476 XSetClassHint(server.dsp, p->main_win, classhint);
477 XFree(classhint);
478 }
479
480
481 void set_panel_background(Panel *p)
482 {
483 if (p->area.pix) XFreePixmap (server.dsp, p->area.pix);
484 p->area.pix = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
485
486 int xoff=0, yoff=0;
487 if (panel_horizontal && panel_position & BOTTOM)
488 yoff = p->area.height-p->hidden_height;
489 else if (!panel_horizontal && panel_position & RIGHT)
490 xoff = p->area.width-p->hidden_width;
491
492 if (server.real_transparency) {
493 clear_pixmap(p->area.pix, 0, 0, p->area.width, p->area.height);
494 }
495 else {
496 get_root_pixmap();
497 // copy background (server.root_pmap) in panel.area.pix
498 Window dummy;
499 int x, y;
500 XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
501 if (panel_autohide && p->is_hidden) {
502 x -= xoff;
503 y -= yoff;
504 }
505 XSetTSOrigin(server.dsp, server.gc, -x, -y);
506 XFillRectangle(server.dsp, p->area.pix, server.gc, 0, 0, p->area.width, p->area.height);
507 }
508
509 // draw background panel
510 cairo_surface_t *cs;
511 cairo_t *c;
512 cs = cairo_xlib_surface_create (server.dsp, p->area.pix, server.visual, p->area.width, p->area.height);
513 c = cairo_create (cs);
514 draw_background(&p->area, c);
515 cairo_destroy (c);
516 cairo_surface_destroy (cs);
517
518 if (panel_autohide) {
519 if (p->hidden_pixmap) XFreePixmap(server.dsp, p->hidden_pixmap);
520 p->hidden_pixmap = XCreatePixmap(server.dsp, server.root_win, p->hidden_width, p->hidden_height, server.depth);
521 XCopyArea(server.dsp, p->area.pix, p->hidden_pixmap, server.gc, xoff, yoff, p->hidden_width, p->hidden_height, 0, 0);
522 }
523
524 // redraw panel's object
525 GSList *l0;
526 Area *a;
527 for (l0 = p->area.list; l0 ; l0 = l0->next) {
528 a = l0->data;
529 set_redraw(a);
530 }
531
532 // reset task/taskbar 'state_pix'
533 int i, k;
534 Taskbar *tskbar;
535 for (i=0 ; i < p->nb_desktop ; i++) {
536 tskbar = &p->taskbar[i];
537 for (k=0; k<TASKBAR_STATE_COUNT; ++k) {
538 if (tskbar->state_pix[k]) XFreePixmap(server.dsp, tskbar->state_pix[k]);
539 tskbar->state_pix[k] = 0;
540 if (tskbar->bar_name.state_pix[k]) XFreePixmap(server.dsp, tskbar->bar_name.state_pix[k]);
541 tskbar->bar_name.state_pix[k] = 0;
542 }
543 tskbar->area.pix = 0;
544 tskbar->bar_name.area.pix = 0;
545 l0 = tskbar->area.list;
546 if (taskbarname_enabled) l0 = l0->next;
547 for (; l0 ; l0 = l0->next) {
548 set_task_redraw((Task *)l0->data);
549 }
550 }
551 }
552
553
554 Panel *get_panel(Window win)
555 {
556 int i;
557 for (i=0 ; i < nb_panel ; i++) {
558 if (panel1[i].main_win == win) {
559 return &panel1[i];
560 }
561 }
562 return 0;
563 }
564
565
566 Taskbar *click_taskbar (Panel *panel, int x, int y)
567 {
568 Taskbar *tskbar;
569 int i;
570
571 if (panel_horizontal) {
572 for (i=0; i < panel->nb_desktop ; i++) {
573 tskbar = &panel->taskbar[i];
574 if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
575 return tskbar;
576 }
577 }
578 else {
579 for (i=0; i < panel->nb_desktop ; i++) {
580 tskbar = &panel->taskbar[i];
581 if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
582 return tskbar;
583 }
584 }
585 return NULL;
586 }
587
588
589 Task *click_task (Panel *panel, int x, int y)
590 {
591 GSList *l0;
592 Taskbar *tskbar;
593
594 if ( (tskbar = click_taskbar(panel, x, y)) ) {
595 if (panel_horizontal) {
596 Task *tsk;
597 l0 = tskbar->area.list;
598 if (taskbarname_enabled) l0 = l0->next;
599 for (; l0 ; l0 = l0->next) {
600 tsk = l0->data;
601 if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
602 return tsk;
603 }
604 }
605 }
606 else {
607 Task *tsk;
608 l0 = tskbar->area.list;
609 if (taskbarname_enabled) l0 = l0->next;
610 for (; l0 ; l0 = l0->next) {
611 tsk = l0->data;
612 if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
613 return tsk;
614 }
615 }
616 }
617 }
618 return NULL;
619 }
620
621
622 Launcher *click_launcher (Panel *panel, int x, int y)
623 {
624 Launcher *launcher = &panel->launcher;
625
626 if (panel_horizontal) {
627 if (launcher->area.on_screen && x >= launcher->area.posx && x <= (launcher->area.posx + launcher->area.width))
628 return launcher;
629 }
630 else {
631 if (launcher->area.on_screen && y >= launcher->area.posy && y <= (launcher->area.posy + launcher->area.height))
632 return launcher;
633 }
634 return NULL;
635 }
636
637
638 LauncherIcon *click_launcher_icon (Panel *panel, int x, int y)
639 {
640 GSList *l0;
641 Launcher *launcher;
642
643 //printf("Click x=%d y=%d\n", x, y);
644 if ( (launcher = click_launcher(panel, x, y)) ) {
645 LauncherIcon *icon;
646 for (l0 = launcher->list_icons; l0 ; l0 = l0->next) {
647 icon = l0->data;
648 if (x >= (launcher->area.posx + icon->x) && x <= (launcher->area.posx + icon->x + icon->icon_size) &&
649 y >= (launcher->area.posy + icon->y) && y <= (launcher->area.posy + icon->y + icon->icon_size)) {
650 //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);
651 return icon;
652 }
653 }
654 }
655 return NULL;
656 }
657
658
659 int click_padding(Panel *panel, int x, int y)
660 {
661 if (panel_horizontal) {
662 if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
663 return 1;
664 }
665 else {
666 if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
667 return 1;
668 }
669 return 0;
670 }
671
672
673 int click_clock(Panel *panel, int x, int y)
674 {
675 Clock clk = panel->clock;
676 if (panel_horizontal) {
677 if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
678 return TRUE;
679 } else {
680 if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
681 return TRUE;
682 }
683 return FALSE;
684 }
685
686
687 Area* click_area(Panel *panel, int x, int y)
688 {
689 Area* result = &panel->area;
690 Area* new_result = result;
691 do {
692 result = new_result;
693 GSList* it = result->list;
694 while (it) {
695 Area* a = it->data;
696 if (panel_horizontal) {
697 if (a->on_screen && x >= a->posx && x <= (a->posx + a->width)) {
698 new_result = a;
699 break;
700 }
701 } else {
702 if (a->on_screen && y >= a->posy && y <= (a->posy + a->height)) {
703 new_result = a;
704 break;
705 }
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.072895 seconds and 4 git commands to generate.