2 #define I3__FILE__ "manage.c"
15 #include <yajl/yajl_gen.h>
22 xcb_query_tree_reply_t *reply;
24 xcb_window_t *children;
25 xcb_get_window_attributes_cookie_t *cookies;
28 if ((reply = xcb_query_tree_reply(
conn, xcb_query_tree(
conn, root), 0)) == NULL)
31 len = xcb_query_tree_children_length(reply);
32 cookies =
smalloc(len *
sizeof(*cookies));
35 children = xcb_query_tree_children(reply);
36 for (i = 0; i < len; ++i)
37 cookies[i] = xcb_get_window_attributes(
conn, children[i]);
40 for (i = 0; i < len; ++i)
56 DLOG(
"Restoring geometry\n");
72 xcb_change_window_attributes(
conn,
root, XCB_CW_EVENT_MASK, (uint32_t[]){ XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT });
85 setlocale(LC_NUMERIC,
"C");
98 const unsigned char *payload;
100 y(get_buf, &payload, &length);
102 ipc_send_event(
"window", I3_IPC_EVENT_WINDOW, (
const char *)payload);
104 setlocale(LC_NUMERIC,
"");
111 void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie,
112 bool needs_to_be_mapped) {
113 xcb_drawable_t d = { window };
114 xcb_get_geometry_cookie_t geomc;
115 xcb_get_geometry_reply_t *geom;
116 xcb_get_window_attributes_reply_t *attr = NULL;
118 xcb_get_property_cookie_t wm_type_cookie, strut_cookie, state_cookie,
119 utf8_title_cookie, title_cookie,
120 class_cookie, leader_cookie, transient_cookie,
121 role_cookie, startup_id_cookie, wm_hints_cookie;
124 geomc = xcb_get_geometry(
conn, d);
128 if ((attr = xcb_get_window_attributes_reply(
conn, cookie, 0)) == NULL) {
129 DLOG(
"Could not get attributes\n");
130 xcb_discard_reply(
conn, geomc.sequence);
134 if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
135 xcb_discard_reply(
conn, geomc.sequence);
140 if (attr->override_redirect) {
141 xcb_discard_reply(
conn, geomc.sequence);
148 xcb_discard_reply(
conn, geomc.sequence);
153 if ((geom = xcb_get_geometry_reply(
conn, geomc, 0)) == NULL) {
154 DLOG(
"could not get geometry\n");
169 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
170 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
171 xcb_void_cookie_t event_mask_cookie =
172 xcb_change_window_attributes_checked(
conn, window, XCB_CW_EVENT_MASK, values);
173 if (xcb_request_check(
conn, event_mask_cookie) != NULL) {
174 LOG(
"Could not change event mask, the window probably already disappeared.\n");
178 #define GET_PROPERTY(atom, len) xcb_get_property(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
180 wm_type_cookie =
GET_PROPERTY(A__NET_WM_WINDOW_TYPE, UINT32_MAX);
181 strut_cookie =
GET_PROPERTY(A__NET_WM_STRUT_PARTIAL, UINT32_MAX);
182 state_cookie =
GET_PROPERTY(A__NET_WM_STATE, UINT32_MAX);
184 leader_cookie =
GET_PROPERTY(A_WM_CLIENT_LEADER, UINT32_MAX);
189 startup_id_cookie =
GET_PROPERTY(A__NET_STARTUP_ID, 512);
193 DLOG(
"Managing window 0x%08x\n", window);
196 cwindow->
id = window;
200 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
201 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
203 XCB_BUTTON_MASK_ANY );
205 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
206 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
208 XCB_BUTTON_MASK_ANY );
210 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
211 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
213 XCB_BUTTON_MASK_ANY );
225 xcb_get_property_reply_t *startup_id_reply;
226 startup_id_reply = xcb_get_property_reply(
conn, startup_id_cookie, NULL);
228 DLOG(
"startup workspace = %s\n", startup_ws);
236 xcb_get_property_reply_t *reply = xcb_get_property_reply(
conn, wm_type_cookie, NULL);
238 LOG(
"This window is of type dock\n");
240 if (output != NULL) {
241 DLOG(
"Starting search at output %s\n", output->
name);
242 search_at = output->
con;
247 DLOG(
"Top dock client\n");
248 cwindow->
dock = W_DOCK_TOP;
250 DLOG(
"Bottom dock client\n");
251 cwindow->
dock = W_DOCK_BOTTOM;
253 DLOG(
"Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
255 DLOG(
"geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
257 cwindow->
dock = W_DOCK_TOP;
259 DLOG(
"geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
261 cwindow->
dock = W_DOCK_BOTTOM;
266 DLOG(
"Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
278 if ((assignment =
assignment_for(cwindow, A_TO_WORKSPACE | A_TO_OUTPUT))) {
279 DLOG(
"Assignment matches (%p)\n", match);
280 if (assignment->
type == A_TO_WORKSPACE) {
283 if (nc->
type == CT_WORKSPACE)
288 }
else if (startup_ws) {
291 DLOG(
"Using workspace on which this application was started (%s)\n", startup_ws);
293 DLOG(
"focused on ws %s: %p / %s\n", startup_ws, nc, nc->
name);
294 if (nc->
type == CT_WORKSPACE)
300 LOG(
"using current container, focused = %p, focused->name = %s\n",
313 DLOG(
"new container = %p\n", nc);
320 sasprintf(&name,
"[i3 con] container around %p", cwindow);
330 DLOG(
"Not in fullscreen mode, focusing\n");
331 if (!cwindow->
dock) {
341 }
else DLOG(
"not focusing, matched with restart_mode == true\n");
342 }
else DLOG(
"workspace not visible, not focusing\n");
343 }
else DLOG(
"dock, not focusing\n");
345 DLOG(
"fs = %p, ws = %p, not focusing\n", fs, ws);
360 bool want_floating =
false;
365 LOG(
"This window is a dialog window, setting floating\n");
366 want_floating =
true;
372 (cwindow->
leader != XCB_NONE &&
375 LOG(
"This window is transient for another window, setting floating\n");
376 want_floating =
true;
380 LOG(
"There is a fullscreen window, leaving fullscreen mode\n");
386 while (transient_win != NULL &&
389 LOG(
"This floating window belongs to the fullscreen window (popup_during_fullscreen == smart)\n");
394 if (next_transient == NULL)
396 transient_win = next_transient->
window;
403 want_floating =
false;
410 nc->
geometry = (
Rect){ geom->
x, geom->y, geom->width, geom->height };
419 values[0] = XCB_NONE;
420 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
422 xcb_void_cookie_t rcookie = xcb_reparent_window_checked(
conn, window, nc->
frame, 0, 0);
423 if (xcb_request_check(
conn, rcookie) != NULL) {
424 LOG(
"Could not reparent the window, aborting\n");
429 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
432 reply = xcb_get_property_reply(
conn, state_cookie, NULL);
442 xcb_change_save_set(
conn, XCB_SET_MODE_INSERT, window);
Con * con_for_window(Con *con, i3Window *window, Match **store_match)
Returns the first container below 'con' which wants to swallow this window TODO: priority.
char * name
Name of the output.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
struct all_cons_head all_cons
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
An Assignment makes specific windows go to a specific workspace/output or run a command for that wind...
void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
void restore_geometry(void)
Restores the geometry of each window by reparenting it to the root window at the position of its fram...
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
Assignment * assignment_for(i3Window *window, int type)
Returns the first matching assignment for the given window.
#define xcb_icccm_get_wm_hints
union Assignment::@17 dest
destination workspace/output/command, depending on the type
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r)
Configures the given window to have the size/position specified by given rect.
#define TAILQ_REMOVE(head, elm, field)
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the WM_WINDOW_ROLE.
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
static void ipc_send_window_new_event(Con *con)
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
char * startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply)
Checks if the given window belongs to a startup notification by checking if the _NET_STARTUP_ID prope...
struct Rect geometry
the geometry this window requested when getting mapped
bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom)
#define XCB_ATOM_WM_CLASS
void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie, bool needs_to_be_mapped)
Do some sanity checks and then reparent the window.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
#define XCB_ATOM_WM_TRANSIENT_FOR
void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given window.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
uint16_t get_visual_depth(xcb_visualid_t visual_id)
Get depth of visual specified by visualid.
enum Match::@15 insert_where
void con_focus(Con *con)
Sets input focus to the given container.
bool window_supports_protocol(xcb_window_t window, xcb_atom_t atom)
Returns true if the client supports the given protocol atom (like WM_DELETE_WINDOW) ...
#define TAILQ_FIRST(head)
#define GET_PROPERTY(atom, len)
An Output is a physical output on your graphics driver.
uint16_t depth
Depth of the window.
void manage_existing_windows(xcb_window_t root)
Go through all existing windows (if the window manager is restarted) and manage them.
Output * get_output_containing(int x, int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
#define TAILQ_FOREACH(var, head, field)
void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_HINTS (we only care about the input focus handling part).
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
Con * workspace_get(const char *num, bool *created)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the name by using WM_NAME (encoded in COMPOUND_TEXT).
enum Window::@11 dock
Whether the window says it is a dock window.
struct reservedpx reserved
Pixels the window reserves.
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name...
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the WM_CLASS (consisting of the class and instance) for the given window. ...
xcb_window_t transient_for
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
enum Assignment::@16 type
type of this assignment:
Con * con
Pointer to the Con which represents this output.
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
Con * con_get_fullscreen_con(Con *con, int fullscreen_mode)
Returns the first fullscreen node below this node.
void run_assignments(i3Window *window)
Checks the list of assignments for the given window and runs all matching ones (unless they have alre...
enum Config::@4 popup_during_fullscreen
What should happen when a new popup is opened during fullscreen mode.
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart)
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.