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>
36 // --------------------------------------------------
41 int mouse_scroll_down
;
47 int panel_dock
=0; // default not in the dock
61 Imlib_Image default_icon
;
71 const gchar
* const *data_dirs
;
72 data_dirs
= g_get_system_data_dirs ();
73 for (i
= 0; data_dirs
[i
] != NULL
; i
++) {
74 path
= g_build_filename(data_dirs
[i
], "tint2", "default_icon.png", NULL
);
75 if (g_file_test (path
, G_FILE_TEST_EXISTS
))
76 default_icon
= imlib_load_image(path
);
80 for (i
=0 ; i
< nb_panel
; i
++) {
85 p
->area
.on_screen
= 1;
87 p
->area
._resize
= resize_panel
;
88 p
->g_taskbar
.parent
= p
;
89 p
->g_taskbar
.panel
= p
;
90 p
->g_task
.area
.panel
= p
;
93 if (p
->clock
.area
.on_screen
)
94 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
96 if (p
->battery
.area
.on_screen
)
97 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->battery
);
99 // systray only on first panel
100 if (systray
.area
.on_screen
&& i
== 0)
101 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
104 if (!p
->initial_width
) {
105 p
->initial_width
= 100;
110 if (panel_horizontal
) {
112 p
->area
.width
= (float)server
.monitor
[p
->monitor
].width
* p
->initial_width
/ 100;
114 p
->area
.width
= p
->initial_width
;
116 p
->area
.height
= (float)server
.monitor
[p
->monitor
].height
* p
->initial_height
/ 100;
118 p
->area
.height
= p
->initial_height
;
119 if (p
->area
.pix
.border
.rounded
> p
->area
.height
/2)
120 p
->area
.pix
.border
.rounded
= p
->area
.height
/2;
124 p
->area
.height
= (float)server
.monitor
[p
->monitor
].height
* p
->initial_width
/ 100;
126 p
->area
.height
= p
->initial_width
;
128 p
->area
.width
= (float)server
.monitor
[p
->monitor
].width
* p
->initial_height
/ 100;
130 p
->area
.width
= p
->initial_height
;
131 if (p
->area
.pix
.border
.rounded
> p
->area
.width
/2)
132 p
->area
.pix
.border
.rounded
= p
->area
.width
/2;
135 /* panel position determined here */
136 if (panel_position
& LEFT
) {
137 p
->posx
= server
.monitor
[p
->monitor
].x
+ p
->marginx
;
140 if (panel_position
& RIGHT
) {
141 p
->posx
= server
.monitor
[p
->monitor
].x
+ server
.monitor
[p
->monitor
].width
- p
->area
.width
- p
->marginx
;
144 if (panel_horizontal
)
145 p
->posx
= server
.monitor
[p
->monitor
].x
+ ((server
.monitor
[p
->monitor
].width
- p
->area
.width
) / 2);
147 p
->posx
= server
.monitor
[p
->monitor
].x
+ p
->marginx
;
150 if (panel_position
& TOP
) {
151 p
->posy
= server
.monitor
[p
->monitor
].y
+ p
->marginy
;
154 if (panel_position
& BOTTOM
) {
155 p
->posy
= server
.monitor
[p
->monitor
].y
+ server
.monitor
[p
->monitor
].height
- p
->area
.height
- p
->marginy
;
158 p
->posy
= server
.monitor
[p
->monitor
].y
+ ((server
.monitor
[p
->monitor
].height
- p
->area
.height
) / 2);
161 // printf("panel : posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height);
164 long event_mask
= ExposureMask
|ButtonPressMask
|ButtonReleaseMask
;
165 if (g_tooltip
.enabled
)
166 event_mask
|= PointerMotionMask
|LeaveWindowMask
;
167 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, event_mask
, NoEventMask
, False
, 0, 0 };
168 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
169 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
);
171 set_panel_properties(p
);
172 set_panel_background(p
);
174 XMapWindow (server
.dsp
, p
->main_win
);
191 imlib_context_set_image(default_icon
);
195 // font allocated once
196 if (panel1
[0].g_task
.font_desc
) {
197 pango_font_description_free(panel1
[0].g_task
.font_desc
);
198 panel1
[0].g_task
.font_desc
= 0;
203 for (i
=0 ; i
< nb_panel
; i
++) {
207 free_area(&p
->g_task
.area
);
208 free_area(&p
->g_taskbar
);
211 XFreePixmap(server
.dsp
, p
->temp_pmap
);
215 XDestroyWindow(server
.dsp
, p
->main_win
);
220 if (panel1
) free(panel1
);
223 if (g_tooltip
.window
) {
224 XDestroyWindow(server
.dsp
, g_tooltip
.window
);
225 g_tooltip
.window
= 0;
227 if (g_tooltip
.font_desc
) {
228 pango_font_description_free(g_tooltip
.font_desc
);
229 g_tooltip
.font_desc
= 0;
234 void resize_panel(void *obj
)
236 Panel
*panel
= (Panel
*)obj
;
238 if (panel_horizontal
) {
239 int taskbar_width
, modulo_width
= 0;
241 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
242 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
243 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
244 #ifdef ENABLE_BATTERY
245 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.width
)
246 taskbar_width
-= (panel
->battery
.area
.width
+ panel
->area
.paddingx
);
248 // TODO : systray only on first panel. search better implementation !
249 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
250 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
252 if (panel_mode
== MULTI_DESKTOP
) {
253 int width
= taskbar_width
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
254 taskbar_width
= width
/ panel
->nb_desktop
;
255 modulo_width
= width
% panel
->nb_desktop
;
258 // change posx and width for all taskbar
260 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
261 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
262 panel
->taskbar
[i
].area
.posx
= posx
;
263 panel
->taskbar
[i
].area
.width
= taskbar_width
;
264 panel
->taskbar
[i
].area
.resize
= 1;
266 panel
->taskbar
[i
].area
.width
++;
269 //printf("taskbar %d : posx %d, width, %d, posy %d\n", i, posx, panel->taskbar[i].area.width, posx + panel->taskbar[i].area.width);
270 if (panel_mode
== MULTI_DESKTOP
)
271 posx
+= panel
->taskbar
[i
].area
.width
+ panel
->area
.paddingx
;
275 int taskbar_height
, modulo_height
= 0;
278 taskbar_height
= panel
->area
.height
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
279 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.height
)
280 taskbar_height
-= (panel
->clock
.area
.height
+ panel
->area
.paddingx
);
281 #ifdef ENABLE_BATTERY
282 if (panel
->battery
.area
.on_screen
&& panel
->battery
.area
.height
)
283 taskbar_height
-= (panel
->battery
.area
.height
+ panel
->area
.paddingx
);
285 // TODO : systray only on first panel. search better implementation !
286 if (systray
.area
.on_screen
&& systray
.area
.height
&& panel
== &panel1
[0])
287 taskbar_height
-= (systray
.area
.height
+ panel
->area
.paddingx
);
289 posy
= panel
->area
.height
- panel
->area
.pix
.border
.width
- panel
->area
.paddingxlr
- taskbar_height
;
290 if (panel_mode
== MULTI_DESKTOP
) {
291 int height
= taskbar_height
- ((panel
->nb_desktop
-1) * panel
->area
.paddingx
);
292 taskbar_height
= height
/ panel
->nb_desktop
;
293 modulo_height
= height
% panel
->nb_desktop
;
296 // change posy and height for all taskbar
297 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
298 panel
->taskbar
[i
].area
.posy
= posy
;
299 panel
->taskbar
[i
].area
.height
= taskbar_height
;
300 panel
->taskbar
[i
].area
.resize
= 1;
302 panel
->taskbar
[i
].area
.height
++;
305 if (panel_mode
== MULTI_DESKTOP
)
306 posy
+= panel
->taskbar
[i
].area
.height
+ panel
->area
.paddingx
;
312 void visible_object()
317 for (i
=0 ; i
< nb_panel
; i
++) {
321 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
322 taskbar
= &panel
->taskbar
[j
];
323 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
324 // SINGLE_DESKTOP and not current desktop
325 taskbar
->area
.on_screen
= 0;
328 taskbar
->area
.on_screen
= 1;
336 void set_panel_properties(Panel
*p
)
338 XStoreName (server
.dsp
, p
->main_win
, "tint2");
340 // TODO: check if the name is really needed for a panel/taskbar ?
342 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
344 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
349 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
350 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
353 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
354 if (panel_horizontal
) {
355 if (panel_position
& TOP
) {
356 struts
[2] = p
->area
.height
+ p
->marginy
;
358 // p->area.width - 1 allowed full screen on monitor 2
359 struts
[9] = p
->posx
+ p
->area
.width
- 1;
362 struts
[3] = p
->area
.height
+ p
->marginy
;
363 struts
[10] = p
->posx
;
364 // p->area.width - 1 allowed full screen on monitor 2
365 struts
[11] = p
->posx
+ p
->area
.width
- 1;
369 if (panel_position
& LEFT
) {
370 struts
[0] = p
->area
.width
+ p
->marginx
;
372 // p->area.width - 1 allowed full screen on monitor 2
373 struts
[5] = p
->posy
+ p
->area
.height
- 1;
376 struts
[1] = p
->area
.width
+ p
->marginx
;
378 // p->area.width - 1 allowed full screen on monitor 2
379 struts
[7] = p
->posy
+ p
->area
.height
- 1;
382 // Old specification : fluxbox need _NET_WM_STRUT.
383 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
384 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
386 // Sticky and below other window
388 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
390 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
391 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
392 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
393 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
394 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
397 XSizeHints size_hints
;
398 size_hints
.flags
= PPosition
;
399 XChangeProperty (server
.dsp
, p
->main_win
, XA_WM_NORMAL_HINTS
, XA_WM_SIZE_HINTS
, 32, PropModeReplace
, (unsigned char *) &size_hints
, sizeof (XSizeHints
) / 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);
425 void set_panel_background(Panel
*p
)
429 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
430 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
432 // copy background (server.root_pmap) in panel.area.pix.pmap
435 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
436 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
437 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
439 // draw background panel
442 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
443 c
= cairo_create (cs
);
445 draw_background(&p
->area
, c
, 0);
448 cairo_surface_destroy (cs
);
450 // redraw panel's object
453 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
460 Panel
*get_panel(Window win
)
463 for (i
=0 ; i
< nb_panel
; i
++) {
464 if (panel1
[i
].main_win
== win
) {