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>
37 // --------------------------------------------------
42 int mouse_scroll_down
;
48 int panel_dock
=0; // default not in the dock
59 // panel's initial config
61 // panels (one panel per monitor)
65 Imlib_Image default_icon
= NULL
;
74 // alloc panels (one monitor or all monitors)
75 if (panel_config
.monitor
>= 0)
78 nb_panel
= server
.nb_monitor
;
79 panel1
= malloc(nb_panel
* sizeof(Panel
));
81 for (i
=0 ; i
< nb_panel
; i
++) {
84 memcpy(p
, &panel_config
, sizeof(Panel
));
88 p
->area
.on_screen
= 1;
90 p
->area
._resize
= resize_panel
;
91 p
->g_taskbar
.parent
= p
;
92 p
->g_taskbar
.panel
= p
;
93 p
->g_task
.area
.panel
= p
;
96 if (p
->clock
.area
.on_screen
)
97 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
99 if (p
->battery
.area
.on_screen
)
100 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
102 // systray only on first panel
103 if (systray
.area
.on_screen
&& i
== 0)
104 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
107 if (!p
->initial_width
) {
108 p
->initial_width
= 100;
112 init_panel_size_and_position(p
);
115 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
116 if (g_tooltip
.enabled
)
117 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
118 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
119 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
120 p
->main_win
= XCreateWindow(server
.dsp
, server
.root_win
, p
->posx
, p
->posy
, p
->area
.width
, p
->area
.height
, 0, server
.depth
, InputOutput
, CopyFromParent
, CWEventMask
, &att
);
122 set_panel_properties(p
);
123 set_panel_background(p
);
125 XMapWindow (server
.dsp
, p
->main_win
);
131 void init_panel_size_and_position(Panel
*panel
)
134 if (panel_horizontal
) {
135 if (panel
->pourcentx
)
136 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_width
/ 100;
138 panel
->area
.width
= panel
->initial_width
;
139 if (panel
->pourcenty
)
140 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_height
/ 100;
142 panel
->area
.height
= panel
->initial_height
;
143 if (panel
->area
.pix
.border
.rounded
> panel
->area
.height
/2)
144 panel
->area
.pix
.border
.rounded
= panel
->area
.height
/2;
147 if (panel
->pourcentx
)
148 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_width
/ 100;
150 panel
->area
.height
= panel
->initial_width
;
151 if (panel
->pourcenty
)
152 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_height
/ 100;
154 panel
->area
.width
= panel
->initial_height
;
155 if (panel
->area
.pix
.border
.rounded
> panel
->area
.width
/2)
156 panel
->area
.pix
.border
.rounded
= panel
->area
.width
/2;
159 // panel position determined here
160 if (panel_position
& LEFT
) {
161 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
164 if (panel_position
& RIGHT
) {
165 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
168 if (panel_horizontal
)
169 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
171 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
174 if (panel_position
& TOP
) {
175 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
178 if (panel_position
& BOTTOM
) {
179 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
182 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
185 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
198 // font allocated once
199 if (panel1
[0].g_task
.font_desc
) {
200 pango_font_description_free(panel1
[0].g_task
.font_desc
);
201 panel1
[0].g_task
.font_desc
= 0;
206 for (i
=0 ; i
< nb_panel
; i
++) {
212 XFreePixmap(server
.dsp
, p
->temp_pmap
);
216 XDestroyWindow(server
.dsp
, p
->main_win
);
221 if (panel1
) free(panel1
);
226 void resize_panel(void *obj
)
228 Panel
*panel
= (Panel
*)obj
;
230 if (panel_horizontal
) {
231 int taskbar_width
, modulo_width
= 0;
233 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
234 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
235 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
236 #ifdef ENABLE_BATTERY
237 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
238 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
240 // TODO : systray only on first panel. search better implementation !
241 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
242 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
244 if (panel_mode
== MULTI_DESKTOP
) {
245 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
246 taskbar_width
= width
/ panel
->nb_desktop
;
247 modulo_width
= width
% panel
->nb_desktop
;
250 // change posx and width for all taskbar
252 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
253 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
254 panel
->taskbar
[i
].area
.posx
= posx
;
255 panel
->taskbar
[i
].area
.width
= taskbar_width
;
256 panel
->taskbar
[i
].area
.resize
= 1;
258 panel
->taskbar
[i
].area
.width
++;
261 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
262 if (panel_mode
== MULTI_DESKTOP
)
263 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
267 int taskbar_height
, modulo_height
= 0;
270 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
271 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
272 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
273 #ifdef ENABLE_BATTERY
274 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
275 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
277 // TODO : systray only on first panel. search better implementation !
278 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
279 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
281 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
282 if (panel_mode
== MULTI_DESKTOP
) {
283 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
284 taskbar_height
= height
/ panel
->nb_desktop
;
285 modulo_height
= height
% panel
->nb_desktop
;
288 // change posy and height for all taskbar
289 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
290 panel
->taskbar
[i
].area
.posy
= posy
;
291 panel
->taskbar
[i
].area
.height
= taskbar_height
;
292 panel
->taskbar
[i
].area
.resize
= 1;
294 panel
->taskbar
[i
].area
.height
++;
297 if (panel_mode
== MULTI_DESKTOP
)
298 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
304 void visible_object()
309 for (i
=0 ; i
< nb_panel
; i
++) {
313 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
314 taskbar
= &panel
->taskbar
[j
];
315 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
316 // SINGLE_DESKTOP and not current desktop
317 taskbar
->area
.on_screen
= 0;
320 taskbar
->area
.on_screen
= 1;
328 void set_panel_properties(Panel
*p
)
330 XStoreName (server
.dsp
, p
->main_win
, "tint2");
333 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
335 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
340 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
341 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
344 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
345 if (panel_horizontal
) {
346 if (panel_position
& TOP
) {
347 struts
[2] = p
->area
.height
+ p
->marginy
;
349 // p->area.width - 1 allowed full screen on monitor 2
350 struts
[9] = p
->posx
+ p
->area
.width
- 1;
353 struts
[3] = p
->area
.height
+ p
->marginy
;
354 struts
[10] = p
->posx
;
355 // p->area.width - 1 allowed full screen on monitor 2
356 struts
[11] = p
->posx
+ p
->area
.width
- 1;
360 if (panel_position
& LEFT
) {
361 struts
[0] = p
->area
.width
+ p
->marginx
;
363 // p->area.width - 1 allowed full screen on monitor 2
364 struts
[5] = p
->posy
+ p
->area
.height
- 1;
367 struts
[1] = p
->area
.width
+ p
->marginx
;
369 // p->area.width - 1 allowed full screen on monitor 2
370 struts
[7] = p
->posy
+ p
->area
.height
- 1;
373 // Old specification : fluxbox need _NET_WM_STRUT.
374 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
375 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
377 // Sticky and below other window
379 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
381 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
382 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
383 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
384 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
385 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
387 // Fixed position and non-resizable window
388 XSizeHints size_hints
;
389 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
390 size_hints
.min_width
= size_hints
.max_width
= p
->area
.width
;
391 size_hints
.min_height
= size_hints
.max_height
= p
->area
.height
;
392 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
397 // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
398 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
399 wmhints
.flags
= StateHint
| IconWindowHint
;
400 wmhints
.initial_state
= WithdrawnState
;
403 wmhints
.flags
= InputHint
;
404 wmhints
.input
= False
;
406 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
409 long prop
[5] = { 2, 0, 0, 0, 0 };
410 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
412 // XdndAware - Register for Xdnd events
414 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
418 void set_panel_background(Panel
*p
)
422 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
423 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
425 // copy background (server.root_pmap) in panel.area.pix.pmap
428 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
429 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
430 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
432 // draw background panel
435 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
436 c
= cairo_create (cs
);
438 draw_background(&p
->area
, c
, 0);
441 cairo_surface_destroy (cs
);
443 // redraw panel's object
446 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
453 Panel
*get_panel(Window win
)
456 for (i
=0 ; i
< nb_panel
; i
++) {
457 if (panel1
[i
].main_win
== win
) {