Close X connection before execing in uicb_exec
[awesome.git] / titlebar.c
blobe4209089a0cadd905c4e42778d0493a6565ac726
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;
34 if(c->titlebar.position == Off
35 || c->titlebar.position == Auto)
37 c->titlebar.position = Off;
38 return;
41 titlebar_height = 1.5 * MAX(c->titlebar.styles.normal.font->height,
42 MAX(c->titlebar.styles.focus.font->height,
43 c->titlebar.styles.urgent.font->height));
45 switch(c->titlebar.position)
47 case Top:
48 c->titlebar.sw = simplewindow_new(globalconf.display,
49 c->phys_screen,
50 c->geometry.x,
51 c->geometry.y - titlebar_height,
52 c->geometry.width + 2 * c->border,
53 titlebar_height,
54 0);
55 break;
56 case Bottom:
57 c->titlebar.sw = simplewindow_new(globalconf.display,
58 c->phys_screen,
59 c->geometry.x,
60 c->geometry.y + c->geometry.height + 2 * c->border,
61 c->geometry.width + 2 * c->border,
62 titlebar_height,
63 0);
64 break;
65 case Left:
66 c->titlebar.sw = simplewindow_new(globalconf.display,
67 c->phys_screen,
68 c->geometry.x - titlebar_height,
69 c->geometry.y,
70 titlebar_height,
71 c->geometry.width + 2 * c->border,
72 0);
73 break;
74 case Right:
75 c->titlebar.sw = simplewindow_new(globalconf.display,
76 c->phys_screen,
77 c->geometry.x + c->geometry.width + 2 * c->border,
78 c->geometry.y,
79 titlebar_height,
80 c->geometry.width + 2 * c->border,
81 0);
82 break;
83 default:
84 break;
88 void
89 titlebar_update(Client *c)
91 Drawable dw = 0;
92 DrawCtx *ctx;
93 style_t style;
94 area_t geometry;
96 if(!c->titlebar.sw)
97 return;
99 switch(c->titlebar.position)
101 case Off:
102 return;
103 case Right:
104 case Left:
105 dw = XCreatePixmap(globalconf.display,
106 RootWindow(globalconf.display, c->titlebar.sw->phys_screen),
107 c->titlebar.sw->geometry.height,
108 c->titlebar.sw->geometry.width,
109 DefaultDepth(globalconf.display, c->titlebar.sw->phys_screen));
110 ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
111 c->titlebar.sw->geometry.height,
112 c->titlebar.sw->geometry.width,
113 dw);
114 geometry.width = c->titlebar.sw->geometry.height;
115 geometry.height = c->titlebar.sw->geometry.width;
116 break;
117 default:
118 ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
119 c->titlebar.sw->geometry.width,
120 c->titlebar.sw->geometry.height,
121 c->titlebar.sw->drawable);
122 geometry = c->titlebar.sw->geometry;
123 break;
127 if(c->isurgent)
128 style = c->titlebar.styles.urgent;
129 else if(globalconf.focus->client == c)
130 style = c->titlebar.styles.focus;
131 else
132 style = c->titlebar.styles.normal;
134 geometry.x = geometry.y = 0;
136 draw_text(ctx, geometry, c->titlebar.text_align, style.font->height / 2,
137 c->name, style);
139 switch(c->titlebar.position)
141 case Left:
142 draw_rotate(ctx, c->titlebar.sw->drawable, ctx->height, ctx->width,
143 - M_PI_2, 0, c->titlebar.sw->geometry.height);
144 XFreePixmap(globalconf.display, dw);
145 break;
146 case Right:
147 draw_rotate(ctx, c->titlebar.sw->drawable, ctx->height, ctx->width,
148 M_PI_2, c->titlebar.sw->geometry.width, 0);
149 XFreePixmap(globalconf.display, dw);
150 default:
151 break;
154 simplewindow_refresh_drawable(c->titlebar.sw, c->titlebar.sw->phys_screen);
156 draw_context_delete(&ctx);
159 void
160 titlebar_update_geometry_floating(Client *c)
162 if(!c->titlebar.sw)
163 return;
165 switch(c->titlebar.position)
167 default:
168 return;
169 case Top:
170 simplewindow_move_resize(c->titlebar.sw,
171 c->geometry.x,
172 c->geometry.y - c->titlebar.sw->geometry.height,
173 c->geometry.width + 2 * c->border,
174 c->titlebar.sw->geometry.height);
175 break;
176 case Bottom:
177 simplewindow_move_resize(c->titlebar.sw,
178 c->geometry.x,
179 c->geometry.y + c->geometry.height + 2 * c->border,
180 c->geometry.width + 2 * c->border,
181 c->titlebar.sw->geometry.height);
182 break;
183 case Left:
184 simplewindow_move_resize(c->titlebar.sw,
185 c->geometry.x - c->titlebar.sw->geometry.width,
186 c->geometry.y,
187 c->titlebar.sw->geometry.width,
188 c->geometry.height + 2 * c->border);
189 break;
190 case Right:
191 simplewindow_move_resize(c->titlebar.sw,
192 c->geometry.x + c->geometry.width + 2 * c->border,
193 c->geometry.y,
194 c->titlebar.sw->geometry.width,
195 c->geometry.height + 2 * c->border);
196 break;
199 titlebar_update(c);
202 area_t
203 titlebar_update_geometry(Client *c, area_t geometry)
205 if(!c->titlebar.sw)
206 return geometry;
208 switch(c->titlebar.position)
210 default:
211 return geometry;
212 case Top:
213 simplewindow_move_resize(c->titlebar.sw,
214 geometry.x,
215 geometry.y,
216 geometry.width + 2 * c->border,
217 c->titlebar.sw->geometry.height);
218 geometry.y += c->titlebar.sw->geometry.height;
219 geometry.height -= c->titlebar.sw->geometry.height;
220 break;
221 case Bottom:
222 geometry.height -= c->titlebar.sw->geometry.height;
223 simplewindow_move_resize(c->titlebar.sw,
224 geometry.x,
225 geometry.y + geometry.height + 2 * c->border,
226 geometry.width + 2 * c->border,
227 c->titlebar.sw->geometry.height);
228 break;
229 case Left:
230 simplewindow_move_resize(c->titlebar.sw,
231 geometry.x,
232 geometry.y,
233 c->titlebar.sw->geometry.width,
234 geometry.height + 2 * c->border);
235 geometry.width -= c->titlebar.sw->geometry.width;
236 geometry.x += c->titlebar.sw->geometry.width;
237 break;
238 case Right:
239 geometry.width -= c->titlebar.sw->geometry.width;
240 simplewindow_move_resize(c->titlebar.sw,
241 geometry.x + geometry.width + 2 * c->border,
242 geometry.y,
243 c->titlebar.sw->geometry.width,
244 geometry.height + 2 * c->border);
245 break;
248 titlebar_update(c);
250 return geometry;
253 /** Toggle window titlebar visibility
254 * \param screen screen number (unused)
255 * \param arg unused argument
256 * \ingroup ui_callback
258 void
259 uicb_client_toggletitlebar(int screen __attribute__ ((unused)),
260 char *arg __attribute__ ((unused)))
262 Client *c = globalconf.focus->client;
264 if(!c || !c->titlebar.sw)
265 return;
267 if(!c->titlebar.position)
268 c->titlebar.position = c->titlebar.dposition;
269 else
271 c->titlebar.position = Off;
272 XUnmapWindow(globalconf.display, c->titlebar.sw->window);
275 globalconf.screens[c->screen].need_arrange = True;
278 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80