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