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
;
75 for (i
=0 ; i
< nb_panel
; i
++) {
76 free_area(&panel1
[i
].area
);
77 if (panel1
[i
].temp_pmap
) {
78 XFreePixmap(server
.dsp
, panel1
[i
].temp_pmap
);
79 panel1
[i
].temp_pmap
= 0;
84 old_nb_panel
= nb_panel
;
85 if (panel_config
.monitor
>= 0)
88 nb_panel
= server
.nb_monitor
;
91 for (i
=nb_panel
; i
< old_nb_panel
; i
++) {
92 if (panel1
[i
].main_win
) {
93 XDestroyWindow(server
.dsp
, panel1
[i
].main_win
);
94 panel1
[i
].main_win
= 0;
98 // alloc & init new panel
100 if (nb_panel
!= old_nb_panel
)
101 new_panel
= realloc(panel1
, nb_panel
* sizeof(Panel
));
104 for (i
=0 ; i
< nb_panel
; i
++) {
105 old_win
= new_panel
[i
].main_win
;
106 memcpy(&new_panel
[i
], &panel_config
, sizeof(Panel
));
107 new_panel
[i
].main_win
= old_win
;
110 fprintf(stderr
, "tint2 : nb monitor %d, nb desktop %d\n", nb_panel
, server
.nb_desktop
);
111 for (i
=0 ; i
< nb_panel
; i
++) {
117 p
->area
.on_screen
= 1;
119 p
->area
._resize
= resize_panel
;
120 p
->g_taskbar
.parent
= p
;
121 p
->g_taskbar
.panel
= p
;
122 p
->g_task
.area
.panel
= p
;
123 init_panel_size_and_position(p
);
126 if (p
->clock
.area
.on_screen
) {
128 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
130 #ifdef ENABLE_BATTERY
131 if (p
->battery
.area
.on_screen
) {
132 init_battery_panel(p
);
133 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
136 // systray only on first panel
137 if (systray
.area
.on_screen
&& i
== 0) {
138 init_systray_panel(p
);
139 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
143 if (!p
->initial_width
) {
144 p
->initial_width
= 100;
148 if (i
>= old_nb_panel
) {
150 //printf("new panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
153 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
154 if (g_tooltip
.enabled
)
155 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
156 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
157 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
158 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
);
160 set_panel_properties(p
);
161 set_panel_background(p
);
162 XMapWindow (server
.dsp
, p
->main_win
);
166 //printf("old panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
167 XMoveResizeWindow(server
.dsp
, p
->main_win
, p
->posx
, p
->posy
, p
->area
.width
, p
->area
.height
);
168 set_panel_background(p
);
177 task_refresh_tasklist();
181 void init_panel_size_and_position(Panel
*panel
)
184 if (panel_horizontal
) {
185 if (panel
->pourcentx
)
186 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_width
/ 100;
188 panel
->area
.width
= panel
->initial_width
;
189 if (panel
->pourcenty
)
190 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_height
/ 100;
192 panel
->area
.height
= panel
->initial_height
;
193 if (panel
->area
.pix
.border
.rounded
> panel
->area
.height
/2)
194 panel
->area
.pix
.border
.rounded
= panel
->area
.height
/2;
197 if (panel
->pourcentx
)
198 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_width
/ 100;
200 panel
->area
.height
= panel
->initial_width
;
201 if (panel
->pourcenty
)
202 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_height
/ 100;
204 panel
->area
.width
= panel
->initial_height
;
205 if (panel
->area
.pix
.border
.rounded
> panel
->area
.width
/2)
206 panel
->area
.pix
.border
.rounded
= panel
->area
.width
/2;
209 // panel position determined here
210 if (panel_position
& LEFT
) {
211 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
214 if (panel_position
& RIGHT
) {
215 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
218 if (panel_horizontal
)
219 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
221 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
224 if (panel_position
& TOP
) {
225 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
228 if (panel_position
& BOTTOM
) {
229 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
232 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
235 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
248 // font allocated once
249 if (panel1
[0].g_task
.font_desc
) {
250 pango_font_description_free(panel1
[0].g_task
.font_desc
);
251 panel1
[0].g_task
.font_desc
= 0;
256 for (i
=0 ; i
< nb_panel
; i
++) {
262 XFreePixmap(server
.dsp
, p
->temp_pmap
);
266 XDestroyWindow(server
.dsp
, p
->main_win
);
271 if (panel1
) free(panel1
);
276 void resize_panel(void *obj
)
278 Panel
*panel
= (Panel
*)obj
;
280 if (panel_horizontal
) {
281 int taskbar_width
, modulo_width
= 0;
283 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
284 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
285 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
286 #ifdef ENABLE_BATTERY
287 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
288 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
290 // TODO : systray only on first panel. search better implementation !
291 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
292 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
294 if (panel_mode
== MULTI_DESKTOP
) {
295 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
296 taskbar_width
= width
/ panel
->nb_desktop
;
297 modulo_width
= width
% panel
->nb_desktop
;
300 // change posx and width for all taskbar
302 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
303 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
304 panel
->taskbar
[i
].area
.posx
= posx
;
305 panel
->taskbar
[i
].area
.width
= taskbar_width
;
306 panel
->taskbar
[i
].area
.resize
= 1;
308 panel
->taskbar
[i
].area
.width
++;
311 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
312 if (panel_mode
== MULTI_DESKTOP
)
313 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
317 int taskbar_height
, modulo_height
= 0;
320 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
321 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
322 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
323 #ifdef ENABLE_BATTERY
324 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
325 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
327 // TODO : systray only on first panel. search better implementation !
328 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
329 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
331 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
332 if (panel_mode
== MULTI_DESKTOP
) {
333 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
334 taskbar_height
= height
/ panel
->nb_desktop
;
335 modulo_height
= height
% panel
->nb_desktop
;
338 // change posy and height for all taskbar
339 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
340 panel
->taskbar
[i
].area
.posy
= posy
;
341 panel
->taskbar
[i
].area
.height
= taskbar_height
;
342 panel
->taskbar
[i
].area
.resize
= 1;
344 panel
->taskbar
[i
].area
.height
++;
347 if (panel_mode
== MULTI_DESKTOP
)
348 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
354 void visible_object()
359 for (i
=0 ; i
< nb_panel
; i
++) {
363 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
364 taskbar
= &panel
->taskbar
[j
];
365 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
366 // SINGLE_DESKTOP and not current desktop
367 taskbar
->area
.on_screen
= 0;
370 taskbar
->area
.on_screen
= 1;
378 void set_panel_properties(Panel
*p
)
380 XStoreName (server
.dsp
, p
->main_win
, "tint2");
383 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
385 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
390 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
391 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
394 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
395 if (panel_horizontal
) {
396 if (panel_position
& TOP
) {
397 struts
[2] = p
->area
.height
+ p
->marginy
;
399 // p->area.width - 1 allowed full screen on monitor 2
400 struts
[9] = p
->posx
+ p
->area
.width
- 1;
403 struts
[3] = p
->area
.height
+ p
->marginy
;
404 struts
[10] = p
->posx
;
405 // p->area.width - 1 allowed full screen on monitor 2
406 struts
[11] = p
->posx
+ p
->area
.width
- 1;
410 if (panel_position
& LEFT
) {
411 struts
[0] = p
->area
.width
+ p
->marginx
;
413 // p->area.width - 1 allowed full screen on monitor 2
414 struts
[5] = p
->posy
+ p
->area
.height
- 1;
417 struts
[1] = p
->area
.width
+ p
->marginx
;
419 // p->area.width - 1 allowed full screen on monitor 2
420 struts
[7] = p
->posy
+ p
->area
.height
- 1;
423 // Old specification : fluxbox need _NET_WM_STRUT.
424 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
425 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
427 // Sticky and below other window
429 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
431 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
432 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
433 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
434 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
435 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
437 // Fixed position and non-resizable window
438 XSizeHints size_hints
;
439 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
440 size_hints
.min_width
= size_hints
.max_width
= p
->area
.width
;
441 size_hints
.min_height
= size_hints
.max_height
= p
->area
.height
;
442 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
447 // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
448 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
449 wmhints
.flags
= StateHint
| IconWindowHint
;
450 wmhints
.initial_state
= WithdrawnState
;
453 wmhints
.flags
= InputHint
;
454 wmhints
.input
= False
;
456 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
459 long prop
[5] = { 2, 0, 0, 0, 0 };
460 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
462 // XdndAware - Register for Xdnd events
464 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
468 void set_panel_background(Panel
*p
)
472 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
473 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
475 // copy background (server.root_pmap) in panel.area.pix.pmap
478 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
479 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
480 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
482 // draw background panel
485 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
486 c
= cairo_create (cs
);
488 draw_background(&p
->area
, c
, 0);
491 cairo_surface_destroy (cs
);
493 // redraw panel's object
496 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
503 Panel
*get_panel(Window win
)
506 for (i
=0 ; i
< nb_panel
; i
++) {
507 if (panel1
[i
].main_win
== win
) {