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 **************************************************************************/
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
25 #include <cairo-xlib.h>
26 #include <pango/pangocairo.h>
35 // --------------------------------------------------
40 int mouse_scroll_down
;
46 int panel_dock
=0; // default not in the dock
67 for (i
=0 ; i
< nb_panel
; i
++) {
72 p
->area
.on_screen
= 1;
74 p
->area
._resize
= resize_panel
;
75 p
->g_taskbar
.parent
= p
;
76 p
->g_taskbar
.panel
= p
;
77 p
->g_task
.area
.panel
= p
;
80 if (p
->clock
.area
.on_screen
)
81 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
83 if (p
->battery
.area
.on_screen
)
84 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
86 // systray only on first panel
87 if (systray
.area
.on_screen
&& i
== 0)
88 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
91 if (!p
->initial_width
) {
92 p
->initial_width
= 100;
97 if (panel_horizontal
) {
99 p
->area
.width
= (float)server
.monitor
[p
->monitor
].width
* p
->initial_width
/ 100;
101 p
->area
.width
= p
->initial_width
;
103 p
->area
.height
= (float)server
.monitor
[p
->monitor
].height
* p
->initial_height
/ 100;
105 p
->area
.height
= p
->initial_height
;
106 if (p
->area
.pix
.border
.rounded
> p
->area
.height
/2)
107 p
->area
.pix
.border
.rounded
= p
->area
.height
/2;
111 p
->area
.height
= (float)server
.monitor
[p
->monitor
].height
* p
->initial_width
/ 100;
113 p
->area
.height
= p
->initial_width
;
115 p
->area
.width
= (float)server
.monitor
[p
->monitor
].width
* p
->initial_height
/ 100;
117 p
->area
.width
= p
->initial_height
;
118 if (p
->area
.pix
.border
.rounded
> p
->area
.width
/2)
119 p
->area
.pix
.border
.rounded
= p
->area
.width
/2;
122 /* panel position determined here */
123 if (panel_position
& LEFT
) {
124 p
->posx
= server
.monitor
[p
->monitor
].x
+ p
->marginx
;
127 if (panel_position
& RIGHT
) {
128 p
->posx
= server
.monitor
[p
->monitor
].x
+ server
.monitor
[p
->monitor
].width
- p
->area
.width
- p
->marginx
;
131 if (panel_horizontal
)
132 p
->posx
= server
.monitor
[p
->monitor
].x
+ ((server
.monitor
[p
->monitor
].width
- p
->area
.width
) / 2);
134 p
->posx
= server
.monitor
[p
->monitor
].x
+ p
->marginx
;
137 if (panel_position
& TOP
) {
138 p
->posy
= server
.monitor
[p
->monitor
].y
+ p
->marginy
;
141 if (panel_position
& BOTTOM
) {
142 p
->posy
= server
.monitor
[p
->monitor
].y
+ server
.monitor
[p
->monitor
].height
- p
->area
.height
- p
->marginy
;
145 p
->posy
= server
.monitor
[p
->monitor
].y
+ ((server
.monitor
[p
->monitor
].height
- p
->area
.height
) / 2);
148 // printf("panel : posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height);
151 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
152 if (g_tooltip
.enabled
)
153 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
154 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
155 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
156 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
);
158 set_panel_properties(p
);
159 set_panel_background(p
);
161 XMapWindow (server
.dsp
, p
->main_win
);
177 // font allocated once
178 if (panel1
[0].g_task
.font_desc
) {
179 pango_font_description_free(panel1
[0].g_task
.font_desc
);
180 panel1
[0].g_task
.font_desc
= 0;
185 for (i
=0 ; i
< nb_panel
; i
++) {
189 free_area(&p
->g_task
.area
);
190 free_area(&p
->g_taskbar
);
193 XFreePixmap(server
.dsp
, p
->temp_pmap
);
197 XDestroyWindow(server
.dsp
, p
->main_win
);
202 if (panel1
) free(panel1
);
205 if (g_tooltip
.window
) {
206 XDestroyWindow(server
.dsp
, g_tooltip
.window
);
207 g_tooltip
.window
= 0;
209 if (g_tooltip
.font_desc
) {
210 pango_font_description_free(g_tooltip
.font_desc
);
211 g_tooltip
.font_desc
= 0;
216 void resize_panel(void *obj
)
218 Panel
*panel
= (Panel
*)obj
;
220 if (panel_horizontal
) {
221 int taskbar_width
, modulo_width
= 0;
223 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
224 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
225 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
226 #ifdef ENABLE_BATTERY
227 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
228 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
230 // TODO : systray only on first panel. search better implementation !
231 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
232 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
234 if (panel_mode
== MULTI_DESKTOP
) {
235 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
236 taskbar_width
= width
/ panel
->nb_desktop
;
237 modulo_width
= width
% panel
->nb_desktop
;
240 // change posx and width for all taskbar
242 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
243 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
244 panel
->taskbar
[i
].area
.posx
= posx
;
245 panel
->taskbar
[i
].area
.width
= taskbar_width
;
246 panel
->taskbar
[i
].area
.resize
= 1;
248 panel
->taskbar
[i
].area
.width
++;
251 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
252 if (panel_mode
== MULTI_DESKTOP
)
253 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
257 int taskbar_height
, modulo_height
= 0;
260 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
261 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
262 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
263 #ifdef ENABLE_BATTERY
264 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
265 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
267 // TODO : systray only on first panel. search better implementation !
268 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
269 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
271 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
272 if (panel_mode
== MULTI_DESKTOP
) {
273 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
274 taskbar_height
= height
/ panel
->nb_desktop
;
275 modulo_height
= height
% panel
->nb_desktop
;
278 // change posy and height for all taskbar
279 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
280 panel
->taskbar
[i
].area
.posy
= posy
;
281 panel
->taskbar
[i
].area
.height
= taskbar_height
;
282 panel
->taskbar
[i
].area
.resize
= 1;
284 panel
->taskbar
[i
].area
.height
++;
287 if (panel_mode
== MULTI_DESKTOP
)
288 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
294 void visible_object()
299 for (i
=0 ; i
< nb_panel
; i
++) {
303 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
304 taskbar
= &panel
->taskbar
[j
];
305 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
306 // SINGLE_DESKTOP and not current desktop
307 taskbar
->area
.on_screen
= 0;
310 taskbar
->area
.on_screen
= 1;
318 void set_panel_properties(Panel
*p
)
320 XStoreName (server
.dsp
, p
->main_win
, "tint2");
322 // TODO: check if the name is really needed for a panel/taskbar ?
324 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
326 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
331 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
332 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
335 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
336 if (panel_horizontal
) {
337 if (panel_position
& TOP
) {
338 struts
[2] = p
->area
.height
+ p
->marginy
;
340 // p->area.width - 1 allowed full screen on monitor 2
341 struts
[9] = p
->posx
+ p
->area
.width
- 1;
344 struts
[3] = p
->area
.height
+ p
->marginy
;
345 struts
[10] = p
->posx
;
346 // p->area.width - 1 allowed full screen on monitor 2
347 struts
[11] = p
->posx
+ p
->area
.width
- 1;
351 if (panel_position
& LEFT
) {
352 struts
[0] = p
->area
.width
+ p
->marginx
;
354 // p->area.width - 1 allowed full screen on monitor 2
355 struts
[5] = p
->posy
+ p
->area
.height
- 1;
358 struts
[1] = p
->area
.width
+ p
->marginx
;
360 // p->area.width - 1 allowed full screen on monitor 2
361 struts
[7] = p
->posy
+ p
->area
.height
- 1;
364 // Old specification : fluxbox need _NET_WM_STRUT.
365 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
366 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
368 // Sticky and below other window
370 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
372 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
373 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
374 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
375 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
376 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
379 XSizeHints size_hints
;
380 size_hints
.flags
= PPosition
;
381 XChangeProperty (server
.dsp
, p
->main_win
, XA_WM_NORMAL_HINTS
, XA_WM_SIZE_HINTS
, 32, PropModeReplace
, (unsigned char *) &size_hints
, sizeof (XSizeHints
) / 4);
386 // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
387 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
388 wmhints
.flags
= StateHint
| IconWindowHint
;
389 wmhints
.initial_state
= WithdrawnState
;
392 wmhints
.flags
= InputHint
;
393 wmhints
.input
= False
;
395 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
398 long prop
[5] = { 2, 0, 0, 0, 0 };
399 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
401 // XdndAware - Register for Xdnd events
403 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
407 void set_panel_background(Panel
*p
)
411 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
412 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
414 // copy background (server.root_pmap) in panel.area.pix.pmap
417 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
418 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
419 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
421 // draw background panel
424 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
425 c
= cairo_create (cs
);
427 draw_background(&p
->area
, c
, 0);
430 cairo_surface_destroy (cs
);
432 // redraw panel's object
435 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
442 Panel
*get_panel(Window win
)
445 for (i
=0 ; i
< nb_panel
; i
++) {
446 if (panel1
[i
].main_win
== win
) {