]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/framerender.c
start of showing/rendering menus. woot!
[mikachu/openbox.git] / openbox / framerender.c
1 #include "frame.h"
2 #include "openbox.h"
3 #include "screen.h"
4 #include "framerender.h"
5 #include "render/theme.h"
6
7 static void framerender_label(Frame *self, Appearance *a);
8 static void framerender_icon(Frame *self, Appearance *a);
9 static void framerender_max(Frame *self, Appearance *a);
10 static void framerender_iconify(Frame *self, Appearance *a);
11 static void framerender_desk(Frame *self, Appearance *a);
12 static void framerender_shade(Frame *self, Appearance *a);
13 static void framerender_close(Frame *self, Appearance *a);
14
15 void framerender_frame(Frame *self)
16 {
17     if (client_focused(self->client)) {
18         XSetWindowBorder(ob_display, self->plate,
19                          theme_cb_focused_color->pixel);
20     } else {
21         XSetWindowBorder(ob_display, self->plate,
22                          theme_cb_unfocused_color->pixel);
23     }
24
25     if (self->client->decorations & Decor_Titlebar) {
26         Appearance *t, *l, *m, *n, *i, *d, *s, *c;
27
28         t = (client_focused(self->client) ?
29              self->a_focused_title : self->a_unfocused_title);
30         l = (client_focused(self->client) ?
31              self->a_focused_label : self->a_unfocused_label);
32         m = (client_focused(self->client) ?
33              (self->client->max_vert || self->client->max_horz ?
34               theme_a_focused_pressed_set_max :
35               (self->max_press ?
36                theme_a_focused_pressed_max : theme_a_focused_unpressed_max)) :
37              (self->client->max_vert || self->client->max_horz ?
38               theme_a_unfocused_pressed_set_max :
39               (self->max_press ?
40                theme_a_unfocused_pressed_max :
41                theme_a_unfocused_unpressed_max)));
42         n = self->a_icon;
43         i = (client_focused(self->client) ?
44              (self->iconify_press ?
45               theme_a_focused_pressed_iconify :
46               theme_a_focused_unpressed_iconify) :
47              (self->iconify_press ?
48               theme_a_unfocused_pressed_iconify :
49               theme_a_unfocused_unpressed_iconify));
50         d = (client_focused(self->client) ?
51              (self->client->desktop == DESKTOP_ALL ?
52               theme_a_focused_pressed_set_desk :
53               (self->desk_press ?
54                theme_a_focused_pressed_desk :
55                theme_a_focused_unpressed_desk)) :
56              (self->client->desktop == DESKTOP_ALL ?
57               theme_a_unfocused_pressed_set_desk :
58               (self->desk_press ?
59                theme_a_unfocused_pressed_desk :
60                theme_a_unfocused_unpressed_desk)));
61         s = (client_focused(self->client) ?
62              (self->client->shaded ?
63               theme_a_focused_pressed_set_shade :
64               (self->shade_press ?
65                theme_a_focused_pressed_shade :
66                theme_a_focused_unpressed_shade)) :
67              (self->client->shaded ?
68               theme_a_unfocused_pressed_set_shade :
69               (self->shade_press ?
70                theme_a_unfocused_pressed_shade :
71                theme_a_unfocused_unpressed_shade)));
72         c = (client_focused(self->client) ?
73              (self->close_press ?
74               theme_a_focused_pressed_close :
75               theme_a_focused_unpressed_close) :
76              (self->close_press ?
77               theme_a_unfocused_pressed_close :
78               theme_a_unfocused_unpressed_close));
79
80         paint(self->title, t);
81
82         /* set parents for any parent relative guys */
83         l->surface.data.planar.parent = t;
84         l->surface.data.planar.parentx = self->label_x;
85         l->surface.data.planar.parenty = theme_bevel;
86
87         m->surface.data.planar.parent = t;
88         m->surface.data.planar.parentx = self->max_x;
89         m->surface.data.planar.parenty = theme_bevel + 1;
90
91         n->surface.data.planar.parent = t;
92         n->surface.data.planar.parentx = self->icon_x;
93         n->surface.data.planar.parenty = theme_bevel + 1;
94
95         i->surface.data.planar.parent = t;
96         i->surface.data.planar.parentx = self->iconify_x;
97         i->surface.data.planar.parenty = theme_bevel + 1;
98
99         d->surface.data.planar.parent = t;
100         d->surface.data.planar.parentx = self->desk_x;
101         d->surface.data.planar.parenty = theme_bevel + 1;
102
103         s->surface.data.planar.parent = t;
104         s->surface.data.planar.parentx = self->shade_x;
105         s->surface.data.planar.parenty = theme_bevel + 1;
106
107         c->surface.data.planar.parent = t;
108         c->surface.data.planar.parentx = self->close_x;
109         c->surface.data.planar.parenty = theme_bevel + 1;
110
111         framerender_label(self, l);
112         framerender_max(self, m);
113         framerender_icon(self, n);
114         framerender_iconify(self, i);
115         framerender_desk(self, d);
116         framerender_shade(self, s);
117         framerender_close(self, c);
118     }
119
120     if (self->client->decorations & Decor_Handle) {
121         Appearance *h, *g;
122
123         h = (client_focused(self->client) ?
124              self->a_focused_handle : self->a_unfocused_handle);
125         g = (client_focused(self->client) ?
126              theme_a_focused_grip : theme_a_unfocused_grip);
127
128         if (g->surface.data.planar.grad == Background_ParentRelative) {
129             g->surface.data.planar.parent = h;
130             paint(self->handle, h);
131         } else
132             paint(self->handle, h);
133
134         g->surface.data.planar.parentx = 0;
135         g->surface.data.planar.parenty = 0;
136
137         paint(self->lgrip, g);
138
139         g->surface.data.planar.parentx = self->width - theme_grip_width;
140         g->surface.data.planar.parenty = 0;
141
142         paint(self->rgrip, g);
143     }
144 }
145
146 static void framerender_label(Frame *self, Appearance *a)
147 {
148     if (self->label_x < 0) return;
149
150
151     /* set the texture's text! */
152     a->texture[0].data.text.string = self->client->title;
153     RECT_SET(a->texture[0].position, 0, 0,
154              self->label_width, theme_label_height);
155
156     paint(self->label, a);
157 }
158
159 static void framerender_icon(Frame *self, Appearance *a)
160 {
161     if (self->icon_x < 0) return;
162
163     if (self->client->nicons) {
164         Icon *icon = client_icon(self->client,
165                                  theme_button_size, theme_button_size);
166         a->texture[0].type = RGBA;
167         a->texture[0].data.rgba.width = icon->width;
168         a->texture[0].data.rgba.height = icon->height;
169         a->texture[0].data.rgba.data = icon->data;
170         RECT_SET(self->a_icon->texture[0].position, 0, 0,
171                  theme_button_size,theme_button_size);
172     } else
173         a->texture[0].type = NoTexture;
174
175     paint(self->icon, a);
176 }
177
178 static void framerender_max(Frame *self, Appearance *a)
179 {
180     if (self->max_x < 0) return;
181
182     RECT_SET(a->texture[0].position, 0, 0,
183              theme_button_size, theme_button_size);
184     paint(self->max, a);
185 }
186
187 static void framerender_iconify(Frame *self, Appearance *a)
188 {
189     if (self->iconify_x < 0) return;
190
191     RECT_SET(a->texture[0].position, 0, 0,
192              theme_button_size, theme_button_size);
193     paint(self->iconify, a);
194 }
195
196 static void framerender_desk(Frame *self, Appearance *a)
197 {
198     if (self->desk_x < 0) return;
199
200     RECT_SET(a->texture[0].position, 0, 0,
201              theme_button_size, theme_button_size);
202     paint(self->desk, a);
203 }
204
205 static void framerender_shade(Frame *self, Appearance *a)
206 {
207     if (self->shade_x < 0) return;
208
209     RECT_SET(a->texture[0].position, 0, 0,
210              theme_button_size, theme_button_size);
211     paint(self->shade, a);
212 }
213
214 static void framerender_close(Frame *self, Appearance *a)
215 {
216     if (self->close_x < 0) return;
217
218     RECT_SET(a->texture[0].position, 0, 0,
219              theme_button_size, theme_button_size);
220     paint(self->close, a);
221 }
222
223 void framerender_popup_label(Window win, Size *sz, char *text)
224 {
225     Appearance *a;
226
227     a = theme_app_hilite_label;
228     a->texture[0].data.text.string = text;
229     RECT_SET(a->area, 0, 0, sz->width, sz->height);
230     a->texture[0].position = a->area;
231
232     XSetWindowBorderWidth(ob_display, win, theme_bwidth);
233     XSetWindowBorder(ob_display, win, theme_b_color->pixel);
234
235     paint(win, a);
236 }
237
238 void framerender_size_popup_label(char *text, Size *sz)
239 {
240     Appearance *a;
241
242     a = theme_app_hilite_label;
243     a->texture[0].data.text.string = text;
244
245     appearance_minsize(a, &sz->width, &sz->height);
246     sz->width += theme_bevel * 2;
247     sz->height += theme_bevel * 2;
248 }