1 /**************************************************************************
3 * Copyright (C) 2008 Pål Staurland (staura@gmail.com)
4 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
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.
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 **************************************************************************/
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
26 #include <cairo-xlib.h>
27 #include <pango/pangocairo.h>
38 // --------------------------------------------------
43 int mouse_scroll_down
;
57 int panel_autohide_show_timeout
;
58 int panel_autohide_hide_timeout
;
59 int panel_autohide_height
;
60 int panel_strut_policy
;
64 // panel's initial config
66 // panels (one panel per monitor)
72 Imlib_Image default_icon
;
81 panel_position
= CENTER
;
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
91 backgrounds
= g_array_new(0, 0, sizeof(Background
));
93 memset(&panel_config
, 0, sizeof(Panel
));
95 // append full transparency background
96 Background transparent_bg
;
97 memset(&transparent_bg
, 0, sizeof(Background
));
98 g_array_append_val(backgrounds
, transparent_bg
);
109 for (i
=0 ; i
< nb_panel
; i
++) {
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
);
118 if (panel1
) free(panel1
);
120 g_array_free(backgrounds
, 1);
121 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
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;
138 #ifdef ENABLE_BATTERY
142 // number of panels (one monitor or 'all' monitors)
143 if (panel_config
.monitor
>= 0)
146 nb_panel
= server
.nb_monitor
;
148 panel1
= malloc(nb_panel
* sizeof(Panel
));
149 for (i
=0 ; i
< nb_panel
; i
++) {
150 memcpy(&panel1
[i
], &panel_config
, sizeof(Panel
));
153 fprintf(stderr
, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server
.nb_monitor
, nb_panel
, server
.nb_desktop
);
154 for (i
=0 ; i
< nb_panel
; i
++) {
157 if (panel_config
.monitor
< 0)
159 if ( p
->area
.bg
== 0 )
160 p
->area
.bg
= &g_array_index(backgrounds
, Background
, 0);
163 p
->area
.on_screen
= 1;
165 p
->area
._resize
= resize_panel
;
166 p
->g_taskbar
.area
.parent
= p
;
167 p
->g_taskbar
.area
.panel
= p
;
168 p
->g_task
.area
.panel
= p
;
169 init_panel_size_and_position(p
);
173 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
175 #ifdef ENABLE_BATTERY
176 if (battery_enabled
) {
177 init_battery_panel(p
);
178 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
181 // systray only on first panel
182 if (systray
.area
.on_screen
&& i
== 0) {
183 init_systray_panel(p
);
184 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
189 XSetWindowAttributes att
= { .colormap
=server
.colormap
, .background_pixel
=0, .border_pixel
=0 };
190 unsigned long mask
= CWEventMask
|CWColormap
|CWBackPixel
|CWBorderPixel
;
191 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
);
193 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
;
194 if (g_tooltip
.enabled
)
195 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
197 event_mask
|= LeaveWindowMask
|EnterWindowMask
;
198 XChangeWindowAttributes(server
.dsp
, p
->main_win
, CWEventMask
, &(XSetWindowAttributes
){.event_mask
=event_mask
});
202 server
.gc
= XCreateGC(server
.dsp
, p
->main_win
, 0, &gcv
);
204 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
205 set_panel_properties(p
);
206 set_panel_background(p
);
207 if (snapshot_path
== 0) {
208 // if we are not in 'snapshot' mode then map new panel
209 XMapWindow (server
.dsp
, p
->main_win
);
213 add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
219 task_refresh_tasklist();
224 void init_panel_size_and_position(Panel
*panel
)
227 if (panel_horizontal
) {
228 if (panel
->pourcentx
)
229 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
230 if (panel
->pourcenty
)
231 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
232 if (panel
->area
.bg
->border
.rounded
> panel
->area
.height
/2) {
233 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
234 g_array_append_val(backgrounds
, *panel
->area
.bg
);
235 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
236 panel
->area
.bg
->border
.rounded
= panel
->area
.height
/2;
240 int old_panel_height
= panel
->area
.height
;
241 if (panel
->pourcentx
)
242 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
244 panel
->area
.height
= panel
->area
.width
;
245 if (panel
->pourcenty
)
246 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
248 panel
->area
.width
= old_panel_height
;
249 if (panel
->area
.bg
->border
.rounded
> panel
->area
.width
/2) {
250 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
251 g_array_append_val(backgrounds
, *panel
->area
.bg
);
252 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
253 panel
->area
.bg
->border
.rounded
= panel
->area
.width
/2;
257 // panel position determined here
258 if (panel_position
& LEFT
) {
259 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
262 if (panel_position
& RIGHT
) {
263 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
266 if (panel_horizontal
)
267 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
269 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
272 if (panel_position
& TOP
) {
273 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
276 if (panel_position
& BOTTOM
) {
277 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
280 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
284 // autohide or strut_policy=minimum
285 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
286 if (panel_horizontal
) {
287 panel
->hidden_width
= panel
->area
.width
;
288 panel
->hidden_height
= panel
->area
.height
- diff
;
291 panel
->hidden_width
= panel
->area
.width
- diff
;
292 panel
->hidden_height
= panel
->area
.height
;
294 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
298 void resize_panel(void *obj
)
300 Panel
*panel
= (Panel
*)obj
;
302 if (panel_horizontal
) {
303 int taskbar_width
, modulo_width
= 0;
305 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
306 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
307 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
308 #ifdef ENABLE_BATTERY
309 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
310 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
312 // TODO : systray only on first panel. search better implementation !
313 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
314 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
316 if (panel_mode
== MULTI_DESKTOP
) {
317 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
318 taskbar_width
= width
/ panel
->nb_desktop
;
319 modulo_width
= width
% panel
->nb_desktop
;
322 // change posx and width for all taskbar
324 posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
325 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
326 panel
->taskbar
[i
].area
.posx
= posx
;
327 panel
->taskbar
[i
].area
.width
= taskbar_width
;
328 panel
->taskbar
[i
].area
.resize
= 1;
330 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
;
339 int taskbar_height
, modulo_height
= 0;
342 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
343 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
344 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
345 #ifdef ENABLE_BATTERY
346 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
347 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
349 // TODO : systray only on first panel. search better implementation !
350 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
351 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
353 posy
= panel
->area
.height
- panel
->area
.bg
->border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
354 if (panel_mode
== MULTI_DESKTOP
) {
355 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
356 taskbar_height
= height
/ panel
->nb_desktop
;
357 modulo_height
= height
% panel
->nb_desktop
;
360 // change posy and height for all taskbar
361 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
362 panel
->taskbar
[i
].area
.posy
= posy
;
363 panel
->taskbar
[i
].area
.height
= taskbar_height
;
364 panel
->taskbar
[i
].area
.resize
= 1;
366 panel
->taskbar
[i
].area
.height
++;
369 if (panel_mode
== MULTI_DESKTOP
)
370 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
376 void visible_object()
381 for (i
=0 ; i
< nb_panel
; i
++) {
385 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
386 taskbar
= &panel
->taskbar
[j
];
387 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
388 // SINGLE_DESKTOP and not current desktop
389 taskbar
->area
.on_screen
= 0;
392 taskbar
->area
.on_screen
= 1;
399 void update_strut(Panel
* p
)
401 if (panel_strut_policy
== STRUT_NONE
) {
402 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
);
403 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
);
408 unsigned int d1
, screen_width
, screen_height
;
411 XGetGeometry(server
.dsp
, server
.root_win
, &d2
, &d3
, &d3
, &screen_width
, &screen_height
, &d1
, &d1
);
412 Monitor monitor
= server
.monitor
[p
->monitor
];
413 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
414 if (panel_horizontal
) {
415 int height
= p
->area
.height
+ p
->marginy
;
416 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
417 height
= p
->hidden_height
;
418 if (panel_position
& TOP
) {
419 struts
[2] = height
+ monitor
.y
;
421 // p->area.width - 1 allowed full screen on monitor 2
422 struts
[9] = p
->posx
+ p
->area
.width
- 1;
425 struts
[3] = height
+ screen_height
- monitor
.y
- monitor
.height
;
426 struts
[10] = p
->posx
;
427 // p->area.width - 1 allowed full screen on monitor 2
428 struts
[11] = p
->posx
+ p
->area
.width
- 1;
432 int width
= p
->area
.width
+ p
->marginx
;
433 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
434 width
= p
->hidden_width
;
435 if (panel_position
& LEFT
) {
436 struts
[0] = width
+ monitor
.x
;
438 // p->area.width - 1 allowed full screen on monitor 2
439 struts
[5] = p
->posy
+ p
->area
.height
- 1;
442 struts
[1] = width
+ screen_width
- monitor
.x
- monitor
.width
;
444 // p->area.width - 1 allowed full screen on monitor 2
445 struts
[7] = p
->posy
+ p
->area
.height
- 1;
448 // Old specification : fluxbox need _NET_WM_STRUT.
449 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
450 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
454 void set_panel_properties(Panel
*p
)
456 XStoreName (server
.dsp
, p
->main_win
, "tint2");
459 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
461 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
466 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
467 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
469 // Sticky and below other window
471 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
473 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
474 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
475 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
476 state
[3] = panel_layer
== BOTTOM_LAYER
? server
.atom
._NET_WM_STATE_BELOW
: server
.atom
._NET_WM_STATE_ABOVE
;
477 int nb_atoms
= panel_layer
== NORMAL_LAYER
? 3 : 4;
478 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, nb_atoms
);
483 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
484 wmhints
.flags
= StateHint
| IconWindowHint
;
485 wmhints
.initial_state
= WithdrawnState
;
488 wmhints
.flags
= InputHint
;
489 wmhints
.input
= False
;
491 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
494 long prop
[5] = { 2, 0, 0, 0, 0 };
495 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
497 // XdndAware - Register for Xdnd events
499 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
503 // Fixed position and non-resizable window
504 // Allow panel move and resize when tint2 reload config file
505 int minwidth
= panel_autohide
? p
->hidden_width
: p
->area
.width
;
506 int minheight
= panel_autohide
? p
->hidden_height
: p
->area
.height
;
507 XSizeHints size_hints
;
508 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
509 size_hints
.min_width
= minwidth
;
510 size_hints
.max_width
= p
->area
.width
;
511 size_hints
.min_height
= minheight
;
512 size_hints
.max_height
= p
->area
.height
;
513 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
516 XClassHint
* classhint
= XAllocClassHint();
517 classhint
->res_name
= "tint2";
518 classhint
->res_class
= "Tint2";
519 XSetClassHint(server
.dsp
, p
->main_win
, classhint
);
524 void set_panel_background(Panel
*p
)
526 if (p
->area
.pix
) XFreePixmap (server
.dsp
, p
->area
.pix
);
527 p
->area
.pix
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
530 if (panel_horizontal
&& panel_position
& BOTTOM
)
531 yoff
= p
->area
.height
-p
->hidden_height
;
532 else if (!panel_horizontal
&& panel_position
& RIGHT
)
533 xoff
= p
->area
.width
-p
->hidden_width
;
535 if (server
.real_transparency
) {
536 clear_pixmap(p
->area
.pix
, 0, 0, p
->area
.width
, p
->area
.height
);
540 // copy background (server.root_pmap) in panel.area.pix
543 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
544 if (panel_autohide
&& p
->is_hidden
) {
548 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
);
549 XFillRectangle(server
.dsp
, p
->area
.pix
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
552 // draw background panel
555 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
, server
.visual
, p
->area
.width
, p
->area
.height
);
556 c
= cairo_create (cs
);
557 draw_background(&p
->area
, c
);
559 cairo_surface_destroy (cs
);
561 if (panel_autohide
) {
562 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
563 p
->hidden_pixmap
= XCreatePixmap(server
.dsp
, server
.root_win
, p
->hidden_width
, p
->hidden_height
, server
.depth
);
564 XCopyArea(server
.dsp
, p
->area
.pix
, p
->hidden_pixmap
, server
.gc
, xoff
, yoff
, p
->hidden_width
, p
->hidden_height
, 0, 0);
567 // redraw panel's object
570 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
574 // reset task 'state_pix'
577 for (i
=0 ; i
< p
->nb_desktop
; i
++) {
578 tskbar
= &p
->taskbar
[i
];
579 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
580 set_task_redraw((Task
*)l0
->data
);
586 Panel
*get_panel(Window win
)
589 for (i
=0 ; i
< nb_panel
; i
++) {
590 if (panel1
[i
].main_win
== win
) {
598 Taskbar
*click_taskbar (Panel
*panel
, int x
, int y
)
603 if (panel_horizontal
) {
604 for (i
=0; i
< panel
->nb_desktop
; i
++) {
605 tskbar
= &panel
->taskbar
[i
];
606 if (tskbar
->area
.on_screen
&& x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
611 for (i
=0; i
< panel
->nb_desktop
; i
++) {
612 tskbar
= &panel
->taskbar
[i
];
613 if (tskbar
->area
.on_screen
&& y
>= tskbar
->area
.posy
&& y
<= (tskbar
->area
.posy
+ tskbar
->area
.height
))
621 Task
*click_task (Panel
*panel
, int x
, int y
)
626 if ( (tskbar
= click_taskbar(panel
, x
, y
)) ) {
627 if (panel_horizontal
) {
629 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
631 if (tsk
->area
.on_screen
&& x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
638 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
640 if (tsk
->area
.on_screen
&& y
>= tsk
->area
.posy
&& y
<= (tsk
->area
.posy
+ tsk
->area
.height
)) {
650 int click_padding(Panel
*panel
, int x
, int y
)
652 if (panel_horizontal
) {
653 if (x
< panel
->area
.paddingxlr
|| x
> panel
->area
.width
-panel
->area
.paddingxlr
)
657 if (y
< panel
->area
.paddingxlr
|| y
> panel
->area
.height
-panel
->area
.paddingxlr
)
664 int click_clock(Panel
*panel
, int x
, int y
)
666 Clock clk
= panel
->clock
;
667 if (panel_horizontal
) {
668 if (clk
.area
.on_screen
&& x
>= clk
.area
.posx
&& x
<= (clk
.area
.posx
+ clk
.area
.width
))
671 if (clk
.area
.on_screen
&& y
>= clk
.area
.posy
&& y
<= (clk
.area
.posy
+ clk
.area
.height
))
678 Area
* click_area(Panel
*panel
, int x
, int y
)
680 Area
* result
= &panel
->area
;
681 Area
* new_result
= result
;
684 GSList
* it
= result
->list
;
687 if (panel_horizontal
) {
688 if (a
->on_screen
&& x
>= a
->posx
&& x
<= (a
->posx
+ a
->width
)) {
693 if (a
->on_screen
&& y
>= a
->posy
&& y
<= (a
->posy
+ a
->height
)) {
700 } while (new_result
!= result
);
705 void stop_autohide_timeout(Panel
* p
)
707 if (p
->autohide_timeout
) {
708 stop_timeout(p
->autohide_timeout
);
709 p
->autohide_timeout
= 0;
714 void autohide_show(void* p
)
717 stop_autohide_timeout(panel
);
718 panel
->is_hidden
= 0;
719 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
722 XMapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
723 if (panel_horizontal
) {
724 if (panel_position
& TOP
)
725 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
727 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
730 if (panel_position
& LEFT
)
731 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
733 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
735 refresh_systray
= 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
740 void autohide_hide(void* p
)
743 stop_autohide_timeout(panel
);
744 panel
->is_hidden
= 1;
745 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
748 XUnmapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
749 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
750 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
751 if (panel_horizontal
) {
752 if (panel_position
& TOP
)
753 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
755 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
+diff
, panel
->hidden_width
, panel
->hidden_height
);
758 if (panel_position
& LEFT
)
759 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
761 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
+diff
, panel
->posy
, panel
->hidden_width
, panel
->hidden_height
);
767 void autohide_trigger_show(Panel
* p
)
771 if (p
->autohide_timeout
)
772 change_timeout(p
->autohide_timeout
, panel_autohide_show_timeout
, 0, autohide_show
, p
);
774 p
->autohide_timeout
= add_timeout(panel_autohide_show_timeout
, 0, autohide_show
, p
);
778 void autohide_trigger_hide(Panel
* p
)
786 if (XQueryPointer(server
.dsp
, p
->main_win
, &root
, &child
, &xr
, &yr
, &xw
, &yw
, &mask
))
787 if (child
) return; // mouse over one of the system tray icons
789 if (p
->autohide_timeout
)
790 change_timeout(p
->autohide_timeout
, panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
792 p
->autohide_timeout
= add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);