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_autohide_show_timeout
= 0;
91 panel_autohide_hide_timeout
= 0;
92 panel_autohide_height
; // for vertical panels this is of course the width
93 panel_strut_policy
= STRUT_MINIMUM
;
94 panel_dock
= 0; // default not in the dock
95 panel_layer
= BOTTOM_LAYER
; // default is bottom layer
98 memset(&panel_config
, 0, sizeof(Panel
));
99 backgrounds
= g_array_new(0, 0, sizeof(Background
));
101 // append full transparency background
102 Background transparent_bg
;
103 memset(&transparent_bg
, 0, sizeof(Background
));
104 g_array_append_val(backgrounds
, transparent_bg
);
111 printf("*** cleanup_panel()\n");
116 for (i
=0 ; i
< nb_panel
; i
++) {
120 if (p
->temp_pmap
) XFreePixmap(server
.dsp
, p
->temp_pmap
);
121 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
122 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
125 if (panel1
) free(panel1
);
126 if (backgrounds
) g_array_free(backgrounds
, 1);
127 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
133 Panel
*new_panel
, *p
;
135 if (panel_config
.monitor
> (server
.nb_monitor
-1)) {
136 // server.nb_monitor minimum value is 1 (see get_monitors())
137 fprintf(stderr
, "warning : monitor not found. tint2 default to all monitors.\n");
138 panel_config
.monitor
= 0;
144 #ifdef ENABLE_BATTERY
149 for (i
=0 ; i
< nb_panel
; i
++) {
150 autohide_show(&panel1
[i
]);
151 free_area(&panel1
[i
].area
);
152 if (panel1
[i
].temp_pmap
) {
153 XFreePixmap(server
.dsp
, panel1
[i
].temp_pmap
);
154 panel1
[i
].temp_pmap
= 0;
159 old_nb_panel
= nb_panel
;
160 if (panel_config
.monitor
>= 0)
163 nb_panel
= server
.nb_monitor
;
166 for (i
=nb_panel
; i
< old_nb_panel
; i
++) {
167 if (panel1
[i
].main_win
) {
168 XDestroyWindow(server
.dsp
, panel1
[i
].main_win
);
169 panel1
[i
].main_win
= 0;
173 // alloc & init new panel
175 if (nb_panel
!= old_nb_panel
)
176 new_panel
= realloc(panel1
, nb_panel
* sizeof(Panel
));
179 for (i
=0 ; i
< nb_panel
; i
++) {
180 old_win
= new_panel
[i
].main_win
;
181 memcpy(&new_panel
[i
], &panel_config
, sizeof(Panel
));
182 new_panel
[i
].main_win
= old_win
;
185 fprintf(stderr
, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server
.nb_monitor
, nb_panel
, server
.nb_desktop
);
186 for (i
=0 ; i
< nb_panel
; i
++) {
189 if (panel_config
.monitor
< 0)
193 p
->area
.on_screen
= 1;
195 p
->area
._resize
= resize_panel
;
196 p
->g_taskbar
.area
.parent
= p
;
197 p
->g_taskbar
.area
.panel
= p
;
198 p
->g_task
.area
.panel
= p
;
199 init_panel_size_and_position(p
);
203 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
205 #ifdef ENABLE_BATTERY
206 if (battery_enabled
) {
207 init_battery_panel(p
);
208 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
211 // systray only on first panel
212 if (systray
.area
.on_screen
&& i
== 0) {
213 init_systray_panel(p
);
214 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
218 if (i
>= old_nb_panel
) {
219 // new panel : catch some events
220 XSetWindowAttributes att
= { .colormap
=server
.colormap
, .background_pixel
=0, .border_pixel
=0 };
221 unsigned long mask
= CWEventMask
|CWColormap
|CWBackPixel
|CWBorderPixel
;
222 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
);
226 XMoveResizeWindow(server
.dsp
, p
->main_win
, p
->posx
, p
->posy
, p
->area
.width
, p
->area
.height
);
229 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
;
230 if (g_tooltip
.enabled
)
231 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
233 event_mask
|= LeaveWindowMask
|EnterWindowMask
;
234 XChangeWindowAttributes(server
.dsp
, p
->main_win
, CWEventMask
, &(XSetWindowAttributes
){.event_mask
=event_mask
});
238 server
.gc
= XCreateGC(server
.dsp
, p
->main_win
, 0, &gcv
);
240 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
241 set_panel_properties(p
);
242 set_panel_background(p
);
243 if (i
>= old_nb_panel
&& snapshot_path
== 0) {
244 // if we are not in 'snapshot' mode then map new panel
245 XMapWindow (server
.dsp
, p
->main_win
);
249 add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
256 task_refresh_tasklist();
261 void init_panel_size_and_position(Panel
*panel
)
264 if (panel_horizontal
) {
265 if (panel
->pourcentx
)
266 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
267 if (panel
->pourcenty
)
268 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
269 if (panel
->area
.bg
->border
.rounded
> panel
->area
.height
/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
.height
/2;
277 int old_panel_height
= panel
->area
.height
;
278 if (panel
->pourcentx
)
279 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
281 panel
->area
.height
= panel
->area
.width
;
282 if (panel
->pourcenty
)
283 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
285 panel
->area
.width
= old_panel_height
;
286 if (panel
->area
.bg
->border
.rounded
> panel
->area
.width
/2) {
287 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
288 g_array_append_val(backgrounds
, *panel
->area
.bg
);
289 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
290 panel
->area
.bg
->border
.rounded
= panel
->area
.width
/2;
294 // panel position determined here
295 if (panel_position
& LEFT
) {
296 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
299 if (panel_position
& RIGHT
) {
300 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
303 if (panel_horizontal
)
304 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
306 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
309 if (panel_position
& TOP
) {
310 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
313 if (panel_position
& BOTTOM
) {
314 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
317 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
321 if (panel_autohide
) {
322 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
323 if (panel_horizontal
) {
324 panel
->hidden_width
= panel
->area
.width
;
325 panel
->hidden_height
= panel
->area
.height
- diff
;
328 panel
->hidden_width
= panel
->area
.width
- diff
;
329 panel
->hidden_height
= panel
->area
.height
;
332 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
336 void resize_panel(void *obj
)
338 Panel
*panel
= (Panel
*)obj
;
340 if (panel_horizontal
) {
341 int taskbar_width
, modulo_width
= 0;
343 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
344 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
345 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
346 #ifdef ENABLE_BATTERY
347 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
348 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
350 // TODO : systray only on first panel. search better implementation !
351 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
352 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
354 if (panel_mode
== MULTI_DESKTOP
) {
355 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
356 taskbar_width
= width
/ panel
->nb_desktop
;
357 modulo_width
= width
% panel
->nb_desktop
;
360 // change posx and width for all taskbar
362 posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
363 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
364 panel
->taskbar
[i
].area
.posx
= posx
;
365 panel
->taskbar
[i
].area
.width
= taskbar_width
;
366 panel
->taskbar
[i
].area
.resize
= 1;
368 panel
->taskbar
[i
].area
.width
++;
371 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
372 if (panel_mode
== MULTI_DESKTOP
)
373 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
377 int taskbar_height
, modulo_height
= 0;
380 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.bg
->border
.width
);
381 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
382 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
383 #ifdef ENABLE_BATTERY
384 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
385 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
387 // TODO : systray only on first panel. search better implementation !
388 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
389 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
391 posy
= panel
->area
.height
- panel
->area
.bg
->border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
392 if (panel_mode
== MULTI_DESKTOP
) {
393 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
394 taskbar_height
= height
/ panel
->nb_desktop
;
395 modulo_height
= height
% panel
->nb_desktop
;
398 // change posy and height for all taskbar
399 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
400 panel
->taskbar
[i
].area
.posy
= posy
;
401 panel
->taskbar
[i
].area
.height
= taskbar_height
;
402 panel
->taskbar
[i
].area
.resize
= 1;
404 panel
->taskbar
[i
].area
.height
++;
407 if (panel_mode
== MULTI_DESKTOP
)
408 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
414 void visible_object()
419 for (i
=0 ; i
< nb_panel
; i
++) {
423 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
424 taskbar
= &panel
->taskbar
[j
];
425 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
426 // SINGLE_DESKTOP and not current desktop
427 taskbar
->area
.on_screen
= 0;
430 taskbar
->area
.on_screen
= 1;
437 void update_strut(Panel
* p
)
439 if (panel_strut_policy
== STRUT_NONE
) {
440 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
);
441 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
);
446 unsigned int d1
, screen_width
, screen_height
;
449 XGetGeometry(server
.dsp
, server
.root_win
, &d2
, &d3
, &d3
, &screen_width
, &screen_height
, &d1
, &d1
);
450 Monitor monitor
= server
.monitor
[p
->monitor
];
451 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
452 if (panel_horizontal
) {
453 int height
= p
->area
.height
+ p
->marginy
;
454 if (panel_autohide
&& (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
)) )
455 height
= p
->hidden_height
;
456 if (panel_position
& TOP
) {
457 struts
[2] = height
+ monitor
.y
;
459 // p->area.width - 1 allowed full screen on monitor 2
460 struts
[9] = p
->posx
+ p
->area
.width
- 1;
463 struts
[3] = height
+ screen_height
- monitor
.y
- monitor
.height
;
464 struts
[10] = p
->posx
;
465 // p->area.width - 1 allowed full screen on monitor 2
466 struts
[11] = p
->posx
+ p
->area
.width
- 1;
470 int width
= p
->area
.width
+ p
->marginx
;
471 if (panel_autohide
&& (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
)) )
472 width
= p
->hidden_width
;
473 if (panel_position
& LEFT
) {
474 struts
[0] = width
+ monitor
.x
;
476 // p->area.width - 1 allowed full screen on monitor 2
477 struts
[5] = p
->posy
+ p
->area
.height
- 1;
480 struts
[1] = width
+ screen_width
- monitor
.x
- monitor
.width
;
482 // p->area.width - 1 allowed full screen on monitor 2
483 struts
[7] = p
->posy
+ p
->area
.height
- 1;
486 // Old specification : fluxbox need _NET_WM_STRUT.
487 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
488 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
492 void set_panel_properties(Panel
*p
)
494 XStoreName (server
.dsp
, p
->main_win
, "tint2");
497 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
499 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
504 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
505 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
507 // Sticky and below other window
509 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
511 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
512 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
513 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
514 state
[3] = panel_layer
== BOTTOM_LAYER
? server
.atom
._NET_WM_STATE_BELOW
: server
.atom
._NET_WM_STATE_ABOVE
;
515 int nb_atoms
= panel_layer
== NORMAL_LAYER
? 3 : 4;
516 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, nb_atoms
);
521 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
522 wmhints
.flags
= StateHint
| IconWindowHint
;
523 wmhints
.initial_state
= WithdrawnState
;
526 wmhints
.flags
= InputHint
;
527 wmhints
.input
= False
;
529 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
532 long prop
[5] = { 2, 0, 0, 0, 0 };
533 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
535 // XdndAware - Register for Xdnd events
537 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
541 // Fixed position and non-resizable window
542 // Allow panel move and resize when tint2 reload config file
543 int minwidth
= panel_autohide
? p
->hidden_width
: p
->area
.width
;
544 int minheight
= panel_autohide
? p
->hidden_height
: p
->area
.height
;
545 XSizeHints size_hints
;
546 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
547 size_hints
.min_width
= minwidth
;
548 size_hints
.max_width
= p
->area
.width
;
549 size_hints
.min_height
= minheight
;
550 size_hints
.max_height
= p
->area
.height
;
551 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
554 XClassHint
* classhint
= XAllocClassHint();
555 classhint
->res_name
= "tint2";
556 classhint
->res_class
= "Tint2";
557 XSetClassHint(server
.dsp
, p
->main_win
, classhint
);
562 void set_panel_background(Panel
*p
)
564 if (p
->area
.pix
) XFreePixmap (server
.dsp
, p
->area
.pix
);
565 p
->area
.pix
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
568 if (panel_horizontal
&& panel_position
& BOTTOM
)
569 yoff
= p
->area
.height
-p
->hidden_height
;
570 else if (!panel_horizontal
&& panel_position
& RIGHT
)
571 xoff
= p
->area
.width
-p
->hidden_width
;
573 if (server
.real_transparency
) {
574 clear_pixmap(p
->area
.pix
, 0, 0, p
->area
.width
, p
->area
.height
);
578 // copy background (server.root_pmap) in panel.area.pix
581 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
582 if (panel_autohide
&& p
->is_hidden
) {
586 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
);
587 XFillRectangle(server
.dsp
, p
->area
.pix
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
590 // draw background panel
593 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
, server
.visual
, p
->area
.width
, p
->area
.height
);
594 c
= cairo_create (cs
);
595 draw_background(&p
->area
, c
);
597 cairo_surface_destroy (cs
);
599 if (panel_autohide
) {
600 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
601 p
->hidden_pixmap
= XCreatePixmap(server
.dsp
, server
.root_win
, p
->hidden_width
, p
->hidden_height
, server
.depth
);
602 XCopyArea(server
.dsp
, p
->area
.pix
, p
->hidden_pixmap
, server
.gc
, xoff
, yoff
, p
->hidden_width
, p
->hidden_height
, 0, 0);
605 // redraw panel's object
608 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
612 // reset task 'state_pix'
615 for (i
=0 ; i
< p
->nb_desktop
; i
++) {
616 tskbar
= &p
->taskbar
[i
];
617 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
618 set_task_redraw((Task
*)l0
->data
);
624 Panel
*get_panel(Window win
)
627 for (i
=0 ; i
< nb_panel
; i
++) {
628 if (panel1
[i
].main_win
== win
) {
636 Taskbar
*click_taskbar (Panel
*panel
, int x
, int y
)
641 if (panel_horizontal
) {
642 for (i
=0; i
< panel
->nb_desktop
; i
++) {
643 tskbar
= &panel
->taskbar
[i
];
644 if (tskbar
->area
.on_screen
&& x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
649 for (i
=0; i
< panel
->nb_desktop
; i
++) {
650 tskbar
= &panel
->taskbar
[i
];
651 if (tskbar
->area
.on_screen
&& y
>= tskbar
->area
.posy
&& y
<= (tskbar
->area
.posy
+ tskbar
->area
.height
))
659 Task
*click_task (Panel
*panel
, int x
, int y
)
664 if ( (tskbar
= click_taskbar(panel
, x
, y
)) ) {
665 if (panel_horizontal
) {
667 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
669 if (tsk
->area
.on_screen
&& x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
676 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
678 if (tsk
->area
.on_screen
&& y
>= tsk
->area
.posy
&& y
<= (tsk
->area
.posy
+ tsk
->area
.height
)) {
688 int click_padding(Panel
*panel
, int x
, int y
)
690 if (panel_horizontal
) {
691 if (x
< panel
->area
.paddingxlr
|| x
> panel
->area
.width
-panel
->area
.paddingxlr
)
695 if (y
< panel
->area
.paddingxlr
|| y
> panel
->area
.height
-panel
->area
.paddingxlr
)
702 int click_clock(Panel
*panel
, int x
, int y
)
704 Clock clk
= panel
->clock
;
705 if (panel_horizontal
) {
706 if (clk
.area
.on_screen
&& x
>= clk
.area
.posx
&& x
<= (clk
.area
.posx
+ clk
.area
.width
))
709 if (clk
.area
.on_screen
&& y
>= clk
.area
.posy
&& y
<= (clk
.area
.posy
+ clk
.area
.height
))
716 Area
* click_area(Panel
*panel
, int x
, int y
)
718 Area
* result
= &panel
->area
;
719 Area
* new_result
= result
;
722 GSList
* it
= result
->list
;
725 if (panel_horizontal
) {
726 if (a
->on_screen
&& x
>= a
->posx
&& x
<= (a
->posx
+ a
->width
)) {
731 if (a
->on_screen
&& y
>= a
->posy
&& y
<= (a
->posy
+ a
->height
)) {
738 } while (new_result
!= result
);
743 void stop_autohide_timeout(Panel
* p
)
745 if (p
->autohide_timeout
) {
746 stop_timeout(p
->autohide_timeout
);
747 p
->autohide_timeout
= 0;
752 void autohide_show(void* p
)
755 stop_autohide_timeout(panel
);
756 panel
->is_hidden
= 0;
757 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
760 XMapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
761 if (panel_horizontal
) {
762 if (panel_position
& TOP
)
763 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
765 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
768 if (panel_position
& LEFT
)
769 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
771 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
773 refresh_systray
= 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
778 void autohide_hide(void* p
)
781 stop_autohide_timeout(panel
);
782 panel
->is_hidden
= 1;
783 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
786 XUnmapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
787 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
788 if (panel_horizontal
) {
789 if (panel_position
& TOP
)
790 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
792 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
+diff
, panel
->hidden_width
, panel
->hidden_height
);
795 if (panel_position
& LEFT
)
796 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
798 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
+diff
, panel
->posy
, panel
->hidden_width
, panel
->hidden_height
);
804 void autohide_trigger_show(Panel
* p
)
808 if (p
->autohide_timeout
)
809 change_timeout(p
->autohide_timeout
, panel_autohide_show_timeout
, 0, autohide_show
, p
);
811 p
->autohide_timeout
= add_timeout(panel_autohide_show_timeout
, 0, autohide_show
, p
);
815 void autohide_trigger_hide(Panel
* p
)
823 if (XQueryPointer(server
.dsp
, p
->main_win
, &root
, &child
, &xr
, &yr
, &xw
, &yw
, &mask
))
824 if (child
) return; // mouse over one of the system tray icons
826 if (p
->autohide_timeout
)
827 change_timeout(p
->autohide_timeout
, panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
829 p
->autohide_timeout
= add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);