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