14 #define MAX(x, y) ((x) > (y) ? (x) : (y)) 98 if (
state->id == window)
102 ELOG(
"No state found for window 0x%08x\n", window);
113 if (new_focus == old_focus) {
119 if (new_focus != XCB_WINDOW_NONE) {
123 if (old_focus != XCB_WINDOW_NONE) {
141 xcb_colormap_t win_colormap;
144 win_colormap = xcb_generate_id(
conn);
145 xcb_create_colormap(
conn, XCB_COLORMAP_ALLOC_NONE, win_colormap,
root, visual);
157 mask |= XCB_CW_BACK_PIXEL;
160 mask |= XCB_CW_BORDER_PIXEL;
164 mask |= XCB_CW_OVERRIDE_REDIRECT;
168 mask |= XCB_CW_EVENT_MASK;
171 mask |= XCB_CW_COLORMAP;
172 values[4] = win_colormap;
174 Rect dims = {-15, -15, 10, 10};
177 xcb_change_property(
conn,
178 XCB_PROP_MODE_REPLACE,
183 (strlen(
"i3-frame") + 1) * 2,
184 "i3-frame\0i3-frame\0");
188 state->mapped =
false;
189 state->initial =
true;
190 DLOG(
"Adding window 0x%08x to lists\n",
state->id);
194 DLOG(
"adding new state for window id 0x%08x\n",
state->id);
207 ELOG(
"window state not found\n");
211 DLOG(
"resetting state %p to initial\n",
state);
212 state->initial =
true;
213 state->child_mapped =
false;
215 memset(&(
state->window_rect), 0,
sizeof(
Rect));
226 ELOG(
"window state for con not found\n");
230 state->need_reparent =
true;
239 struct con_state *state_src, *state_dest;
242 ELOG(
"window state for src not found\n");
247 ELOG(
"window state for dest not found\n");
251 state_dest->
con = state_src->
con;
252 state_src->
con = NULL;
254 Rect zero = {0, 0, 0, 0};
257 DLOG(
"COPYING RECT\n");
311 xcb_get_property_cookie_t cookie;
312 xcb_icccm_get_wm_protocols_reply_t protocols;
315 cookie = xcb_icccm_get_wm_protocols(
conn, window, A_WM_PROTOCOLS);
316 if (xcb_icccm_get_wm_protocols_reply(
conn, cookie, &protocols, NULL) != 1)
320 for (uint32_t i = 0; i < protocols.atoms_len; i++)
321 if (protocols.atoms[i] == atom)
324 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
337 LOG(
"Killing specific window 0x%08x\n", window);
338 xcb_destroy_window(
conn, window);
340 LOG(
"Killing the X11 client which owns window 0x%08x\n", window);
341 xcb_kill_client(
conn, window);
350 xcb_client_message_event_t *ev = event;
352 ev->response_type = XCB_CLIENT_MESSAGE;
354 ev->type = A_WM_PROTOCOLS;
356 ev->data.data32[0] = A_WM_DELETE_WINDOW;
357 ev->data.data32[1] = XCB_CURRENT_TIME;
359 LOG(
"Sending WM_DELETE to the client\n");
360 xcb_send_event(
conn,
false, window, XCB_EVENT_MASK_NO_EVENT, (
char *)ev);
425 rectangles[count++] = (xcb_rectangle_t){
433 rectangles[count++] = (xcb_rectangle_t){
441 rectangles[count++] = (xcb_rectangle_t){
450 rectangles[count++] = (xcb_rectangle_t){
481 parent->
type == CT_OUTPUT ||
482 parent->
type == CT_DOCKAREA ||
566 xcb_rectangle_t rectangles[4];
568 for (
size_t i = 0; i < rectangles_count; i++) {
573 rectangles[i].height);
626 char *formatted_mark =
sstrdup(
"");
627 bool had_visible_mark =
false;
631 if (mark->
name[0] ==
'_')
633 had_visible_mark =
true;
637 free(formatted_mark);
638 formatted_mark = buf;
641 if (had_visible_mark) {
647 : deco_width - mark_width - title_padding;
655 mark_width += title_padding;
658 FREE(formatted_mark);
686 title_offset_x = title_padding;
700 title_offset_x =
max(title_padding + mark_width, deco_width - title_padding -
predict_text_width(title));
708 deco_width - mark_width - 2 * title_padding);
759 if (should_be_hidden ==
state->is_hidden)
762 if (should_be_hidden) {
763 DLOG(
"setting _NET_WM_STATE_HIDDEN for con = %p\n",
con);
766 DLOG(
"removing _NET_WM_STATE_HIDDEN for con = %p\n",
con);
770 state->is_hidden = should_be_hidden;
780 xcb_shape_combine(
conn, XCB_SHAPE_SO_SET, shape_kind, shape_kind,
785 xcb_rectangle_t rectangles[4];
787 if (rectangles_count) {
788 xcb_shape_rectangles(
conn, XCB_SHAPE_SO_UNION, shape_kind,
790 0, 0, rectangles_count, rectangles);
800 xcb_shape_mask(
conn, XCB_SHAPE_SO_SET, shape_kind,
con->
frame.
id, 0, 0, XCB_PIXMAP_NONE);
813 ELOG(
"window state for con %p not found\n",
con);
852 if (
state->name != NULL) {
856 XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen(
state->name),
state->name);
863 uint32_t max_y = 0, max_height = 0;
866 if (dr->
y >= max_y && dr->
height >= max_height) {
876 bool need_reshape =
false;
881 DLOG(
"Reparenting child window\n");
886 uint32_t values[] = {XCB_NONE};
887 xcb_change_window_attributes(
conn,
state->old_frame, XCB_CW_EVENT_MASK, values);
888 xcb_change_window_attributes(
conn,
con->
window->
id, XCB_CW_EVENT_MASK, values);
893 xcb_change_window_attributes(
conn,
state->old_frame, XCB_CW_EVENT_MASK, values);
895 xcb_change_window_attributes(
conn,
con->
window->
id, XCB_CW_EVENT_MASK, values);
897 state->old_frame = XCB_NONE;
898 state->need_reparent =
false;
901 DLOG(
"ignore_unmap for reparenting of con %p (win 0x%08x) is now %d\n",
927 is_pixmap_needed =
false;
929 bool fake_notify =
false;
949 if (is_pixmap_needed && (has_rect_changed ||
con->
frame_buffer.
id == XCB_NONE)) {
1012 DLOG(
"setting window rect (%d, %d, %d, %d)\n",
1026 xcb_void_cookie_t cookie;
1031 long data[] = {XCB_ICCCM_WM_STATE_NORMAL, XCB_NONE};
1033 A_WM_STATE, A_WM_STATE, 32, 2, data);
1043 xcb_change_window_attributes(
conn,
con->
window->
id, XCB_CW_EVENT_MASK, values);
1044 DLOG(
"mapping child window (serial %d)\n", cookie.sequence);
1045 state->child_mapped =
true;
1051 xcb_change_window_attributes(
conn,
con->
frame.
id, XCB_CW_EVENT_MASK, values);
1059 DLOG(
"mapping container %08x (serial %d)\n",
con->
frame.
id, cookie.sequence);
1067 DLOG(
"Sending fake configure notify\n");
1100 if (
state->unmap_now) {
1101 xcb_void_cookie_t cookie;
1104 long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
1106 A_WM_STATE, A_WM_STATE, 32, 2, data);
1110 DLOG(
"unmapping container %p / %s (serial %d)\n",
con,
con->
name, cookie.sequence);
1160 xcb_query_pointer_cookie_t pointercookie;
1164 pointercookie = xcb_query_pointer(
conn,
root);
1167 DLOG(
"-- PUSHING WINDOW STACK --\n");
1172 uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
1175 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
1178 bool order_changed =
false;
1179 bool stacking_changed =
false;
1190 static xcb_window_t *client_list_windows = NULL;
1191 static int client_list_count = 0;
1193 if (cnt != client_list_count) {
1194 client_list_windows =
srealloc(client_list_windows,
sizeof(xcb_window_t) * cnt);
1195 client_list_count = cnt;
1198 xcb_window_t *walk = client_list_windows;
1203 memcpy(walk++, &(
state->con->window->id),
sizeof(xcb_window_t));
1208 if (prev != old_prev)
1209 order_changed =
true;
1211 stacking_changed =
true;
1214 mask |= XCB_CONFIG_WINDOW_SIBLING;
1215 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
1216 uint32_t values[] = {
state->id, XCB_STACK_MODE_ABOVE};
1218 xcb_configure_window(
conn, prev->
id, mask, values);
1220 state->initial =
false;
1225 if (stacking_changed) {
1226 DLOG(
"Client list changed (%i clients)\n", cnt);
1229 walk = client_list_windows;
1234 *walk++ =
state->con->window->id;
1240 DLOG(
"PUSHING CHANGES\n");
1244 xcb_query_pointer_reply_t *pointerreply = xcb_query_pointer_reply(
conn, pointercookie, NULL);
1245 if (!pointerreply) {
1246 ELOG(
"Could not query pointer position, not warping pointer\n");
1253 if (current != target) {
1255 xcb_change_window_attributes(
conn,
root, XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT});
1256 xcb_warp_pointer(
conn, XCB_NONE,
root, 0, 0, 0, 0, mid_x, mid_y);
1269 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
1288 DLOG(
"Updating focus by sending WM_TAKE_FOCUS to window 0x%08x (focused: %p / %s)\n",
1324 DLOG(
"Still no window focused, better set focus to the EWMH support window (%d)\n",
ewmh_window);
1333 DLOG(
"ENDING CHANGES\n");
1344 if (!
state->unmap_now)
1346 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
1388 ELOG(
"window state not found\n");
1402 xcb_delete_property(
conn,
root, A_I3_SHMLOG_PATH);
1404 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root,
1405 A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
1415 pid_t pid = getpid();
1416 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_SOCKET_PATH, A_UTF8_STRING, 8,
1419 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_PID, XCB_ATOM_CARDINAL, 32, 1, &pid);
1420 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_CONFIG_PATH, A_UTF8_STRING, 8,
1447 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
1457 ELOG(
"window state for con %p not found\n",
con);
1462 case XCB_SHAPE_SK_BOUNDING:
1465 case XCB_SHAPE_SK_INPUT:
1469 ELOG(
"Received unknown shape event kind for con %p. This is a bug.\n",
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...
xcb_window_t ewmh_window
The EWMH support window that is used to indicate that an EWMH-compliant window manager is present...
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...
struct Config::config_client client
static con_state * state_for_frame(xcb_window_t window)
#define CIRCLEQ_END(head)
#define COLOR_TRANSPARENT
void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp)
Sends the WM_TAKE_FOCUS ClientMessage to the given window.
void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface)
Destroys the surface.
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...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
static void x_draw_title_border(Con *con, struct deco_render_params *p)
uint16_t depth
Depth of the window.
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
char * current_socketpath
static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p)
bool shaped
The window has a nonrectangular shape.
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
Stores the parameters for rendering a window decoration.
#define CIRCLEQ_ENTRY(type)
static size_t x_get_border_rectangles(Con *con, xcb_rectangle_t rectangles[4])
#define CIRCLEQ_HEAD_INITIALIZER(head)
static void x_push_node_unmaps(Con *con)
struct width_height con_window_rect
#define TAILQ_HEAD(name, type)
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.
#define TAILQ_EMPTY(head)
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_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
xcb_connection_t * conn
XCB connection and root screen.
static void x_shape_frame(Con *con, xcb_shape_sk_t shape_kind)
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 x_raise_con(Con *con)
Raises the specified container in the internal stack of X windows.
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
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.
bool input_shaped
The window has a nonrectangular input shape.
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".
void draw_util_copy_surface(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.
xcb_screen_t * root_screen
#define CIRCLEQ_REMOVE(head, elm, field)
void x_con_init(Con *con)
Initializes the X11 part for the given container.
static void _x_con_kill(Con *con)
Stores a rectangle, for example the size of a window, the child window etc.
void update_shmlog_atom(void)
Set up the SHMLOG_PATH atom.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
#define CIRCLEQ_HEAD(name, type)
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 x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
static void set_hidden_state(Con *con)
void draw_util_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h)
Draws a filled rectangle.
static void set_shape_state(Con *con, bool need_reshape)
void ewmh_update_client_list(xcb_window_t *list, int num_windows)
Updates the _NET_CLIENT_LIST hint.
#define TAILQ_REMOVE(head, elm, field)
void x_reinit(Con *con)
Re-initializes the associated X window state for this 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) ...
xcb_window_t focused_id
Stores the X11 window ID of the currently focused window.
A 'Con' represents everything from the X11 root window down to a single X11 window.
#define TAILQ_FIRST(head)
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...
Stores a width/height pair, used as part of deco_render_params to check whether the rects width/heigh...
bool con_is_floating(Con *con)
Returns true if the node is floating.
kill_window_t
parameter to specify whether tree_close_internal() and x_window_kill() should kill only this specific...
adjacent_t con_adjacent_borders(Con *con)
Returns adjacent borders of the window.
#define TAILQ_NEXT(elm, field)
void x_mask_event_mask(uint32_t mask)
Applies the given mask to the event mask of every i3 window decoration X11 window.
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely...
void ewmh_update_active_window(xcb_window_t window)
Updates _NET_ACTIVE_WINDOW with the currently focused window.
void ewmh_update_focused(xcb_window_t window, bool is_focused)
Set or remove _NEW_WM_STATE_FOCUSED on the window.
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)...
char * current_configpath
#define TAILQ_ENTRY(type)
struct pending_marks * marks
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
static xcb_window_t last_focused
xcb_visualid_t get_visualid_by_depth(uint16_t depth)
Get visualid with specified depth.
struct _i3String i3String
Opaque data structure for storing strings.
xcb_visualtype_t * get_visualtype_by_id(xcb_visualid_t visual_id)
Get visual type specified by visualid.
void draw_util_surface_set_size(surface_t *surface, int width, int height)
Resize the surface to the given size.
border_style_t border_style
An Output is a physical output on your graphics driver.
char * title_format
The format with which the window's name should be displayed.
bool font_is_pango(void)
Returns true if and only if the current font is a pango font.
struct Colortriple focused_inactive
struct width_height con_rect
struct Colortriple focused
char * con_get_tree_representation(Con *con)
Create a string representing the subtree under con.
void x_con_reframe(Con *con)
struct Colortriple unfocused
void draw_util_clear_surface(surface_t *surface, color_t color)
Clears a surface with the given color.
#define CIRCLEQ_PREV(elm, field)
int height
The height of the font, built from font_ascent + font_descent.
void x_deco_recurse(Con *con)
Recursively calls x_draw_decoration.
int con_border_style(Con *con)
Use this function to get a container’s border style.
static void change_ewmh_focus(xcb_window_t new_focus, xcb_window_t old_focus)
bool doesnt_accept_focus
Whether this window accepts focus.
bool show_marks
Specifies whether or not marks should be displayed in the window decoration.
void x_draw_decoration(Con *con)
Draws the decoration of the given container onto its parent.
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
static bool is_con_attached(Con *con)
#define CIRCLEQ_FOREACH_REVERSE(var, head, field)
warping_t mouse_warping
By default, when switching focus to a window on a different output (e.g.
#define TAILQ_PREV(elm, headname, field)
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
struct Colortriple urgent
#define CIRCLEQ_FOREACH(var, head, field)
#define CIRCLEQ_INSERT_TAIL(head, elm, field)
struct Colortriple * color
hide_edge_borders_mode_t hide_edge_borders
Remove borders if they are adjacent to the screen edge.
void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows)
Updates the _NET_CLIENT_LIST_STACKING hint.
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 FRAME_EVENT_MASK
The XCB_CW_EVENT_MASK for its frame.
void x_set_shape(Con *con, xcb_shape_sk_t kind, bool enable)
Enables or disables nonrectangular shape of the container frame.
static void x_unshape_frame(Con *con, xcb_shape_sk_t shape_kind)
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.
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 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)
#define CIRCLEQ_INSERT_HEAD(head, elm, field)
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...
enum Config::@7 title_align
Title alignment options.
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_INSERT_TAIL(head, elm, field)
int predict_text_width(i3String *text)
Predict the text width in pixels for the given text.
#define TAILQ_FOREACH(var, head, field)
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory...
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
bool con_is_hidden(Con *con)
This will only return true for containers which have some parent with a tabbed / stacked parent of wh...
adjacent_t
describes if the window is adjacent to the output (physical screen) edges.