Buttons seem to work!
[dana/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 "obrender/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(obt_display, self->backback, px);
53         XClearWindow(obt_display, self->backback);
54         XSetWindowBackground(obt_display, self->innerleft, px);
55         XClearWindow(obt_display, self->innerleft);
56         XSetWindowBackground(obt_display, self->innertop, px);
57         XClearWindow(obt_display, self->innertop);
58         XSetWindowBackground(obt_display, self->innerright, px);
59         XClearWindow(obt_display, self->innerright);
60         XSetWindowBackground(obt_display, self->innerbottom, px);
61         XClearWindow(obt_display, self->innerbottom);
62         XSetWindowBackground(obt_display, self->innerbll, px);
63         XClearWindow(obt_display, self->innerbll);
64         XSetWindowBackground(obt_display, self->innerbrr, px);
65         XClearWindow(obt_display, self->innerbrr);
66         XSetWindowBackground(obt_display, self->innerblb, px);
67         XClearWindow(obt_display, self->innerblb);
68         XSetWindowBackground(obt_display, self->innerbrb, px);
69         XClearWindow(obt_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(obt_display, self->left, px);
76         XClearWindow(obt_display, self->left);
77         XSetWindowBackground(obt_display, self->right, px);
78         XClearWindow(obt_display, self->right);
79
80         XSetWindowBackground(obt_display, self->titleleft, px);
81         XClearWindow(obt_display, self->titleleft);
82         XSetWindowBackground(obt_display, self->titletop, px);
83         XClearWindow(obt_display, self->titletop);
84         XSetWindowBackground(obt_display, self->titletopleft, px);
85         XClearWindow(obt_display, self->titletopleft);
86         XSetWindowBackground(obt_display, self->titletopright, px);
87         XClearWindow(obt_display, self->titletopright);
88         XSetWindowBackground(obt_display, self->titleright, px);
89         XClearWindow(obt_display, self->titleright);
90
91         XSetWindowBackground(obt_display, self->handleleft, px);
92         XClearWindow(obt_display, self->handleleft);
93         XSetWindowBackground(obt_display, self->handletop, px);
94         XClearWindow(obt_display, self->handletop);
95         XSetWindowBackground(obt_display, self->handleright, px);
96         XClearWindow(obt_display, self->handleright);
97         XSetWindowBackground(obt_display, self->handlebottom, px);
98         XClearWindow(obt_display, self->handlebottom);
99
100         XSetWindowBackground(obt_display, self->lgripleft, px);
101         XClearWindow(obt_display, self->lgripleft);
102         XSetWindowBackground(obt_display, self->lgriptop, px);
103         XClearWindow(obt_display, self->lgriptop);
104         XSetWindowBackground(obt_display, self->lgripbottom, px);
105         XClearWindow(obt_display, self->lgripbottom);
106
107         XSetWindowBackground(obt_display, self->rgripright, px);
108         XClearWindow(obt_display, self->rgripright);
109         XSetWindowBackground(obt_display, self->rgriptop, px);
110         XClearWindow(obt_display, self->rgriptop);
111         XSetWindowBackground(obt_display, self->rgripbottom, px);
112         XClearWindow(obt_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(obt_display, self->titlebottom, px);
121         XClearWindow(obt_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             t = ob_rr_theme->a_focused_title;
128             l = ob_rr_theme->a_focused_label;
129             m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
130                  ob_rr_theme->btn_max->a_disabled_focused :
131                  (self->client->max_vert || self->client->max_horz ?
132                   (self->max_press ?
133                    ob_rr_theme->btn_max->a_toggled_focused_pressed :
134                    (self->max_hover ?
135                     ob_rr_theme->btn_max->a_toggled_hover_focused :
136                     ob_rr_theme->btn_max->a_toggled_focused_unpressed)) :
137                   (self->max_press ?
138                    ob_rr_theme->btn_max->a_focused_pressed :
139                    (self->max_hover ?
140                     ob_rr_theme->btn_max->a_hover_focused :
141                     ob_rr_theme->btn_max->a_focused_unpressed))));
142             n = ob_rr_theme->a_icon;
143             i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
144                  ob_rr_theme->btn_iconify->a_disabled_focused :
145                  (self->iconify_press ?
146                   ob_rr_theme->btn_iconify->a_focused_pressed :
147                   (self->iconify_hover ?
148                    ob_rr_theme->btn_iconify->a_hover_focused :
149                    ob_rr_theme->btn_iconify->a_focused_unpressed)));
150             d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
151                  ob_rr_theme->btn_desk->a_disabled_focused :
152                  (self->client->desktop == DESKTOP_ALL ?
153                   (self->desk_press ?
154                    ob_rr_theme->btn_desk->a_toggled_focused_pressed :
155                    (self->desk_hover ?
156                     ob_rr_theme->btn_desk->a_toggled_hover_focused :
157                     ob_rr_theme->btn_desk->a_toggled_focused_unpressed)) :
158                   (self->desk_press ?
159                    ob_rr_theme->btn_desk->a_focused_pressed :
160                    (self->desk_hover ?
161                     ob_rr_theme->btn_desk->a_hover_focused :
162                     ob_rr_theme->btn_desk->a_focused_unpressed))));
163             s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
164                  ob_rr_theme->btn_shade->a_disabled_focused :
165                  (self->client->shaded ?
166                   (self->shade_press ?
167                    ob_rr_theme->btn_shade->a_toggled_focused_pressed :
168                    (self->shade_hover ?
169                     ob_rr_theme->btn_shade->a_toggled_hover_focused :
170                     ob_rr_theme->btn_shade->a_toggled_focused_unpressed)) :
171                   (self->shade_press ?
172                    ob_rr_theme->btn_shade->a_focused_pressed :
173                    (self->shade_hover ?
174                     ob_rr_theme->btn_shade->a_hover_focused :
175                     ob_rr_theme->btn_shade->a_focused_unpressed))));
176             c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
177                  ob_rr_theme->btn_close->a_disabled_focused :
178                  (self->close_press ?
179                   ob_rr_theme->btn_close->a_focused_pressed :
180                   (self->close_hover ?
181                    ob_rr_theme->btn_close->a_hover_focused :
182                    ob_rr_theme->btn_close->a_focused_unpressed)));
183         } else {
184             t = ob_rr_theme->a_unfocused_title;
185             l = ob_rr_theme->a_unfocused_label;
186             m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
187                  ob_rr_theme->btn_max->a_disabled_unfocused :
188                  (self->client->max_vert || self->client->max_horz ?
189                   (self->max_press ?
190                    ob_rr_theme->btn_max->a_toggled_unfocused_pressed :
191                    (self->max_hover ?
192                     ob_rr_theme->btn_max->a_toggled_hover_unfocused :
193                     ob_rr_theme->btn_max->a_toggled_unfocused_unpressed)) :
194                   (self->max_press ?
195                    ob_rr_theme->btn_max->a_unfocused_pressed :
196                    (self->max_hover ?
197                     ob_rr_theme->btn_max->a_hover_unfocused :
198                     ob_rr_theme->btn_max->a_unfocused_unpressed))));
199             n = ob_rr_theme->a_icon;
200             i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
201                  ob_rr_theme->btn_iconify->a_disabled_unfocused :
202                  (self->iconify_press ?
203                   ob_rr_theme->btn_iconify->a_unfocused_pressed :
204                   (self->iconify_hover ?
205                    ob_rr_theme->btn_iconify->a_hover_unfocused :
206                    ob_rr_theme->btn_iconify->a_unfocused_unpressed)));
207             d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
208                  ob_rr_theme->btn_desk->a_disabled_unfocused :
209                  (self->client->desktop == DESKTOP_ALL ?
210                   (self->desk_press ?
211                    ob_rr_theme->btn_desk->a_toggled_unfocused_pressed :
212                    (self->desk_hover ?
213                     ob_rr_theme->btn_desk->a_toggled_hover_unfocused :
214                     ob_rr_theme->btn_desk->a_toggled_unfocused_unpressed)) :
215                   (self->desk_press ?
216                    ob_rr_theme->btn_desk->a_unfocused_pressed :
217                    (self->desk_hover ?
218                     ob_rr_theme->btn_desk->a_hover_unfocused :
219                     ob_rr_theme->btn_desk->a_unfocused_unpressed))));
220             s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
221                  ob_rr_theme->btn_shade->a_disabled_unfocused :
222                  (self->client->shaded ?
223                   (self->shade_press ?
224                    ob_rr_theme->btn_shade->a_toggled_unfocused_pressed :
225                    (self->shade_hover ?
226                     ob_rr_theme->btn_shade->a_toggled_hover_unfocused :
227                     ob_rr_theme->btn_shade->a_toggled_unfocused_unpressed)) :
228                   (self->shade_press ?
229                    ob_rr_theme->btn_shade->a_unfocused_pressed :
230                    (self->shade_hover ?
231                     ob_rr_theme->btn_shade->a_hover_unfocused :
232                     ob_rr_theme->btn_shade->a_unfocused_unpressed))));
233             c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
234                  ob_rr_theme->btn_close->a_disabled_unfocused :
235                  (self->close_press ?
236                   ob_rr_theme->btn_close->a_unfocused_pressed :
237                   (self->close_hover ?
238                    ob_rr_theme->btn_close->a_hover_unfocused :
239                    ob_rr_theme->btn_close->a_unfocused_unpressed)));
240         }
241         clear = ob_rr_theme->a_clear;
242
243         RrPaint(t, self->title, self->width, ob_rr_theme->title_height);
244
245         clear->surface.parent = t;
246         clear->surface.parenty = 0;
247
248         clear->surface.parentx = ob_rr_theme->grip_width;
249
250         RrPaint(clear, self->topresize,
251                 self->width - ob_rr_theme->grip_width * 2,
252                 ob_rr_theme->paddingy + 1);
253
254         clear->surface.parentx = 0;
255
256         if (ob_rr_theme->grip_width > 0)
257             RrPaint(clear, self->tltresize,
258                     ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
259         if (ob_rr_theme->title_height > 0)
260             RrPaint(clear, self->tllresize,
261                     ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
262
263         clear->surface.parentx = self->width - ob_rr_theme->grip_width;
264
265         if (ob_rr_theme->grip_width > 0)
266             RrPaint(clear, self->trtresize,
267                     ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1);
268
269         clear->surface.parentx = self->width - (ob_rr_theme->paddingx + 1);
270
271         if (ob_rr_theme->title_height > 0)
272             RrPaint(clear, self->trrresize,
273                     ob_rr_theme->paddingx + 1, ob_rr_theme->title_height);
274
275         /* set parents for any parent relative guys */
276         l->surface.parent = t;
277         l->surface.parentx = self->label_x;
278         l->surface.parenty = ob_rr_theme->paddingy;
279
280         m->surface.parent = t;
281         m->surface.parentx = self->max_x;
282         m->surface.parenty = ob_rr_theme->paddingy + 1;
283
284         n->surface.parent = t;
285         n->surface.parentx = self->icon_x;
286         n->surface.parenty = ob_rr_theme->paddingy;
287
288         i->surface.parent = t;
289         i->surface.parentx = self->iconify_x;
290         i->surface.parenty = ob_rr_theme->paddingy + 1;
291
292         d->surface.parent = t;
293         d->surface.parentx = self->desk_x;
294         d->surface.parenty = ob_rr_theme->paddingy + 1;
295
296         s->surface.parent = t;
297         s->surface.parentx = self->shade_x;
298         s->surface.parenty = ob_rr_theme->paddingy + 1;
299
300         c->surface.parent = t;
301         c->surface.parentx = self->close_x;
302         c->surface.parenty = ob_rr_theme->paddingy + 1;
303
304         framerender_label(self, l);
305         framerender_max(self, m);
306         framerender_icon(self, n);
307         framerender_iconify(self, i);
308         framerender_desk(self, d);
309         framerender_shade(self, s);
310         framerender_close(self, c);
311     }
312
313     if (self->decorations & OB_FRAME_DECOR_HANDLE &&
314         ob_rr_theme->handle_height > 0)
315     {
316         RrAppearance *h, *g;
317
318         h = (self->focused ?
319              ob_rr_theme->a_focused_handle : ob_rr_theme->a_unfocused_handle);
320
321         RrPaint(h, self->handle, self->width, ob_rr_theme->handle_height);
322
323         if (self->decorations & OB_FRAME_DECOR_GRIPS) {
324             g = (self->focused ?
325                  ob_rr_theme->a_focused_grip : ob_rr_theme->a_unfocused_grip);
326
327             if (g->surface.grad == RR_SURFACE_PARENTREL)
328                 g->surface.parent = h;
329
330             g->surface.parentx = 0;
331             g->surface.parenty = 0;
332
333             RrPaint(g, self->lgrip,
334                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
335
336             g->surface.parentx = self->width - ob_rr_theme->grip_width;
337             g->surface.parenty = 0;
338
339             RrPaint(g, self->rgrip,
340                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
341         }
342     }
343
344     XFlush(obt_display);
345 }
346
347 static void framerender_label(ObFrame *self, RrAppearance *a)
348 {
349     if (!self->label_on) return;
350     /* set the texture's text! */
351     a->texture[0].data.text.string = self->client->title;
352     RrPaint(a, self->label, self->label_width, ob_rr_theme->label_height);
353 }
354
355 static void framerender_icon(ObFrame *self, RrAppearance *a)
356 {
357     RrImage *icon;
358
359     if (!self->icon_on) return;
360
361     icon = client_icon(self->client);
362
363     if (icon) {
364         RrAppearanceClearTextures(a);
365         a->texture[0].type = RR_TEXTURE_IMAGE;
366         a->texture[0].data.image.alpha = 0xff;
367         a->texture[0].data.image.image = icon;
368     } else {
369         RrAppearanceClearTextures(a);
370         a->texture[0].type = RR_TEXTURE_NONE;
371     }
372
373     RrPaint(a, self->icon,
374             ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
375 }
376
377 static void framerender_max(ObFrame *self, RrAppearance *a)
378 {
379     if (!self->max_on) return;
380     RrPaint(a, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size);
381 }
382
383 static void framerender_iconify(ObFrame *self, RrAppearance *a)
384 {
385     if (!self->iconify_on) return;
386     RrPaint(a, self->iconify,
387             ob_rr_theme->button_size, ob_rr_theme->button_size);
388 }
389
390 static void framerender_desk(ObFrame *self, RrAppearance *a)
391 {
392     if (!self->desk_on) return;
393     RrPaint(a, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size);
394 }
395
396 static void framerender_shade(ObFrame *self, RrAppearance *a)
397 {
398     if (!self->shade_on) return;
399     RrPaint(a, self->shade,
400             ob_rr_theme->button_size, ob_rr_theme->button_size);
401 }
402
403 static void framerender_close(ObFrame *self, RrAppearance *a)
404 {
405     if (!self->close_on) return;
406     RrPaint(a, self->close,
407             ob_rr_theme->button_size, ob_rr_theme->button_size);
408 }