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
;
82 for (i
=0 ; i
< nb_panel
; i
++) {
83 free_area(&panel1
[i
].area
);
84 if (panel1
[i
].temp_pmap
) {
85 XFreePixmap(server
.dsp
, panel1
[i
].temp_pmap
);
86 panel1
[i
].temp_pmap
= 0;
91 old_nb_panel
= nb_panel
;
92 if (panel_config
.monitor
>= 0)
95 nb_panel
= server
.nb_monitor
;
98 for (i
=nb_panel
; i
< old_nb_panel
; i
++) {
99 if (panel1
[i
].main_win
) {
100 XDestroyWindow(server
.dsp
, panel1
[i
].main_win
);
101 panel1
[i
].main_win
= 0;
105 // alloc & init new panel
107 if (nb_panel
!= old_nb_panel
)
108 new_panel
= realloc(panel1
, nb_panel
* sizeof(Panel
));
111 for (i
=0 ; i
< nb_panel
; i
++) {
112 old_win
= new_panel
[i
].main_win
;
113 memcpy(&new_panel
[i
], &panel_config
, sizeof(Panel
));
114 new_panel
[i
].main_win
= old_win
;
117 fprintf(stderr
, "tint2 : nb monitor %d, nb desktop %d\n", nb_panel
, server
.nb_desktop
);
118 for (i
=0 ; i
< nb_panel
; i
++) {
124 p
->area
.on_screen
= 1;
126 p
->area
._resize
= resize_panel
;
127 p
->g_taskbar
.parent
= p
;
128 p
->g_taskbar
.panel
= p
;
129 p
->g_task
.area
.panel
= p
;
130 init_panel_size_and_position(p
);
135 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
137 #ifdef ENABLE_BATTERY
138 if (battery_enabled
) {
139 init_battery_panel(p
);
140 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
143 // systray only on first panel
144 if (systray
.area
.on_screen
&& i
== 0) {
145 init_systray_panel(p
);
146 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
150 if (i
>= old_nb_panel
) {
151 // new panel : catch some events
152 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
153 if (g_tooltip
.enabled
)
154 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
155 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
156 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
157 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
);
161 XMoveResizeWindow(server
.dsp
, p
->main_win
, p
->posx
, p
->posy
, p
->area
.width
, p
->area
.height
);
164 //printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
165 set_panel_properties(p
);
166 set_panel_background(p
);
167 if (i
>= old_nb_panel
) {
169 XMapWindow (server
.dsp
, p
->main_win
);
177 task_refresh_tasklist();
182 void init_panel_size_and_position(Panel
*panel
)
185 if (panel_horizontal
) {
186 if (panel
->pourcentx
)
187 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->area
.width
/ 100;
188 if (panel
->pourcenty
)
189 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.height
/ 100;
190 if (panel
->area
.pix
.border
.rounded
> panel
->area
.height
/2)
191 panel
->area
.pix
.border
.rounded
= panel
->area
.height
/2;
194 int old_panel_height
= panel
->area
.height
;
195 if (panel
->pourcentx
)
196 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->area
.width
/ 100;
198 panel
->area
.height
= panel
->area
.width
;
199 if (panel
->pourcenty
)
200 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* old_panel_height
/ 100;
202 panel
->area
.width
= old_panel_height
;
203 if (panel
->area
.pix
.border
.rounded
> panel
->area
.width
/2)
204 panel
->area
.pix
.border
.rounded
= panel
->area
.width
/2;
207 // panel position determined here
208 if (panel_position
& LEFT
) {
209 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
212 if (panel_position
& RIGHT
) {
213 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
216 if (panel_horizontal
)
217 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
219 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
222 if (panel_position
& TOP
) {
223 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
226 if (panel_position
& BOTTOM
) {
227 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
230 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
233 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
246 // font allocated once
247 if (panel1
[0].g_task
.font_desc
) {
248 pango_font_description_free(panel1
[0].g_task
.font_desc
);
249 panel1
[0].g_task
.font_desc
= 0;
254 for (i
=0 ; i
< nb_panel
; i
++) {
260 XFreePixmap(server
.dsp
, p
->temp_pmap
);
264 XDestroyWindow(server
.dsp
, p
->main_win
);
269 if (panel1
) free(panel1
);
274 void resize_panel(void *obj
)
276 Panel
*panel
= (Panel
*)obj
;
278 if (panel_horizontal
) {
279 int taskbar_width
, modulo_width
= 0;
281 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
282 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
283 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
284 #ifdef ENABLE_BATTERY
285 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
286 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
288 // TODO : systray only on first panel. search better implementation !
289 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
290 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
292 if (panel_mode
== MULTI_DESKTOP
) {
293 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
294 taskbar_width
= width
/ panel
->nb_desktop
;
295 modulo_width
= width
% panel
->nb_desktop
;
298 // change posx and width for all taskbar
300 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
301 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
302 panel
->taskbar
[i
].area
.posx
= posx
;
303 panel
->taskbar
[i
].area
.width
= taskbar_width
;
304 panel
->taskbar
[i
].area
.resize
= 1;
306 panel
->taskbar
[i
].area
.width
++;
309 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
310 if (panel_mode
== MULTI_DESKTOP
)
311 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
315 int taskbar_height
, modulo_height
= 0;
318 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
319 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
320 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
321 #ifdef ENABLE_BATTERY
322 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
323 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
325 // TODO : systray only on first panel. search better implementation !
326 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
327 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
329 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
330 if (panel_mode
== MULTI_DESKTOP
) {
331 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
332 taskbar_height
= height
/ panel
->nb_desktop
;
333 modulo_height
= height
% panel
->nb_desktop
;
336 // change posy and height for all taskbar
337 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
338 panel
->taskbar
[i
].area
.posy
= posy
;
339 panel
->taskbar
[i
].area
.height
= taskbar_height
;
340 panel
->taskbar
[i
].area
.resize
= 1;
342 panel
->taskbar
[i
].area
.height
++;
345 if (panel_mode
== MULTI_DESKTOP
)
346 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
352 void visible_object()
357 for (i
=0 ; i
< nb_panel
; i
++) {
361 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
362 taskbar
= &panel
->taskbar
[j
];
363 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
364 // SINGLE_DESKTOP and not current desktop
365 taskbar
->area
.on_screen
= 0;
368 taskbar
->area
.on_screen
= 1;
376 void set_panel_properties(Panel
*p
)
378 XStoreName (server
.dsp
, p
->main_win
, "tint2");
381 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
383 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
388 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
389 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
391 // Sticky and below other window
393 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
395 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
396 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
397 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
398 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
399 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
404 // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
405 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
406 wmhints
.flags
= StateHint
| IconWindowHint
;
407 wmhints
.initial_state
= WithdrawnState
;
410 wmhints
.flags
= InputHint
;
411 wmhints
.input
= False
;
413 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
416 long prop
[5] = { 2, 0, 0, 0, 0 };
417 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
419 // XdndAware - Register for Xdnd events
421 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
424 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
425 if (panel_horizontal
) {
426 if (panel_position
& TOP
) {
427 struts
[2] = p
->area
.height
+ p
->marginy
;
429 // p->area.width - 1 allowed full screen on monitor 2
430 struts
[9] = p
->posx
+ p
->area
.width
- 1;
433 struts
[3] = p
->area
.height
+ p
->marginy
;
434 struts
[10] = p
->posx
;
435 // p->area.width - 1 allowed full screen on monitor 2
436 struts
[11] = p
->posx
+ p
->area
.width
- 1;
440 if (panel_position
& LEFT
) {
441 struts
[0] = p
->area
.width
+ p
->marginx
;
443 // p->area.width - 1 allowed full screen on monitor 2
444 struts
[5] = p
->posy
+ p
->area
.height
- 1;
447 struts
[1] = p
->area
.width
+ p
->marginx
;
449 // p->area.width - 1 allowed full screen on monitor 2
450 struts
[7] = p
->posy
+ p
->area
.height
- 1;
453 // Old specification : fluxbox need _NET_WM_STRUT.
454 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
455 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
457 // Fixed position and non-resizable window
458 // Allow panel move and resize when tint2 reload config file
459 XSizeHints size_hints
;
460 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
461 size_hints
.min_width
= size_hints
.max_width
= p
->area
.width
;
462 size_hints
.min_height
= size_hints
.max_height
= p
->area
.height
;
463 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
467 void set_panel_background(Panel
*p
)
471 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
472 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
474 // copy background (server.root_pmap) in panel.area.pix.pmap
477 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
478 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
479 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
481 // draw background panel
484 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
485 c
= cairo_create (cs
);
487 draw_background(&p
->area
, c
, 0);
490 cairo_surface_destroy (cs
);
492 // redraw panel's object
495 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
502 Panel
*get_panel(Window win
)
505 for (i
=0 ; i
< nb_panel
; i
++) {
506 if (panel1
[i
].main_win
== win
) {