]> Dogcows Code - chaz/tint2/blob - src/panel.c
big change : panel_monitor = all will draw one panel per monitor, panel_size accept...
[chaz/tint2] / src / panel.c
1 /**************************************************************************
2 *
3 * Copyright (C) 2008 Pål Staurland (staura@gmail.com)
4 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
5 *
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.
9 *
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 **************************************************************************/
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <X11/Xlib.h>
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
24 #include <cairo.h>
25 #include <cairo-xlib.h>
26 #include <pango/pangocairo.h>
27
28 #include "server.h"
29 #include "window.h"
30 #include "task.h"
31 #include "panel.h"
32
33
34 int signal_pending;
35 // --------------------------------------------------
36 // mouse events
37 int mouse_middle;
38 int mouse_right;
39 int mouse_scroll_up;
40 int mouse_scroll_down;
41
42 int panel_mode;
43 int panel_position;
44 int panel_refresh;
45
46 Task *task_active = 0;
47 Task *task_drag = 0;
48
49 Panel *panel1 = 0;
50 int nb_panel;
51
52
53
54 void init_panel()
55 {
56 int i;
57 Panel *p;
58 for (i=0 ; i < nb_panel ; i++) {
59 p = &panel1[i];
60
61 p->area.parent = 0;
62 p->area.panel = p;
63 p->g_taskbar.parent = p;
64 p->g_taskbar.panel = p;
65 p->g_task.area.panel = p;
66
67 if (p->pourcentx)
68 p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100;
69 else
70 p->area.width = p->initial_width;
71 if (p->pourcenty)
72 p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100;
73 else
74 p->area.height = p->initial_height;
75
76 // full width mode
77 if (!p->area.width)
78 p->area.width = server.monitor[p->monitor].width;
79
80 if (p->area.pix.border.rounded > p->area.height/2)
81 p->area.pix.border.rounded = p->area.height/2;
82
83 /* panel position determined here */
84 if (panel_position & LEFT) {
85 p->posx = server.monitor[p->monitor].x + p->marginx;
86 }
87 else {
88 if (panel_position & RIGHT) {
89 p->posx = server.monitor[p->monitor].x + server.monitor[p->monitor].width - p->area.width - p->marginx;
90 }
91 else {
92 p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2);
93 }
94 }
95 if (panel_position & TOP) {
96 p->posy = server.monitor[p->monitor].y + p->marginy;
97 }
98 else {
99 p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy;
100 }
101
102 // Catch some events
103 XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 };
104
105 // XCreateWindow(display, parent, x, y, w, h, border, depth, class, visual, mask, attrib)
106 // main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
107 if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
108 //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);
109 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);
110
111 set_panel_properties(p);
112 set_panel_background(p);
113
114 XMapWindow (server.dsp, p->main_win);
115
116 init_clock(&p->clock, &p->area);
117 }
118 }
119
120
121 void cleanup_panel()
122 {
123 if (!panel1) return;
124
125 cleanup_taskbar();
126
127 int i;
128 Panel *p;
129 for (i=0 ; i < nb_panel ; i++) {
130 p = &panel1[i];
131
132 free_area(&p->area);
133 free_area(&p->g_task.area);
134 free_area(&p->g_taskbar);
135 free_area(&p->clock.area);
136 if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
137 if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
138 }
139
140 // font allocated once
141 if (panel1[0].g_task.font_desc) pango_font_description_free(panel1[0].g_task.font_desc);
142
143 if (panel1) free(panel1);
144 panel1 = 0;
145 }
146
147
148 void visual_refresh (Panel *p)
149 {
150 if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
151 p->root_pmap = XCreatePixmap(server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
152
153 XCopyArea (server.dsp, p->area.pix.pmap, p->root_pmap, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
154
155 // draw child object
156 GSList *l = p->area.list;
157 for (; l ; l = l->next)
158 refresh (l->data);
159
160 XCopyArea(server.dsp, p->root_pmap, p->main_win, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
161
162 // main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
163 // this feature is disabled !
164 //XCopyArea (server.dsp, server.pmap, p->main_win, server.gc, p->area.paddingxlr, 0, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, 0);
165 }
166
167
168 void set_panel_properties(Panel *p)
169 {
170 XStoreName (server.dsp, p->main_win, "tint2");
171
172 // TODO: check if the name is really needed for a panel/taskbar ?
173 gsize len;
174 gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL);
175 if (name != NULL) {
176 XChangeProperty(server.dsp, p->main_win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len);
177 g_free(name);
178 }
179
180 // Dock
181 long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
182 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
183
184 // Reserved space
185 long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
186 if (panel_position & TOP) {
187 struts[2] = p->area.height + p->marginy;
188 struts[8] = p->posx;
189 // p->area.width - 1 allowed full screen on monitor 2
190 struts[9] = p->posx + p->area.width - 1;
191 }
192 else {
193 struts[3] = p->area.height + p->marginy;
194 struts[10] = p->posx;
195 // p->area.width - 1 allowed full screen on monitor 2
196 struts[11] = p->posx + p->area.width - 1;
197 }
198 // Old specification : fluxbox need _NET_WM_STRUT.
199 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
200 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
201
202 // Sticky and below other window
203 val = 0xFFFFFFFF;
204 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
205 Atom state[4];
206 state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
207 state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
208 state[2] = server.atom._NET_WM_STATE_STICKY;
209 state[3] = server.atom._NET_WM_STATE_BELOW;
210 XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4);
211
212 // Fixed position
213 XSizeHints size_hints;
214 size_hints.flags = PPosition;
215 XChangeProperty (server.dsp, p->main_win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &size_hints, sizeof (XSizeHints) / 4);
216
217 // Unfocusable
218 XWMHints wmhints;
219 wmhints.flags = InputHint;
220 wmhints.input = False;
221 XChangeProperty (server.dsp, p->main_win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, (unsigned char *) &wmhints, sizeof (XWMHints) / 4);
222
223 // Undecorated
224 long prop[5] = { 2, 0, 0, 0, 0 };
225 XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
226 }
227
228
229 void visible_object()
230 {
231 Panel *panel;
232 int i, j;
233
234 for (i=0 ; i < nb_panel ; i++) {
235 panel = &panel1[i];
236
237 if (panel->area.list) {
238 g_slist_free(panel->area.list);
239 panel->area.list = 0;
240 }
241
242 // list of visible objects
243 // start with clock because draw(clock) can resize others object
244 if (time1_format)
245 panel->area.list = g_slist_append(panel->area.list, &panel->clock);
246
247 Taskbar *taskbar;
248 for (j=0 ; j < panel->nb_desktop ; j++) {
249 taskbar = &panel->taskbar[j];
250 if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
251 // (SINGLE_DESKTOP or SINGLE_MONITOR) and not current desktop
252 continue;
253 }
254
255 panel->area.list = g_slist_append(panel->area.list, taskbar);
256 }
257 set_redraw(&panel->area);
258 }
259 panel_refresh = 1;
260 }
261
262
263 void set_panel_background(Panel *p)
264 {
265 get_root_pixmap();
266
267 if (p->area.pix.pmap) XFreePixmap (server.dsp, p->area.pix.pmap);
268 p->area.pix.pmap = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
269
270 // copy background (server.root_pmap) in panel
271 Window dummy;
272 int x, y;
273 XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
274 XSetTSOrigin(server.dsp, server.gc, -x, -y) ;
275 XFillRectangle(server.dsp, p->area.pix.pmap, server.gc, 0, 0, p->area.width, p->area.height);
276
277 // draw background panel
278 cairo_surface_t *cs;
279 cairo_t *c;
280 cs = cairo_xlib_surface_create (server.dsp, p->area.pix.pmap, server.visual, p->area.width, p->area.height);
281 c = cairo_create (cs);
282
283 draw_background(&p->area, c, 0);
284
285 cairo_destroy (c);
286 cairo_surface_destroy (cs);
287
288 // redraw panel
289 set_redraw (&p->area);
290
291 // copy background panel on desktop window
292 //XCopyArea (server.dsp, p->area.pix.pmap, server.root_win, server.gc_root, 0, 0, p->area.width, p->area.height, p->posx, p->posy);
293 }
294
295
296 Panel *get_panel(Window win)
297 {
298 int i;
299 for (i=0 ; i < nb_panel ; i++) {
300 if (panel1[i].main_win == win) {
301 return &panel1[i];
302 }
303 }
304 return 0;
305 }
306
This page took 0.049458 seconds and 5 git commands to generate.