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.
30 extern awesome_t globalconf
;
32 /** Get a client by its titlebar.
33 * \param titlebar The titlebar.
37 client_getbytitlebar(wibox_t
*titlebar
)
41 for(c
= globalconf
.clients
; c
; c
= c
->next
)
42 if(c
->titlebar
== titlebar
)
48 /** Get a client by its titlebar window.
49 * \param win The window.
53 client_getbytitlebarwin(xcb_window_t win
)
57 for(c
= globalconf
.clients
; c
; c
= c
->next
)
58 if(c
->titlebar
&& c
->titlebar
->sw
.window
== win
)
65 titlebar_geometry_compute(client_t
*c
, area_t geometry
, area_t
*res
)
67 int width
, x_offset
= 0, y_offset
= 0;
69 switch(c
->titlebar
->position
)
74 width
= MAX(1, geometry
.width
+ 2 * c
->border
- 2 * c
->titlebar
->sw
.border
.width
);
75 switch(c
->titlebar
->align
)
80 x_offset
= 2 * c
->border
+ geometry
.width
- width
- 2 * c
->titlebar
->sw
.border
.width
;
83 x_offset
= (geometry
.width
- width
) / 2;
86 res
->x
= geometry
.x
+ x_offset
;
87 res
->y
= geometry
.y
- c
->titlebar
->sw
.geometry
.height
- 2 * c
->titlebar
->sw
.border
.width
+ c
->border
;
89 res
->height
= c
->titlebar
->sw
.geometry
.height
;
92 width
= MAX(1, geometry
.width
+ 2 * c
->border
- 2 * c
->titlebar
->sw
.border
.width
);
93 switch(c
->titlebar
->align
)
98 x_offset
= 2 * c
->border
+ geometry
.width
- width
- 2 * c
->titlebar
->sw
.border
.width
;
101 x_offset
= (geometry
.width
- width
) / 2;
104 res
->x
= geometry
.x
+ x_offset
;
105 res
->y
= geometry
.y
+ geometry
.height
+ c
->border
;
107 res
->height
= c
->titlebar
->sw
.geometry
.height
;
110 width
= MAX(1, geometry
.height
+ 2 * c
->border
- 2 * c
->titlebar
->sw
.border
.width
);
111 switch(c
->titlebar
->align
)
116 y_offset
= 2 * c
->border
+ geometry
.height
- width
- 2 * c
->titlebar
->sw
.border
.width
;
119 y_offset
= (geometry
.height
- width
) / 2;
122 res
->x
= geometry
.x
- c
->titlebar
->sw
.geometry
.width
+ c
->border
;
123 res
->y
= geometry
.y
+ y_offset
;
124 res
->width
= c
->titlebar
->sw
.geometry
.width
;
128 width
= MAX(1, geometry
.height
+ 2 * c
->border
- 2 * c
->titlebar
->sw
.border
.width
);
129 switch(c
->titlebar
->align
)
134 y_offset
= 2 * c
->border
+ geometry
.height
- width
- 2 * c
->titlebar
->sw
.border
.width
;
137 y_offset
= (geometry
.height
- width
) / 2;
140 res
->x
= geometry
.x
+ geometry
.width
+ c
->border
;
141 res
->y
= geometry
.y
+ y_offset
;
142 res
->width
= c
->titlebar
->sw
.geometry
.width
;
148 /** Detach a wibox titlebar from its client.
149 * \param c The client.
152 titlebar_client_detach(client_t
*c
)
154 /* If client has a titlebar, kick it out. */
157 simplewindow_wipe(&c
->titlebar
->sw
);
158 c
->titlebar
->type
= WIBOX_TYPE_NORMAL
;
159 c
->titlebar
->screen
= SCREEN_UNDEF
;
160 wibox_unref(&c
->titlebar
);
162 client_need_arrange(c
);
167 /** Attach a wibox to a client as its titlebar.
168 * \param c The client.
169 * \param t The wibox/titlebar.
172 titlebar_client_attach(client_t
*c
, wibox_t
*t
)
174 titlebar_client_detach(c
);
180 /* check if titlebar is already on a client */
181 titlebar_client_detach(client_getbytitlebar(t
));
183 c
->titlebar
= wibox_ref(&t
);
184 t
->type
= WIBOX_TYPE_TITLEBAR
;
185 t
->screen
= c
->screen
;
193 if(!t
->sw
.geometry
.height
)
194 t
->sw
.geometry
.height
= 1.5 * globalconf
.font
->height
;
198 if(!t
->sw
.geometry
.width
)
199 t
->sw
.geometry
.width
= 1.5 * globalconf
.font
->height
;
204 titlebar_geometry_compute(c
, c
->geometry
, &wingeom
);
206 simplewindow_init(&t
->sw
, c
->phys_screen
,
207 wingeom
, 0, t
->sw
.orientation
,
208 &t
->sw
.ctx
.fg
, &t
->sw
.ctx
.bg
);
209 simplewindow_border_color_set(&t
->sw
, &t
->sw
.border
.color
);
211 t
->need_update
= true;
214 xcb_map_window(globalconf
.connection
, t
->sw
.window
);
216 client_need_arrange(c
);
221 /** Titlebar newindex.
222 * \param L The Lua VM state.
223 * \param titlebar The wibox titlebar.
224 * \param tok The attribute token.
225 * \return The number of elements pushed on stack.
228 luaA_titlebar_newindex(lua_State
*L
, wibox_t
*titlebar
, awesome_token_t tok
)
240 if((buf
= luaL_checklstring(L
, 3, &len
)))
241 titlebar
->align
= draw_align_fromstr(buf
, len
);
245 case A_TK_BORDER_WIDTH
:
246 if((i
= luaL_checknumber(L
, 3)) >= 0)
247 simplewindow_border_width_set(&titlebar
->sw
, i
);
251 case A_TK_BORDER_COLOR
:
252 if((buf
= luaL_checklstring(L
, 3, &len
)))
253 if(xcolor_init_reply(xcolor_init_unchecked(&titlebar
->sw
.border
.color
, buf
, len
)))
254 simplewindow_border_color_set(&titlebar
->sw
, &titlebar
->sw
.border
.color
);
257 buf
= luaL_checklstring(L
, 3, &len
);
258 position
= position_fromstr(buf
, len
);
259 if(position
!= titlebar
->position
)
264 switch(titlebar
->position
)
273 tmp
= titlebar
->sw
.geometry
.width
;
274 titlebar
->sw
.geometry
.width
= titlebar
->sw
.geometry
.height
;
275 titlebar
->sw
.geometry
.height
= tmp
;
278 simplewindow_orientation_set(&titlebar
->sw
, North
);
281 switch(titlebar
->position
)
290 tmp
= titlebar
->sw
.geometry
.width
;
291 titlebar
->sw
.geometry
.width
= titlebar
->sw
.geometry
.height
;
292 titlebar
->sw
.geometry
.height
= tmp
;
295 simplewindow_orientation_set(&titlebar
->sw
, South
);
300 switch(titlebar
->position
)
305 tmp
= titlebar
->sw
.geometry
.width
;
306 titlebar
->sw
.geometry
.width
= titlebar
->sw
.geometry
.height
;
307 titlebar
->sw
.geometry
.height
= tmp
;
314 simplewindow_orientation_set(&titlebar
->sw
, East
);
317 titlebar
->position
= position
;
318 if((c
= client_getbytitlebar(titlebar
)))
320 titlebar_update_geometry_floating(c
);
321 /* call geometry hook for client because some like to
322 * set titlebar width in that hook, which make sense */
323 hooks_property(c
, "geometry");
331 if((c
|| (c
= client_getbytitlebar(titlebar
))))
332 client_need_arrange(c
);
337 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80