a couple frame layout bugfixes hidden inside all this.. wee
[mikachu/openbox.git] / openbox / framerender.c
1 #include "frame.h"
2 #include "openbox.h"
3 #include "screen.h"
4 #include "client.h"
5 #include "framerender.h"
6 #include "render/theme.h"
7
8 static void framerender_label(ObFrame *self, RrAppearance *a);
9 static void framerender_icon(ObFrame *self, RrAppearance *a);
10 static void framerender_max(ObFrame *self, RrAppearance *a);
11 static void framerender_iconify(ObFrame *self, RrAppearance *a);
12 static void framerender_desk(ObFrame *self, RrAppearance *a);
13 static void framerender_shade(ObFrame *self, RrAppearance *a);
14 static void framerender_close(ObFrame *self, RrAppearance *a);
15
16 void framerender_frame(ObFrame *self)
17 {
18     {
19         unsigned long px;
20
21         px = (self->focused ?
22               RrColorPixel(ob_rr_theme->cb_focused_color) :
23               RrColorPixel(ob_rr_theme->cb_unfocused_color));
24         XSetWindowBackground(ob_display, self->plate, px);
25     }
26
27     if (self->decorations & OB_FRAME_DECOR_TITLEBAR) {
28         RrAppearance *t, *l, *m, *n, *i, *d, *s, *c;
29
30         t = (self->focused ?
31              self->a_focused_title : self->a_unfocused_title);
32         l = (self->focused ?
33              self->a_focused_label : self->a_unfocused_label);
34         m = (!(self->decorations & OB_FRAME_DECOR_MAXIMIZE) ?
35              (self->focused ?
36               ob_rr_theme->a_disabled_focused_max :
37               ob_rr_theme->a_disabled_unfocused_max) :
38              (self->focused ?
39               (self->client->max_vert || self->client->max_horz ?
40                ob_rr_theme->a_toggled_focused_max :
41                (self->max_press ?
42                 ob_rr_theme->a_focused_pressed_max :
43                 (self->max_hover ?
44                  ob_rr_theme->a_hover_focused_max : 
45                  ob_rr_theme->a_focused_unpressed_max))) :
46               (self->client->max_vert || self->client->max_horz ?
47                ob_rr_theme->a_toggled_unfocused_max :
48                (self->max_press ?
49                 ob_rr_theme->a_unfocused_pressed_max :
50                 (self->max_hover ?
51                  ob_rr_theme->a_hover_unfocused_max : 
52                  ob_rr_theme->a_unfocused_unpressed_max)))));
53         n = self->a_icon;
54         i = (!(self->decorations & OB_FRAME_DECOR_ICONIFY) ?
55              (self->focused ?
56               ob_rr_theme->a_disabled_focused_iconify :
57               ob_rr_theme->a_disabled_unfocused_iconify) :
58              (self->focused ?
59               (self->iconify_press ?
60                ob_rr_theme->a_focused_pressed_iconify :
61                (self->iconify_hover ?
62                 ob_rr_theme->a_hover_focused_iconify : 
63                 ob_rr_theme->a_focused_unpressed_iconify)) :
64               (self->iconify_press ?
65                ob_rr_theme->a_unfocused_pressed_iconify :
66                (self->iconify_hover ?
67                 ob_rr_theme->a_hover_unfocused_iconify : 
68                 ob_rr_theme->a_unfocused_unpressed_iconify))));
69         d = (!(self->decorations & OB_FRAME_DECOR_ALLDESKTOPS) ?
70              (self->focused ?
71               ob_rr_theme->a_disabled_focused_desk :
72               ob_rr_theme->a_disabled_unfocused_desk) :
73              (self->focused ?
74               (self->client->desktop == DESKTOP_ALL ?
75                ob_rr_theme->a_toggled_focused_desk :
76                (self->desk_press ?
77                 ob_rr_theme->a_focused_pressed_desk :
78                 (self->desk_hover ?
79                  ob_rr_theme->a_hover_focused_desk : 
80                  ob_rr_theme->a_focused_unpressed_desk))) :
81               (self->client->desktop == DESKTOP_ALL ?
82                ob_rr_theme->a_toggled_unfocused_desk :
83                (self->desk_press ?
84                 ob_rr_theme->a_unfocused_pressed_desk :
85                 (self->desk_hover ?
86                  ob_rr_theme->a_hover_unfocused_desk : 
87                  ob_rr_theme->a_unfocused_unpressed_desk)))));
88         s = (!(self->decorations & OB_FRAME_DECOR_SHADE) ?
89              (self->focused ?
90               ob_rr_theme->a_disabled_focused_shade :
91               ob_rr_theme->a_disabled_unfocused_shade) :
92              (self->focused ?
93               (self->client->shaded ?
94                ob_rr_theme->a_toggled_focused_shade :
95                (self->shade_press ?
96                 ob_rr_theme->a_focused_pressed_shade :
97                 (self->shade_hover ?
98                  ob_rr_theme->a_hover_focused_shade : 
99                  ob_rr_theme->a_focused_unpressed_shade))) :
100               (self->client->shaded ?
101                ob_rr_theme->a_toggled_unfocused_shade :
102                (self->shade_press ?
103                 ob_rr_theme->a_unfocused_pressed_shade :
104                 (self->shade_hover ?
105                  ob_rr_theme->a_hover_unfocused_shade : 
106                  ob_rr_theme->a_unfocused_unpressed_shade)))));
107         c = (!(self->decorations & OB_FRAME_DECOR_CLOSE) ?
108              (self->focused ?
109               ob_rr_theme->a_disabled_focused_close :
110               ob_rr_theme->a_disabled_unfocused_close) :
111              (self->focused ?
112               (self->close_press ?
113                ob_rr_theme->a_focused_pressed_close :
114                (self->close_hover ?
115                 ob_rr_theme->a_hover_focused_close : 
116                 ob_rr_theme->a_focused_unpressed_close)) :
117               (self->close_press ?
118                ob_rr_theme->a_unfocused_pressed_close :
119                (self->close_hover ?
120                 ob_rr_theme->a_hover_unfocused_close : 
121                 ob_rr_theme->a_unfocused_unpressed_close))));
122
123         RrPaint(t, self->title, self->width, ob_rr_theme->title_height);
124
125         ob_rr_theme->a_clear->surface.parent = t;
126         ob_rr_theme->a_clear->surface.parentx = 0;
127         ob_rr_theme->a_clear->surface.parenty = 0;
128
129         RrPaint(ob_rr_theme->a_clear, self->tlresize,
130                 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
131
132         ob_rr_theme->a_clear->surface.parentx =
133             self->width - ob_rr_theme->grip_width;
134
135         RrPaint(ob_rr_theme->a_clear, self->trresize,
136                 ob_rr_theme->grip_width, ob_rr_theme->handle_height);
137
138
139         /* set parents for any parent relative guys */
140         l->surface.parent = t;
141         l->surface.parentx = self->label_x;
142         l->surface.parenty = ob_rr_theme->bevel;
143
144         m->surface.parent = t;
145         m->surface.parentx = self->max_x;
146         m->surface.parenty = ob_rr_theme->bevel + 1;
147
148         n->surface.parent = t;
149         n->surface.parentx = self->icon_x;
150         n->surface.parenty = ob_rr_theme->bevel;
151
152         i->surface.parent = t;
153         i->surface.parentx = self->iconify_x;
154         i->surface.parenty = ob_rr_theme->bevel + 1;
155
156         d->surface.parent = t;
157         d->surface.parentx = self->desk_x;
158         d->surface.parenty = ob_rr_theme->bevel + 1;
159
160         s->surface.parent = t;
161         s->surface.parentx = self->shade_x;
162         s->surface.parenty = ob_rr_theme->bevel + 1;
163
164         c->surface.parent = t;
165         c->surface.parentx = self->close_x;
166         c->surface.parenty = ob_rr_theme->bevel + 1;
167
168         framerender_label(self, l);
169         framerender_max(self, m);
170         framerender_icon(self, n);
171         framerender_iconify(self, i);
172         framerender_desk(self, d);
173         framerender_shade(self, s);
174         framerender_close(self, c);
175     }
176
177     if (self->decorations & OB_FRAME_DECOR_HANDLE) {
178         RrAppearance *h, *g;
179
180         h = (self->focused ?
181              self->a_focused_handle : self->a_unfocused_handle);
182
183         RrPaint(h, self->handle, self->width, ob_rr_theme->handle_height);
184
185         if (self->decorations & OB_FRAME_DECOR_GRIPS) {
186             g = (self->focused ?
187                  ob_rr_theme->a_focused_grip : ob_rr_theme->a_unfocused_grip);
188
189             if (g->surface.grad == RR_SURFACE_PARENTREL)
190                 g->surface.parent = h;
191
192             g->surface.parentx = 0;
193             g->surface.parenty = 0;
194
195             RrPaint(g, self->lgrip,
196                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
197
198             g->surface.parentx = self->width - ob_rr_theme->grip_width;
199             g->surface.parenty = 0;
200
201             RrPaint(g, self->rgrip,
202                     ob_rr_theme->grip_width, ob_rr_theme->handle_height);
203         }
204     }
205 }
206
207 static void framerender_label(ObFrame *self, RrAppearance *a)
208 {
209     if (self->label_x < 0) return;
210     /* set the texture's text! */
211     a->texture[0].data.text.string = self->client->title;
212     RrPaint(a, self->label, self->label_width, ob_rr_theme->label_height);
213 }
214
215 static void framerender_icon(ObFrame *self, RrAppearance *a)
216 {
217     if (self->icon_x < 0) return;
218
219     if (self->client->nicons) {
220         ObClientIcon *icon = client_icon(self->client,
221                                          ob_rr_theme->button_size + 2,
222                                          ob_rr_theme->button_size + 2);
223         a->texture[0].type = RR_TEXTURE_RGBA;
224         a->texture[0].data.rgba.width = icon->width;
225         a->texture[0].data.rgba.height = icon->height;
226         a->texture[0].data.rgba.data = icon->data;
227     } else
228         a->texture[0].type = RR_TEXTURE_NONE;
229
230     RrPaint(a, self->icon,
231             ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2);
232 }
233
234 static void framerender_max(ObFrame *self, RrAppearance *a)
235 {
236     if (self->max_x < 0) return;
237     RrPaint(a, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size);
238 }
239
240 static void framerender_iconify(ObFrame *self, RrAppearance *a)
241 {
242     if (self->iconify_x < 0) return;
243     RrPaint(a, self->iconify,
244             ob_rr_theme->button_size, ob_rr_theme->button_size);
245 }
246
247 static void framerender_desk(ObFrame *self, RrAppearance *a)
248 {
249     if (self->desk_x < 0) return;
250     RrPaint(a, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size);
251 }
252
253 static void framerender_shade(ObFrame *self, RrAppearance *a)
254 {
255     if (self->shade_x < 0) return;
256     RrPaint(a, self->shade,
257             ob_rr_theme->button_size, ob_rr_theme->button_size);
258 }
259
260 static void framerender_close(ObFrame *self, RrAppearance *a)
261 {
262     if (self->close_x < 0) return;
263     RrPaint(a, self->close,
264             ob_rr_theme->button_size, ob_rr_theme->button_size);
265 }