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
;
61 char *panel_items_order
;
65 // panel's initial config
67 // panels (one panel per monitor)
73 Imlib_Image default_icon
;
82 panel_position
= CENTER
;
83 panel_items_order
= 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
93 backgrounds
= g_array_new(0, 0, sizeof(Background
));
95 memset(&panel_config
, 0, sizeof(Panel
));
97 // append full transparency background
98 Background transparent_bg
;
99 memset(&transparent_bg
, 0, sizeof(Background
));
100 g_array_append_val(backgrounds
, transparent_bg
);
111 for (i
=0 ; i
< nb_panel
; i
++) {
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
);
120 if (panel_items_order
) g_free(panel_items_order
);
121 if (panel1
) free(panel1
);
123 g_array_free(backgrounds
, 1);
124 if (panel_config
.g_task
.font_desc
) pango_font_description_free(panel_config
.g_task
.font_desc
);
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;
142 #ifdef ENABLE_BATTERY
147 // number of panels (one monitor or 'all' monitors)
148 if (panel_config
.monitor
>= 0)
151 nb_panel
= server
.nb_monitor
;
153 panel1
= malloc(nb_panel
* sizeof(Panel
));
154 for (i
=0 ; i
< nb_panel
; i
++) {
155 memcpy(&panel1
[i
], &panel_config
, sizeof(Panel
));
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
++) {
162 if (panel_config
.monitor
< 0)
164 if ( p
->area
.bg
== 0 )
165 p
->area
.bg
= &g_array_index(backgrounds
, Background
, 0);
168 p
->area
.on_screen
= 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
180 XSetWindowAttributes att
= { .colormap
=server
.colormap
, .background_pixel
=0, .border_pixel
=0 };
181 unsigned long mask
= CWEventMask
|CWColormap
|CWBackPixel
|CWBorderPixel
;
182 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
);
184 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
;
185 if (g_tooltip
.enabled
)
186 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
188 event_mask
|= LeaveWindowMask
|EnterWindowMask
;
189 XChangeWindowAttributes(server
.dsp
, p
->main_win
, CWEventMask
, &(XSetWindowAttributes
){.event_mask
=event_mask
});
193 server
.gc
= XCreateGC(server
.dsp
, p
->main_win
, 0, &gcv
);
195 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
196 set_panel_properties(p
);
197 set_panel_background(p
);
198 if (snapshot_path
== 0) {
199 // if we are not in 'snapshot' mode then map new panel
200 XMapWindow (server
.dsp
, p
->main_win
);
204 add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
209 task_refresh_tasklist();
214 void init_panel_size_and_position(Panel
*panel
)
217 if (panel_horizontal
) {
218 if (panel
->pourcentx
)
219 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
220 if (panel
->pourcenty
)
221 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
222 if (panel
->area
.bg
->border
.rounded
> panel
->area
.height
/2) {
223 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
224 g_array_append_val(backgrounds
, *panel
->area
.bg
);
225 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
226 panel
->area
.bg
->border
.rounded
= panel
->area
.height
/2;
230 int old_panel_height
= panel
->area
.height
;
231 if (panel
->pourcentx
)
232 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
234 panel
->area
.height
= panel
->area
.width
;
235 if (panel
->pourcenty
)
236 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
238 panel
->area
.width
= old_panel_height
;
239 if (panel
->area
.bg
->border
.rounded
> panel
->area
.width
/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
.width
/2;
247 // panel position determined here
248 if (panel_position
& LEFT
) {
249 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
252 if (panel_position
& RIGHT
) {
253 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
256 if (panel_horizontal
)
257 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
259 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
262 if (panel_position
& TOP
) {
263 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
266 if (panel_position
& BOTTOM
) {
267 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
270 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
274 // autohide or strut_policy=minimum
275 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
276 if (panel_horizontal
) {
277 panel
->hidden_width
= panel
->area
.width
;
278 panel
->hidden_height
= panel
->area
.height
- diff
;
281 panel
->hidden_width
= panel
->area
.width
- diff
;
282 panel
->hidden_height
= panel
->area
.height
;
284 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
288 int resize_panel(void *obj
)
290 Panel
*panel
= (Panel
*)obj
;
291 int size
, nb_by_content
=0, nb_by_layout
=0;
292 Area
*a
= (Area
*)obj
;
293 int paddingx
= a
->paddingx
;;
295 if (panel_horizontal
) {
296 // detect free size for SIZE_BY_LAYOUT's Area
297 size
= a
->width
- (2 * a
->paddingxlr
) - (2 * a
->bg
->border
.width
);
299 for (l
= ((Area
*)obj
)->list
; l
; l
= l
->next
) {
301 if (a
->on_screen
&& a
->width
&& a
->size_mode
== SIZE_BY_CONTENT
) {
305 if (a
->on_screen
&& a
->size_mode
== SIZE_BY_LAYOUT
)
308 if (nb_by_content
+nb_by_layout
)
309 size
-= ((nb_by_content
+nb_by_layout
-1) * paddingx
);
310 //printf("resize_panel : size_panel %d, size_layout %d\n", panel->area.width, size);
312 int width
=0, modulo
=0;
314 width
= size
/ nb_by_layout
;
315 modulo
= size
% nb_by_layout
;
317 //printf(" content %d, layout %d, width %d, modulo %d\n", nb_by_content, nb_by_layout, width, modulo);
319 // change posx and width for all taskbar
321 posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
322 if (panel
->launcher
.area
.on_screen
&& panel
->launcher
.area
.width
)
323 posx
+= (panel
->launcher
.area
.width
+ panel
->area
.paddingx
);
324 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
325 panel
->taskbar
[i
].area
.posx
= posx
;
326 panel
->taskbar
[i
].area
.width
= width
;
327 panel
->taskbar
[i
].area
.resize
= 1;
329 panel
->taskbar
[i
].area
.width
++;
332 //printf(" width %d\n", 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 // detect free size for SIZE_BY_LAYOUT's Area
340 size
= a
->height
- (2 * a
->paddingxlr
) - (2 * a
->bg
->border
.width
);
342 for (l
= ((Area
*)obj
)->list
; l
; l
= l
->next
) {
344 if (a
->on_screen
&& a
->height
&& a
->size_mode
== SIZE_BY_CONTENT
) {
348 if (a
->on_screen
&& a
->size_mode
== SIZE_BY_LAYOUT
)
351 if (nb_by_content
+nb_by_layout
)
352 size
-= ((nb_by_content
+nb_by_layout
-1) * paddingx
);
354 int width
=0, modulo
=0;
356 width
= size
/ nb_by_layout
;
357 modulo
= size
% nb_by_layout
;
360 // change posy and height for all taskbar
362 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
363 panel
->taskbar
[i
].area
.posy
= posy
;
364 panel
->taskbar
[i
].area
.height
= width
;
365 panel
->taskbar
[i
].area
.resize
= 1;
367 panel
->taskbar
[i
].area
.height
++;
370 if (panel_mode
== MULTI_DESKTOP
)
371 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
378 void visible_object()
383 for (i
=0 ; i
< nb_panel
; i
++) {
387 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
388 taskbar
= &panel
->taskbar
[j
];
389 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
390 // SINGLE_DESKTOP and not current desktop
391 taskbar
->area
.on_screen
= 0;
394 taskbar
->area
.on_screen
= 1;
401 void update_strut(Panel
* p
)
403 if (panel_strut_policy
== STRUT_NONE
) {
404 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
);
405 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
);
410 unsigned int d1
, screen_width
, screen_height
;
413 XGetGeometry(server
.dsp
, server
.root_win
, &d2
, &d3
, &d3
, &screen_width
, &screen_height
, &d1
, &d1
);
414 Monitor monitor
= server
.monitor
[p
->monitor
];
415 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
416 if (panel_horizontal
) {
417 int height
= p
->area
.height
+ p
->marginy
;
418 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
419 height
= p
->hidden_height
;
420 if (panel_position
& TOP
) {
421 struts
[2] = height
+ monitor
.y
;
423 // p->area.width - 1 allowed full screen on monitor 2
424 struts
[9] = p
->posx
+ p
->area
.width
- 1;
427 struts
[3] = height
+ screen_height
- monitor
.y
- monitor
.height
;
428 struts
[10] = p
->posx
;
429 // p->area.width - 1 allowed full screen on monitor 2
430 struts
[11] = p
->posx
+ p
->area
.width
- 1;
434 int width
= p
->area
.width
+ p
->marginx
;
435 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
436 width
= p
->hidden_width
;
437 if (panel_position
& LEFT
) {
438 struts
[0] = width
+ monitor
.x
;
440 // p->area.width - 1 allowed full screen on monitor 2
441 struts
[5] = p
->posy
+ p
->area
.height
- 1;
444 struts
[1] = width
+ screen_width
- monitor
.x
- monitor
.width
;
446 // p->area.width - 1 allowed full screen on monitor 2
447 struts
[7] = p
->posy
+ p
->area
.height
- 1;
450 // Old specification : fluxbox need _NET_WM_STRUT.
451 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
452 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
456 void set_panel_items(Panel
*p
)
461 g_slist_free(p
->area
.list
);
464 printf("panel_items_order %s\n", panel_items_order
);
465 for (k
=0 ; k
< strlen(panel_items_order
) ; k
++) {
466 if (panel_items_order
[k
] == 'L') {
467 init_launcher_panel(p
);
468 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->launcher
);
470 if (panel_items_order
[k
] == 'T') {
471 init_taskbar_panel(p
);
472 for (j
=0 ; j
< p
->nb_desktop
; j
++)
473 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->taskbar
[j
]);
475 #ifdef ENABLE_BATTERY
476 if (panel_items_order
[k
] == 'B') {
477 init_battery_panel(p
);
478 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
481 if (panel_items_order
[k
] == 'S') {
482 // TODO : check systray is only on 1 panel
483 init_systray_panel(p
);
485 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
487 if (panel_items_order
[k
] == 'C') {
489 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
495 void set_panel_properties(Panel
*p
)
497 XStoreName (server
.dsp
, p
->main_win
, "tint2");
500 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
502 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
507 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
508 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
510 // Sticky and below other window
512 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
514 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
515 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
516 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
517 state
[3] = panel_layer
== BOTTOM_LAYER
? server
.atom
._NET_WM_STATE_BELOW
: server
.atom
._NET_WM_STATE_ABOVE
;
518 int nb_atoms
= panel_layer
== NORMAL_LAYER
? 3 : 4;
519 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, nb_atoms
);
524 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
525 wmhints
.flags
= StateHint
| IconWindowHint
;
526 wmhints
.initial_state
= WithdrawnState
;
529 wmhints
.flags
= InputHint
;
530 wmhints
.input
= False
;
532 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
535 long prop
[5] = { 2, 0, 0, 0, 0 };
536 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
538 // XdndAware - Register for Xdnd events
540 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
544 // Fixed position and non-resizable window
545 // Allow panel move and resize when tint2 reload config file
546 int minwidth
= panel_autohide
? p
->hidden_width
: p
->area
.width
;
547 int minheight
= panel_autohide
? p
->hidden_height
: p
->area
.height
;
548 XSizeHints size_hints
;
549 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
550 size_hints
.min_width
= minwidth
;
551 size_hints
.max_width
= p
->area
.width
;
552 size_hints
.min_height
= minheight
;
553 size_hints
.max_height
= p
->area
.height
;
554 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
557 XClassHint
* classhint
= XAllocClassHint();
558 classhint
->res_name
= "tint2";
559 classhint
->res_class
= "Tint2";
560 XSetClassHint(server
.dsp
, p
->main_win
, classhint
);
565 void set_panel_background(Panel
*p
)
567 if (p
->area
.pix
) XFreePixmap (server
.dsp
, p
->area
.pix
);
568 p
->area
.pix
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
571 if (panel_horizontal
&& panel_position
& BOTTOM
)
572 yoff
= p
->area
.height
-p
->hidden_height
;
573 else if (!panel_horizontal
&& panel_position
& RIGHT
)
574 xoff
= p
->area
.width
-p
->hidden_width
;
576 if (server
.real_transparency
) {
577 clear_pixmap(p
->area
.pix
, 0, 0, p
->area
.width
, p
->area
.height
);
581 // copy background (server.root_pmap) in panel.area.pix
584 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
585 if (panel_autohide
&& p
->is_hidden
) {
589 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
);
590 XFillRectangle(server
.dsp
, p
->area
.pix
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
593 // draw background panel
596 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
, server
.visual
, p
->area
.width
, p
->area
.height
);
597 c
= cairo_create (cs
);
598 draw_background(&p
->area
, c
);
600 cairo_surface_destroy (cs
);
602 if (panel_autohide
) {
603 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
604 p
->hidden_pixmap
= XCreatePixmap(server
.dsp
, server
.root_win
, p
->hidden_width
, p
->hidden_height
, server
.depth
);
605 XCopyArea(server
.dsp
, p
->area
.pix
, p
->hidden_pixmap
, server
.gc
, xoff
, yoff
, p
->hidden_width
, p
->hidden_height
, 0, 0);
608 // redraw panel's object
609 //p->area.redraw = 1;
612 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
617 // reset task 'state_pix'
620 for (i
=0 ; i
< p
->nb_desktop
; i
++) {
621 tskbar
= &p
->taskbar
[i
];
622 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
623 set_task_redraw((Task
*)l0
->data
);
629 Panel
*get_panel(Window win
)
632 for (i
=0 ; i
< nb_panel
; i
++) {
633 if (panel1
[i
].main_win
== win
) {
641 Taskbar
*click_taskbar (Panel
*panel
, int x
, int y
)
646 if (panel_horizontal
) {
647 for (i
=0; i
< panel
->nb_desktop
; i
++) {
648 tskbar
= &panel
->taskbar
[i
];
649 if (tskbar
->area
.on_screen
&& x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
654 for (i
=0; i
< panel
->nb_desktop
; i
++) {
655 tskbar
= &panel
->taskbar
[i
];
656 if (tskbar
->area
.on_screen
&& y
>= tskbar
->area
.posy
&& y
<= (tskbar
->area
.posy
+ tskbar
->area
.height
))
664 Task
*click_task (Panel
*panel
, int x
, int y
)
669 if ( (tskbar
= click_taskbar(panel
, x
, y
)) ) {
670 if (panel_horizontal
) {
672 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
674 if (tsk
->area
.on_screen
&& x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
681 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
683 if (tsk
->area
.on_screen
&& y
>= tsk
->area
.posy
&& y
<= (tsk
->area
.posy
+ tsk
->area
.height
)) {
693 Launcher
*click_launcher (Panel
*panel
, int x
, int y
)
695 Launcher
*launcher
= &panel
->launcher
;
697 if (panel_horizontal
) {
698 if (launcher
->area
.on_screen
&& x
>= launcher
->area
.posx
&& x
<= (launcher
->area
.posx
+ launcher
->area
.width
))
702 if (launcher
->area
.on_screen
&& y
>= launcher
->area
.posy
&& y
<= (launcher
->area
.posy
+ launcher
->area
.height
))
709 LauncherIcon
*click_launcher_icon (Panel
*panel
, int x
, int y
)
714 //printf("Click x=%d y=%d\n", x, y);
715 if ( (launcher
= click_launcher(panel
, x
, y
)) ) {
717 for (l0
= launcher
->list_icons
; l0
; l0
= l0
->next
) {
719 if (x
>= (launcher
->area
.posx
+ icon
->x
) && x
<= (launcher
->area
.posx
+ icon
->x
+ icon
->icon_size
) &&
720 y
>= (launcher
->area
.posy
+ icon
->y
) && y
<= (launcher
->area
.posy
+ icon
->y
+ icon
->icon_size
)) {
721 //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 int click_padding(Panel
*panel
, int x
, int y
)
732 if (panel_horizontal
) {
733 if (x
< panel
->area
.paddingxlr
|| x
> panel
->area
.width
-panel
->area
.paddingxlr
)
737 if (y
< panel
->area
.paddingxlr
|| y
> panel
->area
.height
-panel
->area
.paddingxlr
)
744 int click_clock(Panel
*panel
, int x
, int y
)
746 Clock clk
= panel
->clock
;
747 if (panel_horizontal
) {
748 if (clk
.area
.on_screen
&& x
>= clk
.area
.posx
&& x
<= (clk
.area
.posx
+ clk
.area
.width
))
751 if (clk
.area
.on_screen
&& y
>= clk
.area
.posy
&& y
<= (clk
.area
.posy
+ clk
.area
.height
))
758 Area
* click_area(Panel
*panel
, int x
, int y
)
760 Area
* result
= &panel
->area
;
761 Area
* new_result
= result
;
764 GSList
* it
= result
->list
;
767 if (panel_horizontal
) {
768 if (a
->on_screen
&& x
>= a
->posx
&& x
<= (a
->posx
+ a
->width
)) {
773 if (a
->on_screen
&& y
>= a
->posy
&& y
<= (a
->posy
+ a
->height
)) {
780 } while (new_result
!= result
);
785 void stop_autohide_timeout(Panel
* p
)
787 if (p
->autohide_timeout
) {
788 stop_timeout(p
->autohide_timeout
);
789 p
->autohide_timeout
= 0;
794 void autohide_show(void* p
)
797 stop_autohide_timeout(panel
);
798 panel
->is_hidden
= 0;
799 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
802 XMapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
803 if (panel_horizontal
) {
804 if (panel_position
& TOP
)
805 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
807 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
810 if (panel_position
& LEFT
)
811 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
813 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
815 refresh_systray
= 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
820 void autohide_hide(void* p
)
823 stop_autohide_timeout(panel
);
824 panel
->is_hidden
= 1;
825 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
828 XUnmapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
829 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
830 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
831 if (panel_horizontal
) {
832 if (panel_position
& TOP
)
833 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
835 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
+diff
, panel
->hidden_width
, panel
->hidden_height
);
838 if (panel_position
& LEFT
)
839 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
841 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
+diff
, panel
->posy
, panel
->hidden_width
, panel
->hidden_height
);
847 void autohide_trigger_show(Panel
* p
)
851 if (p
->autohide_timeout
)
852 change_timeout(p
->autohide_timeout
, panel_autohide_show_timeout
, 0, autohide_show
, p
);
854 p
->autohide_timeout
= add_timeout(panel_autohide_show_timeout
, 0, autohide_show
, p
);
858 void autohide_trigger_hide(Panel
* p
)
866 if (XQueryPointer(server
.dsp
, p
->main_win
, &root
, &child
, &xr
, &yr
, &xw
, &yw
, &mask
))
867 if (child
) return; // mouse over one of the system tray icons
869 if (p
->autohide_timeout
)
870 change_timeout(p
->autohide_timeout
, panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
872 p
->autohide_timeout
= add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);