2 #define I3__FILE__ "manage.c"
19 xcb_query_tree_reply_t *reply;
21 xcb_window_t *children;
22 xcb_get_window_attributes_cookie_t *cookies;
25 if ((reply = xcb_query_tree_reply(
conn, xcb_query_tree(
conn, root), 0)) == NULL)
28 len = xcb_query_tree_children_length(reply);
29 cookies =
smalloc(len *
sizeof(*cookies));
32 children = xcb_query_tree_children(reply);
33 for (i = 0; i < len; ++i)
34 cookies[i] = xcb_get_window_attributes(
conn, children[i]);
37 for (i = 0; i < len; ++i)
53 DLOG(
"Restoring geometry\n");
75 void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie,
76 bool needs_to_be_mapped) {
77 xcb_drawable_t d = { window };
78 xcb_get_geometry_cookie_t geomc;
79 xcb_get_geometry_reply_t *geom;
80 xcb_get_window_attributes_reply_t *attr = NULL;
82 xcb_get_property_cookie_t wm_type_cookie, strut_cookie, state_cookie,
83 utf8_title_cookie, title_cookie,
84 class_cookie, leader_cookie, transient_cookie,
85 role_cookie, startup_id_cookie, wm_hints_cookie;
88 geomc = xcb_get_geometry(
conn, d);
89 #define FREE_GEOMETRY() do { \
90 if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) != NULL) \
96 if ((attr = xcb_get_window_attributes_reply(
conn, cookie, 0)) == NULL) {
97 DLOG(
"Could not get attributes\n");
102 if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
108 if (attr->override_redirect) {
121 if ((geom = xcb_get_geometry_reply(
conn, geomc, 0)) == NULL) {
122 DLOG(
"could not get geometry\n");
132 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
133 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
135 #define GET_PROPERTY(atom, len) xcb_get_property(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
146 startup_id_cookie =
GET_PROPERTY(A__NET_STARTUP_ID, 512);
150 DLOG(
"Managing window 0x%08x\n", window);
153 cwindow->
id = window;
157 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
158 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
160 XCB_BUTTON_MASK_ANY );
162 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
163 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
165 XCB_BUTTON_MASK_ANY );
178 xcb_get_property_reply_t *startup_id_reply;
179 startup_id_reply = xcb_get_property_reply(
conn, startup_id_cookie, NULL);
181 DLOG(
"startup workspace = %s\n", startup_ws);
189 xcb_get_property_reply_t *reply = xcb_get_property_reply(
conn, wm_type_cookie, NULL);
191 LOG(
"This window is of type dock\n");
193 if (output != NULL) {
194 DLOG(
"Starting search at output %s\n", output->
name);
195 search_at = output->
con;
200 DLOG(
"Top dock client\n");
201 cwindow->
dock = W_DOCK_TOP;
203 DLOG(
"Bottom dock client\n");
204 cwindow->
dock = W_DOCK_BOTTOM;
206 DLOG(
"Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
208 DLOG(
"geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
210 cwindow->
dock = W_DOCK_TOP;
212 DLOG(
"geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
214 cwindow->
dock = W_DOCK_BOTTOM;
219 DLOG(
"Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
231 if ((assignment =
assignment_for(cwindow, A_TO_WORKSPACE | A_TO_OUTPUT))) {
232 DLOG(
"Assignment matches (%p)\n", match);
233 if (assignment->
type == A_TO_WORKSPACE) {
236 if (nc->
type == CT_WORKSPACE)
241 }
else if (startup_ws) {
244 DLOG(
"Using workspace on which this application was started (%s)\n", startup_ws);
246 DLOG(
"focused on ws %s: %p / %s\n", startup_ws, nc, nc->
name);
247 if (nc->
type == CT_WORKSPACE)
253 LOG(
"using current container, focused = %p, focused->name = %s\n",
266 DLOG(
"new container = %p\n", nc);
273 sasprintf(&name,
"[i3 con] container around %p", cwindow);
283 DLOG(
"Not in fullscreen mode, focusing\n");
284 if (!cwindow->
dock) {
294 }
else DLOG(
"not focusing, matched with restart_mode == true\n");
295 }
else DLOG(
"workspace not visible, not focusing\n");
296 }
else DLOG(
"dock, not focusing\n");
298 DLOG(
"fs = %p, ws = %p, not focusing\n", fs, ws);
313 bool want_floating =
false;
318 LOG(
"This window is a dialog window, setting floating\n");
319 want_floating =
true;
325 (cwindow->
leader != XCB_NONE &&
328 LOG(
"This window is transient for another window, setting floating\n");
329 want_floating =
true;
333 LOG(
"There is a fullscreen window, leaving fullscreen mode\n");
340 want_floating =
false;
347 nc->
geometry = (
Rect){ geom->
x, geom->y, geom->width, geom->height };
356 values[0] = XCB_NONE;
357 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
359 xcb_void_cookie_t rcookie = xcb_reparent_window_checked(
conn, window, nc->
frame, 0, 0);
360 if (xcb_request_check(
conn, rcookie) != NULL) {
361 LOG(
"Could not reparent the window, aborting\n");
366 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
369 reply = xcb_get_property_reply(
conn, state_cookie, NULL);
379 xcb_change_save_set(
conn, XCB_SET_MODE_INSERT, window);