]> Dogcows Code - chaz/tint2/blob - src/panel.c
fixed bugs with new design (first step)
[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 <X11/Xlib.h>
20 #include <X11/Xutil.h>
21 #include <X11/Xatom.h>
22 #include <cairo.h>
23 #include <cairo-xlib.h>
24 #include <pango/pangocairo.h>
25
26 #include "server.h"
27 #include "window.h"
28 #include "task.h"
29 #include "panel.h"
30
31
32 void visual_refresh ()
33 {
34 if (!server.root_pmap) {
35 Pixmap wall = get_root_pixmap();
36
37 server.root_pmap = server_create_pixmap (panel.area.width, panel.area.height);
38
39 XCopyArea (server.dsp, wall, server.root_pmap, server.gc, server.posx, server.posy, panel.area.width, panel.area.height, 0, 0);
40
41 redraw (&panel.area);
42 }
43
44 if (server.pmap) XFreePixmap (server.dsp, server.pmap);
45 server.pmap = server_create_pixmap (panel.area.width, panel.area.height);
46
47 XCopyArea (server.dsp, server.root_pmap, server.pmap, server.gc, 0, 0, panel.area.width, panel.area.height, 0, 0);
48
49 draw (&panel.area);
50
51 XCopyArea (server.dsp, server.pmap, window.main_win, server.gc, 0, 0, panel.area.width, panel.area.height, 0, 0);
52 XFlush(server.dsp);
53 panel.refresh = 0;
54 }
55
56
57 void set_panel_properties (Window win)
58 {
59 XStoreName (server.dsp, win, "tint2");
60
61 // TODO: check if the name is really needed for a panel/taskbar ?
62 gsize len;
63 gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL);
64 if (name != NULL) {
65 XChangeProperty(server.dsp, win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len);
66 g_free(name);
67 }
68
69 // Dock
70 long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
71 XChangeProperty (server.dsp, win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
72
73 // Reserved space
74 long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
75 if (panel.position & TOP) {
76 struts[2] = panel.area.height + panel.marginy;
77 struts[8] = server.posx;
78 struts[9] = server.posx + panel.area.width;
79 }
80 else {
81 struts[3] = panel.area.height + panel.marginy;
82 struts[10] = server.posx;
83 struts[11] = server.posx + panel.area.width;
84 }
85 // Old specification : fluxbox need _NET_WM_STRUT.
86 XChangeProperty (server.dsp, win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
87 XChangeProperty (server.dsp, win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
88
89 // Sticky and below other window
90 val = 0xFFFFFFFF;
91 XChangeProperty (server.dsp, win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
92 Atom state[4];
93 state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
94 state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
95 state[2] = server.atom._NET_WM_STATE_STICKY;
96 state[3] = server.atom._NET_WM_STATE_BELOW;
97 XChangeProperty (server.dsp, win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4);
98
99 // Fixed position
100 XSizeHints size_hints;
101 size_hints.flags = PPosition;
102 XChangeProperty (server.dsp, win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &size_hints, sizeof (XSizeHints) / 4);
103
104 // Unfocusable
105 XWMHints wmhints;
106 wmhints.flags = InputHint;
107 wmhints.input = False;
108 XChangeProperty (server.dsp, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, (unsigned char *) &wmhints, sizeof (XWMHints) / 4);
109 }
110
111
112 void window_draw_panel ()
113 {
114 Window win;
115
116 /* panel position determined here */
117 if (panel.position & LEFT) server.posx = server.monitor[panel.monitor].x + panel.marginx;
118 else {
119 if (panel.position & RIGHT) server.posx = server.monitor[panel.monitor].x + server.monitor[panel.monitor].width - panel.area.width - panel.marginx;
120 else server.posx = server.monitor[panel.monitor].x + ((server.monitor[panel.monitor].width - panel.area.width) / 2);
121 }
122 if (panel.position & TOP) server.posy = server.monitor[panel.monitor].y + panel.marginy;
123 else server.posy = server.monitor[panel.monitor].y + server.monitor[panel.monitor].height - panel.area.height - panel.marginy;
124
125 /* Catch some events */
126 XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 };
127
128 /* XCreateWindow(display, parent, x, y, w, h, border, depth, class, visual, mask, attrib) */
129 if (window.main_win) XDestroyWindow(server.dsp, window.main_win);
130 win = XCreateWindow (server.dsp, server.root_win, server.posx, server.posy, panel.area.width, panel.area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
131
132 set_panel_properties (win);
133 window.main_win = win;
134
135 // replaced : server.gc = DefaultGC (server.dsp, 0);
136 if (server.gc) XFree(server.gc);
137 XGCValues gcValues;
138 server.gc = XCreateGC(server.dsp, win, (unsigned long) 0, &gcValues);
139
140 XMapWindow (server.dsp, win);
141 XFlush (server.dsp);
142 }
143
144
145 void visible_object()
146 {
147 if (panel.area.list) {
148 g_slist_free(panel.area.list);
149 panel.area.list = 0;
150 }
151
152 // list of visible objects
153 // start with clock because draw(clock) can resize others object
154 if (panel.clock.time1_format)
155 panel.area.list = g_slist_append(panel.area.list, &panel.clock);
156
157 int i, j;
158 Taskbar *taskbar;
159 for (i=0 ; i < panel.nb_desktop ; i++) {
160 for (j=0 ; j < panel.nb_monitor ; j++) {
161 taskbar = &panel.taskbar[index(i,j)];
162 if (panel.mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) continue;
163
164 panel.area.list = g_slist_append(panel.area.list, taskbar);
165 }
166 }
167 panel.refresh = 1;
168 }
169
170
This page took 0.045906 seconds and 5 git commands to generate.