7 #include <openbox/theme.h>
11 static RrAppearance *background;
12 static RrAppearance *focused_task;
13 static RrAppearance *iconified_task;
14 static RrAppearance *unfocused_task;
15 static RrAppearance *normal_text;
16 static RrAppearance *iconified_text;
17 static RrAppearance *shaded_text;
18 static RrAppearance *focused_text;
19 static RrAppearance *a_icon;
20 static RrColor *normal_text_color;
21 static RrColor *focused_text_color;
23 /* you can edit these */
24 #define MAX_TASK_WIDTH 500
25 #define HEIGHT (24 + sc->theme->obwidth)
27 #define ICON_SIZE (HEIGHT - sc->theme->obwidth - PADDING*2)
28 #define ICON_SPACE (ICON_SIZE + PADDING*2)
30 static void set_icon_geometry(screen *sc, taskbar *tb, task *tk);
32 #define SURF(x) with->surface.x
33 #define TEXT(x) with->texture[0].data.text.x
34 #define USE(x) (with = x)
35 #define SETTEXT(x, y, z) with->texture[0].type = RR_TEXTURE_TEXT; \
36 with->texture[0].data.text.font = x; \
37 with->texture[0].data.text.justify = y; \
38 with->texture[0].data.text.ellipsize = z;
39 #define SETSHADOW(y, z, u, v) with->texture[0].data.text.shadow_offset_x = y; \
40 with->texture[0].data.text.shadow_offset_y = z; \
41 with->texture[0].data.text.shadow_alpha = u; \
42 with->texture[0].data.text.shadow_color = v;
44 void gui_init(screen *sc)
48 gcv.graphics_exposures = False;
49 sc->fore_gc = XCreateGC(sc->dd, sc->root, GCGraphicsExposures, &gcv);
54 void gui_load_theme(screen *sc)
60 printf("loading theme\n");
62 RrAppearanceFree(background);
63 RrAppearanceFree(focused_task);
64 RrAppearanceFree(iconified_task);
65 RrAppearanceFree(unfocused_task);
66 RrAppearanceFree(normal_text);
67 RrAppearanceFree(iconified_text);
68 RrAppearanceFree(shaded_text);
69 RrAppearanceFree(focused_text);
70 RrAppearanceFree(a_icon);
71 RrColorFree(normal_text_color);
72 RrColorFree(focused_text_color);
74 name = xprop_get_utf8(sc, sc->root, _OB_THEME);
75 RrThemeFree(sc->theme);
76 sc->theme = RrThemeNew(sc->rr, name, TRUE, NULL, NULL, NULL, NULL, NULL);
78 /* We don't allow different fonts for various window states... */
79 font = RrFontOpen(sc->rr, "Candara, sans", 10,
80 RR_FONTWEIGHT_NORMAL, RR_FONTSLANT_NORMAL);
82 /* this appearance will be used to draw icons */
83 a_icon = RrAppearanceNew(sc->rr, 1);
85 SURF(grad) = RR_SURFACE_PARENTREL;
86 SURF(parentx) = PADDING;
87 SURF(parenty) = PADDING;
88 a_icon->texture[0].type = RR_TEXTURE_RGBA;
90 /* this is the appearance for the background of the panel */
91 background = RrAppearanceCopy(sc->theme->osd_hilite_bg);
93 /* this is the appearance for unfocused tasks,
94 * text needs to be separate appearances so we can align it correctly */
95 unfocused_task = RrAppearanceNew(sc->rr, 0);
97 SURF(parent) = background;
98 SURF(grad) = RR_SURFACE_PARENTREL;
100 /* ... for iconified tasks, also used for shaded ones currently */
101 iconified_task = RrAppearanceCopy(unfocused_task);
103 SURF(parent) = background; /* RrAppearanceCopy doesn't copy .parent */
105 /* ... for focused tasks */
106 focused_task = RrAppearanceCopy(sc->theme->a_hover_focused_max);
108 SURF(parent) = background;
110 /* this is the text used for all normal unfocused tasks */
111 /* we don't set .parent here, but in draw_task, since we
112 * want to combine _task and _text semirandomly.
113 * XXX plz not when themes are here */
114 normal_text = RrAppearanceCopy(sc->theme->osd_hilite_label);
115 normal_text_color = RrColorNew(sc->rr,
116 RrColorRed(sc->theme->osd_color),
117 RrColorGreen(sc->theme->osd_color),
118 RrColorBlue(sc->theme->osd_color));
120 TEXT(color) = normal_text_color;
121 TEXT(ellipsize) = RR_ELLIPSIZE_END;
123 /* ... for iconified tasks */
124 iconified_text = RrAppearanceCopy(normal_text);
125 shaded_text = RrAppearanceCopy(normal_text);
127 focused_text = RrAppearanceCopy(normal_text);
130 RrColorRed(sc->theme->titlebut_hover_focused_color),
131 RrColorGreen(sc->theme->titlebut_hover_focused_color),
132 RrColorBlue(sc->theme->titlebut_hover_focused_color));
134 TEXT(color) = focused_text_color;
135 TEXT(ellipsize) = RR_ELLIPSIZE_END;
140 void gui_create_taskbar(screen *sc, taskbar *tb)
142 XSizeHints size_hints;
143 XSetWindowAttributes att;
146 att.event_mask = ButtonPressMask;
148 /* XXX make this stuff conigurable */
149 tb->w = sc->width * 0.7;
152 tb->x = (sc->width - tb->w) / 2;
153 tb->y = sc->height - tb->h;
155 tb->win = XCreateWindow(/* display */ sc->dd,
156 /* parent */ sc->root,
162 /* depth */ CopyFromParent,
163 /* class */ InputOutput,
164 /* visual */ CopyFromParent,
165 /*value mask*/ CWEventMask,
167 tb->bgwin = XCreateWindow(/* display */ sc->dd,
168 /* parent */ tb->win,
174 /* depth */ CopyFromParent,
175 /* class */ InputOutput,
176 /* visual */ CopyFromParent,
181 /* reside on ALL desktops */
182 xprop_set_num(sc, tb->win, _NET_WM_DESKTOP, 0xFFFFFFFF);
183 xprop_set_atom(sc, tb->win, _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DOCK);
184 xprop_set_atom(sc, tb->win, _NET_WM_STATE, _NET_WM_STATE_BELOW);
185 xprop_set_string(sc, tb->win, WM_NAME, "rspanel");
187 /* make sure the WM obays our window position */
188 size_hints.flags = PPosition;
189 size_hints.x = tb->x;
190 size_hints.y = tb->y;
191 /*XSetWMNormalHints (sc->dd, tb->win, &size_hints); */
192 XChangeProperty(sc->dd, tb->win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32,
193 PropModeReplace, (unsigned char *)&size_hints,
194 sizeof(XSizeHints) / 4);
196 xclhints.res_name = "rspanel";
197 xclhints.res_class = "RSPanel";
198 XSetClassHint(sc->dd, tb->win, &xclhints);
200 XMapWindow(sc->dd, tb->win);
201 XMapWindow(sc->dd, tb->bgwin);
204 void gui_draw_task(screen *sc, taskbar *tb, task *tk, int redraw)
214 else if (tk->focused)
225 else if (tk->focused)
231 name = g_strconcat("(", tk->name, ")", NULL);
233 name = g_strdup(tk->name);
235 i = icon_get_best(tk->icons, tk->nicons, ICON_SIZE, ICON_SIZE);
238 RrTextureRGBA *d = &a_icon->texture[0].data.rgba;
239 icon_space = ICON_SPACE;
240 a_icon->surface.parent = b;
241 a_icon->surface.parentx = (icon_space - ICON_SIZE) / 2;
242 a_icon->surface.parenty = (tb->drawh - ICON_SIZE) / 2;
244 d->height = i->height;
245 d->alpha = tk->iconified ? 0x70 : tk->shaded ? 0xB0 : 0xff;
249 a->surface.parent = b;
250 a->surface.parentx = icon_space;
251 a->texture[0].data.text.string = name;
252 b->surface.parentx = tk->pos_x;
254 RrPaintPixmap(b, tk->width, tb->drawh);
255 RrPaintPixmap(a, tk->width-icon_space, tb->drawh);
258 RrPaintPixmap(a_icon, ICON_SIZE, ICON_SIZE);
259 XCopyArea(sc->dd, a_icon->pixmap, b->pixmap, sc->fore_gc, 0, 0,
260 ICON_SIZE, ICON_SIZE,
261 (icon_space - ICON_SIZE) / 2,
262 (tb->drawh - ICON_SIZE) / 2);
265 XCopyArea(sc->dd, a->pixmap, b->pixmap, sc->fore_gc, 0, 0,
266 tk->width-icon_space, tb->drawh,
268 XCopyArea(sc->dd, b->pixmap, tb->bg, sc->fore_gc, 0, 0,
269 tk->width, tb->drawh, tk->pos_x, 0);
271 XFreePixmap(sc->dd, a->pixmap);
272 XFreePixmap(sc->dd, b->pixmap);
273 XFreePixmap(sc->dd, a_icon->pixmap);
275 XSetWindowBackgroundPixmap(sc->dd, tb->bgwin, tb->bg);
276 XClearWindow(sc->dd, tb->bgwin);
282 void gui_draw_taskbar(screen *sc, taskbar *tb)
291 pager_size = TEXTPAD;
294 tb->draww = tb->w - sc->theme->obwidth * 2;
295 tb->drawh = tb->h - sc->theme->obwidth;
296 XMoveResizeWindow(sc->dd, tb->bgwin, 0,
297 (tb->at_top ? -sc->theme->obwidth : 0),
298 tb->draww, tb->drawh);
301 width = tb->draww - (pager_size + GRILL_WIDTH);
302 #warning only rerender if width changed!
303 if (tb->bg) XFreePixmap(sc->dd, tb->bg);
304 tb->bg = XCreatePixmap(sc->dd, sc->root, tb->draww, tb->drawh,
307 XFreePixmap(sc->dd, RrPaintPixmap(background, tb->draww, tb->drawh));
308 XCopyArea(sc->dd, background->pixmap, tb->bg, sc->fore_gc, 0, 0,
309 tb->draww, tb->drawh, 0, 0);
311 /* find the number of visible tasks */
312 for (tk = tb->task_list; tk; tk = tk->next) {
321 taskw = width / num_tasks;
322 if (taskw > MAX_TASK_WIDTH)
323 taskw = MAX_TASK_WIDTH;
325 for (tk = tb->task_list; tk; tk = tk->next) {
329 tk->width = taskw - 1;
330 gui_draw_task(sc, tb, tk, FALSE);
331 set_icon_geometry(sc, tb, tk);
336 XSetWindowBackgroundPixmap(sc->dd, tb->bgwin, tb->bg);
337 XClearWindow(sc->dd, tb->bgwin);
338 XSetWindowBorderWidth(sc->dd, tb->bgwin, sc->theme->obwidth);
339 XSetWindowBorder(sc->dd, tb->bgwin,
340 RrColorPixel(sc->theme->osd_border_color));
343 void gui_move_taskbar(screen *sc, taskbar *tb)
348 tb->x = TEXTPAD - tb->w;
351 tb->y = sc->height - tb->h;
353 XMoveWindow(sc->dd, tb->win, tb->x, tb->y);
355 gui_draw_taskbar(sc, tb);
358 static void set_icon_geometry(screen *sc, taskbar *tb, task *tk)
362 coords[0] = tb->x + tk->pos_x;
364 coords[2] = MAX(tk->width, 1);
367 xprop_set_array(sc, tk->win, _NET_WM_ICON_GEOMETRY, coords, 4);