fixed to accomodate the changes to the render/ API.
[dana/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, RrAppearance *a);
8 static void framerender_icon(Frame *self, RrAppearance *a);
9 static void framerender_max(Frame *self, RrAppearance *a);
10 static void framerender_iconify(Frame *self, RrAppearance *a);
11 static void framerender_desk(Frame *self, RrAppearance *a);
12 static void framerender_shade(Frame *self, RrAppearance *a);
13 static void framerender_close(Frame *self, RrAppearance *a);
14
15 void framerender_frame(Frame *self)
16 {
17     if (self->focused)
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     if (self->client->decorations & Decor_Titlebar) {
25         RrAppearance *t, *l, *m, *n, *i, *d, *s, *c;
26
27         t = (self->focused ?
28              self->a_focused_title : self->a_unfocused_title);
29         l = (self->focused ?
30              self->a_focused_label : self->a_unfocused_label);
31         m = (self->focused ?
32              (self->client->max_vert || self->client->max_horz ?
33               theme_a_focused_pressed_set_max :
34               (self->max_press ?
35                theme_a_focused_pressed_max : theme_a_focused_unpressed_max)) :
36              (self->client->max_vert || self->client->max_horz ?
37               theme_a_unfocused_pressed_set_max :
38               (self->max_press ?
39                theme_a_unfocused_pressed_max :
40                theme_a_unfocused_unpressed_max)));
41         n = self->a_icon;
42         i = (self->focused ?
43              (self->iconify_press ?
44               theme_a_focused_pressed_iconify :
45               theme_a_focused_unpressed_iconify) :
46              (self->iconify_press ?
47               theme_a_unfocused_pressed_iconify :
48               theme_a_unfocused_unpressed_iconify));
49         d = (self->focused ?
50              (self->client->desktop == DESKTOP_ALL ?
51               theme_a_focused_pressed_set_desk :
52               (self->desk_press ?
53                theme_a_focused_pressed_desk :
54                theme_a_focused_unpressed_desk)) :
55              (self->client->desktop == DESKTOP_ALL ?
56               theme_a_unfocused_pressed_set_desk :
57               (self->desk_press ?
58                theme_a_unfocused_pressed_desk :
59                theme_a_unfocused_unpressed_desk)));
60         s = (self->focused ?
61              (self->client->shaded ?
62               theme_a_focused_pressed_set_shade :
63               (self->shade_press ?
64                theme_a_focused_pressed_shade :
65                theme_a_focused_unpressed_shade)) :
66              (self->client->shaded ?
67               theme_a_unfocused_pressed_set_shade :
68               (self->shade_press ?
69                theme_a_unfocused_pressed_shade :
70                theme_a_unfocused_unpressed_shade)));
71         c = (self->focused ?
72              (self->close_press ?
73               theme_a_focused_pressed_close :
74               theme_a_focused_unpressed_close) :
75              (self->close_press ?
76               theme_a_unfocused_pressed_close :
77               theme_a_unfocused_unpressed_close));
78
79         RrPaint(t, self->title, self->width, theme_title_height);
80
81         /* set parents for any parent relative guys */
82         l->surface.parent = t;
83         l->surface.parentx = self->label_x;
84         l->surface.parenty = theme_bevel;
85
86         m->surface.parent = t;
87         m->surface.parentx = self->max_x;
88         m->surface.parenty = theme_bevel + 1;
89
90         n->surface.parent = t;
91         n->surface.parentx = self->icon_x;
92         n->surface.parenty = theme_bevel;
93
94         i->surface.parent = t;
95         i->surface.parentx = self->iconify_x;
96         i->surface.parenty = theme_bevel + 1;
97
98         d->surface.parent = t;
99         d->surface.parentx = self->desk_x;
100         d->surface.parenty = theme_bevel + 1;
101
102         s->surface.parent = t;
103         s->surface.parentx = self->shade_x;
104         s->surface.parenty = theme_bevel + 1;
105
106         c->surface.parent = t;
107         c->surface.parentx = self->close_x;
108         c->surface.parenty = theme_bevel + 1;
109
110         framerender_label(self, l);
111         framerender_max(self, m);
112         framerender_icon(self, n);
113         framerender_iconify(self, i);
114         framerender_desk(self, d);
115         framerender_shade(self, s);
116         framerender_close(self, c);
117     }
118
119     if (self->client->decorations & Decor_Handle) {
120         RrAppearance *h, *g;
121
122         h = (self->focused ?
123              self->a_focused_handle : self->a_unfocused_handle);
124
125         RrPaint(h, self->handle, self->width, theme_handle_height);
126
127         g = (self->focused ?
128              theme_a_focused_grip : theme_a_unfocused_grip);
129
130         if (g->surface.grad == RR_SURFACE_PARENTREL)
131             g->surface.parent = h;
132
133         g->surface.parentx = 0;
134         g->surface.parenty = 0;
135
136         RrPaint(g, self->lgrip, theme_grip_width, theme_handle_height);
137
138         g->surface.parentx = self->width - theme_grip_width;
139         g->surface.parenty = 0;
140
141         RrPaint(g, self->rgrip, theme_grip_width, theme_handle_height);
142     }
143 }
144
145 static void framerender_label(Frame *self, RrAppearance *a)
146 {
147     if (self->label_x < 0) return;
148     /* set the texture's text! */
149     a->texture[0].data.text.string = self->client->title;
150     RrPaint(a, self->label, self->label_width, theme_label_height);
151 }
152
153 static void framerender_icon(Frame *self, RrAppearance *a)
154 {
155     if (self->icon_x < 0) return;
156
157     if (self->client->nicons) {
158         Icon *icon = client_icon(self->client,
159                                  theme_button_size + 2, theme_button_size + 2);
160         a->texture[0].type = RR_TEXTURE_RGBA;
161         a->texture[0].data.rgba.width = icon->width;
162         a->texture[0].data.rgba.height = icon->height;
163         a->texture[0].data.rgba.data = icon->data;
164     } else
165         a->texture[0].type = RR_TEXTURE_NONE;
166
167     RrPaint(a, self->icon, theme_button_size + 2, theme_button_size + 2);
168 }
169
170 static void framerender_max(Frame *self, RrAppearance *a)
171 {
172     if (self->max_x < 0) return;
173     RrPaint(a, self->max, theme_button_size, theme_button_size);
174 }
175
176 static void framerender_iconify(Frame *self, RrAppearance *a)
177 {
178     if (self->iconify_x < 0) return;
179     RrPaint(a, self->iconify, theme_button_size, theme_button_size);
180 }
181
182 static void framerender_desk(Frame *self, RrAppearance *a)
183 {
184     if (self->desk_x < 0) return;
185     RrPaint(a, self->desk, theme_button_size, theme_button_size);
186 }
187
188 static void framerender_shade(Frame *self, RrAppearance *a)
189 {
190     if (self->shade_x < 0) return;
191     RrPaint(a, self->shade, theme_button_size, theme_button_size);
192 }
193
194 static void framerender_close(Frame *self, RrAppearance *a)
195 {
196     if (self->close_x < 0) return;
197     RrPaint(a, self->close, theme_button_size, theme_button_size);
198 }