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