2 #define I3__FILE__ "x.c"
80 static
con_state *state_for_frame(xcb_window_t window) {
83 if (state->
id == window)
87 ELOG(
"No state found\n");
107 xcb_colormap_t win_colormap = xcb_generate_id(
conn);
108 xcb_create_colormap_checked(
conn, XCB_COLORMAP_ALLOC_NONE, win_colormap,
root, visual);
114 mask |= XCB_CW_BACK_PIXEL;
117 mask |= XCB_CW_BORDER_PIXEL;
121 mask |= XCB_CW_OVERRIDE_REDIRECT;
125 mask |= XCB_CW_EVENT_MASK;
128 mask |= XCB_CW_COLORMAP;
129 values[4] = win_colormap;
131 Rect dims = {-15, -15, 10, 10};
134 xcb_change_property(
conn,
135 XCB_PROP_MODE_REPLACE,
140 (strlen(
"i3-frame") + 1) * 2,
141 "i3-frame\0i3-frame\0");
143 if (win_colormap != XCB_NONE)
144 xcb_free_colormap(
conn, win_colormap);
150 DLOG(
"Adding window 0x%08x to lists\n", state->
id);
154 DLOG(
"adding new state for window id 0x%08x\n", state->
id);
166 if ((state = state_for_frame(con->
frame.
id)) == NULL) {
167 ELOG(
"window state not found\n");
171 DLOG(
"resetting state %p to initial\n", state);
185 if ((state = state_for_frame(con->
frame.
id)) == NULL) {
186 ELOG(
"window state for con not found\n");
199 struct con_state *state_src, *state_dest;
201 if ((state_src = state_for_frame(src->
frame.
id)) == NULL) {
202 ELOG(
"window state for src not found\n");
206 if ((state_dest = state_for_frame(dest->
frame.
id)) == NULL) {
207 ELOG(
"window state for dest not found\n");
211 state_dest->
con = state_src->
con;
212 state_src->
con = NULL;
214 Rect zero = {0, 0, 0, 0};
217 DLOG(
"COPYING RECT\n");
232 state = state_for_frame(con->
frame.
id);
235 TAILQ_REMOVE(&initial_mapping_head, state, initial_mapping_order);
248 xcb_get_property_cookie_t cookie;
257 for (uint32_t i = 0; i < protocols.atoms_len; i++)
258 if (protocols.atoms[i] == atom)
274 LOG(
"Killing specific window 0x%08x\n", window);
275 xcb_destroy_window(
conn, window);
277 LOG(
"Killing the X11 client which owns window 0x%08x\n", window);
278 xcb_kill_client(
conn, window);
287 xcb_client_message_event_t *ev = event;
289 ev->response_type = XCB_CLIENT_MESSAGE;
291 ev->type = A_WM_PROTOCOLS;
293 ev->data.data32[0] = A_WM_DELETE_WINDOW;
294 ev->data.data32[1] = XCB_CURRENT_TIME;
296 LOG(
"Sending WM_DELETE to the client\n");
297 xcb_send_event(
conn,
false, window, XCB_EVENT_MASK_NO_EVENT, (
char *)ev);
303 assert(con->
parent != NULL);
319 dr->
x + deco_diff_l, dr->
y + dr->
height - 1, dr->
width - (deco_diff_l + deco_diff_r), 1);
323 assert(con->
parent != NULL);
369 parent->
type == CT_OUTPUT ||
370 parent->
type == CT_DOCKAREA ||
371 con->
type == CT_FLOATING_CON)
392 else if (con ==
TAILQ_FIRST(&(parent->focus_head)))
434 if (con->
window != NULL) {
458 DLOG(
"border_rect spans (%d, %d) with %d x %d\n", br.
x, br.
y, br.
width, br.
height);
554 if (win->
name == NULL)
557 int indent_level = 0,
559 Con *il_parent = parent;
565 if (il_parent->
type == CT_WORKSPACE || il_parent->
type == CT_DOCKAREA || il_parent->
type == CT_OUTPUT)
567 il_parent = il_parent->
parent;
572 int indent_px = (indent_level * 5) * indent_mult;
576 char *formatted_mark =
sstrdup(
"");
577 bool had_visible_mark =
false;
581 if (mark->
name[0] ==
'_')
583 had_visible_mark =
true;
587 free(formatted_mark);
588 formatted_mark = buf;
591 if (had_visible_mark) {
598 con->
deco_rect.
y + text_offset_y, mark_width);
603 FREE(formatted_mark);
636 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
644 if ((con->
type != CT_ROOT && con->
type != CT_OUTPUT) &&
654 if (con->
window == NULL) {
660 if (should_be_hidden == state->
is_hidden)
663 if (should_be_hidden) {
664 DLOG(
"setting _NET_WM_STATE_HIDDEN for con = %p\n", con);
667 DLOG(
"removing _NET_WM_STATE_HIDDEN for con = %p\n", con);
686 state = state_for_frame(con->
frame.
id);
688 if (state->
name != NULL) {
689 DLOG(
"pushing name %s for con %p\n", state->
name, con);
691 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
frame.
id,
696 if (con->
window == NULL) {
699 uint32_t max_y = 0, max_height = 0;
702 if (dr->
y >= max_y && dr->
height >= max_height) {
707 rect.
height = max_y + max_height;
715 DLOG(
"Reparenting child window\n");
720 uint32_t values[] = {XCB_NONE};
721 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
722 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
727 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
729 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
735 DLOG(
"ignore_unmap for reparenting of con %p (win 0x%08x) is now %d\n",
749 if (con->
type == CT_ROOT || con->
type == CT_OUTPUT)
750 is_pixmap_needed =
false;
752 bool fake_notify =
false;
755 if ((is_pixmap_needed && con->
frame_buffer.
id == XCB_NONE) || (memcmp(&(state->
rect), &rect,
sizeof(
Rect)) != 0 &&
775 if (is_pixmap_needed && (has_rect_changed || con->
frame_buffer.
id == XCB_NONE)) {
802 xcb_change_gc(
conn, con->
frame_buffer.
gc, XCB_GC_GRAPHICS_EXPOSURES, (uint32_t[]){0});
819 DLOG(
"setting rect (%d, %d, %d, %d)\n", rect.
x, rect.
y, rect.
width, rect.
height);
831 memcpy(&(state->
rect), &rect,
sizeof(
Rect));
838 DLOG(
"setting window rect (%d, %d, %d, %d)\n",
850 xcb_void_cookie_t cookie;
857 A_WM_STATE, A_WM_STATE, 32, 2, data);
867 xcb_change_window_attributes(
conn,
con->
window->
id, XCB_CW_EVENT_MASK, values);
868 DLOG(
"mapping child window (serial %d)\n", cookie.sequence);
869 state->child_mapped =
true;
875 xcb_change_window_attributes(
conn,
con->
frame.
id, XCB_CW_EVENT_MASK, values);
883 DLOG(
"mapping container %08x (serial %d)\n",
con->
frame.
id, cookie.sequence);
890 DLOG(
"Sending fake configure notify\n");
917 state = state_for_frame(con->frame.id);
923 xcb_void_cookie_t cookie;
924 if (con->window != NULL) {
927 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->window->id,
928 A_WM_STATE, A_WM_STATE, 32, 2, data);
931 cookie = xcb_unmap_window(
conn, con->frame.id);
932 DLOG(
"unmapping container %p / %s (serial %d)\n", con, con->name, cookie.sequence);
936 if (con->window != NULL) {
938 DLOG(
"ignore_unmap for con %p (frame 0x%08x) now %d\n", con, con->frame.id, con->ignore_unmap);
940 state->
mapped = con->mapped;
947 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
982 xcb_query_pointer_cookie_t pointercookie;
986 pointercookie = xcb_query_pointer(
conn,
root);
989 DLOG(
"-- PUSHING WINDOW STACK --\n");
994 uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
997 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
1000 bool order_changed =
false;
1001 bool stacking_changed =
false;
1012 static xcb_window_t *client_list_windows = NULL;
1013 static int client_list_count = 0;
1015 if (cnt != client_list_count) {
1016 client_list_windows =
srealloc(client_list_windows,
sizeof(xcb_window_t) * cnt);
1017 client_list_count = cnt;
1020 xcb_window_t *walk = client_list_windows;
1025 memcpy(walk++, &(state->
con->
window->
id),
sizeof(xcb_window_t));
1030 if (prev != old_prev)
1031 order_changed =
true;
1033 stacking_changed =
true;
1036 mask |= XCB_CONFIG_WINDOW_SIBLING;
1037 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
1038 uint32_t values[] = {state->
id, XCB_STACK_MODE_ABOVE};
1040 xcb_configure_window(
conn, prev->
id, mask, values);
1047 if (stacking_changed) {
1048 DLOG(
"Client list changed (%i clients)\n", cnt);
1051 walk = client_list_windows;
1054 TAILQ_FOREACH(state, &initial_mapping_head, initial_mapping_order) {
1062 DLOG(
"PUSHING CHANGES\n");
1066 xcb_query_pointer_reply_t *pointerreply = xcb_query_pointer_reply(
conn, pointercookie, NULL);
1067 if (!pointerreply) {
1068 ELOG(
"Could not query pointer position, not warping pointer\n");
1070 int mid_x = warp_to->
x + (warp_to->
width / 2);
1071 int mid_y = warp_to->
y + (warp_to->
height / 2);
1075 if (current != target) {
1077 xcb_change_window_attributes(
conn,
root, XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT});
1078 xcb_warp_pointer(
conn, XCB_NONE,
root, 0, 0, 0, 0, mid_x, mid_y);
1091 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
1110 DLOG(
"Updating focus by sending WM_TAKE_FOCUS to window 0x%08x (focused: %p / %s)\n",
1127 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT, to_focus, XCB_CURRENT_TIME);
1146 DLOG(
"Still no window focused, better set focus to the EWMH support window (%d)\n",
ewmh_window);
1147 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT,
ewmh_window, XCB_CURRENT_TIME);
1153 DLOG(
"ENDING CHANGES\n");
1166 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
1191 state = state_for_frame(con->
frame.
id);
1207 if ((state = state_for_frame(con->
frame.
id)) == NULL) {
1208 ELOG(
"window state not found\n");
1221 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root,
1222 A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
1231 pid_t pid = getpid();
1232 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_SOCKET_PATH, A_UTF8_STRING, 8,
1236 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_CONFIG_PATH, A_UTF8_STRING, 8,
1263 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
struct Colortriple focused_inactive
#define XCB_ICCCM_WM_STATE_NORMAL
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
#define xcb_icccm_get_wm_protocols_reply
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
void x_mask_event_mask(uint32_t mask)
Applies the given mask to the event mask of every i3 window decoration X11 window.
adjacent_t con_adjacent_borders(Con *con)
Returns adjacent borders of the window.
void draw_util_copy_surface(xcb_connection_t *conn, surface_t *src, surface_t *dest, double src_x, double src_y, double dest_x, double dest_y, double width, double height)
Copies a surface onto another surface.
char * title_format
The format with which the window's name should be displayed.
#define TAILQ_ENTRY(type)
void x_con_init(Con *con, uint16_t depth)
Initializes the X11 part for the given container.
struct Colortriple * color
int height
The height of the font, built from font_ascent + font_descent.
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
i3String * name
The name of the window.
struct Config::config_client client
#define XCB_ATOM_CARDINAL
#define TAILQ_EMPTY(head)
static xcb_window_t last_focused
bool doesnt_accept_focus
Whether this window accepts focus.
#define CIRCLEQ_ENTRY(type)
void ewmh_update_active_window(xcb_window_t window)
Updates _NET_ACTIVE_WINDOW with the currently focused window.
#define COLOR_TRANSPARENT
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 draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t color, double x, double y, double w, double h)
Draws a filled rectangle.
#define CIRCLEQ_FOREACH_REVERSE(var, head, field)
Con * con
The con for which this state is.
xcb_window_t ewmh_window
The EWMH support window that is used to indicate that an EWMH-compliant window manager is present...
#define TAILQ_FOREACH(var, head, field)
void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_drawable_t drawable, xcb_visualtype_t *visual, int width, int height)
Initialize the surface to represent the given drawable.
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...
void x_deco_recurse(Con *con)
Recursively calls x_draw_decoration.
xcb_connection_t * conn
XCB connection and root screen.
void x_draw_decoration(Con *con)
Draws the decoration of the given container onto its parent.
#define TAILQ_NEXT(elm, field)
static bool is_con_attached(Con *con)
Rect con_border_style_rect(Con *con)
Returns a "relative" Rect which contains the amount of pixels that need to be added to the original R...
adjacent_t
describes if the window is adjacent to the output (physical screen) edges.
#define CIRCLEQ_HEAD_INITIALIZER(head)
void x_push_node(Con *con)
This function pushes the properties of each node of the layout tree to X11 if they have changed (like...
void x_con_kill(Con *con)
Kills the window decoration associated with the given container.
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width)
Draw the given text using libi3.
void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp)
Sends the WM_TAKE_FOCUS ClientMessage to the given window.
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory...
adjacent_t hide_edge_borders
Remove borders if they are adjacent to the screen edge.
#define TAILQ_REMOVE(head, 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...
#define TAILQ_HEAD(name, type)
struct Colortriple unfocused
#define XCB_ICCCM_WM_STATE_WITHDRAWN
#define xcb_icccm_get_wm_protocols
#define CIRCLEQ_INSERT_TAIL(head, elm, field)
struct Colortriple urgent
kill_window_t
parameter to specify whether tree_close_internal() and x_window_kill() should kill only this specific...
uint16_t depth
Depth of the window.
bool show_marks
Specifies whether or not marks should be displayed in the window decoration.
Stores a rectangle, for example the size of a window, the child window etc.
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p)
xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t depth, xcb_visualid_t visual, uint16_t window_class, enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values)
Convenience wrapper around xcb_create_window which takes care of depth, generating an ID and checking...
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".
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...
Stores the parameters for rendering a window decoration.
int con_border_style(Con *con)
Use this function to get a container’s border style.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
#define xcb_icccm_get_wm_protocols_reply_t
void ewmh_update_client_list(xcb_window_t *list, int num_windows)
Updates the _NET_CLIENT_LIST hint.
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
void xcb_add_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Add an atom to a list of atoms the given property defines.
void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t color)
Clears a surface with the given color.
static void x_draw_title_border(Con *con, struct deco_render_params *p)
#define CIRCLEQ_FOREACH(var, head, field)
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
#define XCB_ATOM_WM_CLASS
struct width_height con_window_rect
bool con_is_hidden(Con *con)
This will only return true for containers which have some parent with a tabbed / stacked parent of wh...
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
#define TAILQ_FIRST(head)
void x_raise_con(Con *con)
Raises the specified container in the internal stack of X windows.
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 CIRCLEQ_REMOVE(head, elm, field)
#define CIRCLEQ_PREV(elm, field)
static void x_push_node_unmaps(Con *con)
warping_t mouse_warping
By default, when switching focus to a window on a different output (e.g.
void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows)
Updates the _NET_CLIENT_LIST_STACKING hint.
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
struct _i3String i3String
Opaque data structure for storing strings.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_INSERT_TAIL(head, elm, field)
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
#define CIRCLEQ_END(head)
xcb_screen_t * root_screen
CIRCLEQ_HEAD(state_head, con_state)
int predict_text_width(i3String *text)
Predict the text width in pixels for the given text.
border_style_t border_style
struct Colortriple focused
void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface)
Destroys the surface.
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
#define xcb_icccm_get_wm_protocols_reply_wipe
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Remove an atom from a list of atoms the given property defines without removing any other potentially...
char * con_get_tree_representation(Con *con)
Create a string representing the subtree under con.
static void set_hidden_state(Con *con)
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
char * current_configpath
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.
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_window_t focused_id
Stores the X11 window ID of the currently focused window.
An Output is a physical output on your graphics driver.
xcb_visualid_t get_visualid_by_depth(uint16_t depth)
Get visualid with specified depth.
#define TAILQ_PREV(elm, headname, field)
#define FRAME_EVENT_MASK
The XCB_CW_EVENT_MASK for its frame.
void draw_util_surface_set_size(surface_t *surface, int width, int height)
Resize the surface to the given size.
#define CIRCLEQ_INSERT_HEAD(head, elm, field)
struct width_height con_rect
bool con_has_managed_window(Con *con)
Returns true when this con is a leaf node with a managed X11 window (e.g., excluding dock containers)...
Stores a width/height pair, used as part of deco_render_params to check whether the rects width/heigh...
char * current_socketpath
#define TAILQ_HEAD_INITIALIZER(head)
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely...
xcb_visualtype_t * get_visualtype_by_id(xcb_visualid_t visual_id)
Get visual type specified by visualid.