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
;
66 // panel's initial config
68 // panels (one panel per monitor)
74 Imlib_Image default_icon
;
77 void autohide_hide(void* p
);
78 void autohide_show(void* p
);
90 panel_position
= CENTER
;
92 panel_autohide_show_timeout
= 0;
93 panel_autohide_hide_timeout
= 0;
94 panel_autohide_height
= 5; // for vertical panels this is of course the width
95 panel_strut_policy
= STRUT_MINIMUM
;
96 panel_dock
= 0; // default not in the dock
97 panel_layer
= BOTTOM_LAYER
; // default is bottom layer
100 backgrounds
= g_array_new(0, 0, sizeof(Background
));
102 memset(&panel_config
, 0, sizeof(Panel
));
104 // append full transparency background
105 Background transparent_bg
;
106 memset(&transparent_bg
, 0, sizeof(Background
));
107 g_array_append_val(backgrounds
, transparent_bg
);
118 for (i
=0 ; i
< nb_panel
; i
++) {
122 if (p
->temp_pmap
) XFreePixmap(server
.dsp
, p
->temp_pmap
);
123 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
124 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
127 if (panel1
) free(panel1
);
128 if (backgrounds
) g_array_free(backgrounds
, 1);
129 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
137 if (panel_config
.monitor
> (server
.nb_monitor
-1)) {
138 // server.nb_monitor minimum value is 1 (see get_monitors())
139 fprintf(stderr
, "warning : monitor not found. tint2 default to all monitors.\n");
140 panel_config
.monitor
= 0;
146 #ifdef ENABLE_BATTERY
150 // number of panels (one monitor or 'all' monitors)
151 if (panel_config
.monitor
>= 0)
154 nb_panel
= server
.nb_monitor
;
156 panel1
= malloc(nb_panel
* sizeof(Panel
));
157 for (i
=0 ; i
< nb_panel
; i
++) {
158 memcpy(&panel1
[i
], &panel_config
, sizeof(Panel
));
161 fprintf(stderr
, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server
.nb_monitor
, nb_panel
, server
.nb_desktop
);
162 for (i
=0 ; i
< nb_panel
; i
++) {
165 if (panel_config
.monitor
< 0)
169 p
->area
.on_screen
= 1;
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
);
179 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
181 #ifdef ENABLE_BATTERY
182 if (battery_enabled
) {
183 init_battery_panel(p
);
184 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
187 // systray only on first panel
188 if (systray
.area
.on_screen
&& i
== 0) {
189 init_systray_panel(p
);
190 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
195 XSetWindowAttributes att
= { .colormap
=server
.colormap
, .background_pixel
=0, .border_pixel
=0 };
196 unsigned long mask
= CWEventMask
|CWColormap
|CWBackPixel
|CWBorderPixel
;
197 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
);
199 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
;
200 if (g_tooltip
.enabled
)
201 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
203 event_mask
|= LeaveWindowMask
|EnterWindowMask
;
204 XChangeWindowAttributes(server
.dsp
, p
->main_win
, CWEventMask
, &(XSetWindowAttributes
){.event_mask
=event_mask
});
208 server
.gc
= XCreateGC(server
.dsp
, p
->main_win
, 0, &gcv
);
210 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
211 set_panel_properties(p
);
212 set_panel_background(p
);
213 if (snapshot_path
== 0) {
214 // if we are not in 'snapshot' mode then map new panel
215 XMapWindow (server
.dsp
, p
->main_win
);
219 add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
225 task_refresh_tasklist();
230 void init_panel_size_and_position(Panel
*panel
)
233 if (panel_horizontal
) {
234 if (panel
->pourcentx
)
235 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
236 if (panel
->pourcenty
)
237 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
238 if (panel
->area
.bg
->border
.rounded
> panel
->area
.height
/2) {
239 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
240 g_array_append_val(backgrounds
, *panel
->area
.bg
);
241 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
242 panel
->area
.bg
->border
.rounded
= panel
->area
.height
/2;
246 int old_panel_height
= panel
->area
.height
;
247 if (panel
->pourcentx
)
248 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
250 panel
->area
.height
= panel
->area
.width
;
251 if (panel
->pourcenty
)
252 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
254 panel
->area
.width
= old_panel_height
;
255 if (panel
->area
.bg
->border
.rounded
> panel
->area
.width
/2) {
256 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
257 g_array_append_val(backgrounds
, *panel
->area
.bg
);
258 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
259 panel
->area
.bg
->border
.rounded
= panel
->area
.width
/2;
263 // panel position determined here
264 if (panel_position
& LEFT
) {
265 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
268 if (panel_position
& RIGHT
) {
269 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
272 if (panel_horizontal
)
273 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
275 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
278 if (panel_position
& TOP
) {
279 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
282 if (panel_position
& BOTTOM
) {
283 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
286 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
290 if (panel_autohide
) {
291 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
292 if (panel_horizontal
) {
293 panel
->hidden_width
= panel
->area
.width
;
294 panel
->hidden_height
= panel
->area
.height
- diff
;
297 panel
->hidden_width
= panel
->area
.width
- diff
;
298 panel
->hidden_height
= panel
->area
.height
;
301 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
305 void resize_panel(void *obj
)
307 Panel
*panel
= (Panel
*)obj
;
309 if (panel_horizontal
) {
310 int taskbar_width
, modulo_width
= 0;
312 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
313 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
314 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
315 #ifdef ENABLE_BATTERY
316 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
317 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
319 // TODO : systray only on first panel. search better implementation !
320 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
321 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
323 if (panel_mode
== MULTI_DESKTOP
) {
324 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
325 taskbar_width
= width
/ panel
->nb_desktop
;
326 modulo_width
= width
% panel
->nb_desktop
;
329 // change posx and width for all taskbar
331 posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
332 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
333 panel
->taskbar
[i
].area
.posx
= posx
;
334 panel
->taskbar
[i
].area
.width
= taskbar_width
;
335 panel
->taskbar
[i
].area
.resize
= 1;
337 panel
->taskbar
[i
].area
.width
++;
340 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
341 if (panel_mode
== MULTI_DESKTOP
)
342 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
346 int taskbar_height
, modulo_height
= 0;
349 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
350 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
351 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
352 #ifdef ENABLE_BATTERY
353 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
354 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
356 // TODO : systray only on first panel. search better implementation !
357 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
358 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
360 posy
= panel
->area
.height
- panel
->area
.bg
->border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
361 if (panel_mode
== MULTI_DESKTOP
) {
362 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
363 taskbar_height
= height
/ panel
->nb_desktop
;
364 modulo_height
= height
% panel
->nb_desktop
;
367 // change posy and height for all taskbar
368 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
369 panel
->taskbar
[i
].area
.posy
= posy
;
370 panel
->taskbar
[i
].area
.height
= taskbar_height
;
371 panel
->taskbar
[i
].area
.resize
= 1;
373 panel
->taskbar
[i
].area
.height
++;
376 if (panel_mode
== MULTI_DESKTOP
)
377 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
383 void visible_object()
388 for (i
=0 ; i
< nb_panel
; i
++) {
392 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
393 taskbar
= &panel
->taskbar
[j
];
394 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
395 // SINGLE_DESKTOP and not current desktop
396 taskbar
->area
.on_screen
= 0;
399 taskbar
->area
.on_screen
= 1;
406 void update_strut(Panel
* p
)
408 if (panel_strut_policy
== STRUT_NONE
) {
409 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
);
410 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
);
415 unsigned int d1
, screen_width
, screen_height
;
418 XGetGeometry(server
.dsp
, server
.root_win
, &d2
, &d3
, &d3
, &screen_width
, &screen_height
, &d1
, &d1
);
419 Monitor monitor
= server
.monitor
[p
->monitor
];
420 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
421 if (panel_horizontal
) {
422 int height
= p
->area
.height
+ p
->marginy
;
423 if (panel_autohide
&& (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
)) )
424 height
= p
->hidden_height
;
425 if (panel_position
& TOP
) {
426 struts
[2] = height
+ monitor
.y
;
428 // p->area.width - 1 allowed full screen on monitor 2
429 struts
[9] = p
->posx
+ p
->area
.width
- 1;
432 struts
[3] = height
+ screen_height
- monitor
.y
- monitor
.height
;
433 struts
[10] = p
->posx
;
434 // p->area.width - 1 allowed full screen on monitor 2
435 struts
[11] = p
->posx
+ p
->area
.width
- 1;
439 int width
= p
->area
.width
+ p
->marginx
;
440 if (panel_autohide
&& (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
)) )
441 width
= p
->hidden_width
;
442 if (panel_position
& LEFT
) {
443 struts
[0] = width
+ monitor
.x
;
445 // p->area.width - 1 allowed full screen on monitor 2
446 struts
[5] = p
->posy
+ p
->area
.height
- 1;
449 struts
[1] = width
+ screen_width
- monitor
.x
- monitor
.width
;
451 // p->area.width - 1 allowed full screen on monitor 2
452 struts
[7] = p
->posy
+ p
->area
.height
- 1;
455 // Old specification : fluxbox need _NET_WM_STRUT.
456 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
457 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
461 void set_panel_properties(Panel
*p
)
463 XStoreName (server
.dsp
, p
->main_win
, "tint2");
466 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
468 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
473 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
474 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
476 // Sticky and below other window
478 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
480 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
481 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
482 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
483 state
[3] = panel_layer
== BOTTOM_LAYER
? server
.atom
._NET_WM_STATE_BELOW
: server
.atom
._NET_WM_STATE_ABOVE
;
484 int nb_atoms
= panel_layer
== NORMAL_LAYER
? 3 : 4;
485 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, nb_atoms
);
490 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
491 wmhints
.flags
= StateHint
| IconWindowHint
;
492 wmhints
.initial_state
= WithdrawnState
;
495 wmhints
.flags
= InputHint
;
496 wmhints
.input
= False
;
498 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
501 long prop
[5] = { 2, 0, 0, 0, 0 };
502 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
504 // XdndAware - Register for Xdnd events
506 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
510 // Fixed position and non-resizable window
511 // Allow panel move and resize when tint2 reload config file
512 int minwidth
= panel_autohide
? p
->hidden_width
: p
->area
.width
;
513 int minheight
= panel_autohide
? p
->hidden_height
: p
->area
.height
;
514 XSizeHints size_hints
;
515 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
516 size_hints
.min_width
= minwidth
;
517 size_hints
.max_width
= p
->area
.width
;
518 size_hints
.min_height
= minheight
;
519 size_hints
.max_height
= p
->area
.height
;
520 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
523 XClassHint
* classhint
= XAllocClassHint();
524 classhint
->res_name
= "tint2";
525 classhint
->res_class
= "Tint2";
526 XSetClassHint(server
.dsp
, p
->main_win
, classhint
);
531 void set_panel_background(Panel
*p
)
533 if (p
->area
.pix
) XFreePixmap (server
.dsp
, p
->area
.pix
);
534 p
->area
.pix
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
537 if (panel_horizontal
&& panel_position
& BOTTOM
)
538 yoff
= p
->area
.height
-p
->hidden_height
;
539 else if (!panel_horizontal
&& panel_position
& RIGHT
)
540 xoff
= p
->area
.width
-p
->hidden_width
;
542 if (server
.real_transparency
) {
543 clear_pixmap(p
->area
.pix
, 0, 0, p
->area
.width
, p
->area
.height
);
547 // copy background (server.root_pmap) in panel.area.pix
550 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
551 if (panel_autohide
&& p
->is_hidden
) {
555 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
);
556 XFillRectangle(server
.dsp
, p
->area
.pix
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
559 // draw background panel
562 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
, server
.visual
, p
->area
.width
, p
->area
.height
);
563 c
= cairo_create (cs
);
564 draw_background(&p
->area
, c
);
566 cairo_surface_destroy (cs
);
568 if (panel_autohide
) {
569 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
570 p
->hidden_pixmap
= XCreatePixmap(server
.dsp
, server
.root_win
, p
->hidden_width
, p
->hidden_height
, server
.depth
);
571 XCopyArea(server
.dsp
, p
->area
.pix
, p
->hidden_pixmap
, server
.gc
, xoff
, yoff
, p
->hidden_width
, p
->hidden_height
, 0, 0);
574 // redraw panel's object
577 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
581 // reset task 'state_pix'
584 for (i
=0 ; i
< p
->nb_desktop
; i
++) {
585 tskbar
= &p
->taskbar
[i
];
586 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
587 set_task_redraw((Task
*)l0
->data
);
593 Panel
*get_panel(Window win
)
596 for (i
=0 ; i
< nb_panel
; i
++) {
597 if (panel1
[i
].main_win
== win
) {
605 Taskbar
*click_taskbar (Panel
*panel
, int x
, int y
)
610 if (panel_horizontal
) {
611 for (i
=0; i
< panel
->nb_desktop
; i
++) {
612 tskbar
= &panel
->taskbar
[i
];
613 if (tskbar
->area
.on_screen
&& x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
618 for (i
=0; i
< panel
->nb_desktop
; i
++) {
619 tskbar
= &panel
->taskbar
[i
];
620 if (tskbar
->area
.on_screen
&& y
>= tskbar
->area
.posy
&& y
<= (tskbar
->area
.posy
+ tskbar
->area
.height
))
628 Task
*click_task (Panel
*panel
, int x
, int y
)
633 if ( (tskbar
= click_taskbar(panel
, x
, y
)) ) {
634 if (panel_horizontal
) {
636 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
638 if (tsk
->area
.on_screen
&& x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
645 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
647 if (tsk
->area
.on_screen
&& y
>= tsk
->area
.posy
&& y
<= (tsk
->area
.posy
+ tsk
->area
.height
)) {
657 int click_padding(Panel
*panel
, int x
, int y
)
659 if (panel_horizontal
) {
660 if (x
< panel
->area
.paddingxlr
|| x
> panel
->area
.width
-panel
->area
.paddingxlr
)
664 if (y
< panel
->area
.paddingxlr
|| y
> panel
->area
.height
-panel
->area
.paddingxlr
)
671 int click_clock(Panel
*panel
, int x
, int y
)
673 Clock clk
= panel
->clock
;
674 if (panel_horizontal
) {
675 if (clk
.area
.on_screen
&& x
>= clk
.area
.posx
&& x
<= (clk
.area
.posx
+ clk
.area
.width
))
678 if (clk
.area
.on_screen
&& y
>= clk
.area
.posy
&& y
<= (clk
.area
.posy
+ clk
.area
.height
))
685 Area
* click_area(Panel
*panel
, int x
, int y
)
687 Area
* result
= &panel
->area
;
688 Area
* new_result
= result
;
691 GSList
* it
= result
->list
;
694 if (panel_horizontal
) {
695 if (a
->on_screen
&& x
>= a
->posx
&& x
<= (a
->posx
+ a
->width
)) {
700 if (a
->on_screen
&& y
>= a
->posy
&& y
<= (a
->posy
+ a
->height
)) {
707 } while (new_result
!= result
);
712 void stop_autohide_timeout(Panel
* p
)
714 if (p
->autohide_timeout
) {
715 stop_timeout(p
->autohide_timeout
);
716 p
->autohide_timeout
= 0;
721 void autohide_show(void* p
)
724 stop_autohide_timeout(panel
);
725 panel
->is_hidden
= 0;
726 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
729 XMapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
730 if (panel_horizontal
) {
731 if (panel_position
& TOP
)
732 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
734 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
737 if (panel_position
& LEFT
)
738 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
740 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
742 refresh_systray
= 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
747 void autohide_hide(void* p
)
750 stop_autohide_timeout(panel
);
751 panel
->is_hidden
= 1;
752 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
755 XUnmapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
756 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
757 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
758 if (panel_horizontal
) {
759 if (panel_position
& TOP
)
760 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
762 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
+diff
, panel
->hidden_width
, panel
->hidden_height
);
765 if (panel_position
& LEFT
)
766 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
768 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
+diff
, panel
->posy
, panel
->hidden_width
, panel
->hidden_height
);
774 void autohide_trigger_show(Panel
* p
)
778 if (p
->autohide_timeout
)
779 change_timeout(p
->autohide_timeout
, panel_autohide_show_timeout
, 0, autohide_show
, p
);
781 p
->autohide_timeout
= add_timeout(panel_autohide_show_timeout
, 0, autohide_show
, p
);
785 void autohide_trigger_hide(Panel
* p
)
793 if (XQueryPointer(server
.dsp
, p
->main_win
, &root
, &child
, &xr
, &yr
, &xw
, &yw
, &mask
))
794 if (child
) return; // mouse over one of the system tray icons
796 if (p
->autohide_timeout
)
797 change_timeout(p
->autohide_timeout
, panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
799 p
->autohide_timeout
= add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);