2 #define I3__FILE__ "x.c"
73 static
con_state *state_for_frame(xcb_window_t window) {
76 if (state->
id == window)
80 ELOG(
"No state found\n");
97 xcb_visualid_t visual = XCB_COPY_FROM_PARENT;
98 xcb_colormap_t win_colormap = XCB_NONE;
99 if (depth !=
root_depth && depth != XCB_COPY_FROM_PARENT) {
103 win_colormap = xcb_generate_id(
conn);
104 xcb_create_colormap_checked(
conn, XCB_COLORMAP_ALLOC_NONE, win_colormap,
root, visual);
110 mask |= XCB_CW_BACK_PIXEL;
113 mask |= XCB_CW_BORDER_PIXEL;
117 mask |= XCB_CW_OVERRIDE_REDIRECT;
121 mask |= XCB_CW_EVENT_MASK;
124 mask |= XCB_CW_COLORMAP;
125 values[4] = win_colormap;
128 mask = XCB_CW_OVERRIDE_REDIRECT;
132 mask |= XCB_CW_EVENT_MASK;
135 mask |= XCB_CW_COLORMAP;
139 Rect dims = { -15, -15, 10, 10 };
142 if (win_colormap != XCB_NONE)
143 xcb_free_colormap(
conn, win_colormap);
151 DLOG(
"adding new state for window id 0x%08x\n", state->
id);
163 if ((state = state_for_frame(con->
frame)) == NULL) {
164 ELOG(
"window state not found\n");
168 DLOG(
"resetting state %p to initial\n", state);
182 if ((state = state_for_frame(con->
frame)) == NULL) {
183 ELOG(
"window state for con not found\n");
196 struct con_state *state_src, *state_dest;
198 if ((state_src = state_for_frame(src->
frame)) == NULL) {
199 ELOG(
"window state for src not found\n");
203 if ((state_dest = state_for_frame(dest->
frame)) == NULL) {
204 ELOG(
"window state for dest not found\n");
208 state_dest->
con = state_src->
con;
209 state_src->
con = NULL;
211 Rect zero = { 0, 0, 0, 0 };
214 DLOG(
"COPYING RECT\n");
228 state = state_for_frame(con->
frame);
243 xcb_get_property_cookie_t cookie;
252 for (uint32_t i = 0; i < protocols.atoms_len; i++)
253 if (protocols.atoms[i] == atom)
269 LOG(
"Killing specific window 0x%08x\n", window);
270 xcb_destroy_window(
conn, window);
272 LOG(
"Killing the X11 client which owns window 0x%08x\n", window);
273 xcb_kill_client(
conn, window);
282 xcb_client_message_event_t *ev = event;
284 ev->response_type = XCB_CLIENT_MESSAGE;
286 ev->type = A_WM_PROTOCOLS;
288 ev->data.data32[0] = A_WM_DELETE_WINDOW;
289 ev->data.data32[1] = XCB_CURRENT_TIME;
291 LOG(
"Sending WM_DELETE to the client\n");
292 xcb_send_event(
conn,
false, window, XCB_EVENT_MASK_NO_EVENT, (
char*)ev);
314 parent->
layout != L_STACKED &&
315 parent->
layout != L_TABBED) ||
316 parent->
type == CT_OUTPUT ||
317 parent->
type == CT_DOCKAREA ||
318 con->
type == CT_FLOATING_CON)
328 if (leaf && con->
pixmap == XCB_NONE)
339 else if (con ==
TAILQ_FIRST(&(parent->focus_head)))
378 if (con->
window != NULL) {
379 xcb_rectangle_t background[] = {
390 for (
int i = 0; i < 4; i++)
391 DLOG(
"rect is (%d, %d) with %d x %d\n",
400 xcb_poly_fill_rectangle(
conn, con->
pixmap, con->
pm_gc,
sizeof(background) /
sizeof(xcb_rectangle_t), background);
404 if (p->border_style !=
BS_NONE && p->con_is_leaf) {
412 DLOG(
"border_rect spans (%d, %d) with %d x %d\n", br.
x, br.
y, br.
width, br.
height);
420 xcb_change_gc(
conn,
con->
pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
422 xcb_rectangle_t leftline = { 0, 0, br.
x, r->height };
426 xcb_rectangle_t rightline = { r->width + br.
width + br.
x, 0, r->width, r->height };
430 xcb_rectangle_t bottomline = { 0, r->height + br.
height + br.
y, r->width, r->height };
446 xcb_change_gc(
conn,
con->
pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->indicator });
449 { r->width + br.
width + br.
x, 0, r->width, r->height + br.
height } });
451 xcb_poly_fill_rectangle(
conn, con->pixmap, con->pm_gc, 1, (xcb_rectangle_t[]){
452 { br.
x, r->height + br.
height + br.
y, r->width - (2 * br.
x), r->height } });
463 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
464 xcb_rectangle_t drect = { con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height };
465 xcb_poly_fill_rectangle(
conn, parent->pixmap, parent->pm_gc, 1, &drect);
468 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
469 Rect *dr = &(con->deco_rect);
470 xcb_segment_t segments[] = {
472 dr->x + dr->width - 1, dr->y },
474 { dr->x + 2, dr->y + dr->height - 1,
475 dr->x + dr->width - 3, dr->y + dr->height - 1 }
477 xcb_poly_segment(
conn, parent->pixmap, parent->pm_gc, 2, segments);
483 struct Window *win = con->window;
484 if (win == NULL || win->
name == NULL) {
488 parent->pixmap, parent->pm_gc,
489 con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
490 con->deco_rect.width - 2);
494 int indent_level = 0,
496 Con *il_parent = parent;
497 if (il_parent->
layout != L_STACKED) {
500 if (il_parent->
layout == L_STACKED)
502 if (il_parent->
type == CT_WORKSPACE || il_parent->
type == CT_DOCKAREA || il_parent->
type == CT_OUTPUT)
504 il_parent = il_parent->
parent;
509 int indent_px = (indent_level * 5) * indent_mult;
512 parent->pixmap, parent->pm_gc,
513 con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
514 con->deco_rect.width - 2 - indent_px);
523 if (parent->layout == L_TABBED &&
TAILQ_NEXT(con, nodes) != NULL) {
524 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
526 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->background });
528 xcb_poly_line(
conn, XCB_COORD_MODE_ORIGIN, parent->pixmap, parent->pm_gc, 4,
530 { dr->x + dr->width - 1, dr->y },
531 { dr->x + dr->width - 1, dr->y + dr->height },
532 { dr->x + dr->width - 2, dr->y },
533 { dr->x + dr->width - 2, dr->y + dr->height }
536 xcb_change_gc(
conn, parent->pm_gc, XCB_GC_FOREGROUND, (uint32_t[]){ p->color->border });
537 xcb_poly_segment(
conn, parent->pixmap, parent->pm_gc, 2, segments);
540 xcb_copy_area(
conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);
559 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
566 if ((con->
type != CT_ROOT && con->
type != CT_OUTPUT) &&
583 state = state_for_frame(con->
frame);
585 if (state->
name != NULL) {
586 DLOG(
"pushing name %s for con %p\n", state->
name, con);
588 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
frame,
593 if (con->
window == NULL) {
596 uint32_t max_y = 0, max_height = 0;
599 if (dr->
y >= max_y && dr->
height >= max_height) {
604 rect.
height = max_y + max_height;
612 DLOG(
"Reparenting child window\n");
617 uint32_t values[] = { XCB_NONE };
618 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
619 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
624 xcb_change_window_attributes(
conn, state->
old_frame, XCB_CW_EVENT_MASK, values);
626 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
632 DLOG(
"ignore_unmap for reparenting of con %p (win 0x%08x) is now %d\n",
636 bool fake_notify =
false;
638 if (memcmp(&(state->
rect), &rect,
sizeof(
Rect)) != 0 &&
669 uint32_t values[] = { 0 };
670 xcb_create_gc(
conn, con->
pm_gc, con->
pixmap, XCB_GC_GRAPHICS_EXPOSURES, values);
685 DLOG(
"setting rect (%d, %d, %d, %d)\n", rect.
x, rect.
y, rect.
width, rect.
height);
692 if (con->
pixmap != XCB_NONE)
696 memcpy(&(state->
rect), &rect,
sizeof(
Rect));
701 if (con->
window != NULL &&
703 DLOG(
"setting window rect (%d, %d, %d, %d)\n",
716 xcb_void_cookie_t cookie;
718 if (con->
window != NULL) {
722 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
723 A_WM_STATE, A_WM_STATE, 32, 2, data);
733 xcb_change_window_attributes(
conn, con->
window->
id, XCB_CW_EVENT_MASK, values);
734 DLOG(
"mapping child window (serial %d)\n", cookie.sequence);
738 cookie = xcb_map_window(
conn, con->
frame);
741 xcb_change_window_attributes(
conn, con->
frame, XCB_CW_EVENT_MASK, values);
744 if (con->
pixmap != XCB_NONE)
748 DLOG(
"mapping container %08x (serial %d)\n", con->
frame, cookie.sequence);
755 DLOG(
"Sending fake configure notify\n");
780 state = state_for_frame(con->
frame);
786 xcb_void_cookie_t cookie;
787 if (con->
window != NULL) {
790 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
791 A_WM_STATE, A_WM_STATE, 32, 2, data);
794 cookie = xcb_unmap_window(
conn, con->
frame);
795 DLOG(
"unmapping container (serial %d)\n", cookie.sequence);
799 if (con->
window != NULL) {
810 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
827 xcb_query_pointer_cookie_t pointercookie;
831 pointercookie = xcb_query_pointer(
conn,
root);
834 DLOG(
"-- PUSHING WINDOW STACK --\n");
836 uint32_t values[1] = { XCB_NONE };
839 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
842 bool order_changed =
false;
843 bool stacking_changed =
false;
862 memcpy(walk++, &(state->
con->
window->
id),
sizeof(xcb_window_t));
867 if (prev != old_prev)
868 order_changed =
true;
870 stacking_changed =
true;
873 mask |= XCB_CONFIG_WINDOW_SIBLING;
874 mask |= XCB_CONFIG_WINDOW_STACK_MODE;
875 uint32_t values[] = {state->
id, XCB_STACK_MODE_ABOVE};
877 xcb_configure_window(
conn, prev->
id, mask, values);
884 if (stacking_changed)
887 DLOG(
"PUSHING CHANGES\n");
891 xcb_query_pointer_reply_t *pointerreply = xcb_query_pointer_reply(
conn, pointercookie, NULL);
893 ELOG(
"Could not query pointer position, not warping pointer\n");
895 int mid_x = warp_to->
x + (warp_to->
width / 2);
896 int mid_y = warp_to->
y + (warp_to->
height / 2);
900 if (current != target)
901 xcb_warp_pointer(
conn, XCB_NONE,
root, 0, 0, 0, 0, mid_x, mid_y);
910 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
926 bool set_focus =
true;
929 DLOG(
"Updating focus by sending WM_TAKE_FOCUS to window 0x%08x (focused: %p / %s)\n",
933 DLOG(
"set_focus = %d\n", set_focus);
945 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT, to_focus, XCB_CURRENT_TIME);
959 DLOG(
"Still no window focused, better set focus to the root window\n");
960 xcb_set_input_focus(
conn, XCB_INPUT_FOCUS_POINTER_ROOT,
root, XCB_CURRENT_TIME);
965 DLOG(
"ENDING CHANGES\n");
978 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);
1003 state = state_for_frame(con->
frame);
1019 if ((state = state_for_frame(con->
frame)) == NULL) {
1020 ELOG(
"window state not found\n");
1033 pid_t pid = getpid();
1034 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_SOCKET_PATH, A_UTF8_STRING, 8,
1038 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_CONFIG_PATH, A_UTF8_STRING, 8,
1040 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE,
root, A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
1066 xcb_change_window_attributes(
conn, state->
id, XCB_CW_EVENT_MASK, values);