Cosmetics
[awesome.git] / titlebar.c
blob46e53168ad802c6168801c637ac46a4227bed0eb
1 /*
2 * titlebar.c - titlebar management
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <math.h>
24 #include "titlebar.h"
25 #include "screen.h"
27 extern AwesomeConf globalconf;
29 void
30 titlebar_init(Client *c)
32 int titlebar_height = 1.5 * MAX(globalconf.screens[c->screen].styles.normal.font->height,
33 MAX(globalconf.screens[c->screen].styles.focus.font->height,
34 globalconf.screens[c->screen].styles.urgent.font->height));
35 int phys_screen = get_phys_screen(c->screen);
37 switch(c->titlebar.position)
39 case Top:
40 c->titlebar.sw = simplewindow_new(globalconf.display,
41 phys_screen,
42 c->geometry.x,
43 c->geometry.y - titlebar_height,
44 c->geometry.width + 2 * c->border,
45 titlebar_height,
46 0);
47 break;
48 case Bottom:
49 c->titlebar.sw = simplewindow_new(globalconf.display,
50 phys_screen,
51 c->geometry.x,
52 c->geometry.y + c->geometry.height + 2 * c->border,
53 c->geometry.width + 2 * c->border,
54 titlebar_height,
55 0);
56 break;
57 case Left:
58 c->titlebar.sw = simplewindow_new(globalconf.display,
59 phys_screen,
60 c->geometry.x - titlebar_height,
61 c->geometry.y,
62 titlebar_height,
63 c->geometry.width + 2 * c->border,
64 0);
65 break;
66 case Right:
67 c->titlebar.sw = simplewindow_new(globalconf.display,
68 phys_screen,
69 c->geometry.x + c->geometry.width + 2 * c->border,
70 c->geometry.y,
71 titlebar_height,
72 c->geometry.width + 2 * c->border,
73 0);
74 break;
75 case Off:
76 break;
77 default:
78 c->titlebar.position = Off;
79 break;
83 void
84 titlebar_update(Client *c)
86 Drawable d;
87 DrawCtx *ctx;
88 style_t style;
89 area_t geometry;
91 if(!c->titlebar.sw)
92 return;
94 switch(c->titlebar.position)
96 case Off:
97 return;
98 case Right:
99 case Left:
100 XFreePixmap(globalconf.display, c->titlebar.sw->drawable);
101 c->titlebar.sw->drawable =
102 XCreatePixmap(globalconf.display,
103 RootWindow(globalconf.display, c->titlebar.sw->phys_screen),
104 c->titlebar.sw->geometry.height,
105 c->titlebar.sw->geometry.width,
106 DefaultDepth(globalconf.display, c->titlebar.sw->phys_screen));
107 ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
108 c->titlebar.sw->geometry.height,
109 c->titlebar.sw->geometry.width,
110 c->titlebar.sw->drawable);
111 geometry.width = c->titlebar.sw->geometry.height;
112 geometry.height = c->titlebar.sw->geometry.width;
113 break;
114 default:
115 ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
116 c->titlebar.sw->geometry.width,
117 c->titlebar.sw->geometry.height,
118 c->titlebar.sw->drawable);
119 geometry = c->titlebar.sw->geometry;
120 break;
124 if(c->isurgent)
125 style = globalconf.screens[c->screen].styles.urgent;
126 else if(globalconf.focus->client == c)
127 style = globalconf.screens[c->screen].styles.focus;
128 else
129 style = globalconf.screens[c->screen].styles.normal;
131 geometry.x = geometry.y = 0;
133 draw_text(ctx, geometry, c->titlebar.text_align, style.font->height / 2,
134 c->name, style);
136 switch(c->titlebar.position)
138 case Left:
139 d = draw_rotate(ctx, c->titlebar.sw->phys_screen, - M_PI_2,
140 0, c->titlebar.sw->geometry.height);
141 XFreePixmap(globalconf.display, c->titlebar.sw->drawable);
142 c->titlebar.sw->drawable = d;
143 break;
144 case Right:
145 d = draw_rotate(ctx, c->titlebar.sw->phys_screen, M_PI_2,
146 c->titlebar.sw->geometry.width, 0);
147 XFreePixmap(globalconf.display, c->titlebar.sw->drawable);
148 c->titlebar.sw->drawable = d;
149 default:
150 break;
153 simplewindow_refresh_drawable(c->titlebar.sw, c->titlebar.sw->phys_screen);
155 draw_context_delete(ctx);
158 void
159 titlebar_update_geometry_floating(Client *c)
161 if(!c->titlebar.sw)
162 return;
164 switch(c->titlebar.position)
166 default:
167 return;
168 case Top:
169 simplewindow_move_resize(c->titlebar.sw,
170 c->geometry.x,
171 c->geometry.y - c->titlebar.sw->geometry.height,
172 c->geometry.width + 2 * c->border,
173 c->titlebar.sw->geometry.height);
174 break;
175 case Bottom:
176 simplewindow_move_resize(c->titlebar.sw,
177 c->geometry.x,
178 c->geometry.y + c->geometry.height + 2 * c->border,
179 c->geometry.width + 2 * c->border,
180 c->titlebar.sw->geometry.height);
181 break;
182 case Left:
183 simplewindow_move_resize(c->titlebar.sw,
184 c->geometry.x - c->titlebar.sw->geometry.width,
185 c->geometry.y,
186 c->titlebar.sw->geometry.width,
187 c->geometry.height + 2 * c->border);
188 break;
189 case Right:
190 simplewindow_move_resize(c->titlebar.sw,
191 c->geometry.x + c->geometry.width + 2 * c->border,
192 c->geometry.y,
193 c->titlebar.sw->geometry.width,
194 c->geometry.height + 2 * c->border);
195 break;
198 titlebar_update(c);
201 area_t
202 titlebar_update_geometry(Client *c, area_t geometry)
204 if(!c->titlebar.sw)
205 return geometry;
207 switch(c->titlebar.position)
209 default:
210 return geometry;
211 case Top:
212 simplewindow_move_resize(c->titlebar.sw,
213 geometry.x,
214 geometry.y,
215 geometry.width + 2 * c->border,
216 c->titlebar.sw->geometry.height);
217 geometry.y += c->titlebar.sw->geometry.height;
218 geometry.height -= c->titlebar.sw->geometry.height;
219 break;
220 case Bottom:
221 geometry.height -= c->titlebar.sw->geometry.height;
222 simplewindow_move_resize(c->titlebar.sw,
223 geometry.x,
224 geometry.y + geometry.height + 2 * c->border,
225 geometry.width + 2 * c->border,
226 c->titlebar.sw->geometry.height);
227 break;
228 case Left:
229 simplewindow_move_resize(c->titlebar.sw,
230 geometry.x,
231 geometry.y,
232 c->titlebar.sw->geometry.width,
233 geometry.height + 2 * c->border);
234 geometry.width -= c->titlebar.sw->geometry.width;
235 geometry.x += c->titlebar.sw->geometry.width;
236 break;
237 case Right:
238 geometry.width -= c->titlebar.sw->geometry.width;
239 simplewindow_move_resize(c->titlebar.sw,
240 geometry.x + geometry.width + 2 * c->border,
241 geometry.y,
242 c->titlebar.sw->geometry.width,
243 geometry.height + 2 * c->border);
244 break;
247 titlebar_update(c);
249 return geometry;
252 /** Toggle window titlebar visibility
253 * \param screen screen number (unused)
254 * \param arg unused argument
255 * \ingroup ui_callback
257 void
258 uicb_client_toggletitlebar(int screen __attribute__ ((unused)),
259 char *arg __attribute__ ((unused)))
261 Client *c = globalconf.focus->client;
263 if(!c || !c->titlebar.sw)
264 return;
266 if(!c->titlebar.position)
267 c->titlebar.position = c->titlebar.dposition;
268 else
270 c->titlebar.position = Off;
271 XUnmapWindow(globalconf.display, c->titlebar.sw->window);
274 globalconf.screens[c->screen].need_arrange = True;
277 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80