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