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
);
79 // alloc panels (one monitor or all monitors)
80 old_nb_panel
= nb_panel
;
81 if (panel_config
.monitor
>= 0)
84 nb_panel
= server
.nb_monitor
;
85 fprintf(stderr
, "tint2 : nb monitor %d, nb desktop %d\n", nb_panel
, server
.nb_desktop
);
87 /* if (nb_panel < old_nb_panel) {
89 for (i=nb_panel ; i < old_nb_panel ; i++) {
93 if (nb_panel
!= old_nb_panel
)
94 new_panel
= realloc(panel1
, nb_panel
* sizeof(Panel
));
98 for (i
=0 ; i
< nb_panel
; i
++) {
101 if (i
>= old_nb_panel
) {
103 memcpy(p
, &panel_config
, sizeof(Panel
));
108 p
->area
.on_screen
= 1;
110 p
->area
._resize
= resize_panel
;
111 p
->g_taskbar
.parent
= p
;
112 p
->g_taskbar
.panel
= p
;
113 p
->g_task
.area
.panel
= p
;
114 init_panel_size_and_position(p
);
117 if (p
->clock
.area
.on_screen
) {
119 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
121 #ifdef ENABLE_BATTERY
122 if (p
->battery
.area
.on_screen
) {
123 init_battery_panel(p
);
124 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
127 // systray only on first panel
128 if (systray
.area
.on_screen
&& i
== 0) {
129 init_systray_panel(p
);
130 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
134 if (!p
->initial_width
) {
135 p
->initial_width
= 100;
139 if (i
>= old_nb_panel
) {
141 //printf("new window\n");
144 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
145 if (g_tooltip
.enabled
)
146 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
147 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
148 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
149 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
);
151 set_panel_properties(p
);
152 set_panel_background(p
);
153 XMapWindow (server
.dsp
, p
->main_win
);
157 //printf("move old window\n");
158 XMoveResizeWindow(server
.dsp
, p
->main_win
, p
->posx
, p
->posy
, p
->area
.width
, p
->area
.height
);
159 set_panel_background(p
);
167 task_refresh_tasklist();
171 void init_panel_size_and_position(Panel
*panel
)
174 if (panel_horizontal
) {
175 if (panel
->pourcentx
)
176 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_width
/ 100;
178 panel
->area
.width
= panel
->initial_width
;
179 if (panel
->pourcenty
)
180 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_height
/ 100;
182 panel
->area
.height
= panel
->initial_height
;
183 if (panel
->area
.pix
.border
.rounded
> panel
->area
.height
/2)
184 panel
->area
.pix
.border
.rounded
= panel
->area
.height
/2;
187 if (panel
->pourcentx
)
188 panel
->area
.height
= (float)server
.monitor
[panel
->monitor
].height
* panel
->initial_width
/ 100;
190 panel
->area
.height
= panel
->initial_width
;
191 if (panel
->pourcenty
)
192 panel
->area
.width
= (float)server
.monitor
[panel
->monitor
].width
* panel
->initial_height
/ 100;
194 panel
->area
.width
= panel
->initial_height
;
195 if (panel
->area
.pix
.border
.rounded
> panel
->area
.width
/2)
196 panel
->area
.pix
.border
.rounded
= panel
->area
.width
/2;
199 // panel position determined here
200 if (panel_position
& LEFT
) {
201 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
204 if (panel_position
& RIGHT
) {
205 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ server
.monitor
[panel
->monitor
].width
- panel
->area
.width
- panel
->marginx
;
208 if (panel_horizontal
)
209 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ ((server
.monitor
[panel
->monitor
].width
- panel
->area
.width
) / 2);
211 panel
->posx
= server
.monitor
[panel
->monitor
].x
+ panel
->marginx
;
214 if (panel_position
& TOP
) {
215 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ panel
->marginy
;
218 if (panel_position
& BOTTOM
) {
219 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ server
.monitor
[panel
->monitor
].height
- panel
->area
.height
- panel
->marginy
;
222 panel
->posy
= server
.monitor
[panel
->monitor
].y
+ ((server
.monitor
[panel
->monitor
].height
- panel
->area
.height
) / 2);
225 // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, panel->area.height);
238 // font allocated once
239 if (panel1
[0].g_task
.font_desc
) {
240 pango_font_description_free(panel1
[0].g_task
.font_desc
);
241 panel1
[0].g_task
.font_desc
= 0;
246 for (i
=0 ; i
< nb_panel
; i
++) {
252 XFreePixmap(server
.dsp
, p
->temp_pmap
);
256 XDestroyWindow(server
.dsp
, p
->main_win
);
261 if (panel1
) free(panel1
);
266 void resize_panel(void *obj
)
268 Panel
*panel
= (Panel
*)obj
;
270 if (panel_horizontal
) {
271 int taskbar_width
, modulo_width
= 0;
273 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
274 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
275 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
276 #ifdef ENABLE_BATTERY
277 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
278 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
280 // TODO : systray only on first panel. search better implementation !
281 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
282 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
284 if (panel_mode
== MULTI_DESKTOP
) {
285 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
286 taskbar_width
= width
/ panel
->nb_desktop
;
287 modulo_width
= width
% panel
->nb_desktop
;
290 // change posx and width for all taskbar
292 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
293 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
294 panel
->taskbar
[i
].area
.posx
= posx
;
295 panel
->taskbar
[i
].area
.width
= taskbar_width
;
296 panel
->taskbar
[i
].area
.resize
= 1;
298 panel
->taskbar
[i
].area
.width
++;
301 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
302 if (panel_mode
== MULTI_DESKTOP
)
303 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
307 int taskbar_height
, modulo_height
= 0;
310 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
311 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
312 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
313 #ifdef ENABLE_BATTERY
314 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
315 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
317 // TODO : systray only on first panel. search better implementation !
318 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
319 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
321 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
322 if (panel_mode
== MULTI_DESKTOP
) {
323 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
324 taskbar_height
= height
/ panel
->nb_desktop
;
325 modulo_height
= height
% panel
->nb_desktop
;
328 // change posy and height for all taskbar
329 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
330 panel
->taskbar
[i
].area
.posy
= posy
;
331 panel
->taskbar
[i
].area
.height
= taskbar_height
;
332 panel
->taskbar
[i
].area
.resize
= 1;
334 panel
->taskbar
[i
].area
.height
++;
337 if (panel_mode
== MULTI_DESKTOP
)
338 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
344 void visible_object()
349 for (i
=0 ; i
< nb_panel
; i
++) {
353 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
354 taskbar
= &panel
->taskbar
[j
];
355 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
356 // SINGLE_DESKTOP and not current desktop
357 taskbar
->area
.on_screen
= 0;
360 taskbar
->area
.on_screen
= 1;
368 void set_panel_properties(Panel
*p
)
370 XStoreName (server
.dsp
, p
->main_win
, "tint2");
373 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
375 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
380 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
381 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
384 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
385 if (panel_horizontal
) {
386 if (panel_position
& TOP
) {
387 struts
[2] = p
->area
.height
+ p
->marginy
;
389 // p->area.width - 1 allowed full screen on monitor 2
390 struts
[9] = p
->posx
+ p
->area
.width
- 1;
393 struts
[3] = p
->area
.height
+ p
->marginy
;
394 struts
[10] = p
->posx
;
395 // p->area.width - 1 allowed full screen on monitor 2
396 struts
[11] = p
->posx
+ p
->area
.width
- 1;
400 if (panel_position
& LEFT
) {
401 struts
[0] = p
->area
.width
+ p
->marginx
;
403 // p->area.width - 1 allowed full screen on monitor 2
404 struts
[5] = p
->posy
+ p
->area
.height
- 1;
407 struts
[1] = p
->area
.width
+ p
->marginx
;
409 // p->area.width - 1 allowed full screen on monitor 2
410 struts
[7] = p
->posy
+ p
->area
.height
- 1;
413 // Old specification : fluxbox need _NET_WM_STRUT.
414 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
415 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
417 // Sticky and below other window
419 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
421 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
422 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
423 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
424 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
425 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
427 // Fixed position and non-resizable window
428 XSizeHints size_hints
;
429 size_hints
.flags
= PPosition
|PMinSize
|PMaxSize
;
430 size_hints
.min_width
= size_hints
.max_width
= p
->area
.width
;
431 size_hints
.min_height
= size_hints
.max_height
= p
->area
.height
;
432 XSetWMNormalHints(server
.dsp
, p
->main_win
, &size_hints
);
437 // TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
438 wmhints
.icon_window
= wmhints
.window_group
= p
->main_win
;
439 wmhints
.flags
= StateHint
| IconWindowHint
;
440 wmhints
.initial_state
= WithdrawnState
;
443 wmhints
.flags
= InputHint
;
444 wmhints
.input
= False
;
446 XSetWMHints(server
.dsp
, p
->main_win
, &wmhints
);
449 long prop
[5] = { 2, 0, 0, 0, 0 };
450 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
452 // XdndAware - Register for Xdnd events
454 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
.XdndAware
, XA_ATOM
, 32, PropModeReplace
, (unsigned char*)&version
, 1);
458 void set_panel_background(Panel
*p
)
462 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
463 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
465 // copy background (server.root_pmap) in panel.area.pix.pmap
468 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
469 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
470 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
472 // draw background panel
475 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
476 c
= cairo_create (cs
);
478 draw_background(&p
->area
, c
, 0);
481 cairo_surface_destroy (cs
);
483 // redraw panel's object
486 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
493 Panel
*get_panel(Window win
)
496 for (i
=0 ; i
< nb_panel
; i
++) {
497 if (panel1
[i
].main_win
== win
) {