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 Task
*task_active
= 0;
59 for (i
=0 ; i
< nb_panel
; i
++) {
64 p
->area
.on_screen
= 1;
66 p
->area
._resize
= resize_panel
;
67 p
->g_taskbar
.parent
= p
;
68 p
->g_taskbar
.panel
= p
;
69 p
->g_task
.area
.panel
= p
;
72 if (p
->clock
.area
.on_screen
)
73 p
->area
.list
= g_slist_append(p
->area
.list
, &p
->clock
);
74 if (systray
.area
.on_screen
&& i
== 0) {
75 // systray only on first panel
76 p
->area
.list
= g_slist_append(p
->area
.list
, &systray
);
81 p
->area
.width
= (float)server
.monitor
[p
->monitor
].width
* p
->initial_width
/ 100;
83 p
->area
.width
= p
->initial_width
;
85 p
->area
.height
= (float)server
.monitor
[p
->monitor
].height
* p
->initial_height
/ 100;
87 p
->area
.height
= p
->initial_height
;
91 p
->area
.width
= server
.monitor
[p
->monitor
].width
;
93 if (p
->area
.pix
.border
.rounded
> p
->area
.height
/2)
94 p
->area
.pix
.border
.rounded
= p
->area
.height
/2;
96 /* panel position determined here */
97 if (panel_position
& LEFT
) {
98 p
->posx
= server
.monitor
[p
->monitor
].x
+ p
->marginx
;
101 if (panel_position
& RIGHT
) {
102 p
->posx
= server
.monitor
[p
->monitor
].x
+ server
.monitor
[p
->monitor
].width
- p
->area
.width
- p
->marginx
;
105 p
->posx
= server
.monitor
[p
->monitor
].x
+ ((server
.monitor
[p
->monitor
].width
- p
->area
.width
) / 2);
108 if (panel_position
& TOP
) {
109 p
->posy
= server
.monitor
[p
->monitor
].y
+ p
->marginy
;
112 p
->posy
= server
.monitor
[p
->monitor
].y
+ server
.monitor
[p
->monitor
].height
- p
->area
.height
- p
->marginy
;
116 XSetWindowAttributes att
= { ParentRelative
, 0L, 0, 0L, 0, 0, Always
, 0L, 0L, False
, ExposureMask
|ButtonPressMask
|ButtonReleaseMask
, NoEventMask
, False
, 0, 0 };
118 // XCreateWindow(display, parent, x, y, w, h, border, depth, class, visual, mask, attrib)
119 // main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
120 if (p
->main_win
) XDestroyWindow(server
.dsp
, p
->main_win
);
121 //win = XCreateWindow (server.dsp, server.root_win, p->posx+p->area.paddingxlr, p->posy, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
122 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
);
124 set_panel_properties(p
);
125 set_panel_background(p
);
127 XMapWindow (server
.dsp
, p
->main_win
);
140 // font allocated once
141 if (panel1
[0].g_task
.font_desc
) {
142 pango_font_description_free(panel1
[0].g_task
.font_desc
);
143 panel1
[0].g_task
.font_desc
= 0;
148 for (i
=0 ; i
< nb_panel
; i
++) {
152 free_area(&p
->g_task
.area
);
153 free_area(&p
->g_taskbar
);
156 XFreePixmap(server
.dsp
, p
->temp_pmap
);
160 XDestroyWindow(server
.dsp
, p
->main_win
);
165 if (panel1
) free(panel1
);
170 void resize_panel(void *obj
)
172 Panel
*panel
= (Panel
*)obj
;
173 int taskbar_width
, modulo_width
, taskbar_on_screen
;
175 //printf("resize_panel : : posx et width des barres de taches\n");
177 if (panel_mode
== MULTI_DESKTOP
) taskbar_on_screen
= panel
->nb_desktop
;
178 else taskbar_on_screen
= 1;
180 taskbar_width
= panel
->area
.width
- (2 * panel
->area
.paddingxlr
) - (2 * panel
->area
.pix
.border
.width
);
181 if (panel
->clock
.area
.on_screen
&& panel
->clock
.area
.width
)
182 taskbar_width
-= (panel
->clock
.area
.width
+ panel
->area
.paddingx
);
183 // TODO : systray only on first panel. search better implementation !
184 if (systray
.area
.on_screen
&& systray
.area
.width
&& panel
== &panel1
[0])
185 taskbar_width
-= (systray
.area
.width
+ panel
->area
.paddingx
);
187 taskbar_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
->area
.paddingx
)) / taskbar_on_screen
;
189 if (taskbar_on_screen
> 1)
190 modulo_width
= (taskbar_width
- ((taskbar_on_screen
-1) * panel
->area
.paddingx
)) % taskbar_on_screen
;
194 // change posx and width for all taskbar
195 int i
, modulo
=0, posx
=0;
196 for (i
=0 ; i
< panel
->nb_desktop
; i
++) {
197 if ((i
% taskbar_on_screen
) == 0) {
198 posx
= panel
->area
.pix
.border
.width
+ panel
->area
.paddingxlr
;
199 modulo
= modulo_width
;
201 else posx
+= taskbar_width
+ panel
->area
.paddingx
;
203 panel
->taskbar
[i
].area
.posx
= posx
;
204 panel
->taskbar
[i
].area
.width
= taskbar_width
;
205 panel
->taskbar
[i
].area
.resize
= 1;
207 panel
->taskbar
[i
].area
.width
++;
214 void visible_object()
219 for (i
=0 ; i
< nb_panel
; i
++) {
223 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
224 taskbar
= &panel
->taskbar
[j
];
225 if (panel_mode
!= MULTI_DESKTOP
&& taskbar
->desktop
!= server
.desktop
) {
226 // (SINGLE_DESKTOP or SINGLE_MONITOR) and not current desktop
227 taskbar
->area
.on_screen
= 0;
230 taskbar
->area
.on_screen
= 1;
238 void set_panel_properties(Panel
*p
)
240 XStoreName (server
.dsp
, p
->main_win
, "tint2");
242 // TODO: check if the name is really needed for a panel/taskbar ?
244 gchar
*name
= g_locale_to_utf8("tint2", -1, NULL
, &len
, NULL
);
246 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 8, PropModeReplace
, (unsigned char *) name
, (int) len
);
251 long val
= server
.atom
._NET_WM_WINDOW_TYPE_DOCK
;
252 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_WINDOW_TYPE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
255 long struts
[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
256 if (panel_position
& TOP
) {
257 struts
[2] = p
->area
.height
+ p
->marginy
;
259 // p->area.width - 1 allowed full screen on monitor 2
260 struts
[9] = p
->posx
+ p
->area
.width
- 1;
263 struts
[3] = p
->area
.height
+ p
->marginy
;
264 struts
[10] = p
->posx
;
265 // p->area.width - 1 allowed full screen on monitor 2
266 struts
[11] = p
->posx
+ p
->area
.width
- 1;
268 // Old specification : fluxbox need _NET_WM_STRUT.
269 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 4);
270 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STRUT_PARTIAL
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &struts
, 12);
272 // Sticky and below other window
274 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_DESKTOP
, XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &val
, 1);
276 state
[0] = server
.atom
._NET_WM_STATE_SKIP_PAGER
;
277 state
[1] = server
.atom
._NET_WM_STATE_SKIP_TASKBAR
;
278 state
[2] = server
.atom
._NET_WM_STATE_STICKY
;
279 state
[3] = server
.atom
._NET_WM_STATE_BELOW
;
280 XChangeProperty (server
.dsp
, p
->main_win
, server
.atom
._NET_WM_STATE
, XA_ATOM
, 32, PropModeReplace
, (unsigned char *) state
, 4);
283 XSizeHints size_hints
;
284 size_hints
.flags
= PPosition
;
285 XChangeProperty (server
.dsp
, p
->main_win
, XA_WM_NORMAL_HINTS
, XA_WM_SIZE_HINTS
, 32, PropModeReplace
, (unsigned char *) &size_hints
, sizeof (XSizeHints
) / 4);
289 wmhints
.flags
= InputHint
;
290 wmhints
.input
= False
;
291 XChangeProperty (server
.dsp
, p
->main_win
, XA_WM_HINTS
, XA_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) &wmhints
, sizeof (XWMHints
) / 4);
294 long prop
[5] = { 2, 0, 0, 0, 0 };
295 XChangeProperty(server
.dsp
, p
->main_win
, server
.atom
._MOTIF_WM_HINTS
, server
.atom
._MOTIF_WM_HINTS
, 32, PropModeReplace
, (unsigned char *) prop
, 5);
299 void set_panel_background(Panel
*p
)
303 if (p
->area
.pix
.pmap
) XFreePixmap (server
.dsp
, p
->area
.pix
.pmap
);
304 p
->area
.pix
.pmap
= XCreatePixmap (server
.dsp
, server
.root_win
, p
->area
.width
, p
->area
.height
, server
.depth
);
306 // copy background (server.root_pmap) in panel.area.pix.pmap
309 XTranslateCoordinates(server
.dsp
, p
->main_win
, server
.root_win
, 0, 0, &x
, &y
, &dummy
);
310 XSetTSOrigin(server
.dsp
, server
.gc
, -x
, -y
) ;
311 XFillRectangle(server
.dsp
, p
->area
.pix
.pmap
, server
.gc
, 0, 0, p
->area
.width
, p
->area
.height
);
313 // draw background panel
316 cs
= cairo_xlib_surface_create (server
.dsp
, p
->area
.pix
.pmap
, server
.visual
, p
->area
.width
, p
->area
.height
);
317 c
= cairo_create (cs
);
319 draw_background(&p
->area
, c
, 0);
322 cairo_surface_destroy (cs
);
324 // redraw panel's object
327 for (l0
= p
->area
.list
; l0
; l0
= l0
->next
) {
334 Panel
*get_panel(Window win
)
337 for (i
=0 ; i
< nb_panel
; i
++) {
338 if (panel1
[i
].main_win
== win
) {