Use a libev prepare watcher for calling awesome_refresh()
[awesome.git] / client.h
blobe7ac0e38694ab98ea0a05716b34b073e0dddeb1b
1 /*
2 * client.h - client management header
4 * Copyright © 2007-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_CLIENT_H
23 #define AWESOME_CLIENT_H
25 #include "mouse.h"
26 #include "stack.h"
28 #define CLIENT_SELECT_INPUT_EVENT_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY \
29 | XCB_EVENT_MASK_PROPERTY_CHANGE \
30 | XCB_EVENT_MASK_ENTER_WINDOW \
31 | XCB_EVENT_MASK_LEAVE_WINDOW \
32 | XCB_EVENT_MASK_FOCUS_CHANGE)
34 /** Windows type */
35 typedef enum
37 WINDOW_TYPE_NORMAL = 0,
38 WINDOW_TYPE_DESKTOP,
39 WINDOW_TYPE_DOCK,
40 WINDOW_TYPE_SPLASH,
41 WINDOW_TYPE_DIALOG,
42 /* The ones below may have TRANSIENT_FOR, but are not plain dialogs.
43 * They were purposefully placed below DIALOG.
45 WINDOW_TYPE_MENU,
46 WINDOW_TYPE_TOOLBAR,
47 WINDOW_TYPE_UTILITY,
48 /* This ones are usually set on override-redirect windows. */
49 WINDOW_TYPE_DROPDOWN_MENU,
50 WINDOW_TYPE_POPUP_MENU,
51 WINDOW_TYPE_TOOLTIP,
52 WINDOW_TYPE_NOTIFICATION,
53 WINDOW_TYPE_COMBO,
54 WINDOW_TYPE_DND
55 } window_type_t;
57 /* Strut */
58 typedef struct
60 uint16_t left, right, top, bottom;
61 uint16_t left_start_y, left_end_y;
62 uint16_t right_start_y, right_end_y;
63 uint16_t top_start_x, top_end_x;
64 uint16_t bottom_start_x, bottom_end_x;
65 } strut_t;
67 /** client_t type */
68 struct client_t
70 LUA_OBJECT_HEADER
71 /** Valid, or not ? */
72 bool invalid;
73 /** Client name */
74 char *name, *icon_name;
75 /** WM_CLASS stuff */
76 char *class, *instance;
77 /** Startup ID */
78 char *startup_id;
79 /** Window geometry */
80 area_t geometry;
81 struct
83 /** Client geometry when (un)fullscreen */
84 area_t fullscreen;
85 /** Client geometry when (un)-max */
86 area_t max;
87 /** Internal geometry (matching X11 protocol) */
88 area_t internal;
89 } geometries;
90 /** Strut */
91 strut_t strut;
92 /** Border width and pre-fullscreen border width */
93 int border, border_fs;
94 xcolor_t border_color;
95 /** True if the client is sticky */
96 bool issticky;
97 /** Has urgency hint */
98 bool isurgent;
99 /** True if the client is hidden */
100 bool ishidden;
101 /** True if the client is minimized */
102 bool isminimized;
103 /** True if the client is fullscreen */
104 bool isfullscreen;
105 /** True if the client is maximized horizontally */
106 bool ismaxhoriz;
107 /** True if the client is maximized vertically */
108 bool ismaxvert;
109 /** True if the client is above others */
110 bool isabove;
111 /** True if the client is below others */
112 bool isbelow;
113 /** True if the client is modal */
114 bool ismodal;
115 /** True if the client is on top */
116 bool isontop;
117 /** True if a client is banned to a position outside the viewport.
118 * Note that the geometry remains unchanged and that the window is still mapped.
120 bool isbanned;
121 /** true if the client must be skipped from task bar client list */
122 bool skiptb;
123 /** True if the client cannot have focus */
124 bool nofocus;
125 /** The window type */
126 window_type_t type;
127 /** Window of the client */
128 xcb_window_t win;
129 /** Window of the group leader */
130 xcb_window_t group_win;
131 /** Window holding command needed to start it (session management related) */
132 xcb_window_t leader_win;
133 /** Client logical screen */
134 screen_t *screen;
135 /** Client physical screen */
136 int phys_screen;
137 /** Titlebar */
138 wibox_t *titlebar;
139 /** Button bindings */
140 button_array_t buttons;
141 /** Key bindings */
142 key_array_t keys;
143 /** Icon */
144 image_t *icon;
145 /** Size hints */
146 xcb_size_hints_t size_hints;
147 bool size_hints_honor;
148 /** Window it is transient for */
149 client_t *transient_for;
152 client_t * luaA_client_checkudata(lua_State *, int);
154 ARRAY_FUNCS(client_t *, client, DO_NOTHING)
155 LUA_OBJECT_FUNCS(client_t, client, "client")
157 #define client_need_reban(c) \
158 do { \
159 if(!c->screen->need_reban \
160 && client_isvisible(c, (c)->screen)) \
161 c->screen->need_reban = true; \
162 } while(0)
164 bool client_maybevisible(client_t *, screen_t *);
165 client_t * client_getbywin(xcb_window_t);
166 void client_ban(client_t *);
167 void client_unban(client_t *);
168 void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int, bool);
169 area_t client_geometry_hints(client_t *, area_t);
170 bool client_resize(client_t *, area_t, bool);
171 void client_unmanage(client_t *);
172 void client_kill(client_t *);
173 void client_setsticky(client_t *, bool);
174 void client_setabove(client_t *, bool);
175 void client_setbelow(client_t *, bool);
176 void client_setmodal(client_t *, bool);
177 void client_setontop(client_t *, bool);
178 void client_setfullscreen(client_t *, bool);
179 void client_setmaxhoriz(client_t *, bool);
180 void client_setmaxvert(client_t *, bool);
181 void client_setminimized(client_t *, bool);
182 void client_setborder(client_t *, int);
183 void client_seturgent(client_t *, bool);
184 void client_focus(client_t *);
185 void client_focus_update(client_t *);
186 void client_unfocus(client_t *);
187 void client_unfocus_update(client_t *);
188 void client_stack_refresh(void);
190 static inline void
191 client_stack(void)
193 globalconf.client_need_stack_refresh = true;
196 /** Put client on top of the stack.
197 * \param c The client to raise.
199 static inline void
200 client_raise(client_t *c)
202 client_t *tc = c;
203 int counter = 0;
205 /* Find number of transient layers. */
206 for(counter = 0; tc->transient_for; counter++)
207 tc = tc->transient_for;
209 /* Push them in reverse order. */
210 for(; counter > 0; counter--)
212 tc = c;
213 for(int i = 0; i < counter; i++)
214 tc = tc->transient_for;
215 stack_client_append(tc);
218 /* Push c on top of the stack. */
219 stack_client_append(c);
220 client_stack();
223 /** Put client on the end of the stack.
224 * \param c The client to lower.
226 static inline void
227 client_lower(client_t *c)
229 stack_client_push(c);
231 /* Traverse all transient layers. */
232 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
233 stack_client_push(tc);
235 client_stack();
238 /** Check if a client has fixed size.
239 * \param c A client.
240 * \return A boolean value, true if the client has a fixed size.
242 static inline bool
243 client_isfixed(client_t *c)
245 return (c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE
246 && c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE
247 && c->size_hints.max_width == c->size_hints.min_width
248 && c->size_hints.max_height == c->size_hints.min_height
249 && c->size_hints.max_width
250 && c->size_hints.max_height);
253 /** Returns true if a client is tagged with one of the tags of the
254 * specified screen and is not hidden. Note that "banned" clients are included.
255 * \param c The client to check.
256 * \param screen Virtual screen number.
257 * \return true if the client is visible, false otherwise.
259 static inline bool
260 client_isvisible(client_t *c, screen_t *screen)
262 return (!c->ishidden && !c->isminimized && client_maybevisible(c, screen));
265 /** Check if a client has strut information.
266 * \param c A client.
267 * \return A boolean value, true if the client has strut information.
269 static inline bool
270 client_hasstrut(client_t *c)
272 return (c->strut.left
273 || c->strut.right
274 || c->strut.top
275 || c->strut.bottom
276 || c->strut.left_start_y
277 || c->strut.left_end_y
278 || c->strut.right_start_y
279 || c->strut.right_end_y
280 || c->strut.top_start_x
281 || c->strut.top_end_x
282 || c->strut.bottom_start_x
283 || c->strut.bottom_end_x);
286 #endif
287 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80