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