18 xcb_window_t old_frame = XCB_NONE;
45 xcb_query_tree_reply_t *reply;
47 xcb_window_t *children;
48 xcb_get_window_attributes_cookie_t *cookies;
51 if ((reply = xcb_query_tree_reply(
conn, xcb_query_tree(
conn,
root), 0)) == NULL) {
55 len = xcb_query_tree_children_length(reply);
56 cookies =
smalloc(len *
sizeof(*cookies));
59 children = xcb_query_tree_children(reply);
60 for (i = 0; i < len; ++i) {
61 cookies[i] = xcb_get_window_attributes(
conn, children[i]);
65 for (i = 0; i < len; ++i) {
82 DLOG(
"Restoring geometry\n");
99 xcb_change_window_attributes(
conn,
root, XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT});
109void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cookie,
110 bool needs_to_be_mapped) {
111 DLOG(
"window 0x%08x\n", window);
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,
122 wm_normal_hints_cookie, motif_wm_hints_cookie, wm_user_time_cookie, wm_desktop_cookie,
125 xcb_get_property_cookie_t wm_icon_cookie;
127 geomc = xcb_get_geometry(
conn, d);
131 if ((attr = xcb_get_window_attributes_reply(
conn, cookie, 0)) == NULL) {
132 DLOG(
"Could not get attributes\n");
133 xcb_discard_reply(
conn, geomc.sequence);
137 if (needs_to_be_mapped && attr->map_state != XCB_MAP_STATE_VIEWABLE) {
138 xcb_discard_reply(
conn, geomc.sequence);
143 if (attr->override_redirect) {
144 xcb_discard_reply(
conn, geomc.sequence);
151 xcb_discard_reply(
conn, geomc.sequence);
156 if ((geom = xcb_get_geometry_reply(
conn, geomc, 0)) == NULL) {
157 DLOG(
"could not get geometry\n");
172 values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
173 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
174 xcb_void_cookie_t event_mask_cookie =
175 xcb_change_window_attributes_checked(
conn, window, XCB_CW_EVENT_MASK, values);
176 if (xcb_request_check(
conn, event_mask_cookie) != NULL) {
177 LOG(
"Could not change event mask, the window probably already disappeared.\n");
181#define GET_PROPERTY(atom, len) xcb_get_property(conn, false, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, len)
183 wm_type_cookie =
GET_PROPERTY(A__NET_WM_WINDOW_TYPE, UINT32_MAX);
184 strut_cookie =
GET_PROPERTY(A__NET_WM_STRUT_PARTIAL, UINT32_MAX);
185 state_cookie =
GET_PROPERTY(A__NET_WM_STATE, UINT32_MAX);
187 leader_cookie =
GET_PROPERTY(A_WM_CLIENT_LEADER, UINT32_MAX);
188 transient_cookie =
GET_PROPERTY(XCB_ATOM_WM_TRANSIENT_FOR, UINT32_MAX);
192 startup_id_cookie =
GET_PROPERTY(A__NET_STARTUP_ID, 512);
193 wm_hints_cookie = xcb_icccm_get_wm_hints(
conn, window);
194 wm_normal_hints_cookie = xcb_icccm_get_wm_normal_hints(
conn, window);
195 motif_wm_hints_cookie =
GET_PROPERTY(A__MOTIF_WM_HINTS, 5 *
sizeof(uint64_t));
196 wm_user_time_cookie =
GET_PROPERTY(A__NET_WM_USER_TIME, UINT32_MAX);
197 wm_desktop_cookie =
GET_PROPERTY(A__NET_WM_DESKTOP, UINT32_MAX);
198 wm_machine_cookie =
GET_PROPERTY(XCB_ATOM_WM_CLIENT_MACHINE, UINT32_MAX);
199 wm_icon_cookie =
GET_PROPERTY(A__NET_WM_ICON, UINT32_MAX);
202 cwindow->
id = window;
224 xcb_get_property_reply_t *type_reply = xcb_get_property_reply(
conn, wm_type_cookie, NULL);
225 xcb_get_property_reply_t *state_reply = xcb_get_property_reply(
conn, state_cookie, NULL);
227 xcb_get_property_reply_t *startup_id_reply;
228 startup_id_reply = xcb_get_property_reply(
conn, startup_id_cookie, NULL);
230 DLOG(
"startup workspace = %s\n", startup_ws);
233 xcb_get_property_reply_t *wm_desktop_reply;
234 wm_desktop_reply = xcb_get_property_reply(
conn, wm_desktop_cookie, NULL);
236 if (wm_desktop_reply != NULL && xcb_get_property_value_length(wm_desktop_reply) != 0) {
237 uint32_t *wm_desktops = xcb_get_property_value(wm_desktop_reply);
238 cwindow->
wm_desktop = (int32_t)wm_desktops[0];
240 FREE(wm_desktop_reply);
252 LOG(
"This window is of type dock\n");
254 if (output != NULL) {
256 search_at = output->
con;
261 DLOG(
"Top dock client\n");
262 cwindow->
dock = W_DOCK_TOP;
264 DLOG(
"Bottom dock client\n");
265 cwindow->
dock = W_DOCK_BOTTOM;
267 DLOG(
"Ignoring invalid reserved edges (_NET_WM_STRUT_PARTIAL), using position as fallback:\n");
268 if (geom->y < (int16_t)(search_at->
rect.
height / 2)) {
269 DLOG(
"geom->y = %d < rect.height / 2 = %d, it is a top dock client\n",
271 cwindow->
dock = W_DOCK_TOP;
273 DLOG(
"geom->y = %d >= rect.height / 2 = %d, it is a bottom dock client\n",
275 cwindow->
dock = W_DOCK_BOTTOM;
280 DLOG(
"Initial geometry: (%d, %d, %d, %d)\n", geom->x, geom->y, geom->width, geom->height);
286 const bool match_from_restart_mode = (match && match->
restart_mode);
288 Con *wm_desktop_ws = NULL;
294 DLOG(
"Assignment matches (%p)\n", match);
296 Con *assigned_ws = NULL;
297 if (assignment->
type == A_TO_WORKSPACE_NUMBER) {
309 DLOG(
"focused on ws %s: %p / %s\n", assigned_ws->
name, nc, nc->
name);
310 if (nc->
type == CT_WORKSPACE) {
327 DLOG(
"Using workspace %p / %s because _NET_WM_DESKTOP = %d.\n",
331 if (nc->
type == CT_WORKSPACE) {
336 }
else if (startup_ws) {
338 DLOG(
"Using workspace on which this application was started (%s)\n", startup_ws);
340 DLOG(
"focused on ws %s: %p / %s\n", startup_ws, nc, nc->
name);
341 if (nc->
type == CT_WORKSPACE) {
349 LOG(
"using current container, focused = %p, focused->name = %s\n",
372 DLOG(
"Removing match %p from container %p\n", match, nc);
381 DLOG(
"new container = %p\n", nc);
384 DLOG(
"Uh?! Container without a placeholder, but with a window, has swallowed this to-be-managed window?!\n");
390 xcb_window_t old_frame = XCB_NONE;
401 sasprintf(&name,
"[i3 con] container around %p", cwindow);
418 if (output != NULL) {
426 bool set_focus =
false;
429 DLOG(
"Not in fullscreen mode, focusing\n");
430 if (!cwindow->
dock) {
438 if (!match_from_restart_mode) {
441 DLOG(
"not focusing, matched with restart_mode == true\n");
444 DLOG(
"workspace not visible, not focusing\n");
447 DLOG(
"dock, not focusing\n");
450 DLOG(
"fs = %p, ws = %p, not focusing\n", fs, ws);
465 bool want_floating =
false;
475 LOG(
"This window is a dialog window, setting floating\n");
476 want_floating =
true;
487 DLOG(
"This window has _NET_WM_DESKTOP = 0xFFFFFFFF. Will float it and make it sticky.\n");
489 want_floating =
true;
496 (cwindow->
leader != XCB_NONE &&
499 DLOG(
"This window is transient for another window, setting floating\n");
500 want_floating =
true;
504 DLOG(
"There is a fullscreen window, leaving fullscreen mode\n");
515 want_floating =
false;
524 nc->
geometry = (
Rect){geom->x, geom->y, geom->width, geom->height};
539 DLOG(
"MOTIF_WM_HINTS specifies decorations (border_style = %d)\n", motif_border_style);
554 values[0] = XCB_NONE;
555 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
557 xcb_void_cookie_t rcookie = xcb_reparent_window_checked(
conn, window, nc->
frame.
id, 0, 0);
558 if (xcb_request_check(
conn, rcookie) != NULL) {
559 LOG(
"Could not reparent the window, aborting\n");
564 xcb_change_window_attributes(
conn, window, XCB_CW_EVENT_MASK, values);
571 xcb_change_save_set(
conn, XCB_SET_MODE_INSERT, window);
576 xcb_shape_select_input(
conn, window,
true);
580 xcb_shape_query_extents_cookie_t cookie =
581 xcb_shape_query_extents(
conn, window);
582 xcb_shape_query_extents_reply_t *reply =
583 xcb_shape_query_extents_reply(
conn, cookie, NULL);
584 if (reply != NULL && reply->bounding_shaped) {
629 DLOG(
"This is the first window on this workspace, ignoring no_focus.\n");
631 DLOG(
"no_focus was set for con = %p, not setting focus.\n", nc);
637 DLOG(
"Checking con = %p for _NET_WM_USER_TIME.\n", nc);
639 uint32_t *wm_user_time;
640 xcb_get_property_reply_t *wm_user_time_reply = xcb_get_property_reply(
conn, wm_user_time_cookie, NULL);
641 if (wm_user_time_reply != NULL && xcb_get_property_value_length(wm_user_time_reply) != 0 &&
642 (wm_user_time = xcb_get_property_value(wm_user_time_reply)) &&
643 wm_user_time[0] == 0) {
644 DLOG(
"_NET_WM_USER_TIME set to 0, not focusing con = %p.\n", nc);
648 FREE(wm_user_time_reply);
650 xcb_discard_reply(
conn, wm_user_time_cookie.sequence);
664 if (set_focus && nc->
mapped) {
665 DLOG(
"Now setting focus.\n");
673 if (old_frame != XCB_NONE) {
674 xcb_destroy_window(
conn, old_frame);
729 DLOG(
"Uh?! Container without a placeholder, but with a window, has swallowed this managed window?!\n");
745 if (old_frame != XCB_NONE) {
746 xcb_destroy_window(
conn, old_frame);
751 if (moved_workpaces) {
void run_assignments(i3Window *window)
Checks the list of assignments for the given window and runs all matching ones (unless they have alre...
Assignment * assignment_for(i3Window *window, int type)
Returns the first matching assignment for the given window.
int * bindings_get_buttons_to_grab(void)
Returns a list of buttons that should be grabbed on a window.
bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the output s...
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
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_get_workspace(Con *con)
Gets the workspace container this node is on.
bool con_find_transient_for_window(Con *start, xcb_window_t target)
Start from a container and traverse the transient_for linked list.
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
void con_set_border_style(Con *con, border_style_t 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.
Con * con_get_fullscreen_covering_ws(Con *ws)
Returns the fullscreen node that covers the given workspace if it exists.
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
void con_move_to_output(Con *con, Output *output, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the given ou...
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
void con_merge_into(Con *old, Con *new)
Merges container specific data that should move with the window (e.g.
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
int con_num_windows(Con *con)
Count the number of windows (i.e., leaf containers).
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
Con * ewmh_get_workspace_by_index(uint32_t idx)
Returns the workspace container as enumerated by the EWMH desktop model.
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
bool floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
void restore_geometry(void)
Restores the geometry of each window by reparenting it to the root window at the position of its fram...
static void _remove_matches(Con *con)
static Con * placeholder_for_con(Con *con)
static xcb_window_t _match_depth(i3Window *win, Con *con)
void manage_existing_windows(xcb_window_t root)
Go through all existing windows (if the window manager is restarted) and manage them.
Con * remanage_window(Con *con)
Remanages a window: performs a swallow check and runs assignments.
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 GET_PROPERTY(atom, len)
void match_free(Match *match)
Frees the given match.
void output_push_sticky_windows(Con *old_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Output * get_output_with_dimensions(Rect rect)
Returns the active output which spans exactly the area specified by rect or NULL if there is no outpu...
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...
void render_con(Con *con)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
bool restore_kill_placeholder(xcb_window_t placeholder)
Kill the placeholder window, if placeholder refers to a placeholder window.
void startup_sequence_delete_by_window(i3Window *win)
Deletes the startup sequence for a window if it exists.
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...
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
struct all_cons_head all_cons
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
int ws_name_to_number(const char *name)
Parses the workspace name as a number.
void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop)
Updates the _NET_WM_ICON.
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_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_role(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_WINDOW_ROLE.
void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using WM_NAME (encoded in COMPOUND_TEXT).
void window_free(i3Window *win)
Frees an i3Window and all its members.
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
Updates the TRANSIENT_FOR (logical parent window).
void window_update_machine(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLIENT_MACHINE.
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop)
Updates the CLIENT_LEADER (logical parent window).
bool window_update_normal_hints(i3Window *win, xcb_get_property_reply_t *reply, xcb_get_geometry_reply_t *geom)
Updates the WM_NORMAL_HINTS.
void window_update_name(i3Window *win, xcb_get_property_reply_t *prop)
Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given window.
void window_update_class(i3Window *win, xcb_get_property_reply_t *prop)
Updates the WM_CLASS (consisting of the class and instance) for the given window.
bool window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style)
Updates the MOTIF_WM_HINTS.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Con * workspace_get(const char *num)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Con * get_existing_workspace_by_num(int num)
Returns the workspace with the given number or NULL if such a workspace does not exist.
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
void x_con_reframe(Con *con)
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
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.
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)
xcb_atom_t xcb_get_preferred_window_type(xcb_get_property_reply_t *reply)
Returns the first supported _NET_WM_WINDOW_TYPE atom.
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.
bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom)
Returns true if the given reply contains the given data.
void xcb_grab_buttons(xcb_connection_t *conn, xcb_window_t window, int *buttons)
Grab the specified buttons on a window when managing it.
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,...
xcb_connection_t * conn
XCB connection and root screen.
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
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...
uint16_t get_visual_depth(xcb_visualid_t visual_id)
Get depth of visual specified by visualid.
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)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_EMPTY(head)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
#define NET_WM_DESKTOP_ALL
#define NET_WM_DESKTOP_NONE
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
enum Config::@6 popup_during_fullscreen
What should happen when a new popup is opened during fullscreen mode.
int default_floating_border_width
Stores a rectangle, for example the size of a window, the child window etc.
An Output is a physical output on your graphics driver.
Con * con
Pointer to the Con which represents this output.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
enum Window::@11 dock
Whether the window says it is a dock window.
xcb_atom_t window_type
The _NET_WM_WINDOW_TYPE for this window.
bool doesnt_accept_focus
Whether this window accepts focus.
bool shaped
The window has a nonrectangular shape.
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.
xcb_window_t transient_for
uint32_t wm_desktop
The _NET_WM_DESKTOP for this window.
struct reservedpx reserved
Pixels the window reserves.
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
uint16_t depth
Depth of the window.
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
enum Match::@15 insert_where
An Assignment makes specific windows go to a specific workspace/output or run a command for that wind...
union Assignment::@17 dest
destination workspace/command/output, depending on the type
enum Assignment::@16 type
type of this assignment:
A 'Con' represents everything from the X11 root window down to a single X11 window.
struct Rect geometry
the geometry this window requested when getting mapped
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...