]> Dogcows Code - chaz/tint2/blob - src/panel.c
cleanup taskbar_name
[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 (g_tooltip.enabled)
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 }
541 tskbar->area.pix = 0;
542 l0 = tskbar->area.list;
543 if (taskbarname_enabled) l0 = l0->next;
544 for (; l0 ; l0 = l0->next) {
545 set_task_redraw((Task *)l0->data);
546 }
547 }
548 }
549
550
551 Panel *get_panel(Window win)
552 {
553 int i;
554 for (i=0 ; i < nb_panel ; i++) {
555 if (panel1[i].main_win == win) {
556 return &panel1[i];
557 }
558 }
559 return 0;
560 }
561
562
563 Taskbar *click_taskbar (Panel *panel, int x, int y)
564 {
565 Taskbar *tskbar;
566 int i;
567
568 if (panel_horizontal) {
569 for (i=0; i < panel->nb_desktop ; i++) {
570 tskbar = &panel->taskbar[i];
571 if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
572 return tskbar;
573 }
574 }
575 else {
576 for (i=0; i < panel->nb_desktop ; i++) {
577 tskbar = &panel->taskbar[i];
578 if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
579 return tskbar;
580 }
581 }
582 return NULL;
583 }
584
585
586 Task *click_task (Panel *panel, int x, int y)
587 {
588 GSList *l0;
589 Taskbar *tskbar;
590
591 if ( (tskbar = click_taskbar(panel, x, y)) ) {
592 if (panel_horizontal) {
593 Task *tsk;
594 l0 = tskbar->area.list;
595 if (taskbarname_enabled) l0 = l0->next;
596 for (; l0 ; l0 = l0->next) {
597 tsk = l0->data;
598 if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
599 return tsk;
600 }
601 }
602 }
603 else {
604 Task *tsk;
605 l0 = tskbar->area.list;
606 if (taskbarname_enabled) l0 = l0->next;
607 for (; l0 ; l0 = l0->next) {
608 tsk = l0->data;
609 if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
610 return tsk;
611 }
612 }
613 }
614 }
615 return NULL;
616 }
617
618
619 Launcher *click_launcher (Panel *panel, int x, int y)
620 {
621 Launcher *launcher = &panel->launcher;
622
623 if (panel_horizontal) {
624 if (launcher->area.on_screen && x >= launcher->area.posx && x <= (launcher->area.posx + launcher->area.width))
625 return launcher;
626 }
627 else {
628 if (launcher->area.on_screen && y >= launcher->area.posy && y <= (launcher->area.posy + launcher->area.height))
629 return launcher;
630 }
631 return NULL;
632 }
633
634
635 LauncherIcon *click_launcher_icon (Panel *panel, int x, int y)
636 {
637 GSList *l0;
638 Launcher *launcher;
639
640 //printf("Click x=%d y=%d\n", x, y);
641 if ( (launcher = click_launcher(panel, x, y)) ) {
642 LauncherIcon *icon;
643 for (l0 = launcher->list_icons; l0 ; l0 = l0->next) {
644 icon = l0->data;
645 if (x >= (launcher->area.posx + icon->x) && x <= (launcher->area.posx + icon->x + icon->icon_size) &&
646 y >= (launcher->area.posy + icon->y) && y <= (launcher->area.posy + icon->y + icon->icon_size)) {
647 //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);
648 return icon;
649 }
650 }
651 }
652 return NULL;
653 }
654
655
656 int click_padding(Panel *panel, int x, int y)
657 {
658 if (panel_horizontal) {
659 if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
660 return 1;
661 }
662 else {
663 if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
664 return 1;
665 }
666 return 0;
667 }
668
669
670 int click_clock(Panel *panel, int x, int y)
671 {
672 Clock clk = panel->clock;
673 if (panel_horizontal) {
674 if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
675 return TRUE;
676 } else {
677 if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
678 return TRUE;
679 }
680 return FALSE;
681 }
682
683
684 Area* click_area(Panel *panel, int x, int y)
685 {
686 Area* result = &panel->area;
687 Area* new_result = result;
688 do {
689 result = new_result;
690 GSList* it = result->list;
691 while (it) {
692 Area* a = it->data;
693 if (panel_horizontal) {
694 if (a->on_screen && x >= a->posx && x <= (a->posx + a->width)) {
695 new_result = a;
696 break;
697 }
698 } else {
699 if (a->on_screen && y >= a->posy && y <= (a->posy + a->height)) {
700 new_result = a;
701 break;
702 }
703 }
704 it = it->next;
705 }
706 } while (new_result != result);
707 return result;
708 }
709
710
711 void stop_autohide_timeout(Panel* p)
712 {
713 if (p->autohide_timeout) {
714 stop_timeout(p->autohide_timeout);
715 p->autohide_timeout = 0;
716 }
717 }
718
719
720 void autohide_show(void* p)
721 {
722 Panel* panel = p;
723 stop_autohide_timeout(panel);
724 panel->is_hidden = 0;
725 if (panel_strut_policy == STRUT_FOLLOW_SIZE)
726 update_strut(p);
727
728 XMapSubwindows(server.dsp, panel->main_win); // systray windows
729 if (panel_horizontal) {
730 if (panel_position & TOP)
731 XResizeWindow(server.dsp, panel->main_win, panel->area.width, panel->area.height);
732 else
733 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
734 }
735 else {
736 if (panel_position & LEFT)
737 XResizeWindow(server.dsp, panel->main_win, panel->area.width, panel->area.height);
738 else
739 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy, panel->area.width, panel->area.height);
740 }
741 refresh_systray = 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
742 panel_refresh = 1;
743 }
744
745
746 void autohide_hide(void* p)
747 {
748 Panel* panel = p;
749 stop_autohide_timeout(panel);
750 panel->is_hidden = 1;
751 if (panel_strut_policy == STRUT_FOLLOW_SIZE)
752 update_strut(p);
753
754 XUnmapSubwindows(server.dsp, panel->main_win); // systray windows
755 int diff = (panel_horizontal ? panel->area.height : panel->area.width) - panel_autohide_height;
756 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
757 if (panel_horizontal) {
758 if (panel_position & TOP)
759 XResizeWindow(server.dsp, panel->main_win, panel->hidden_width, panel->hidden_height);
760 else
761 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx, panel->posy+diff, panel->hidden_width, panel->hidden_height);
762 }
763 else {
764 if (panel_position & LEFT)
765 XResizeWindow(server.dsp, panel->main_win, panel->hidden_width, panel->hidden_height);
766 else
767 XMoveResizeWindow(server.dsp, panel->main_win, panel->posx+diff, panel->posy, panel->hidden_width, panel->hidden_height);
768 }
769 panel_refresh = 1;
770 }
771
772
773 void autohide_trigger_show(Panel* p)
774 {
775 if (!p)
776 return;
777 if (p->autohide_timeout)
778 change_timeout(p->autohide_timeout, panel_autohide_show_timeout, 0, autohide_show, p);
779 else
780 p->autohide_timeout = add_timeout(panel_autohide_show_timeout, 0, autohide_show, p);
781 }
782
783
784 void autohide_trigger_hide(Panel* p)
785 {
786 if (!p)
787 return;
788
789 Window root, child;
790 int xr, yr, xw, yw;
791 unsigned int mask;
792 if (XQueryPointer(server.dsp, p->main_win, &root, &child, &xr, &yr, &xw, &yw, &mask))
793 if (child) return; // mouse over one of the system tray icons
794
795 if (p->autohide_timeout)
796 change_timeout(p->autohide_timeout, panel_autohide_hide_timeout, 0, autohide_hide, p);
797 else
798 p->autohide_timeout = add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p);
799 }
This page took 0.076998 seconds and 4 git commands to generate.