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