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});
82 void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie,
83 bool needs_to_be_mapped) {
84 xcb_drawable_t d = {window};
85 xcb_get_geometry_cookie_t geomc;
86 xcb_get_geometry_reply_t *geom;
87 xcb_get_window_attributes_reply_t *attr = NULL;
89 xcb_get_property_cookie_t wm_type_cookie, strut_cookie, state_cookie,
90 utf8_title_cookie, title_cookie,
91 class_cookie, leader_cookie, transient_cookie,
92 role_cookie, startup_id_cookie, wm_hints_cookie,
93 wm_normal_hints_cookie, motif_wm_hints_cookie;
95 geomc = xcb_get_geometry(
conn, d);
99 if ((attr = xcb_get_window_attributes_reply(
conn, cookie, 0)) == NULL) {
100 DLOG(
"Could not get attributes\n");
101 xcb_discard_reply(
conn, geomc.sequence);
105 if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
106 xcb_discard_reply(
conn, geomc.sequence);
111 if (attr->override_redirect) {
112 xcb_discard_reply(
conn, geomc.sequence);
119 xcb_discard_reply(
conn, geomc.sequence);
124 if ((geom = xcb_get_geometry_reply(
conn, geomc, 0)) == NULL) {
125 DLOG(
"could not get geometry\n");
140 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
141 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
142 xcb_void_cookie_t event_mask_cookie =
143 xcb_change_window_attributes_checked(
conn, window, XCB_CW_EVENT_MASK, values);
144 if (xcb_request_check(
conn, event_mask_cookie) != NULL) {
145 LOG(
"Could not change event mask, the window probably already disappeared.\n");
149 #define GET_PROPERTY(atom, len) xcb_get_property(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
151 wm_type_cookie =
GET_PROPERTY(A__NET_WM_WINDOW_TYPE, UINT32_MAX);
152 strut_cookie =
GET_PROPERTY(A__NET_WM_STRUT_PARTIAL, UINT32_MAX);
153 state_cookie =
GET_PROPERTY(A__NET_WM_STATE, UINT32_MAX);
155 leader_cookie =
GET_PROPERTY(A_WM_CLIENT_LEADER, UINT32_MAX);
160 startup_id_cookie =
GET_PROPERTY(A__NET_STARTUP_ID, 512);
163 motif_wm_hints_cookie =
GET_PROPERTY(A__MOTIF_WM_HINTS, 5 *
sizeof(uint64_t));
165 DLOG(
"Managing window 0x%08x\n", window);
168 cwindow->
id = window;
172 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
173 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
175 XCB_BUTTON_MASK_ANY );
177 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
178 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
180 XCB_BUTTON_MASK_ANY );
182 xcb_grab_button(
conn,
false, window, XCB_EVENT_MASK_BUTTON_PRESS,
183 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
root, XCB_NONE,
185 XCB_BUTTON_MASK_ANY );
199 xcb_size_hints_t wm_size_hints;
201 memset(&wm_size_hints,
'\0',
sizeof(xcb_size_hints_t));
202 xcb_get_property_reply_t *type_reply = xcb_get_property_reply(
conn, wm_type_cookie, NULL);
203 xcb_get_property_reply_t *state_reply = xcb_get_property_reply(
conn, state_cookie, NULL);
205 xcb_get_property_reply_t *startup_id_reply;
206 startup_id_reply = xcb_get_property_reply(
conn, startup_id_cookie, NULL);
208 DLOG(
"startup workspace = %s\n", startup_ws);
217 LOG(
"This window is of type dock\n");
219 if (output != NULL) {
220 DLOG(
"Starting search at output %s\n", output->
name);
221 search_at = output->
con;
226 DLOG(
"Top dock client\n");
227 cwindow->
dock = W_DOCK_TOP;
229 DLOG(
"Bottom dock client\n");
230 cwindow->
dock = W_DOCK_BOTTOM;
232 DLOG(
"Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
233 if (geom->y < (int16_t)(search_at->
rect.
height / 2)) {
234 DLOG(
"geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
236 cwindow->
dock = W_DOCK_TOP;
238 DLOG(
"geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
240 cwindow->
dock = W_DOCK_BOTTOM;
245 DLOG(
"Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
257 if ((assignment =
assignment_for(cwindow, A_TO_WORKSPACE | A_TO_OUTPUT))) {
258 DLOG(
"Assignment matches (%p)\n", match);
259 if (assignment->
type == A_TO_WORKSPACE) {
262 DLOG(
"focused on ws %s: %p / %s\n", assigned_ws->
name, nc, nc->
name);
263 if (nc->
type == CT_WORKSPACE)
273 }
else if (startup_ws) {
276 DLOG(
"Using workspace on which this application was started (%s)\n", startup_ws);
278 DLOG(
"focused on ws %s: %p / %s\n", startup_ws, nc, nc->
name);
279 if (nc->
type == CT_WORKSPACE)
286 LOG(
"using current container, focused = %p, focused->name = %s\n",
304 DLOG(
"Removing match %p from container %p\n", match, nc);
309 DLOG(
"new container = %p\n", nc);
312 DLOG(
"Uh?! Container without a placeholder, but with a window, has swallowed this to-be-managed window?!\n");
321 sasprintf(&name,
"[i3 con] container around %p", cwindow);
339 bool set_focus =
false;
342 DLOG(
"Not in fullscreen mode, focusing\n");
343 if (!cwindow->
dock) {
354 DLOG(
"not focusing, matched with restart_mode == true\n");
356 DLOG(
"workspace not visible, not focusing\n");
358 DLOG(
"dock, not focusing\n");
360 DLOG(
"fs = %p, ws = %p, not focusing\n", fs, ws);
375 bool want_floating =
false;
383 wm_size_hints.min_height == wm_size_hints.max_height &&
384 wm_size_hints.min_width == wm_size_hints.max_width)) {
385 LOG(
"This window is a dialog window, setting floating\n");
386 want_floating =
true;
393 (cwindow->
leader != XCB_NONE &&
396 LOG(
"This window is transient for another window, setting floating\n");
397 want_floating =
true;
401 LOG(
"There is a fullscreen window, leaving fullscreen mode\n");
407 while (transient_win != NULL &&
410 LOG(
"This floating window belongs to the fullscreen window (popup_during_fullscreen == smart)\n");
415 if (next_transient == NULL)
420 if (transient_win == next_transient->
window)
422 transient_win = next_transient->
window;
429 want_floating =
false;
437 nc->
geometry = (
Rect) {geom->
x, geom->y, geom->width, geom->height};
445 DLOG(
"MOTIF_WM_HINTS specifies decorations (border_style = %d)\n", motif_border_style);
455 values[0] = XCB_NONE;
456 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
458 xcb_void_cookie_t rcookie = xcb_reparent_window_checked(
conn, window, nc->
frame, 0, 0);
459 if (xcb_request_check(
conn, rcookie) != NULL) {
460 LOG(
"Could not reparent the window, aborting\n");
465 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
472 xcb_change_save_set(
conn, XCB_SET_MODE_INSERT, window);
508 if (set_focus && nc->
mapped) {
509 DLOG(
"Now setting focus.\n");
char * name
Name of the output.
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
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.
#define TAILQ_REMOVE(head, elm, field)
int default_floating_border_width
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
#define xcb_icccm_get_wm_hints
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.
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...
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) ...
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
struct all_cons_head all_cons
bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom)
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
uint16_t depth
Depth of the window.
union Assignment::@17 dest
destination workspace/output/command, depending on the type
struct reservedpx reserved
Pixels the window reserves.
#define TAILQ_FIRST(head)
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
An Output is a physical output on your graphics driver.
bool restore_kill_placeholder(xcb_window_t placeholder)
Kill the placeholder window, if placeholder refers to a placeholder window.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
void con_set_border_style(Con *con, int border_style, int border_width)
Sets the given border style on con, correctly keeping the position/size of a floating 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 manage_existing_windows(xcb_window_t root)
Go through all existing windows (if the window manager is restarted) and manage them.
xcb_window_t transient_for
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...
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 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).
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
#define XCB_ICCCM_SIZE_HINT_P_MIN_SIZE
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.
Con * con
Pointer to the Con which represents this output.
struct Rect geometry
the geometry this window requested when getting mapped
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.
void run_assignments(i3Window *window)
Checks the list of assignments for the given window and runs all matching ones (unless they have alre...
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
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...
void con_focus(Con *con)
Sets input focus to the given container.
#define xcb_icccm_get_wm_size_hints_reply
#define xcb_icccm_get_wm_normal_hints
void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style)
Updates the MOTIF_WM_HINTS.
enum Window::@11 dock
Whether the window says it is a dock window.
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
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...
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. ...
A 'Con' represents everything from the X11 root window down to a single X11 window.
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define GET_PROPERTY(atom, len)
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_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint)
Updates the WM_HINTS (we only care about the input focus handling part).
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.
#define XCB_ICCCM_SIZE_HINT_P_MAX_SIZE
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
enum Match::@15 insert_where
void restore_geometry(void)
Restores the geometry of each window by reparenting it to the root window at the position of its fram...
enum Assignment::@16 type
type of this assignment:
Assignment * assignment_for(i3Window *window, int type)
Returns the first matching assignment for the given window.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
uint16_t get_visual_depth(xcb_visualid_t visual_id)
Get depth of visual specified by visualid.
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 * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_FOREACH(var, head, field)
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt)
Updates the WM_WINDOW_ROLE.
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
enum Config::@4 popup_during_fullscreen
What should happen when a new popup is opened during fullscreen mode.
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container, in "container".
#define XCB_ATOM_WM_CLASS
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
#define XCB_ATOM_WM_TRANSIENT_FOR