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);