naughty: check for D-Bus availability
[awesome.git] / titlebar.h
blobdd8e9b993a143c17c3dc150c11efeb284884d34f
1 /*
2 * titlebar.h - titlebar management header
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 #ifndef AWESOME_TITLEBAR_H
23 #define AWESOME_TITLEBAR_H
25 #include "wibox.h"
27 client_t * client_getbytitlebar(wibox_t *);
28 client_t * client_getbytitlebarwin(xcb_window_t);
29 void titlebar_geometry_compute(client_t *, area_t, area_t *);
30 void titlebar_init(client_t *);
31 void titlebar_client_detach(client_t *);
32 void titlebar_client_attach(client_t *, wibox_t *);
33 void titlebar_set_visible(wibox_t *t, bool visible);
35 int luaA_titlebar_newindex(lua_State *, wibox_t *, awesome_token_t);
37 /** Add the titlebar geometry and border to a geometry.
38 * \param t The titlebar
39 * \param border The client border size.
40 * \param geometry The geometry
41 * \return A new geometry bigger if the titlebar is visible.
43 static inline area_t
44 titlebar_geometry_add(wibox_t *t, int border, area_t geometry)
46 /* We need to add titlebar border to the total width and height.
47 * This can then be substracted/added to the witdh/height/x/y.
48 * In this case the border is included, because it belongs to a different window.
50 if(t)
51 switch(t->position)
53 case Top:
54 geometry.y -= t->sw.geometry.height;
55 geometry.height += t->sw.geometry.height;
56 break;
57 case Bottom:
58 geometry.height += t->sw.geometry.height;
59 break;
60 case Left:
61 geometry.x -= t->sw.geometry.width;
62 geometry.width += t->sw.geometry.width;
63 break;
64 case Right:
65 geometry.width += t->sw.geometry.width;
66 break;
67 default:
68 break;
71 /* Adding a border to a client only changes width and height, x and y are including border. */
72 geometry.width += 2 * border;
73 geometry.height += 2 * border;
75 return geometry;
78 /** Remove the titlebar geometry and border width to a geometry.
79 * \param t The titlebar.
80 * \param border The client border size.
81 * \param geometry The geometry.
82 * \return A new geometry smaller if the titlebar is visible.
84 static inline area_t
85 titlebar_geometry_remove(wibox_t *t, int border, area_t geometry)
87 /* We need to add titlebar border to the total width and height.
88 * This can then be substracted/added to the witdh/height/x/y.
89 * In this case the border is included, because it belongs to a different window.
91 if(t)
92 switch(t->position)
94 case Top:
95 geometry.y += t->sw.geometry.height;
96 unsigned_subtract(geometry.height, t->sw.geometry.height);
97 break;
98 case Bottom:
99 unsigned_subtract(geometry.height, t->sw.geometry.height);
100 break;
101 case Left:
102 geometry.x += t->sw.geometry.width;
103 unsigned_subtract(geometry.width, t->sw.geometry.width);
104 break;
105 case Right:
106 unsigned_subtract(geometry.width, t->sw.geometry.width);
107 break;
108 default:
109 break;
112 /* Adding a border to a client only changes width and height, x and y are including border. */
113 unsigned_subtract(geometry.width, 2*border);
114 unsigned_subtract(geometry.height, 2*border);
116 return geometry;
119 /** Update the titlebar geometry for a client.
120 * \param c The client.
122 static inline void
123 titlebar_update_geometry(client_t *c)
125 area_t geom;
127 if(!c->titlebar)
128 return;
130 titlebar_geometry_compute(c, c->geometry, &geom);
131 /* Can't actually move titlebar right now, but we will resize it. */
132 if(c->isbanned)
134 area_t moved_geom = geom;
136 /* Make sure it stays outside the viewport. */
137 moved_geom.x = - geom.width;
138 moved_geom.y = - geom.height;
140 wibox_moveresize(c->titlebar, moved_geom);
142 /* Store the real geometry. */
143 c->titlebar->sw.geometry = geom;
145 else
146 wibox_moveresize(c->titlebar, geom);
149 #endif
150 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80