Use relative paths for the titlebar icons (FS#809)
[awesome.git] / titlebar.h
blob42d0af666a3de68c29e43885491f0c59946c2918
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"
26 #include "client.h"
27 #include "window.h"
29 client_t * client_getbytitlebar(wibox_t *);
30 client_t * client_getbytitlebarwin(xcb_window_t);
31 void titlebar_geometry_compute(client_t *, area_t, area_t *);
32 void titlebar_init(client_t *);
33 void titlebar_client_detach(client_t *);
34 void titlebar_client_attach(client_t *);
35 void titlebar_set_visible(wibox_t *, bool);
36 void titlebar_ban(wibox_t *);
37 void titlebar_unban(wibox_t *);
39 int luaA_titlebar_set_position(lua_State *, int);
41 static inline bool
42 titlebar_isvisible(client_t *c, screen_t *screen)
44 if(client_isvisible(c, screen))
46 if(c->fullscreen)
47 return false;
48 if(!c->titlebar || !c->titlebar->visible)
49 return false;
50 return true;
52 return false;
55 /** Add the titlebar geometry and border to a geometry.
56 * \param t The titlebar
57 * \param border The client border size.
58 * \param geometry The geometry
59 * \return A new geometry bigger if the titlebar is visible.
61 static inline area_t
62 titlebar_geometry_add(wibox_t *t, int border, area_t geometry)
64 /* We need to add titlebar border to the total width and height.
65 * This can then be subtracted/added to the width/height/x/y.
66 * In this case the border is included, because it belongs to a different window.
68 if(t && t->visible)
69 switch(t->position)
71 case Top:
72 geometry.y -= t->geometry.height;
73 geometry.height += t->geometry.height;
74 break;
75 case Bottom:
76 geometry.height += t->geometry.height;
77 break;
78 case Left:
79 geometry.x -= t->geometry.width;
80 geometry.width += t->geometry.width;
81 break;
82 case Right:
83 geometry.width += t->geometry.width;
84 break;
85 default:
86 break;
89 /* Adding a border to a client only changes width and height, x and y are including border. */
90 geometry.width += 2 * border;
91 geometry.height += 2 * border;
93 return geometry;
96 /** Remove the titlebar geometry and border width to a geometry.
97 * \param t The titlebar.
98 * \param border The client border size.
99 * \param geometry The geometry.
100 * \return A new geometry smaller if the titlebar is visible.
102 static inline area_t
103 titlebar_geometry_remove(wibox_t *t, int border, area_t geometry)
105 /* We need to add titlebar border to the total width and height.
106 * This can then be subtracted/added to the width/height/x/y.
107 * In this case the border is included, because it belongs to a different window.
109 if(t && t->visible)
110 switch(t->position)
112 case Top:
113 geometry.y += t->geometry.height;
114 unsigned_subtract(geometry.height, t->geometry.height);
115 break;
116 case Bottom:
117 unsigned_subtract(geometry.height, t->geometry.height);
118 break;
119 case Left:
120 geometry.x += t->geometry.width;
121 unsigned_subtract(geometry.width, t->geometry.width);
122 break;
123 case Right:
124 unsigned_subtract(geometry.width, t->geometry.width);
125 break;
126 default:
127 break;
130 /* Adding a border to a client only changes width and height, x and y are including border. */
131 unsigned_subtract(geometry.width, 2*border);
132 unsigned_subtract(geometry.height, 2*border);
134 return geometry;
137 /** Update the titlebar geometry for a client.
138 * \param c The client.
140 static inline void
141 titlebar_update_geometry(client_t *c)
143 area_t geom;
145 if(!c->titlebar)
146 return;
148 /* Client geometry without titlebar, but including borders, since that is always consistent. */
149 titlebar_geometry_compute(c, titlebar_geometry_remove(c->titlebar, 0, c->geometry), &geom);
150 luaA_object_push(globalconf.L, c->titlebar);
151 wibox_moveresize(globalconf.L, -1, geom);
152 lua_pop(globalconf.L, 1);
155 #endif
156 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80