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.
27 extern AwesomeConf globalconf
;
30 titlebar_init(Client
*c
)
34 if(c
->titlebar
.position
== Off
35 || c
->titlebar
.position
== Auto
)
37 c
->titlebar
.position
= Off
;
41 if(!c
->titlebar
.height
)
42 c
->titlebar
.height
= 1.5 * MAX(c
->titlebar
.styles
.normal
.font
->height
,
43 MAX(c
->titlebar
.styles
.focus
.font
->height
,
44 c
->titlebar
.styles
.urgent
.font
->height
));
46 switch(c
->titlebar
.position
)
49 if(!c
->titlebar
.width
)
50 width
= c
->geometry
.width
+ 2 * c
->border
;
52 width
= MIN(c
->titlebar
.width
, c
->geometry
.width
);
53 c
->titlebar
.sw
= simplewindow_new(globalconf
.display
,
56 c
->geometry
.y
- c
->titlebar
.height
,
62 if(!c
->titlebar
.width
)
63 width
= c
->geometry
.width
+ 2 * c
->border
;
65 width
= MIN(c
->titlebar
.width
, c
->geometry
.width
);
66 c
->titlebar
.sw
= simplewindow_new(globalconf
.display
,
69 c
->geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
,
75 if(!c
->titlebar
.width
)
76 width
= c
->geometry
.height
+ 2 * c
->border
;
78 width
= MIN(c
->titlebar
.width
, c
->geometry
.height
);
79 c
->titlebar
.sw
= simplewindow_new(globalconf
.display
,
81 c
->geometry
.x
- c
->titlebar
.height
,
88 if(!c
->titlebar
.width
)
89 width
= c
->geometry
.height
+ 2 * c
->border
;
91 width
= MIN(c
->titlebar
.width
, c
->geometry
.height
);
92 c
->titlebar
.sw
= simplewindow_new(globalconf
.display
,
94 c
->geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
,
106 titlebar_update(Client
*c
)
116 switch(c
->titlebar
.position
)
122 dw
= XCreatePixmap(globalconf
.display
,
123 RootWindow(globalconf
.display
, c
->titlebar
.sw
->phys_screen
),
124 c
->titlebar
.sw
->geometry
.height
,
125 c
->titlebar
.sw
->geometry
.width
,
126 DefaultDepth(globalconf
.display
, c
->titlebar
.sw
->phys_screen
));
127 ctx
= draw_context_new(globalconf
.display
, c
->titlebar
.sw
->phys_screen
,
128 c
->titlebar
.sw
->geometry
.height
,
129 c
->titlebar
.sw
->geometry
.width
,
131 geometry
.width
= c
->titlebar
.sw
->geometry
.height
;
132 geometry
.height
= c
->titlebar
.sw
->geometry
.width
;
135 ctx
= draw_context_new(globalconf
.display
, c
->titlebar
.sw
->phys_screen
,
136 c
->titlebar
.sw
->geometry
.width
,
137 c
->titlebar
.sw
->geometry
.height
,
138 c
->titlebar
.sw
->drawable
);
139 geometry
= c
->titlebar
.sw
->geometry
;
145 style
= c
->titlebar
.styles
.urgent
;
146 else if(globalconf
.focus
->client
== c
)
147 style
= c
->titlebar
.styles
.focus
;
149 style
= c
->titlebar
.styles
.normal
;
151 geometry
.x
= geometry
.y
= 0;
153 draw_text(ctx
, geometry
, c
->titlebar
.text_align
, style
.font
->height
/ 2,
156 switch(c
->titlebar
.position
)
159 draw_rotate(ctx
, c
->titlebar
.sw
->drawable
, ctx
->height
, ctx
->width
,
160 - M_PI_2
, 0, c
->titlebar
.sw
->geometry
.height
);
161 XFreePixmap(globalconf
.display
, dw
);
164 draw_rotate(ctx
, c
->titlebar
.sw
->drawable
, ctx
->height
, ctx
->width
,
165 M_PI_2
, c
->titlebar
.sw
->geometry
.width
, 0);
166 XFreePixmap(globalconf
.display
, dw
);
171 simplewindow_refresh_drawable(c
->titlebar
.sw
, c
->titlebar
.sw
->phys_screen
);
173 draw_context_delete(&ctx
);
177 titlebar_update_geometry_floating(Client
*c
)
179 int width
, x_offset
= 0, y_offset
= 0;
184 switch(c
->titlebar
.position
)
189 if(!c
->titlebar
.width
)
190 width
= c
->geometry
.width
+ 2 * c
->border
;
192 width
= MIN(c
->titlebar
.width
, c
->geometry
.width
);
193 switch(c
->titlebar
.align
)
198 x_offset
= 2 * c
->border
+ c
->geometry
.width
- width
;
201 x_offset
= (c
->geometry
.width
- width
) / 2;
204 simplewindow_move_resize(c
->titlebar
.sw
,
205 c
->geometry
.x
+ x_offset
,
206 c
->geometry
.y
- c
->titlebar
.sw
->geometry
.height
,
208 c
->titlebar
.sw
->geometry
.height
);
211 if(!c
->titlebar
.width
)
212 width
= c
->geometry
.width
+ 2 * c
->border
;
214 width
= MIN(c
->titlebar
.width
, c
->geometry
.width
);
215 switch(c
->titlebar
.align
)
220 x_offset
= 2 * c
->border
+ c
->geometry
.width
- width
;
223 x_offset
= (c
->geometry
.width
- width
) / 2;
226 simplewindow_move_resize(c
->titlebar
.sw
,
227 c
->geometry
.x
+ x_offset
,
228 c
->geometry
.y
+ c
->geometry
.height
+ 2 * c
->border
,
230 c
->titlebar
.sw
->geometry
.height
);
233 if(!c
->titlebar
.width
)
234 width
= c
->geometry
.height
+ 2 * c
->border
;
236 width
= MIN(c
->titlebar
.width
, c
->geometry
.height
);
237 switch(c
->titlebar
.align
)
242 y_offset
= 2 * c
->border
+ c
->geometry
.height
- width
;
245 y_offset
= (c
->geometry
.height
- width
) / 2;
248 simplewindow_move_resize(c
->titlebar
.sw
,
249 c
->geometry
.x
- c
->titlebar
.sw
->geometry
.width
,
250 c
->geometry
.y
+ y_offset
,
251 c
->titlebar
.sw
->geometry
.width
,
255 if(!c
->titlebar
.width
)
256 width
= c
->geometry
.height
+ 2 * c
->border
;
258 width
= MIN(c
->titlebar
.width
, c
->geometry
.height
);
259 switch(c
->titlebar
.align
)
264 y_offset
= 2 * c
->border
+ c
->geometry
.height
- width
;
267 y_offset
= (c
->geometry
.height
- width
) / 2;
270 simplewindow_move_resize(c
->titlebar
.sw
,
271 c
->geometry
.x
+ c
->geometry
.width
+ 2 * c
->border
,
272 c
->geometry
.y
+ y_offset
,
273 c
->titlebar
.sw
->geometry
.width
,
282 titlebar_update_geometry(Client
*c
, area_t geometry
)
284 int width
, x_offset
= 0 , y_offset
= 0;
289 switch(c
->titlebar
.position
)
294 if(!c
->titlebar
.width
)
295 width
= geometry
.width
+ 2 * c
->border
;
297 width
= MIN(c
->titlebar
.width
, geometry
.width
);
298 switch(c
->titlebar
.align
)
303 x_offset
= 2 * c
->border
+ geometry
.width
- width
;
306 x_offset
= (geometry
.width
- width
) / 2;
309 simplewindow_move_resize(c
->titlebar
.sw
,
310 geometry
.x
+ x_offset
,
313 c
->titlebar
.sw
->geometry
.height
);
314 geometry
.y
+= c
->titlebar
.sw
->geometry
.height
;
315 geometry
.height
-= c
->titlebar
.sw
->geometry
.height
;
318 if(!c
->titlebar
.width
)
319 width
= geometry
.width
+ 2 * c
->border
;
321 width
= MIN(c
->titlebar
.width
, geometry
.width
);
322 switch(c
->titlebar
.align
)
327 x_offset
= 2 * c
->border
+ geometry
.width
- width
;
330 x_offset
= (geometry
.width
- width
) / 2;
333 geometry
.height
-= c
->titlebar
.sw
->geometry
.height
;
334 simplewindow_move_resize(c
->titlebar
.sw
,
335 geometry
.x
+ x_offset
,
336 geometry
.y
+ geometry
.height
+ 2 * c
->border
,
338 c
->titlebar
.sw
->geometry
.height
);
341 if(!c
->titlebar
.width
)
342 width
= geometry
.height
+ 2 * c
->border
;
344 width
= MIN(c
->titlebar
.width
, geometry
.height
);
345 switch(c
->titlebar
.align
)
350 y_offset
= 2 * c
->border
+ geometry
.height
- width
;
353 y_offset
= (geometry
.height
- width
) / 2;
356 simplewindow_move_resize(c
->titlebar
.sw
,
358 geometry
.y
+ y_offset
,
359 c
->titlebar
.sw
->geometry
.width
,
361 geometry
.width
-= c
->titlebar
.sw
->geometry
.width
;
362 geometry
.x
+= c
->titlebar
.sw
->geometry
.width
;
365 if(!c
->titlebar
.width
)
366 width
= geometry
.height
+ 2 * c
->border
;
368 width
= MIN(c
->titlebar
.width
, geometry
.height
);
369 switch(c
->titlebar
.align
)
374 y_offset
= 2 * c
->border
+ geometry
.height
- width
;
377 y_offset
= (geometry
.height
- width
) / 2;
380 geometry
.width
-= c
->titlebar
.sw
->geometry
.width
;
381 simplewindow_move_resize(c
->titlebar
.sw
,
382 geometry
.x
+ geometry
.width
+ 2 * c
->border
,
383 geometry
.y
+ y_offset
,
384 c
->titlebar
.sw
->geometry
.width
,
394 /** Toggle window titlebar visibility
395 * \param screen screen number (unused)
396 * \param arg unused argument
397 * \ingroup ui_callback
400 uicb_client_toggletitlebar(int screen
__attribute__ ((unused
)),
401 char *arg
__attribute__ ((unused
)))
403 Client
*c
= globalconf
.focus
->client
;
405 if(!c
|| !c
->titlebar
.sw
)
408 if(!c
->titlebar
.position
)
409 c
->titlebar
.position
= c
->titlebar
.dposition
;
412 c
->titlebar
.position
= Off
;
413 XUnmapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
416 globalconf
.screens
[c
->screen
].need_arrange
= True
;
419 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80