]> icculus.org git repositories - mikachu/openbox.git/blob - engines/openbox/obrender.c
split the render functions into obrender.c. rename all the src files to obfoo so...
[mikachu/openbox.git] / engines / openbox / obrender.c
1 #include "obengine.h"
2 #include "../../kernel/openbox.h"
3 #include "../../kernel/screen.h"
4
5 static void render_label(ObFrame *self, Appearance *a);
6 static void render_max(ObFrame *self, Appearance *a);
7 static void render_icon(ObFrame *self, Appearance *a);
8 static void render_iconify(ObFrame *self, Appearance *a);
9 static void render_desk(ObFrame *self, Appearance *a);
10 static void render_close(ObFrame *self, Appearance *a);
11
12 void render_frame(ObFrame *self)
13 {
14     if (client_focused(self->frame.client)) {
15         XSetWindowBorder(ob_display, self->frame.plate,
16                          s_cb_focused_color->pixel);
17     } else {
18         XSetWindowBorder(ob_display, self->frame.plate,
19                          s_cb_unfocused_color->pixel);
20     }
21
22     if (self->frame.client->decorations & Decor_Titlebar) {
23         Appearance *t, *l, *m, *n, *i, *d, *c;
24
25         t = (client_focused(self->frame.client) ?
26              self->a_focused_title : self->a_unfocused_title);
27         l = (client_focused(self->frame.client) ?
28              self->a_focused_label : self->a_unfocused_label);
29         m = (client_focused(self->frame.client) ?
30              ((self->max_press ||
31               self->frame.client->max_vert || self->frame.client->max_horz) ?
32               a_focused_pressed_max : a_focused_unpressed_max) :
33              ((self->max_press ||
34               self->frame.client->max_vert || self->frame.client->max_horz) ?
35               a_unfocused_pressed_max : a_unfocused_unpressed_max));
36         n = self->a_icon;
37         i = (client_focused(self->frame.client) ?
38              (self->iconify_press ?
39               a_focused_pressed_iconify : a_focused_unpressed_iconify) :
40              (self->iconify_press ?
41               a_unfocused_pressed_iconify : a_unfocused_unpressed_iconify));
42         d = (client_focused(self->frame.client) ?
43              (self->desk_press || self->frame.client->desktop == DESKTOP_ALL ?
44               a_focused_pressed_desk : a_focused_unpressed_desk) :
45              (self->desk_press || self->frame.client->desktop == DESKTOP_ALL ?
46               a_unfocused_pressed_desk : a_unfocused_unpressed_desk));
47         c = (client_focused(self->frame.client) ?
48              (self->close_press ?
49               a_focused_pressed_close : a_focused_unpressed_close) :
50              (self->close_press ?
51               a_unfocused_pressed_close : a_unfocused_unpressed_close));
52
53         paint(self->title, t);
54
55         /* set parents for any parent relative guys */
56         l->surface.data.planar.parent = t;
57         l->surface.data.planar.parentx = self->label_x;
58         l->surface.data.planar.parenty = s_bevel;
59
60         m->surface.data.planar.parent = t;
61         m->surface.data.planar.parentx = self->max_x;
62         m->surface.data.planar.parenty = s_bevel + 1;
63
64         n->surface.data.planar.parent = t;
65         n->surface.data.planar.parentx = self->icon_x;
66         n->surface.data.planar.parenty = s_bevel + 1;
67
68         i->surface.data.planar.parent = t;
69         i->surface.data.planar.parentx = self->iconify_x;
70         i->surface.data.planar.parenty = s_bevel + 1;
71
72         d->surface.data.planar.parent = t;
73         d->surface.data.planar.parentx = self->desk_x;
74         d->surface.data.planar.parenty = s_bevel + 1;
75
76         c->surface.data.planar.parent = t;
77         c->surface.data.planar.parentx = self->close_x;
78         c->surface.data.planar.parenty = s_bevel + 1;
79
80         render_label(self, l);
81         render_max(self, m);
82         render_icon(self, n);
83         render_iconify(self, i);
84         render_desk(self, d);
85         render_close(self, c);
86     }
87
88     if (self->frame.client->decorations & Decor_Handle) {
89         Appearance *h, *g;
90
91         h = (client_focused(self->frame.client) ?
92              self->a_focused_handle : self->a_unfocused_handle);
93         g = (client_focused(self->frame.client) ?
94              a_focused_grip : a_unfocused_grip);
95
96         if (g->surface.data.planar.grad == Background_ParentRelative) {
97             g->surface.data.planar.parent = h;
98             paint(self->handle, h);
99         } else
100             paint(self->handle, h);
101
102         g->surface.data.planar.parentx = 0;
103         g->surface.data.planar.parenty = 0;
104
105         paint(self->lgrip, g);
106
107         g->surface.data.planar.parentx = self->width - GRIP_WIDTH;
108         g->surface.data.planar.parenty = 0;
109
110         paint(self->rgrip, g);
111     }
112 }
113
114 static void render_label(ObFrame *self, Appearance *a)
115 {
116     if (self->label_x < 0) return;
117
118
119     /* set the texture's text! */
120     a->texture[0].data.text.string = self->frame.client->title;
121     RECT_SET(a->texture[0].position, 0, 0, self->label_width, LABEL_HEIGHT);
122
123     paint(self->label, a);
124 }
125
126 static void render_icon(ObFrame *self, Appearance *a)
127 {
128     if (self->icon_x < 0) return;
129
130     if (self->frame.client->nicons) {
131         Icon *icon = client_icon(self->frame.client, BUTTON_SIZE, BUTTON_SIZE);
132         a->texture[0].type = RGBA;
133         a->texture[0].data.rgba.width = icon->width;
134         a->texture[0].data.rgba.height = icon->height;
135         a->texture[0].data.rgba.data = icon->data;
136         RECT_SET(self->a_icon->texture[0].position, 0, 0,
137                  BUTTON_SIZE,BUTTON_SIZE);
138     } else
139         a->texture[0].type = NoTexture;
140
141     paint(self->icon, a);
142 }
143
144 static void render_max(ObFrame *self, Appearance *a)
145 {
146     if (self->max_x < 0) return;
147
148     RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE);
149     paint(self->max, a);
150 }
151
152 static void render_iconify(ObFrame *self, Appearance *a)
153 {
154     if (self->iconify_x < 0) return;
155
156     RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE);
157     paint(self->iconify, a);
158 }
159
160 static void render_desk(ObFrame *self, Appearance *a)
161 {
162     if (self->desk_x < 0) return;
163
164     RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE);
165     paint(self->desk, a);
166 }
167
168 static void render_close(ObFrame *self, Appearance *a)
169 {
170     if (self->close_x < 0) return;
171
172     RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE);
173     paint(self->close, a);
174 }
175
176 GQuark get_context(Client *client, Window win)
177 {
178     ObFrame *self;
179
180     if (win == ob_root) return g_quark_try_string("root");
181     if (client == NULL) return g_quark_try_string("none");
182     if (win == client->window) return g_quark_try_string("client");
183
184     self = (ObFrame*) client->frame;
185     if (win == self->frame.window) return g_quark_try_string("frame");
186     if (win == self->frame.plate)  return g_quark_try_string("client");
187     if (win == self->title)  return g_quark_try_string("titlebar");
188     if (win == self->label)  return g_quark_try_string("titlebar");
189     if (win == self->handle) return g_quark_try_string("handle");
190     if (win == self->lgrip)  return g_quark_try_string("blcorner");
191     if (win == self->rgrip)  return g_quark_try_string("brcorner");
192     if (win == self->max)  return g_quark_try_string("maximize");
193     if (win == self->iconify)  return g_quark_try_string("iconify");
194     if (win == self->close)  return g_quark_try_string("close");
195     if (win == self->icon)  return g_quark_try_string("icon");
196     if (win == self->desk)  return g_quark_try_string("alldesktops");
197
198     return g_quark_try_string("none");
199 }