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