17 xcb_query_tree_reply_t *reply;
19 xcb_window_t *children;
20 xcb_get_window_attributes_cookie_t *cookies;
23 if ((reply = xcb_query_tree_reply(
conn, xcb_query_tree(
conn, root), 0)) == NULL)
26 len = xcb_query_tree_children_length(reply);
27 cookies =
smalloc(len *
sizeof(*cookies));
30 children = xcb_query_tree_children(reply);
31 for (i = 0; i < len; ++i)
32 cookies[i] = xcb_get_window_attributes(
conn, children[i]);
35 for (i = 0; i < len; ++i)
51 DLOG(
"Restoring geometry\n");
73 void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie,
74 bool needs_to_be_mapped) {
75 xcb_drawable_t d = { window };
76 xcb_get_geometry_cookie_t geomc;
77 xcb_get_geometry_reply_t *geom;
78 xcb_get_window_attributes_reply_t *attr = NULL;
80 xcb_get_property_cookie_t wm_type_cookie, strut_cookie, state_cookie,
81 utf8_title_cookie, title_cookie,
82 class_cookie, leader_cookie, transient_cookie,
83 role_cookie, startup_id_cookie, wm_hints_cookie;
86 geomc = xcb_get_geometry(
conn, d);
87 #define FREE_GEOMETRY() do { \
88 if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) != NULL) \
94 if ((attr = xcb_get_window_attributes_reply(
conn, cookie, 0)) == NULL) {
95 DLOG(
"Could not get attributes\n");
100 if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
106 if (attr->override_redirect) {
119 if ((geom = xcb_get_geometry_reply(
conn, geomc, 0)) == NULL) {
120 DLOG(
"could not get geometry\n");
130 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
131 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
133 #define GET_PROPERTY(atom, len) xcb_get_property(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
144 startup_id_cookie =
GET_PROPERTY(A__NET_STARTUP_ID, 512);
148 DLOG(
"Managing window 0x%08x\n", window);
151 cwindow->
id = window;
155 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
156 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
158 XCB_BUTTON_MASK_ANY );
160 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
161 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
163 XCB_BUTTON_MASK_ANY );
176 xcb_get_property_reply_t *startup_id_reply;
177 startup_id_reply = xcb_get_property_reply(
conn, startup_id_cookie, NULL);
179 DLOG(
"startup workspace = %s\n", startup_ws);
187 xcb_get_property_reply_t *reply = xcb_get_property_reply(
conn, wm_type_cookie, NULL);
189 LOG(
"This window is of type dock\n");
191 if (output != NULL) {
192 DLOG(
"Starting search at output %s\n", output->
name);
193 search_at = output->
con;
198 DLOG(
"Top dock client\n");
199 cwindow->
dock = W_DOCK_TOP;
201 DLOG(
"Bottom dock client\n");
202 cwindow->
dock = W_DOCK_BOTTOM;
204 DLOG(
"Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
206 DLOG(
"geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
208 cwindow->
dock = W_DOCK_TOP;
210 DLOG(
"geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
212 cwindow->
dock = W_DOCK_BOTTOM;
217 DLOG(
"Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
229 if ((assignment =
assignment_for(cwindow, A_TO_WORKSPACE | A_TO_OUTPUT))) {
230 DLOG(
"Assignment matches (%p)\n", match);
231 if (assignment->
type == A_TO_WORKSPACE) {
234 if (nc->
type == CT_WORKSPACE)
239 }
else if (startup_ws) {
242 DLOG(
"Using workspace on which this application was started (%s)\n", startup_ws);
244 DLOG(
"focused on ws %s: %p / %s\n", startup_ws, nc, nc->
name);
245 if (nc->
type == CT_WORKSPACE)
251 LOG(
"using current container, focused = %p, focused->name = %s\n",
264 DLOG(
"new container = %p\n", nc);
271 sasprintf(&name,
"[i3 con] container around %p", cwindow);
281 DLOG(
"Not in fullscreen mode, focusing\n");
282 if (!cwindow->
dock) {
292 }
else DLOG(
"not focusing, matched with restart_mode == true\n");
293 }
else DLOG(
"workspace not visible, not focusing\n");
294 }
else DLOG(
"dock, not focusing\n");
296 DLOG(
"fs = %p, ws = %p, not focusing\n", fs, ws);
311 bool want_floating =
false;
316 LOG(
"This window is a dialog window, setting floating\n");
317 want_floating =
true;
323 (cwindow->
leader != XCB_NONE &&
326 LOG(
"This window is transiert for another window, setting floating\n");
327 want_floating =
true;
331 LOG(
"There is a fullscreen window, leaving fullscreen mode\n");
338 want_floating =
false;
345 nc->
geometry = (
Rect){ geom->
x, geom->y, geom->width, geom->height };
354 values[0] = XCB_NONE;
355 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
357 xcb_void_cookie_t rcookie = xcb_reparent_window_checked(
conn, window, nc->
frame, 0, 0);
358 if (xcb_request_check(
conn, rcookie) != NULL) {
359 LOG(
"Could not reparent the window, aborting\n");
364 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
367 reply = xcb_get_property_reply(
conn, state_cookie, NULL);
377 xcb_change_save_set(
conn, XCB_SET_MODE_INSERT, window);