have the clientpadding color show during resize, and no flashing on unmap. we win !
[mikachu/openbox.git] / 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     {
38         gulong px;
39
40         px = (self->focused ?
41               RrColorPixel(ob_rr_theme->cb_focused_color) :
42               RrColorPixel(ob_rr_theme->cb_unfocused_color));
43
44         XSetWindowBackground(ob_display, self->backback, px);
45         XClearWindow(ob_display, self->backback);
46         XSetWindowBackground(ob_display, self->innerleft, px);
47         XClearWindow(ob_display, self->innerleft);
48         XSetWindowBackground(ob_display, self->innertop, px);
49         XClearWindow(ob_display, self->innertop);
50         XSetWindowBackground(ob_display, self->innerright, px);
51         XClearWindow(ob_display, self->innerright);
52         XSetWindowBackground(ob_display, self->innerbottom, px);
53         XClearWindow(ob_display, self->innerbottom);
54
55         px = (self->focused ?
56               RrColorPixel(ob_rr_theme->frame_focused_border_color) :
57               RrColorPixel(ob_rr_theme->frame_unfocused_border_color));
58
59         XSetWindowBackground(ob_display, self->left, px);
60         XClearWindow(ob_display, self->left);
61         XSetWindowBackground(ob_display, self->right, px);
62         XClearWindow(ob_display, self->right);
63
64         XSetWindowBackground(ob_display, self->titleleft, px);
65         XClearWindow(ob_display, self->titleleft);
66         XSetWindowBackground(ob_display, self->titletop, px);
67         XClearWindow(ob_display, self->titletop);
68         XSetWindowBackground(ob_display, self->titletopleft, px);
69         XClearWindow(ob_display, self->titletopleft);
70         XSetWindowBackground(ob_display, self->titletopright, px);
71         XClearWindow(ob_display, self->titletopright);
72         XSetWindowBackground(ob_display, self->titleright, px);
73         XClearWindow(ob_display, self->titleright);
74         XSetWindowBackground(ob_display, self->titlebottom, px);
75         XClearWindow(ob_display, self->titlebottom);
76
77         XSetWindowBackground(ob_display, self->handleleft, px);
78         XClearWindow(ob_display, self->handleleft);
79         XSetWindowBackground(ob_display, self->handletop, px);
80         XClearWindow(ob_display, self->handletop);
81         XSetWindowBackground(ob_display, self->handleright, px);
82         XClearWindow(ob_display, self->handleright);
83         XSetWindowBackground(ob_display, self->handlebottom, px);
84         XClearWindow(ob_display, self->handlebottom);
85
86         XSetWindowBackground(ob_display, self->lgripleft, px);
87         XClearWindow(ob_display, self->lgripleft);
88         XSetWindowBackground(ob_display, self->lgriptop, px);
89         XClearWindow(ob_display, self->lgriptop);
90         XSetWindowBackground(ob_display, self->lgripbottom, px);
91         XClearWindow(ob_display, self->lgripbottom);
92
93         XSetWindowBackground(ob_display, self->rgripright, px);
94         XClearWindow(ob_display, self->rgripright);
95         XSetWindowBackground(ob_display, self->rgriptop, px);
96         XClearWindow(ob_display, self->rgriptop);
97         XSetWindowBackground(ob_display, self->rgripbottom, px);
98         XClearWindow(ob_display, self->rgripbottom);
99     }
100
101     if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
102         RrAppearance *t, *l, *m, *n, *i, *d, *s, *c, *clear;
103         if (self->focused) {
104
105             t = self->a_focused_title;
106             l = self->a_focused_label;
107
108             m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
109                  ob_rr_theme->a_disabled_focused_max :
110                  (self->client->max_vert || self->client->max_horz ?
111                   (self->max_press ?
112                    ob_rr_theme->a_toggled_focused_pressed_max :
113                    (self->max_hover ?
114                     ob_rr_theme->a_toggled_hover_focused_max : 
115                     ob_rr_theme->a_toggled_focused_unpressed_max)) :
116                   (self->max_press ?
117                    ob_rr_theme->a_focused_pressed_max :
118                    (self->max_hover ?
119                     ob_rr_theme->a_hover_focused_max : 
120                     ob_rr_theme->a_focused_unpressed_max))));
121             n = self->a_icon;
122             i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
123                  ob_rr_theme->a_disabled_focused_iconify :
124                  (self->iconify_press ?
125                   ob_rr_theme->a_focused_pressed_iconify :
126                   (self->iconify_hover ?
127                    ob_rr_theme->a_hover_focused_iconify : 
128                    ob_rr_theme->a_focused_unpressed_iconify)));
129             d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
130                  ob_rr_theme->a_disabled_focused_desk :
131                  (self->client->desktop == DESKTOP_ALL ?
132                   (self->desk_press ?
133                    ob_rr_theme->a_toggled_focused_pressed_desk :
134                    (self->desk_hover ?
135                     ob_rr_theme->a_toggled_hover_focused_desk : 
136                     ob_rr_theme->a_toggled_focused_unpressed_desk)) :
137                   (self->desk_press ?
138                    ob_rr_theme->a_focused_pressed_desk :
139                    (self->desk_hover ?
140                     ob_rr_theme->a_hover_focused_desk : 
141                     ob_rr_theme->a_focused_unpressed_desk))));
142             s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
143                  ob_rr_theme->a_disabled_focused_shade :
144                  (self->client->shaded ?
145                   (self->shade_press ?
146                    ob_rr_theme->a_toggled_focused_pressed_shade :
147                    (self->shade_hover ?
148                     ob_rr_theme->a_toggled_hover_focused_shade : 
149                     ob_rr_theme->a_toggled_focused_unpressed_shade)) :
150                   (self->shade_press ?
151                    ob_rr_theme->a_focused_pressed_shade :
152                    (self->shade_hover ?
153                     ob_rr_theme->a_hover_focused_shade : 
154                     ob_rr_theme->a_focused_unpressed_shade))));
155             c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
156                  ob_rr_theme->a_disabled_focused_close :
157                  (self->close_press ?
158                   ob_rr_theme->a_focused_pressed_close :
159                   (self->close_hover ?
160                    ob_rr_theme->a_hover_focused_close : 
161                    ob_rr_theme->a_focused_unpressed_close)));
162         } else {
163             t = self->a_unfocused_title;
164             l = self->a_unfocused_label;
165             m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
166                  ob_rr_theme->a_disabled_unfocused_max :
167                  (self->client->max_vert || self->client->max_horz ?
168                   (self->max_press ?
169                    ob_rr_theme->a_toggled_unfocused_pressed_max :
170                    (self->max_hover ?
171                     ob_rr_theme->a_toggled_hover_unfocused_max : 
172                     ob_rr_theme->a_toggled_unfocused_unpressed_max)) :
173                   (self->max_press ?
174                    ob_rr_theme->a_unfocused_pressed_max :
175                    (self->max_hover ?
176                     ob_rr_theme->a_hover_unfocused_max : 
177                     ob_rr_theme->a_unfocused_unpressed_max))));
178             n = self->a_icon;
179             i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
180                  ob_rr_theme->a_disabled_unfocused_iconify :
181                  (self->iconify_press ?
182                   ob_rr_theme->a_unfocused_pressed_iconify :
183                   (self->iconify_hover ?
184                    ob_rr_theme->a_hover_unfocused_iconify : 
185                    ob_rr_theme->a_unfocused_unpressed_iconify)));
186             d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
187                  ob_rr_theme->a_disabled_unfocused_desk :
188                  (self->client->desktop == DESKTOP_ALL ?
189                   (self->desk_press ?
190                    ob_rr_theme->a_toggled_unfocused_pressed_desk :
191                    (self->desk_hover ?
192                     ob_rr_theme->a_toggled_hover_unfocused_desk : 
193                     ob_rr_theme->a_toggled_unfocused_unpressed_desk)) :
194                   (self->desk_press ?
195                    ob_rr_theme->a_unfocused_pressed_desk :
196                    (self->desk_hover ?
197                     ob_rr_theme->a_hover_unfocused_desk : 
198                     ob_rr_theme->a_unfocused_unpressed_desk))));
199             s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
200                  ob_rr_theme->a_disabled_unfocused_shade :
201                  (self->client->shaded ?
202                   (self->shade_press ?
203                    ob_rr_theme->a_toggled_unfocused_pressed_shade :
204                    (self->shade_hover ?
205                     ob_rr_theme->a_toggled_hover_unfocused_shade : 
206                     ob_rr_theme->a_toggled_unfocused_unpressed_shade)) :
207                   (self->shade_press ?
208                    ob_rr_theme->a_unfocused_pressed_shade :
209                    (self->shade_hover ?
210                     ob_rr_theme->a_hover_unfocused_shade : 
211                     ob_rr_theme->a_unfocused_unpressed_shade))));
212             c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
213                  ob_rr_theme->a_disabled_unfocused_close :
214                  (self->close_press ?
215                   ob_rr_theme->a_unfocused_pressed_close :
216                   (self->close_hover ?
217                    ob_rr_theme->a_hover_unfocused_close : 
218                    ob_rr_theme->a_unfocused_unpressed_close)));
219         }
220         clear = ob_rr_theme->a_clear;
221
222         RrPaint(t, self->title, self->width, ob_rr_theme->title_height);
223
224         clear->surface.parent = t;
225         clear->surface.parenty = 0;
226
227         clear->surface.parentx = ob_rr_theme->grip_width;
228
229         RrPaint(clear, self->topresize,
230                 self->width - ob_rr_theme->grip_width * 2,
231                 ob_rr_theme->paddingy + 1);
232
233         clear->surface.parentx = 0;
234
235         if (ob_rr_theme->grip_width > 0)
236             RrPaint(clear, self->tltresize,
237                     ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
238         if (ob_rr_theme->title_height > 0)
239             RrPaint(clear, self->tllresize,
240                     ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
241
242         clear->surface.parentx = self->width - ob_rr_theme->grip_width;
243
244         if (ob_rr_theme->grip_width > 0)
245             RrPaint(clear, self->trtresize,
246                     ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
247
248         clear->surface.parentx = self->width - (ob_rr_theme->paddingx + 1);
249
250         if (ob_rr_theme->title_height > 0)
251             RrPaint(clear, self->trrresize,
252                     ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
253
254         /* set parents for any parent relative guys */
255         l->surface.parent = t;
256         l->surface.parentx = self->label_x;
257         l->surface.parenty = ob_rr_theme->paddingy;
258
259         m->surface.parent = t;
260         m->surface.parentx = self->max_x;
261         m->surface.parenty = ob_rr_theme->paddingy + 1;
262
263         n->surface.parent = t;
264         n->surface.parentx = self->icon_x;
265         n->surface.parenty = ob_rr_theme->paddingy;
266
267         i->surface.parent = t;
268         i->surface.parentx = self->iconify_x;
269         i->surface.parenty = ob_rr_theme->paddingy + 1;
270
271         d->surface.parent = t;
272         d->surface.parentx = self->desk_x;
273         d->surface.parenty = ob_rr_theme->paddingy + 1;
274
275         s->surface.parent = t;
276         s->surface.parentx = self->shade_x;
277         s->surface.parenty = ob_rr_theme->paddingy + 1;
278
279         c->surface.parent = t;
280         c->surface.parentx = self->close_x;
281         c->surface.parenty = ob_rr_theme->paddingy + 1;
282
283         framerender_label(self, l);
284         framerender_max(self, m);
285         framerender_icon(self, n);
286         framerender_iconify(self, i);
287         framerender_desk(self, d);
288         framerender_shade(self, s);
289         framerender_close(self, c);
290     }
291
292     if (self->decorations & OB_FRAME_DECOR_HANDLE &&
293         ob_rr_theme->handle_height > 0)
294     {
295         RrAppearance *h, *g;
296
297         h = (self->focused ?
298              self->a_focused_handle : self->a_unfocused_handle);
299
300         RrPaint(h, self->handle, self->width, ob_rr_theme->handle_height);
301
302         if (self->decorations & OB_FRAME_DECOR_GRIPS) {
303             g = (self->focused ?
304                  ob_rr_theme->a_focused_grip : ob_rr_theme->a_unfocused_grip);
305
306             if (g->surface.grad == RR_SURFACE_PARENTREL)
307                 g->surface.parent = h;
308
309             g->surface.parentx = 0;
310             g->surface.parenty = 0;
311
312             RrPaint(g, self->lgrip,
313                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
314
315             g->surface.parentx = self->width - ob_rr_theme->grip_width;
316             g->surface.parenty = 0;
317
318             RrPaint(g, self->rgrip,
319                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
320         }
321     }
322
323     XFlush(ob_display);
324 }
325
326 static void framerender_label(ObFrame *self, RrAppearance *a)
327 {
328     if (!self->label_on) return;
329     /* set the texture's text! */
330     a->texture[0].data.text.string = self->client->title;
331     RrPaint(a, self->label, self->label_width, ob_rr_theme->label_height);
332 }
333
334 static void framerender_icon(ObFrame *self, RrAppearance *a)
335 {
336     const ObClientIcon *icon;
337
338     if (!self->icon_on) return;
339
340     icon = client_icon(self->client,
341                        ob_rr_theme->button_size + 2,
342                        ob_rr_theme->button_size + 2);
343     if (icon) {
344         a->texture[0].type = RR_TEXTURE_RGBA;
345         a->texture[0].data.rgba.width = icon->width;
346         a->texture[0].data.rgba.height = icon->height;
347         a->texture[0].data.rgba.data = icon->data;
348     } else
349         a->texture[0].type = RR_TEXTURE_NONE;
350
351     RrPaint(a, self->icon,
352             ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
353 }
354
355 static void framerender_max(ObFrame *self, RrAppearance *a)
356 {
357     if (!self->max_on) return;
358     RrPaint(a, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size);
359 }
360
361 static void framerender_iconify(ObFrame *self, RrAppearance *a)
362 {
363     if (!self->iconify_on) return;
364     RrPaint(a, self->iconify,
365             ob_rr_theme->button_size, ob_rr_theme->button_size);
366 }
367
368 static void framerender_desk(ObFrame *self, RrAppearance *a)
369 {
370     if (!self->desk_on) return;
371     RrPaint(a, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size);
372 }
373
374 static void framerender_shade(ObFrame *self, RrAppearance *a)
375 {
376     if (!self->shade_on) return;
377     RrPaint(a, self->shade,
378             ob_rr_theme->button_size, ob_rr_theme->button_size);
379 }
380
381 static void framerender_close(ObFrame *self, RrAppearance *a)
382 {
383     if (!self->close_on) return;
384     RrPaint(a, self->close,
385             ob_rr_theme->button_size, ob_rr_theme->button_size);
386 }