2 #define I3__FILE__ "x.c"
74 static
con_state *state_for_frame(xcb_window_t window) {
77 if (state->
id == window)
81 ELOG(
"No state found\n");
98 xcb_visualid_t visual = XCB_COPY_FROM_PARENT;
99 xcb_colormap_t win_colormap = XCB_NONE;
100 if (depth !=
root_depth && depth != XCB_COPY_FROM_PARENT) {
104 win_colormap = xcb_generate_id(
conn);
105 xcb_create_colormap_checked(
conn, XCB_COLORMAP_ALLOC_NONE, win_colormap,
root, visual);
111 mask |= XCB_CW_BACK_PIXEL;
114 mask |= XCB_CW_BORDER_PIXEL;
118 mask |= XCB_CW_OVERRIDE_REDIRECT;
122 mask |= XCB_CW_EVENT_MASK;
125 mask |= XCB_CW_COLORMAP;
126 values[4] = win_colormap;
129 mask = XCB_CW_OVERRIDE_REDIRECT;
133 mask |= XCB_CW_EVENT_MASK;
136 mask |= XCB_CW_COLORMAP;
140 Rect dims = { -15, -15, 10, 10 };
143 if (win_colormap != XCB_NONE)
144 xcb_free_colormap(
conn, win_colormap);
152 DLOG(
"adding new state for window id 0x%08x\n", state->
id);
164 if ((state = state_for_frame(con->
frame)) == NULL) {
165 ELOG(
"window state not found\n");
169 DLOG(
"resetting state %p to initial\n", state);
183 if ((state = state_for_frame(con->
frame)) == NULL) {
184 ELOG(
"window state for con not found\n");
197 struct con_state *state_src, *state_dest;
199 if ((state_src = state_for_frame(src->
frame)) == NULL) {
200 ELOG(
"window state for src not found\n");
204 if ((state_dest = state_for_frame(dest->
frame)) == NULL) {
205 ELOG(
"window state for dest not found\n");
209 state_dest->
con = state_src->
con;
210 state_src->
con = NULL;
212 Rect zero = { 0, 0, 0, 0 };
215 DLOG(
"COPYING RECT\n");
229 state = state_for_frame(con->
frame);
244 xcb_get_property_cookie_t cookie;
253 for (uint32_t i = 0; i < protocols.atoms_len; i++)
254 if (protocols.atoms[i] == atom)
270 LOG(
"Killing specific window 0x%08x\n", window);
271 xcb_destroy_window(
conn, window);
273 LOG(
"Killing the X11 client which owns window 0x%08x\n", window);
274 xcb_kill_client(
conn, window);
283 xcb_client_message_event_t *ev = event;
285 ev->response_type = XCB_CLIENT_MESSAGE;
287 ev->type = A_WM_PROTOCOLS;
289 ev->data.data32[0] = A_WM_DELETE_WINDOW;
290 ev->data.data32[1] = XCB_CURRENT_TIME;
292 LOG(
"Sending WM_DELETE to the client\n");
293 xcb_send_event(
conn,
false, window, XCB_EVENT_MASK_NO_EVENT, (
char*)ev);
317 parent->
type == CT_OUTPUT ||
318 parent->
type == CT_DOCKAREA ||
319 con->
type == CT_FLOATING_CON)
329 if (leaf && con->
pixmap == XCB_NONE)
340 else if (con ==
TAILQ_FIRST(&(parent->focus_head)))
380 if (con->
window != NULL) {
381 xcb_rectangle_t background[] = {
392 for (
int i = 0; i < 4; i++)
393 DLOG(
"rect is (%d, %d) with %d x %d\n",
402 xcb_poly_fill_rectangle(
conn, con->
pixmap, con->
pm_gc,
sizeof(background) /
sizeof(xcb_rectangle_t), background);
406 if (p->border_style !=
BS_NONE && p->con_is_leaf) {
414 DLOG(
"border_rect spans (%d, %d) with %d x %d\n", br.
x, br.
y, br.
width, br.
height);
422 xcb_change_gc(
conn,
con->
pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
424 xcb_rectangle_t leftline = { 0, 0, br.
x, r->height };
428 xcb_rectangle_t rightline = { r->width + br.
width + br.
x, 0, r->width, r->height };
432 xcb_rectangle_t bottomline = { 0, r->height + br.
height + br.
y, r->width, r->height };
448 xcb_change_gc(
conn,
con->
pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->indicator });
451 { r->width + br.
width + br.
x, br.
y, r->width, r->height + br.
height } });
452 else if (p->parent_layout ==
L_SPLITV)
453 xcb_poly_fill_rectangle(
conn, con->pixmap, con->pm_gc, 1, (xcb_rectangle_t[]){
454 { br.
x, r->height + br.
height + br.
y, r->width - (2 * br.
x), r->height } });
465 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
466 xcb_rectangle_t drect = { con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height };
467 xcb_poly_fill_rectangle(
conn, parent->pixmap, parent->pm_gc, 1, &drect);
470 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
471 Rect *dr = &(con->deco_rect);
475 if (
TAILQ_PREV(con, nodes_head, nodes) != NULL)
480 xcb_segment_t segments[] = {
482 dr->x + dr->width - 1, dr->y },
484 { dr->x + deco_diff_l, dr->y + dr->height - 1,
485 dr->x - deco_diff_r + dr->width - 1, dr->y + dr->height - 1 }
487 xcb_poly_segment(
conn, parent->pixmap, parent->pm_gc, 2, segments);
493 struct Window *win = con->window;
504 parent->pixmap, parent->pm_gc,
505 con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
506 con->deco_rect.width - 2);
512 if (win->
name == NULL)
515 int indent_level = 0,
517 Con *il_parent = parent;
523 if (il_parent->
type == CT_WORKSPACE || il_parent->
type == CT_DOCKAREA || il_parent->
type == CT_OUTPUT)
525 il_parent = il_parent->
parent;
530 int indent_px = (indent_level * 5) * indent_mult;
533 parent->pixmap, parent->pm_gc,
534 con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
535 con->deco_rect.width - 2 - indent_px);
546 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
548 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
550 xcb_poly_line(
conn, XCB_COORD_MODE_ORIGIN, parent->pixmap, parent->pm_gc, 6,
552 { dr->x + dr->width, dr->y },
553 { dr->x + dr->width, dr->y + dr->height },
554 { dr->x + dr->width - 1, dr->y },
555 { dr->x + dr->width - 1, dr->y + dr->height },
556 { dr->x, dr->y + dr->height },
560 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
561 xcb_poly_segment(
conn, parent->pixmap, parent->pm_gc, 2, segments);
564 xcb_copy_area(
conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);
583 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
590 if ((con->
type != CT_ROOT && con->
type != CT_OUTPUT) &&
607 state = state_for_frame(con->
frame);
609 if (state->
name != NULL) {
610 DLOG(
"pushing name %s for con %p\n", state->
name, con);
612 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
frame,
617 if (con->
window == NULL) {
620 uint32_t max_y = 0, max_height = 0;
623 if (dr->
y >= max_y && dr->
height >= max_height) {
628 rect.
height = max_y + max_height;
636 DLOG(
"Reparenting child window\n");
641 uint32_t values[] = { XCB_NONE };
642 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
643 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
648 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
650 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
656 DLOG(
"ignore_unmap for reparenting of con %p (win 0x%08x) is now %d\n",
660 bool fake_notify =
false;
662 if (memcmp(&(state->
rect), &rect,
sizeof(
Rect)) != 0 &&
693 uint32_t values[] = { 0 };
694 xcb_create_gc(
conn, con->
pm_gc, con->
pixmap, XCB_GC_GRAPHICS_EXPOSURES, values);
709 DLOG(
"setting rect (%d, %d, %d, %d)\n", rect.
x, rect.
y, rect.
width, rect.
height);
716 if (con->
pixmap != XCB_NONE)
720 memcpy(&(state->
rect), &rect,
sizeof(
Rect));
725 if (con->
window != NULL &&
727 DLOG(
"setting window rect (%d, %d, %d, %d)\n",
740 xcb_void_cookie_t cookie;
742 if (con->
window != NULL) {
746 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
747 A_WM_STATE, A_WM_STATE, 32, 2, data);
757 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
758 DLOG(
"mapping child window (serial %d)\n", cookie.sequence);
762 cookie = xcb_map_window(
conn, con->
frame);
765 xcb_change_window_attributes(
conn, con->
frame, XCB_CW_EVENT_MASK, values);
768 if (con->
pixmap != XCB_NONE)
772 DLOG(
"mapping container %08x (serial %d)\n", con->
frame, cookie.sequence);
779 DLOG(
"Sending fake configure notify\n");
804 state = state_for_frame(con->
frame);
810 xcb_void_cookie_t cookie;
811 if (con->
window != NULL) {
814 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
815 A_WM_STATE, A_WM_STATE, 32, 2, data);
818 cookie = xcb_unmap_window(
conn, con->
frame);
819 DLOG(
"unmapping container %p / %s (serial %d)\n", con, con->
name, cookie.sequence);
823 if (con->
window != NULL) {
834 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
851 xcb_query_pointer_cookie_t pointercookie;
855 pointercookie = xcb_query_pointer(
conn,
root);
858 DLOG(
"-- PUSHING WINDOW STACK --\n");
860 uint32_t values[1] = { XCB_NONE };
863 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
866 bool order_changed =
false;
867 bool stacking_changed =
false;
886 memcpy(walk++, &(state->
con->
window->
id),
sizeof(xcb_window_t));
891 if (prev != old_prev)
892 order_changed =
true;
894 stacking_changed =
true;
897 mask |= XCB_CONFIG_WINDOW_SIBLING;
898 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
899 uint32_t values[] = {state->
id, XCB_STACK_MODE_ABOVE};
901 xcb_configure_window(
conn, prev->
id, mask, values);
904 DLOG(
"above all: 0x%08x\n", state->
id);
905 xcb_configure_window(
conn, state->
id, XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){ XCB_STACK_MODE_ABOVE });
912 if (stacking_changed)
915 DLOG(
"PUSHING CHANGES\n");
919 xcb_query_pointer_reply_t *pointerreply = xcb_query_pointer_reply(
conn, pointercookie, NULL);
921 ELOG(
"Could not query pointer position, not warping pointer\n");
923 int mid_x = warp_to->
x + (warp_to->
width / 2);
924 int mid_y = warp_to->
y + (warp_to->
height / 2);
928 if (current != target) {
930 xcb_change_window_attributes(
conn,
root, XCB_CW_EVENT_MASK, (uint32_t[]){ XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT });
931 xcb_warp_pointer(
conn, XCB_NONE,
root, 0, 0, 0, 0, mid_x, mid_y);
942 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
958 bool set_focus =
true;
961 DLOG(
"Updating focus by sending WM_TAKE_FOCUS to window 0x%08x (focused: %p / %s)\n",
965 DLOG(
"set_focus = %d\n", set_focus);
977 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT, to_focus, XCB_CURRENT_TIME);
991 DLOG(
"Still no window focused, better set focus to the root window\n");
992 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT,
root, XCB_CURRENT_TIME);
997 DLOG(
"ENDING CHANGES\n");
1008 if (!
state->unmap_now)
1010 xcb_change_window_attributes(
conn,
state->id, XCB_CW_EVENT_MASK, values);
1039 state = state_for_frame(con->
frame);
1057 if ((state = state_for_frame(con->
frame)) == NULL) {
1058 ELOG(
"window state not found\n");
1071 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root,
1072 A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
1081 pid_t pid = getpid();
1082 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_SOCKET_PATH, A_UTF8_STRING, 8,
1086 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_CONFIG_PATH, A_UTF8_STRING, 8,
1113 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
#define XCB_ICCCM_WM_STATE_WITHDRAWN
uint8_t ignore_unmap
This counter contains the number of UnmapNotify events for this container (or, more precisely...
#define CIRCLEQ_ENTRY(type)
#define XCB_ICCCM_WM_STATE_NORMAL
A 'Con' represents everything from the X11 root window down to a single X11 window.
static void x_push_node_unmaps(Con *con)
kill_window_t
parameter to specify whether tree_close() and x_window_kill() should kill only this specific window o...
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
Stores a rectangle, for example the size of a window, the child window etc.
#define CIRCLEQ_INSERT_HEAD(head, elm, field)
struct Colortriple unfocused
void x_con_init(Con *con, uint16_t depth)
Initializes the X11 part for the given container.
adjacent_t
describes if the window is adjacent to the output (physical screen) edges.
char * con_get_tree_representation(Con *con)
Create a string representing the subtree under con.
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
void x_window_kill(xcb_window_t window, kill_window_t kill_window)
Kills the given X11 window using WM_DELETE_WINDOW (if supported).
struct width_height con_rect
#define FRAME_EVENT_MASK
The XCB_CW_EVENT_MASK for its frame.
void x_mask_event_mask(uint32_t mask)
Applies the given mask to the event mask of every i3 window decoration X11 window.
#define CIRCLEQ_HEAD_INITIALIZER(head)
struct width_height con_window_rect
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...
#define TAILQ_EMPTY(head)
i3String * name
The name of the window.
void draw_text_ascii(const char *text, xcb_drawable_t drawable, xcb_gcontext_t gc, int x, int y, int max_width)
ASCII version of draw_text to print static 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_PREV(elm, headname, field)
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
struct Config::config_client client
#define xcb_icccm_get_wm_protocols_reply
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.
Con * con
The con for which this state is.
#define xcb_icccm_get_wm_protocols
#define xcb_icccm_get_wm_protocols_reply_t
void ewmh_update_active_window(xcb_window_t window)
Updates _NET_ACTIVE_WINDOW with the currently focused window.
struct Colortriple * color
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
bool doesnt_accept_focus
Whether this window accepts focus.
void x_reinit(Con *con)
Re-initializes the associated X window state for this container.
xcb_visualid_t get_visualid_by_depth(uint16_t depth)
Get visualid with specified depth.
void x_con_kill(Con *con)
Kills the window decoration associated with the given container.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
#define CIRCLEQ_END(head)
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
adjacent_t con_adjacent_borders(Con *con)
Returns adjacent borders of the window.
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
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 the parameters for rendering a window decoration.
xcb_screen_t * root_screen
struct Colortriple urgent
#define CIRCLEQ_INSERT_TAIL(head, elm, field)
#define CIRCLEQ_REMOVE(head, elm, field)
#define CIRCLEQ_PREV(elm, field)
void x_deco_recurse(Con *con)
Recursively calls x_draw_decoration.
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
void ewmh_update_client_list_stacking(xcb_window_t *stack, int num_windows)
Updates the _NET_CLIENT_LIST_STACKING hint.
void x_draw_decoration(Con *con)
Draws the decoration of the given container onto its parent.
#define TAILQ_NEXT(elm, field)
Stores a width/height pair, used as part of deco_render_params to check whether the rects width/heigh...
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) ...
struct Colortriple focused
#define TAILQ_FIRST(head)
char * current_socketpath
char * current_configpath
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...
adjacent_t hide_edge_borders
Remove borders if they are adjacent to the screen edge.
An Output is a physical output on your graphics driver.
struct Colortriple focused_inactive
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
uint16_t depth
Depth of the window.
#define CIRCLEQ_FOREACH(var, head, field)
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
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 xcb_icccm_get_wm_protocols_reply_wipe
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
#define TAILQ_FOREACH(var, head, field)
#define CIRCLEQ_FOREACH_REVERSE(var, head, field)
static xcb_window_t * btt_stack
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...
xcb_window_t focused_id
Stores the X11 window ID of the currently focused window.
void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc, int x, int y, int max_width)
Draws text onto the specified X drawable (normally a pixmap) at the specified coordinates (from the t...
#define XCB_ATOM_CARDINAL
void x_raise_con(Con *con, bool above_all)
Raises the specified container in the internal stack of X windows.
CIRCLEQ_HEAD(state_head, con_state)
int con_border_style(Con *con)
Use this function to get a container’s border style.
int height
The height of the font, built from font_ascent + font_descent.
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 x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
void send_take_focus(xcb_window_t window)
Sends the WM_TAKE_FOCUS ClientMessage to the given window.
#define CHILD_EVENT_MASK
The XCB_CW_EVENT_MASK for the child (= real window)
void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background)
Defines the colors to be used for the forthcoming draw_text calls.
bool needs_take_focus
Whether the application needs to receive WM_TAKE_FOCUS.