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