titlebar: fix removal of too much elements (FS#603)
[awesome.git] / client.h
blob0bc9b3de8253ecf2d38bf47e53726bdc1aa9d4d6
1 /*
2 * client.h - client management header
4 * Copyright © 2007-2009 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_CLIENT_H
23 #define AWESOME_CLIENT_H
25 #include "mouse.h"
26 #include "stack.h"
27 #include "strut.h"
28 #include "common/luaobject.h"
30 #define CLIENT_SELECT_INPUT_EVENT_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY \
31 | XCB_EVENT_MASK_PROPERTY_CHANGE \
32 | XCB_EVENT_MASK_ENTER_WINDOW \
33 | XCB_EVENT_MASK_LEAVE_WINDOW \
34 | XCB_EVENT_MASK_FOCUS_CHANGE)
36 /** Windows type */
37 typedef enum
39 WINDOW_TYPE_NORMAL = 0,
40 WINDOW_TYPE_DESKTOP,
41 WINDOW_TYPE_DOCK,
42 WINDOW_TYPE_SPLASH,
43 WINDOW_TYPE_DIALOG,
44 /* The ones below may have TRANSIENT_FOR, but are not plain dialogs.
45 * They were purposefully placed below DIALOG.
47 WINDOW_TYPE_MENU,
48 WINDOW_TYPE_TOOLBAR,
49 WINDOW_TYPE_UTILITY,
50 /* This ones are usually set on override-redirect windows. */
51 WINDOW_TYPE_DROPDOWN_MENU,
52 WINDOW_TYPE_POPUP_MENU,
53 WINDOW_TYPE_TOOLTIP,
54 WINDOW_TYPE_NOTIFICATION,
55 WINDOW_TYPE_COMBO,
56 WINDOW_TYPE_DND
57 } window_type_t;
59 /** client_t type */
60 struct client_t
62 LUA_OBJECT_HEADER
63 /** Valid, or not ? */
64 bool invalid;
65 /** Client name */
66 char *name, *alt_name, *icon_name, *alt_icon_name;
67 /** WM_CLASS stuff */
68 char *class, *instance;
69 /** Window geometry */
70 area_t geometry;
71 struct
73 /** Client geometry when (un)fullscreen */
74 area_t fullscreen;
75 /** Client geometry when (un)-max */
76 area_t max;
77 /** Internal geometry (matching X11 protocol) */
78 area_t internal;
79 } geometries;
80 /** Strut */
81 strut_t strut;
82 /** Border width and pre-fullscreen border width */
83 int border_width, border_width_fs;
84 xcolor_t border_color;
85 /** True if the client is sticky */
86 bool sticky;
87 /** Has urgency hint */
88 bool urgent;
89 /** True if the client is hidden */
90 bool hidden;
91 /** True if the client is minimized */
92 bool minimized;
93 /** True if the client is fullscreen */
94 bool fullscreen;
95 /** True if the client is maximized horizontally */
96 bool maximized_horizontal;
97 /** True if the client is maximized vertically */
98 bool maximized_vertical;
99 /** True if the client is above others */
100 bool above;
101 /** True if the client is below others */
102 bool below;
103 /** True if the client is modal */
104 bool modal;
105 /** True if the client is on top */
106 bool ontop;
107 /** True if a client is banned to a position outside the viewport.
108 * Note that the geometry remains unchanged and that the window is still mapped.
110 bool isbanned;
111 /** true if the client must be skipped from task bar client list */
112 bool skip_taskbar;
113 /** True if the client cannot have focus */
114 bool nofocus;
115 /** The window type */
116 window_type_t type;
117 /** Window of the client */
118 xcb_window_t window;
119 /** Window of the group leader */
120 xcb_window_t group_window;
121 /** Window holding command needed to start it (session management related) */
122 xcb_window_t leader_window;
123 /** Client's WM_PROTOCOLS property */
124 xcb_get_wm_protocols_reply_t protocols;
125 /** Client logical screen */
126 screen_t *screen;
127 /** Client physical screen */
128 int phys_screen;
129 /** Titlebar */
130 wibox_t *titlebar;
131 /** Button bindings */
132 button_array_t buttons;
133 /** Key bindings */
134 key_array_t keys;
135 /** Icon */
136 image_t *icon;
137 /** Size hints */
138 xcb_size_hints_t size_hints;
139 bool size_hints_honor;
140 /** Machine the client is running on. */
141 char *machine;
142 /** Role of the client */
143 char *role;
144 /** Client pid */
145 uint32_t pid;
146 /** Window it is transient for */
147 client_t *transient_for;
148 /** Window opacity */
149 double opacity;
152 client_t * luaA_client_checkudata(lua_State *, int);
154 ARRAY_FUNCS(client_t *, client, DO_NOTHING)
156 /** Client class */
157 lua_class_t client_class;
159 LUA_OBJECT_FUNCS(client_class, client_t, client)
161 #define client_need_reban(c) \
162 do { \
163 if(!c->screen->need_reban \
164 && client_isvisible(c, (c)->screen)) \
165 c->screen->need_reban = true; \
166 } while(0)
168 bool client_maybevisible(client_t *, screen_t *);
169 client_t * client_getbywin(xcb_window_t);
170 void client_ban(client_t *);
171 void client_unban(client_t *);
172 void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int, bool);
173 area_t client_geometry_hints(client_t *, area_t);
174 bool client_resize(client_t *, area_t, bool);
175 void client_unmanage(client_t *);
176 void client_kill(client_t *);
177 void client_set_sticky(lua_State *, int, bool);
178 void client_set_above(lua_State *, int, bool);
179 void client_set_below(lua_State *, int, bool);
180 void client_set_modal(lua_State *, int, bool);
181 void client_set_ontop(lua_State *, int, bool);
182 void client_set_fullscreen(lua_State *, int, bool);
183 void client_set_maximized_horizontal(lua_State *, int, bool);
184 void client_set_maximized_vertical(lua_State *, int, bool);
185 void client_set_minimized(lua_State *, int, bool);
186 void client_set_border_width(lua_State *, int, int);
187 void client_set_urgent(lua_State *, int, bool);
188 void client_set_pid(lua_State *, int, uint32_t);
189 void client_set_role(lua_State *, int, char *);
190 void client_set_machine(lua_State *, int, char *);
191 void client_set_icon_name(lua_State *, int, char *);
192 void client_set_alt_icon_name(lua_State *, int, char *);
193 void client_set_class_instance(lua_State *, int, const char *, const char *);
194 void client_set_type(lua_State *L, int, window_type_t);
195 void client_set_transient_for(lua_State *L, int, client_t *);
196 void client_set_name(lua_State *L, int, char *);
197 void client_set_alt_name(lua_State *L, int, char *);
198 void client_set_group_window(lua_State *, int, xcb_window_t);
199 void client_set_icon(lua_State *, int, int);
200 void client_set_skip_taskbar(lua_State *, int, bool);
201 void client_set_opacity(lua_State *, int, double);
202 void client_focus(client_t *);
203 void client_focus_update(client_t *);
204 void client_unfocus(client_t *);
205 void client_unfocus_update(client_t *);
206 void client_stack_refresh(void);
207 bool client_hasproto(client_t *, xcb_atom_t);
208 void client_set_focus(client_t *, bool);
209 void client_ignore_enterleave_events(void);
210 void client_restore_enterleave_events(void);
211 void client_class_setup(lua_State *);
213 static inline void
214 client_stack(void)
216 globalconf.client_need_stack_refresh = true;
219 /** Put client on top of the stack.
220 * \param c The client to raise.
222 static inline void
223 client_raise(client_t *c)
225 client_t *tc = c;
226 int counter = 0;
228 /* Find number of transient layers.
229 * We limit the counter to the stack length: if some case, a buggy
230 * application might set transient_for as a loop… */
231 for(counter = 0; tc->transient_for && counter <= globalconf.stack.len; counter++)
232 tc = tc->transient_for;
234 /* Push them in reverse order. */
235 for(; counter > 0; counter--)
237 tc = c;
238 for(int i = 0; i < counter; i++)
239 tc = tc->transient_for;
240 stack_client_append(tc);
243 /* Push c on top of the stack. */
244 stack_client_append(c);
245 client_stack();
248 /** Put client on the end of the stack.
249 * \param c The client to lower.
251 static inline void
252 client_lower(client_t *c)
254 stack_client_push(c);
256 /* Traverse all transient layers. */
257 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
258 stack_client_push(tc);
260 client_stack();
263 /** Check if a client has fixed size.
264 * \param c A client.
265 * \return A boolean value, true if the client has a fixed size.
267 static inline bool
268 client_isfixed(client_t *c)
270 return (c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE
271 && c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE
272 && c->size_hints.max_width == c->size_hints.min_width
273 && c->size_hints.max_height == c->size_hints.min_height
274 && c->size_hints.max_width
275 && c->size_hints.max_height);
278 /** Returns true if a client is tagged with one of the tags of the
279 * specified screen and is not hidden. Note that "banned" clients are included.
280 * \param c The client to check.
281 * \param screen Virtual screen number.
282 * \return true if the client is visible, false otherwise.
284 static inline bool
285 client_isvisible(client_t *c, screen_t *screen)
287 return (!c->hidden && !c->minimized && client_maybevisible(c, screen));
290 /** Check if a client has strut information.
291 * \param c A client.
292 * \return A boolean value, true if the client has strut information.
294 static inline bool
295 client_hasstrut(client_t *c)
297 return (c->strut.left
298 || c->strut.right
299 || c->strut.top
300 || c->strut.bottom
301 || c->strut.left_start_y
302 || c->strut.left_end_y
303 || c->strut.right_start_y
304 || c->strut.right_end_y
305 || c->strut.top_start_x
306 || c->strut.top_end_x
307 || c->strut.bottom_start_x
308 || c->strut.bottom_end_x);
311 #endif
312 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80