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;
139 #ifdef ENABLE_BATTERY
143 // number of panels (one monitor or 'all' monitors)
144 if (panel_config
.monitor
>= 0)
147 nb_panel
= server
.nb_monitor
;
149 panel1
= malloc(nb_panel
* sizeof(Panel
));
150 for (i
=0 ; i
< nb_panel
; i
++) {
151 memcpy(&panel1
[i
], &panel_config
, sizeof(Panel
));
154 fprintf(stderr
, "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", server
.nb_monitor
, nb_panel
, server
.nb_desktop
);
155 for (i
=0 ; i
< nb_panel
; i
++) {
158 if (panel_config
.monitor
< 0)
160 if ( p
->area
.bg
== 0 )
161 p
->area
.bg
= &g_array_index(backgrounds
, Background
, 0);
164 p
->area
.on_screen
= 1;
166 p
->area
.size_mode
= SIZE_BY_LAYOUT
;
167 p
->area
._resize
= resize_panel
;
168 p
->g_taskbar
.area
.parent
= p
;
169 p
->g_taskbar
.area
.panel
= p
;
170 p
->g_task
.area
.panel
= p
;
171 init_panel_size_and_position(p
);
173 // TODO : should respect the order of 'panel_items' config parameter
174 if (launcher_enabled
) {
175 init_launcher_panel(p
);
176 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->launcher
);
178 p
->nb_desktop
= server
.nb_desktop
;
179 p
->taskbar
= calloc(p
->nb_desktop
, sizeof(Taskbar
));
180 for (j
=0 ; j
< p
->nb_desktop
; j
++) {
181 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->taskbar
[j
]);
183 #ifdef ENABLE_BATTERY
184 if (battery_enabled
) {
185 init_battery_panel(p
);
186 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
189 // systray only on first panel
190 if (systray
.area
.on_screen
&& i
== 0) {
191 init_systray_panel(p
);
192 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
197 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
201 XSetWindowAttributes att
= { .colormap
=server
.colormap
, .background_pixel
=0, .border_pixel
=0 };
202 unsigned long mask
= CWEventMask
|CWColormap
|CWBackPixel
|CWBorderPixel
;
203 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
);
205 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
|ButtonMotionMask
;
206 if (g_tooltip
.enabled
)
207 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
209 event_mask
|= LeaveWindowMask
|EnterWindowMask
;
210 XChangeWindowAttributes(server
.dsp
, p
->main_win
, CWEventMask
, &(XSetWindowAttributes
){.event_mask
=event_mask
});
214 server
.gc
= XCreateGC(server
.dsp
, p
->main_win
, 0, &gcv
);
216 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
217 set_panel_properties(p
);
218 set_panel_background(p
);
219 if (snapshot_path
== 0) {
220 // if we are not in 'snapshot' mode then map new panel
221 XMapWindow (server
.dsp
, p
->main_win
);
225 add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
231 task_refresh_tasklist();
236 void init_panel_size_and_position(Panel
*panel
)
239 if (panel_horizontal
) {
240 if (panel
->pourcentx
)
241 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
242 if (panel
->pourcenty
)
243 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
244 if (panel
->area
.bg
->border
.rounded
> panel
->area
.height
/2) {
245 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
246 g_array_append_val(backgrounds
, *panel
->area
.bg
);
247 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
248 panel
->area
.bg
->border
.rounded
= panel
->area
.height
/2;
252 int old_panel_height
= panel
->area
.height
;
253 if (panel
->pourcentx
)
254 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
256 panel
->area
.height
= panel
->area
.width
;
257 if (panel
->pourcenty
)
258 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
260 panel
->area
.width
= old_panel_height
;
261 if (panel
->area
.bg
->border
.rounded
> panel
->area
.width
/2) {
262 printf("panel_background_id rounded is too big... please fix your tint2rc\n");
263 g_array_append_val(backgrounds
, *panel
->area
.bg
);
264 panel
->area
.bg
= &g_array_index(backgrounds
, Background
, backgrounds
->len
-1);
265 panel
->area
.bg
->border
.rounded
= panel
->area
.width
/2;
269 // panel position determined here
270 if (panel_position
& LEFT
) {
271 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
274 if (panel_position
& RIGHT
) {
275 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
278 if (panel_horizontal
)
279 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
281 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
284 if (panel_position
& TOP
) {
285 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
288 if (panel_position
& BOTTOM
) {
289 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
292 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
296 // autohide or strut_policy=minimum
297 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
298 if (panel_horizontal
) {
299 panel
->hidden_width
= panel
->area
.width
;
300 panel
->hidden_height
= panel
->area
.height
- diff
;
303 panel
->hidden_width
= panel
->area
.width
- diff
;
304 panel
->hidden_height
= panel
->area
.height
;
306 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
310 int resize_panel(void *obj
)
312 Panel
*panel
= (Panel
*)obj
;
313 int size
, nb_by_content
=0, nb_by_layout
=0;
314 Area
*a
= (Area
*)obj
;
315 int paddingx
= a
->paddingx
;;
317 if (panel_horizontal
) {
318 // detect free size for SIZE_BY_LAYOUT's Area
319 size
= a
->width
- (2 * a
->paddingxlr
) - (2 * a
->bg
->border
.width
);
321 for (l
= ((Area
*)obj
)->list
; l
; l
= l
->next
) {
323 if (a
->on_screen
&& a
->width
&& a
->size_mode
== SIZE_BY_CONTENT
) {
327 if (a
->on_screen
&& a
->size_mode
== SIZE_BY_LAYOUT
)
330 if (nb_by_content
+nb_by_layout
)
331 size
-= ((nb_by_content
+nb_by_layout
-1) * paddingx
);
332 //printf("resize_panel : size_panel %d, size_layout %d\n", panel->area.width, size);
334 int width
=0, modulo
=0;
336 width
= size
/ nb_by_layout
;
337 modulo
= size
% nb_by_layout
;
339 //printf(" content %d, layout %d, width %d, modulo %d\n", nb_by_content, nb_by_layout, width, modulo);
341 // change posx and width for all taskbar
343 posx
= panel
->area
.bg
->border
.width
+ panel
->area
.paddingxlr
;
344 if (panel
->launcher
.area
.on_screen
&& panel
->launcher
.area
.width
)
345 posx
+= (panel
->launcher
.area
.width
+ panel
->area
.paddingx
);
346 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
347 panel
->taskbar
[i
].area
.posx
= posx
;
348 panel
->taskbar
[i
].area
.width
= width
;
349 panel
->taskbar
[i
].area
.resize
= 1;
351 panel
->taskbar
[i
].area
.width
++;
354 //printf(" width %d\n", panel->taskbar[i].area.width);
355 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
356 if (panel_mode
== MULTI_DESKTOP
)
357 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
361 // detect free size for SIZE_BY_LAYOUT's Area
362 size
= a
->height
- (2 * a
->paddingxlr
) - (2 * a
->bg
->border
.width
);
364 for (l
= ((Area
*)obj
)->list
; l
; l
= l
->next
) {
366 if (a
->on_screen
&& a
->height
&& a
->size_mode
== SIZE_BY_CONTENT
) {
370 if (a
->on_screen
&& a
->size_mode
== SIZE_BY_LAYOUT
)
373 if (nb_by_content
+nb_by_layout
)
374 size
-= ((nb_by_content
+nb_by_layout
-1) * paddingx
);
376 int width
=0, modulo
=0;
378 width
= size
/ nb_by_layout
;
379 modulo
= size
% nb_by_layout
;
382 // change posy and height for all taskbar
384 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
385 panel
->taskbar
[i
].area
.posy
= posy
;
386 panel
->taskbar
[i
].area
.height
= width
;
387 panel
->taskbar
[i
].area
.resize
= 1;
389 panel
->taskbar
[i
].area
.height
++;
392 if (panel_mode
== MULTI_DESKTOP
)
393 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
400 void visible_object()
405 for (i
=0 ; i
< nb_panel
; i
++) {
409 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
410 taskbar
= &panel
->taskbar
[j
];
411 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
412 // SINGLE_DESKTOP and not current desktop
413 taskbar
->area
.on_screen
= 0;
416 taskbar
->area
.on_screen
= 1;
423 void update_strut(Panel
* p
)
425 if (panel_strut_policy
== STRUT_NONE
) {
426 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
);
427 XDeleteProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
);
432 unsigned int d1
, screen_width
, screen_height
;
435 XGetGeometry(server
.dsp
, server
.root_win
, &d2
, &d3
, &d3
, &screen_width
, &screen_height
, &d1
, &d1
);
436 Monitor monitor
= server
.monitor
[p
->monitor
];
437 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
438 if (panel_horizontal
) {
439 int height
= p
->area
.height
+ p
->marginy
;
440 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
441 height
= p
->hidden_height
;
442 if (panel_position
& TOP
) {
443 struts
[2] = height
+ monitor
.y
;
445 // p->area.width - 1 allowed full screen on monitor 2
446 struts
[9] = p
->posx
+ p
->area
.width
- 1;
449 struts
[3] = height
+ screen_height
- monitor
.y
- monitor
.height
;
450 struts
[10] = p
->posx
;
451 // p->area.width - 1 allowed full screen on monitor 2
452 struts
[11] = p
->posx
+ p
->area
.width
- 1;
456 int width
= p
->area
.width
+ p
->marginx
;
457 if (panel_strut_policy
== STRUT_MINIMUM
|| (panel_strut_policy
== STRUT_FOLLOW_SIZE
&& p
->is_hidden
))
458 width
= p
->hidden_width
;
459 if (panel_position
& LEFT
) {
460 struts
[0] = width
+ monitor
.x
;
462 // p->area.width - 1 allowed full screen on monitor 2
463 struts
[5] = p
->posy
+ p
->area
.height
- 1;
466 struts
[1] = width
+ screen_width
- monitor
.x
- monitor
.width
;
468 // p->area.width - 1 allowed full screen on monitor 2
469 struts
[7] = p
->posy
+ p
->area
.height
- 1;
472 // Old specification : fluxbox need _NET_WM_STRUT.
473 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
474 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
478 void set_panel_properties(Panel
*p
)
480 XStoreName (server
.dsp
, p
->main_win
, "tint2");
483 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
485 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
490 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
491 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
493 // Sticky and below other window
495 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
497 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
498 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
499 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
500 state
[3] = panel_layer
== BOTTOM_LAYER
? server
.atom
._NET_WM_STATE_BELOW
: server
.atom
._NET_WM_STATE_ABOVE
;
501 int nb_atoms
= panel_layer
== NORMAL_LAYER
? 3 : 4;
502 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, nb_atoms
);
507 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
508 wmhints
.flags
= StateHint
| IconWindowHint
;
509 wmhints
.initial_state
= WithdrawnState
;
512 wmhints
.flags
= InputHint
;
513 wmhints
.input
= False
;
515 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
518 long prop
[5] = { 2, 0, 0, 0, 0 };
519 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
521 // XdndAware - Register for Xdnd events
523 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
527 // Fixed position and non-resizable window
528 // Allow panel move and resize when tint2 reload config file
529 int minwidth
= panel_autohide
? p
->hidden_width
: p
->area
.width
;
530 int minheight
= panel_autohide
? p
->hidden_height
: p
->area
.height
;
531 XSizeHints size_hints
;
532 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
533 size_hints
.min_width
= minwidth
;
534 size_hints
.max_width
= p
->area
.width
;
535 size_hints
.min_height
= minheight
;
536 size_hints
.max_height
= p
->area
.height
;
537 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
540 XClassHint
* classhint
= XAllocClassHint();
541 classhint
->res_name
= "tint2";
542 classhint
->res_class
= "Tint2";
543 XSetClassHint(server
.dsp
, p
->main_win
, classhint
);
548 void set_panel_background(Panel
*p
)
550 if (p
->area
.pix
) XFreePixmap (server
.dsp
, p
->area
.pix
);
551 p
->area
.pix
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
554 if (panel_horizontal
&& panel_position
& BOTTOM
)
555 yoff
= p
->area
.height
-p
->hidden_height
;
556 else if (!panel_horizontal
&& panel_position
& RIGHT
)
557 xoff
= p
->area
.width
-p
->hidden_width
;
559 if (server
.real_transparency
) {
560 clear_pixmap(p
->area
.pix
, 0, 0, p
->area
.width
, p
->area
.height
);
564 // copy background (server.root_pmap) in panel.area.pix
567 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
568 if (panel_autohide
&& p
->is_hidden
) {
572 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
);
573 XFillRectangle(server
.dsp
, p
->area
.pix
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
576 // draw background panel
579 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
, server
.visual
, p
->area
.width
, p
->area
.height
);
580 c
= cairo_create (cs
);
581 draw_background(&p
->area
, c
);
583 cairo_surface_destroy (cs
);
585 if (panel_autohide
) {
586 if (p
->hidden_pixmap
) XFreePixmap(server
.dsp
, p
->hidden_pixmap
);
587 p
->hidden_pixmap
= XCreatePixmap(server
.dsp
, server
.root_win
, p
->hidden_width
, p
->hidden_height
, server
.depth
);
588 XCopyArea(server
.dsp
, p
->area
.pix
, p
->hidden_pixmap
, server
.gc
, xoff
, yoff
, p
->hidden_width
, p
->hidden_height
, 0, 0);
591 // redraw panel's object
592 //p->area.redraw = 1;
595 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
600 // reset task 'state_pix'
603 for (i
=0 ; i
< p
->nb_desktop
; i
++) {
604 tskbar
= &p
->taskbar
[i
];
605 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
606 set_task_redraw((Task
*)l0
->data
);
612 Panel
*get_panel(Window win
)
615 for (i
=0 ; i
< nb_panel
; i
++) {
616 if (panel1
[i
].main_win
== win
) {
624 Taskbar
*click_taskbar (Panel
*panel
, int x
, int y
)
629 if (panel_horizontal
) {
630 for (i
=0; i
< panel
->nb_desktop
; i
++) {
631 tskbar
= &panel
->taskbar
[i
];
632 if (tskbar
->area
.on_screen
&& x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
637 for (i
=0; i
< panel
->nb_desktop
; i
++) {
638 tskbar
= &panel
->taskbar
[i
];
639 if (tskbar
->area
.on_screen
&& y
>= tskbar
->area
.posy
&& y
<= (tskbar
->area
.posy
+ tskbar
->area
.height
))
647 Task
*click_task (Panel
*panel
, int x
, int y
)
652 if ( (tskbar
= click_taskbar(panel
, x
, y
)) ) {
653 if (panel_horizontal
) {
655 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
657 if (tsk
->area
.on_screen
&& x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
664 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
666 if (tsk
->area
.on_screen
&& y
>= tsk
->area
.posy
&& y
<= (tsk
->area
.posy
+ tsk
->area
.height
)) {
676 Launcher
*click_launcher (Panel
*panel
, int x
, int y
)
678 Launcher
*launcher
= &panel
->launcher
;
680 if (panel_horizontal
) {
681 if (launcher
->area
.on_screen
&& x
>= launcher
->area
.posx
&& x
<= (launcher
->area
.posx
+ launcher
->area
.width
))
685 if (launcher
->area
.on_screen
&& y
>= launcher
->area
.posy
&& y
<= (launcher
->area
.posy
+ launcher
->area
.height
))
692 LauncherIcon
*click_launcher_icon (Panel
*panel
, int x
, int y
)
697 //printf("Click x=%d y=%d\n", x, y);
698 if ( (launcher
= click_launcher(panel
, x
, y
)) ) {
700 for (l0
= launcher
->list_icons
; l0
; l0
= l0
->next
) {
702 if (x
>= (launcher
->area
.posx
+ icon
->x
) && x
<= (launcher
->area
.posx
+ icon
->x
+ icon
->icon_size
) &&
703 y
>= (launcher
->area
.posy
+ icon
->y
) && y
<= (launcher
->area
.posy
+ icon
->y
+ icon
->icon_size
)) {
704 //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);
713 int click_padding(Panel
*panel
, int x
, int y
)
715 if (panel_horizontal
) {
716 if (x
< panel
->area
.paddingxlr
|| x
> panel
->area
.width
-panel
->area
.paddingxlr
)
720 if (y
< panel
->area
.paddingxlr
|| y
> panel
->area
.height
-panel
->area
.paddingxlr
)
727 int click_clock(Panel
*panel
, int x
, int y
)
729 Clock clk
= panel
->clock
;
730 if (panel_horizontal
) {
731 if (clk
.area
.on_screen
&& x
>= clk
.area
.posx
&& x
<= (clk
.area
.posx
+ clk
.area
.width
))
734 if (clk
.area
.on_screen
&& y
>= clk
.area
.posy
&& y
<= (clk
.area
.posy
+ clk
.area
.height
))
741 Area
* click_area(Panel
*panel
, int x
, int y
)
743 Area
* result
= &panel
->area
;
744 Area
* new_result
= result
;
747 GSList
* it
= result
->list
;
750 if (panel_horizontal
) {
751 if (a
->on_screen
&& x
>= a
->posx
&& x
<= (a
->posx
+ a
->width
)) {
756 if (a
->on_screen
&& y
>= a
->posy
&& y
<= (a
->posy
+ a
->height
)) {
763 } while (new_result
!= result
);
768 void stop_autohide_timeout(Panel
* p
)
770 if (p
->autohide_timeout
) {
771 stop_timeout(p
->autohide_timeout
);
772 p
->autohide_timeout
= 0;
777 void autohide_show(void* p
)
780 stop_autohide_timeout(panel
);
781 panel
->is_hidden
= 0;
782 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
785 XMapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
786 if (panel_horizontal
) {
787 if (panel_position
& TOP
)
788 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
790 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
793 if (panel_position
& LEFT
)
794 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->area
.width
, panel
->area
.height
);
796 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
, panel
->area
.width
, panel
->area
.height
);
798 refresh_systray
= 1; // ugly hack, because we actually only need to call XSetBackgroundPixmap
803 void autohide_hide(void* p
)
806 stop_autohide_timeout(panel
);
807 panel
->is_hidden
= 1;
808 if (panel_strut_policy
== STRUT_FOLLOW_SIZE
)
811 XUnmapSubwindows(server
.dsp
, panel
->main_win
); // systray windows
812 int diff
= (panel_horizontal
? panel
->area
.height
: panel
->area
.width
) - panel_autohide_height
;
813 //printf("autohide_hide : diff %d, w %d, h %d\n", diff, panel->hidden_width, panel->hidden_height);
814 if (panel_horizontal
) {
815 if (panel_position
& TOP
)
816 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
818 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
, panel
->posy
+diff
, panel
->hidden_width
, panel
->hidden_height
);
821 if (panel_position
& LEFT
)
822 XResizeWindow(server
.dsp
, panel
->main_win
, panel
->hidden_width
, panel
->hidden_height
);
824 XMoveResizeWindow(server
.dsp
, panel
->main_win
, panel
->posx
+diff
, panel
->posy
, panel
->hidden_width
, panel
->hidden_height
);
830 void autohide_trigger_show(Panel
* p
)
834 if (p
->autohide_timeout
)
835 change_timeout(p
->autohide_timeout
, panel_autohide_show_timeout
, 0, autohide_show
, p
);
837 p
->autohide_timeout
= add_timeout(panel_autohide_show_timeout
, 0, autohide_show
, p
);
841 void autohide_trigger_hide(Panel
* p
)
849 if (XQueryPointer(server
.dsp
, p
->main_win
, &root
, &child
, &xr
, &yr
, &xw
, &yw
, &mask
))
850 if (child
) return; // mouse over one of the system tray icons
852 if (p
->autohide_timeout
)
853 change_timeout(p
->autohide_timeout
, panel_autohide_hide_timeout
, 0, autohide_hide
, p
);
855 p
->autohide_timeout
= add_timeout(panel_autohide_hide_timeout
, 0, autohide_hide
, p
);