change codename
[awesome.git] / titlebar.h
blob691b695060797a90d55c03ed5f08388e1a154cbf
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 *, bool);
34 void titlebar_ban(wibox_t *);
36 int luaA_titlebar_newindex(lua_State *, wibox_t *, awesome_token_t);
38 /** Add the titlebar geometry and border to a geometry.
39 * \param t The titlebar
40 * \param border The client border size.
41 * \param geometry The geometry
42 * \return A new geometry bigger if the titlebar is visible.
44 static inline area_t
45 titlebar_geometry_add(wibox_t *t, int border, area_t geometry)
47 /* We need to add titlebar border to the total width and height.
48 * This can then be substracted/added to the witdh/height/x/y.
49 * In this case the border is included, because it belongs to a different window.
51 if(t)
52 switch(t->position)
54 case Top:
55 geometry.y -= t->sw.geometry.height;
56 geometry.height += t->sw.geometry.height;
57 break;
58 case Bottom:
59 geometry.height += t->sw.geometry.height;
60 break;
61 case Left:
62 geometry.x -= t->sw.geometry.width;
63 geometry.width += t->sw.geometry.width;
64 break;
65 case Right:
66 geometry.width += t->sw.geometry.width;
67 break;
68 default:
69 break;
72 /* Adding a border to a client only changes width and height, x and y are including border. */
73 geometry.width += 2 * border;
74 geometry.height += 2 * border;
76 return geometry;
79 /** Remove the titlebar geometry and border width to a geometry.
80 * \param t The titlebar.
81 * \param border The client border size.
82 * \param geometry The geometry.
83 * \return A new geometry smaller if the titlebar is visible.
85 static inline area_t
86 titlebar_geometry_remove(wibox_t *t, int border, area_t geometry)
88 /* We need to add titlebar border to the total width and height.
89 * This can then be substracted/added to the witdh/height/x/y.
90 * In this case the border is included, because it belongs to a different window.
92 if(t)
93 switch(t->position)
95 case Top:
96 geometry.y += t->sw.geometry.height;
97 unsigned_subtract(geometry.height, t->sw.geometry.height);
98 break;
99 case Bottom:
100 unsigned_subtract(geometry.height, t->sw.geometry.height);
101 break;
102 case Left:
103 geometry.x += t->sw.geometry.width;
104 unsigned_subtract(geometry.width, t->sw.geometry.width);
105 break;
106 case Right:
107 unsigned_subtract(geometry.width, t->sw.geometry.width);
108 break;
109 default:
110 break;
113 /* Adding a border to a client only changes width and height, x and y are including border. */
114 unsigned_subtract(geometry.width, 2*border);
115 unsigned_subtract(geometry.height, 2*border);
117 return geometry;
120 /** Update the titlebar geometry for a client.
121 * \param c The client.
123 static inline void
124 titlebar_update_geometry(client_t *c)
126 area_t geom;
128 if(!c->titlebar)
129 return;
131 /* Client geometry without titlebar, but including borders, since that is always consistent. */
132 titlebar_geometry_compute(c, titlebar_geometry_remove(c->titlebar, 0, c->geometry), &geom);
133 wibox_moveresize(c->titlebar, geom);
135 /* If the client is banned, move the titlebar out! */
136 if(c->isbanned)
137 titlebar_ban(c->titlebar);
140 #endif
141 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80