]> Dogcows Code - chaz/openbox/blob - openbox/framerender.c
fix a mem leak
[chaz/openbox] / openbox / framerender.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 framerender.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
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.
11
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.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "frame.h"
21 #include "openbox.h"
22 #include "screen.h"
23 #include "client.h"
24 #include "framerender.h"
25 #include "render/theme.h"
26
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);
34
35 void framerender_frame(ObFrame *self)
36 {
37 if (frame_iconify_animating(self))
38 return; /* delay redrawing until the animation is done */
39 if (!self->need_render)
40 return;
41 if (!self->visible)
42 return;
43 self->need_render = FALSE;
44
45 {
46 gulong px;
47
48 px = (self->focused ?
49 RrColorPixel(ob_rr_theme->cb_focused_color) :
50 RrColorPixel(ob_rr_theme->cb_unfocused_color));
51
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);
70
71 px = (self->focused ?
72 RrColorPixel(ob_rr_theme->frame_focused_border_color) :
73 RrColorPixel(ob_rr_theme->frame_unfocused_border_color));
74
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);
79
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);
90
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);
99
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);
106
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);
113
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));
119
120 XSetWindowBackground(ob_display, self->titlebottom, px);
121 XClearWindow(ob_display, self->titlebottom);
122 }
123
124 if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
125 RrAppearance *t, *l, *m, *n, *i, *d, *s, *c, *clear;
126 if (self->focused) {
127
128 t = self->a_focused_title;
129 l = self->a_focused_label;
130
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 ?
134 (self->max_press ?
135 ob_rr_theme->a_toggled_focused_pressed_max :
136 (self->max_hover ?
137 ob_rr_theme->a_toggled_hover_focused_max :
138 ob_rr_theme->a_toggled_focused_unpressed_max)) :
139 (self->max_press ?
140 ob_rr_theme->a_focused_pressed_max :
141 (self->max_hover ?
142 ob_rr_theme->a_hover_focused_max :
143 ob_rr_theme->a_focused_unpressed_max))));
144 n = self->a_icon;
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 ?
155 (self->desk_press ?
156 ob_rr_theme->a_toggled_focused_pressed_desk :
157 (self->desk_hover ?
158 ob_rr_theme->a_toggled_hover_focused_desk :
159 ob_rr_theme->a_toggled_focused_unpressed_desk)) :
160 (self->desk_press ?
161 ob_rr_theme->a_focused_pressed_desk :
162 (self->desk_hover ?
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 ?
168 (self->shade_press ?
169 ob_rr_theme->a_toggled_focused_pressed_shade :
170 (self->shade_hover ?
171 ob_rr_theme->a_toggled_hover_focused_shade :
172 ob_rr_theme->a_toggled_focused_unpressed_shade)) :
173 (self->shade_press ?
174 ob_rr_theme->a_focused_pressed_shade :
175 (self->shade_hover ?
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 :
180 (self->close_press ?
181 ob_rr_theme->a_focused_pressed_close :
182 (self->close_hover ?
183 ob_rr_theme->a_hover_focused_close :
184 ob_rr_theme->a_focused_unpressed_close)));
185 } else {
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 ?
191 (self->max_press ?
192 ob_rr_theme->a_toggled_unfocused_pressed_max :
193 (self->max_hover ?
194 ob_rr_theme->a_toggled_hover_unfocused_max :
195 ob_rr_theme->a_toggled_unfocused_unpressed_max)) :
196 (self->max_press ?
197 ob_rr_theme->a_unfocused_pressed_max :
198 (self->max_hover ?
199 ob_rr_theme->a_hover_unfocused_max :
200 ob_rr_theme->a_unfocused_unpressed_max))));
201 n = self->a_icon;
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 ?
212 (self->desk_press ?
213 ob_rr_theme->a_toggled_unfocused_pressed_desk :
214 (self->desk_hover ?
215 ob_rr_theme->a_toggled_hover_unfocused_desk :
216 ob_rr_theme->a_toggled_unfocused_unpressed_desk)) :
217 (self->desk_press ?
218 ob_rr_theme->a_unfocused_pressed_desk :
219 (self->desk_hover ?
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 ?
225 (self->shade_press ?
226 ob_rr_theme->a_toggled_unfocused_pressed_shade :
227 (self->shade_hover ?
228 ob_rr_theme->a_toggled_hover_unfocused_shade :
229 ob_rr_theme->a_toggled_unfocused_unpressed_shade)) :
230 (self->shade_press ?
231 ob_rr_theme->a_unfocused_pressed_shade :
232 (self->shade_hover ?
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 :
237 (self->close_press ?
238 ob_rr_theme->a_unfocused_pressed_close :
239 (self->close_hover ?
240 ob_rr_theme->a_hover_unfocused_close :
241 ob_rr_theme->a_unfocused_unpressed_close)));
242 }
243 clear = ob_rr_theme->a_clear;
244
245 RrPaint(t, self->title, self->width, ob_rr_theme->title_height);
246
247 clear->surface.parent = t;
248 clear->surface.parenty = 0;
249
250 clear->surface.parentx = ob_rr_theme->grip_width;
251
252 RrPaint(clear, self->topresize,
253 self->width - ob_rr_theme->grip_width * 2,
254 ob_rr_theme->paddingy + 1);
255
256 clear->surface.parentx = 0;
257
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);
264
265 clear->surface.parentx = self->width - ob_rr_theme->grip_width;
266
267 if (ob_rr_theme->grip_width > 0)
268 RrPaint(clear, self->trtresize,
269 ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
270
271 clear->surface.parentx = self->width - (ob_rr_theme->paddingx + 1);
272
273 if (ob_rr_theme->title_height > 0)
274 RrPaint(clear, self->trrresize,
275 ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
276
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;
281
282 m->surface.parent = t;
283 m->surface.parentx = self->max_x;
284 m->surface.parenty = ob_rr_theme->paddingy + 1;
285
286 n->surface.parent = t;
287 n->surface.parentx = self->icon_x;
288 n->surface.parenty = ob_rr_theme->paddingy;
289
290 i->surface.parent = t;
291 i->surface.parentx = self->iconify_x;
292 i->surface.parenty = ob_rr_theme->paddingy + 1;
293
294 d->surface.parent = t;
295 d->surface.parentx = self->desk_x;
296 d->surface.parenty = ob_rr_theme->paddingy + 1;
297
298 s->surface.parent = t;
299 s->surface.parentx = self->shade_x;
300 s->surface.parenty = ob_rr_theme->paddingy + 1;
301
302 c->surface.parent = t;
303 c->surface.parentx = self->close_x;
304 c->surface.parenty = ob_rr_theme->paddingy + 1;
305
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);
313 }
314
315 if (self->decorations & OB_FRAME_DECOR_HANDLE &&
316 ob_rr_theme->handle_height > 0)
317 {
318 RrAppearance *h, *g;
319
320 h = (self->focused ?
321 self->a_focused_handle : self->a_unfocused_handle);
322
323 RrPaint(h, self->handle, self->width, ob_rr_theme->handle_height);
324
325 if (self->decorations & OB_FRAME_DECOR_GRIPS) {
326 g = (self->focused ?
327 ob_rr_theme->a_focused_grip : ob_rr_theme->a_unfocused_grip);
328
329 if (g->surface.grad == RR_SURFACE_PARENTREL)
330 g->surface.parent = h;
331
332 g->surface.parentx = 0;
333 g->surface.parenty = 0;
334
335 RrPaint(g, self->lgrip,
336 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
337
338 g->surface.parentx = self->width - ob_rr_theme->grip_width;
339 g->surface.parenty = 0;
340
341 RrPaint(g, self->rgrip,
342 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
343 }
344 }
345
346 XFlush(ob_display);
347 }
348
349 static void framerender_label(ObFrame *self, RrAppearance *a)
350 {
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);
355 }
356
357 static void framerender_icon(ObFrame *self, RrAppearance *a)
358 {
359 const ObClientIcon *icon;
360
361 if (!self->icon_on) return;
362
363 icon = client_icon(self->client,
364 ob_rr_theme->button_size + 2,
365 ob_rr_theme->button_size + 2);
366 if (icon) {
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;
372 } else
373 a->texture[0].type = RR_TEXTURE_NONE;
374
375 RrPaint(a, self->icon,
376 ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
377 }
378
379 static void framerender_max(ObFrame *self, RrAppearance *a)
380 {
381 if (!self->max_on) return;
382 RrPaint(a, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size);
383 }
384
385 static void framerender_iconify(ObFrame *self, RrAppearance *a)
386 {
387 if (!self->iconify_on) return;
388 RrPaint(a, self->iconify,
389 ob_rr_theme->button_size, ob_rr_theme->button_size);
390 }
391
392 static void framerender_desk(ObFrame *self, RrAppearance *a)
393 {
394 if (!self->desk_on) return;
395 RrPaint(a, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size);
396 }
397
398 static void framerender_shade(ObFrame *self, RrAppearance *a)
399 {
400 if (!self->shade_on) return;
401 RrPaint(a, self->shade,
402 ob_rr_theme->button_size, ob_rr_theme->button_size);
403 }
404
405 static void framerender_close(ObFrame *self, RrAppearance *a)
406 {
407 if (!self->close_on) return;
408 RrPaint(a, self->close,
409 ob_rr_theme->button_size, ob_rr_theme->button_size);
410 }
This page took 0.052877 seconds and 4 git commands to generate.