1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 framerender.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
24 #include "framerender.h"
25 #include "render/theme.h"
27 static void framerender_label(ObFrame *self, RrAppearance *a);
28 static void framerender_icon(ObFrame *self, RrAppearance *a);
29 static void framerender_max(ObFrame *self, RrAppearance *a);
30 static void framerender_iconify(ObFrame *self, RrAppearance *a);
31 static void framerender_desk(ObFrame *self, RrAppearance *a);
32 static void framerender_shade(ObFrame *self, RrAppearance *a);
33 static void framerender_close(ObFrame *self, RrAppearance *a);
35 void framerender_frame(ObFrame *self)
37 if (frame_iconify_animating(self))
38 return; /* delay redrawing until the animation is done */
39 if (!self->need_render)
43 self->need_render = FALSE;
49 RrColorPixel(ob_rr_theme->cb_focused_color) :
50 RrColorPixel(ob_rr_theme->cb_unfocused_color));
52 XSetWindowBackground(ob_display, self->backback, px);
53 XClearWindow(ob_display, self->backback);
54 XSetWindowBackground(ob_display, self->innerleft, px);
55 XClearWindow(ob_display, self->innerleft);
56 XSetWindowBackground(ob_display, self->innertop, px);
57 XClearWindow(ob_display, self->innertop);
58 XSetWindowBackground(ob_display, self->innerright, px);
59 XClearWindow(ob_display, self->innerright);
60 XSetWindowBackground(ob_display, self->innerbottom, px);
61 XClearWindow(ob_display, self->innerbottom);
62 XSetWindowBackground(ob_display, self->innerbll, px);
63 XClearWindow(ob_display, self->innerbll);
64 XSetWindowBackground(ob_display, self->innerbrr, px);
65 XClearWindow(ob_display, self->innerbrr);
66 XSetWindowBackground(ob_display, self->innerblb, px);
67 XClearWindow(ob_display, self->innerblb);
68 XSetWindowBackground(ob_display, self->innerbrb, px);
69 XClearWindow(ob_display, self->innerbrb);
72 RrColorPixel(ob_rr_theme->frame_focused_border_color) :
73 RrColorPixel(ob_rr_theme->frame_unfocused_border_color));
75 XSetWindowBackground(ob_display, self->left, px);
76 XClearWindow(ob_display, self->left);
77 XSetWindowBackground(ob_display, self->right, px);
78 XClearWindow(ob_display, self->right);
80 XSetWindowBackground(ob_display, self->titleleft, px);
81 XClearWindow(ob_display, self->titleleft);
82 XSetWindowBackground(ob_display, self->titletop, px);
83 XClearWindow(ob_display, self->titletop);
84 XSetWindowBackground(ob_display, self->titletopleft, px);
85 XClearWindow(ob_display, self->titletopleft);
86 XSetWindowBackground(ob_display, self->titletopright, px);
87 XClearWindow(ob_display, self->titletopright);
88 XSetWindowBackground(ob_display, self->titleright, px);
89 XClearWindow(ob_display, self->titleright);
91 XSetWindowBackground(ob_display, self->handleleft, px);
92 XClearWindow(ob_display, self->handleleft);
93 XSetWindowBackground(ob_display, self->handletop, px);
94 XClearWindow(ob_display, self->handletop);
95 XSetWindowBackground(ob_display, self->handleright, px);
96 XClearWindow(ob_display, self->handleright);
97 XSetWindowBackground(ob_display, self->handlebottom, px);
98 XClearWindow(ob_display, self->handlebottom);
100 XSetWindowBackground(ob_display, self->lgripleft, px);
101 XClearWindow(ob_display, self->lgripleft);
102 XSetWindowBackground(ob_display, self->lgriptop, px);
103 XClearWindow(ob_display, self->lgriptop);
104 XSetWindowBackground(ob_display, self->lgripbottom, px);
105 XClearWindow(ob_display, self->lgripbottom);
107 XSetWindowBackground(ob_display, self->rgripright, px);
108 XClearWindow(ob_display, self->rgripright);
109 XSetWindowBackground(ob_display, self->rgriptop, px);
110 XClearWindow(ob_display, self->rgriptop);
111 XSetWindowBackground(ob_display, self->rgripbottom, px);
112 XClearWindow(ob_display, self->rgripbottom);
114 /* don't use the separator color for shaded windows */
115 if (!self->client->shaded)
116 px = (self->focused ?
117 RrColorPixel(ob_rr_theme->title_separator_focused_color) :
118 RrColorPixel(ob_rr_theme->title_separator_unfocused_color));
120 XSetWindowBackground(ob_display, self->titlebottom, px);
121 XClearWindow(ob_display, self->titlebottom);
124 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
125 RrAppearance *t, *l, *m, *n, *i, *d, *s, *c, *clear;
128 t = self->a_focused_title;
129 l = self->a_focused_label;
131 m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
132 ob_rr_theme->a_disabled_focused_max :
133 (self->client->max_vert || self->client->max_horz ?
135 ob_rr_theme->a_toggled_focused_pressed_max :
137 ob_rr_theme->a_toggled_hover_focused_max :
138 ob_rr_theme->a_toggled_focused_unpressed_max)) :
140 ob_rr_theme->a_focused_pressed_max :
142 ob_rr_theme->a_hover_focused_max :
143 ob_rr_theme->a_focused_unpressed_max))));
145 i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
146 ob_rr_theme->a_disabled_focused_iconify :
147 (self->iconify_press ?
148 ob_rr_theme->a_focused_pressed_iconify :
149 (self->iconify_hover ?
150 ob_rr_theme->a_hover_focused_iconify :
151 ob_rr_theme->a_focused_unpressed_iconify)));
152 d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
153 ob_rr_theme->a_disabled_focused_desk :
154 (self->client->desktop == DESKTOP_ALL ?
156 ob_rr_theme->a_toggled_focused_pressed_desk :
158 ob_rr_theme->a_toggled_hover_focused_desk :
159 ob_rr_theme->a_toggled_focused_unpressed_desk)) :
161 ob_rr_theme->a_focused_pressed_desk :
163 ob_rr_theme->a_hover_focused_desk :
164 ob_rr_theme->a_focused_unpressed_desk))));
165 s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
166 ob_rr_theme->a_disabled_focused_shade :
167 (self->client->shaded ?
169 ob_rr_theme->a_toggled_focused_pressed_shade :
171 ob_rr_theme->a_toggled_hover_focused_shade :
172 ob_rr_theme->a_toggled_focused_unpressed_shade)) :
174 ob_rr_theme->a_focused_pressed_shade :
176 ob_rr_theme->a_hover_focused_shade :
177 ob_rr_theme->a_focused_unpressed_shade))));
178 c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
179 ob_rr_theme->a_disabled_focused_close :
181 ob_rr_theme->a_focused_pressed_close :
183 ob_rr_theme->a_hover_focused_close :
184 ob_rr_theme->a_focused_unpressed_close)));
186 t = self->a_unfocused_title;
187 l = self->a_unfocused_label;
188 m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
189 ob_rr_theme->a_disabled_unfocused_max :
190 (self->client->max_vert || self->client->max_horz ?
192 ob_rr_theme->a_toggled_unfocused_pressed_max :
194 ob_rr_theme->a_toggled_hover_unfocused_max :
195 ob_rr_theme->a_toggled_unfocused_unpressed_max)) :
197 ob_rr_theme->a_unfocused_pressed_max :
199 ob_rr_theme->a_hover_unfocused_max :
200 ob_rr_theme->a_unfocused_unpressed_max))));
202 i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
203 ob_rr_theme->a_disabled_unfocused_iconify :
204 (self->iconify_press ?
205 ob_rr_theme->a_unfocused_pressed_iconify :
206 (self->iconify_hover ?
207 ob_rr_theme->a_hover_unfocused_iconify :
208 ob_rr_theme->a_unfocused_unpressed_iconify)));
209 d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
210 ob_rr_theme->a_disabled_unfocused_desk :
211 (self->client->desktop == DESKTOP_ALL ?
213 ob_rr_theme->a_toggled_unfocused_pressed_desk :
215 ob_rr_theme->a_toggled_hover_unfocused_desk :
216 ob_rr_theme->a_toggled_unfocused_unpressed_desk)) :
218 ob_rr_theme->a_unfocused_pressed_desk :
220 ob_rr_theme->a_hover_unfocused_desk :
221 ob_rr_theme->a_unfocused_unpressed_desk))));
222 s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
223 ob_rr_theme->a_disabled_unfocused_shade :
224 (self->client->shaded ?
226 ob_rr_theme->a_toggled_unfocused_pressed_shade :
228 ob_rr_theme->a_toggled_hover_unfocused_shade :
229 ob_rr_theme->a_toggled_unfocused_unpressed_shade)) :
231 ob_rr_theme->a_unfocused_pressed_shade :
233 ob_rr_theme->a_hover_unfocused_shade :
234 ob_rr_theme->a_unfocused_unpressed_shade))));
235 c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
236 ob_rr_theme->a_disabled_unfocused_close :
238 ob_rr_theme->a_unfocused_pressed_close :
240 ob_rr_theme->a_hover_unfocused_close :
241 ob_rr_theme->a_unfocused_unpressed_close)));
243 clear = ob_rr_theme->a_clear;
245 RrPaint(t, self->title, self->width, ob_rr_theme->title_height);
247 clear->surface.parent = t;
248 clear->surface.parenty = 0;
250 clear->surface.parentx = ob_rr_theme->grip_width;
252 RrPaint(clear, self->topresize,
253 self->width - ob_rr_theme->grip_width * 2,
254 ob_rr_theme->paddingy + 1);
256 clear->surface.parentx = 0;
258 if (ob_rr_theme->grip_width > 0)
259 RrPaint(clear, self->tltresize,
260 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
261 if (ob_rr_theme->title_height > 0)
262 RrPaint(clear, self->tllresize,
263 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
265 clear->surface.parentx = self->width - ob_rr_theme->grip_width;
267 if (ob_rr_theme->grip_width > 0)
268 RrPaint(clear, self->trtresize,
269 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
271 clear->surface.parentx = self->width - (ob_rr_theme->paddingx + 1);
273 if (ob_rr_theme->title_height > 0)
274 RrPaint(clear, self->trrresize,
275 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
277 /* set parents for any parent relative guys */
278 l->surface.parent = t;
279 l->surface.parentx = self->label_x;
280 l->surface.parenty = ob_rr_theme->paddingy;
282 m->surface.parent = t;
283 m->surface.parentx = self->max_x;
284 m->surface.parenty = ob_rr_theme->paddingy + 1;
286 n->surface.parent = t;
287 n->surface.parentx = self->icon_x;
288 n->surface.parenty = ob_rr_theme->paddingy;
290 i->surface.parent = t;
291 i->surface.parentx = self->iconify_x;
292 i->surface.parenty = ob_rr_theme->paddingy + 1;
294 d->surface.parent = t;
295 d->surface.parentx = self->desk_x;
296 d->surface.parenty = ob_rr_theme->paddingy + 1;
298 s->surface.parent = t;
299 s->surface.parentx = self->shade_x;
300 s->surface.parenty = ob_rr_theme->paddingy + 1;
302 c->surface.parent = t;
303 c->surface.parentx = self->close_x;
304 c->surface.parenty = ob_rr_theme->paddingy + 1;
306 framerender_label(self, l);
307 framerender_max(self, m);
308 framerender_icon(self, n);
309 framerender_iconify(self, i);
310 framerender_desk(self, d);
311 framerender_shade(self, s);
312 framerender_close(self, c);
315 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
316 ob_rr_theme->handle_height > 0)
321 self->a_focused_handle : self->a_unfocused_handle);
323 RrPaint(h, self->handle, self->width, ob_rr_theme->handle_height);
325 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
327 ob_rr_theme->a_focused_grip : ob_rr_theme->a_unfocused_grip);
329 if (g->surface.grad == RR_SURFACE_PARENTREL)
330 g->surface.parent = h;
332 g->surface.parentx = 0;
333 g->surface.parenty = 0;
335 RrPaint(g, self->lgrip,
336 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
338 g->surface.parentx = self->width - ob_rr_theme->grip_width;
339 g->surface.parenty = 0;
341 RrPaint(g, self->rgrip,
342 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
349 static void framerender_label(ObFrame *self, RrAppearance *a)
351 if (!self->label_on) return;
352 /* set the texture's text! */
353 a->texture[0].data.text.string = self->client->title;
354 RrPaint(a, self->label, self->label_width, ob_rr_theme->label_height);
357 static void framerender_icon(ObFrame *self, RrAppearance *a)
359 const ObClientIcon *icon;
361 if (!self->icon_on) return;
363 icon = client_icon(self->client,
364 ob_rr_theme->button_size + 2,
365 ob_rr_theme->button_size + 2);
367 a->texture[0].type = RR_TEXTURE_RGBA;
368 a->texture[0].data.rgba.width = icon->width;
369 a->texture[0].data.rgba.height = icon->height;
370 a->texture[0].data.rgba.alpha = 0xff;
371 a->texture[0].data.rgba.data = icon->data;
373 a->texture[0].type = RR_TEXTURE_NONE;
375 RrPaint(a, self->icon,
376 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
379 static void framerender_max(ObFrame *self, RrAppearance *a)
381 if (!self->max_on) return;
382 RrPaint(a, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size);
385 static void framerender_iconify(ObFrame *self, RrAppearance *a)
387 if (!self->iconify_on) return;
388 RrPaint(a, self->iconify,
389 ob_rr_theme->button_size, ob_rr_theme->button_size);
392 static void framerender_desk(ObFrame *self, RrAppearance *a)
394 if (!self->desk_on) return;
395 RrPaint(a, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size);
398 static void framerender_shade(ObFrame *self, RrAppearance *a)
400 if (!self->shade_on) return;
401 RrPaint(a, self->shade,
402 ob_rr_theme->button_size, ob_rr_theme->button_size);
405 static void framerender_close(ObFrame *self, RrAppearance *a)
407 if (!self->close_on) return;
408 RrPaint(a, self->close,
409 ob_rr_theme->button_size, ob_rr_theme->button_size);