+ int focus = reply->focus;
+ free(reply);
+ return focus;
+}
+
+static xcb_atom_t do_intern_atom(const char *name)
+{
+ xcb_intern_atom_cookie_t cookie =
+ xcb_intern_atom(conn, 0, strlen(name), name);
+ if (!cookie.sequence)
+ return warn("do_intern_atom: bad cookie");
+
+ xcb_intern_atom_reply_t *reply =
+ xcb_intern_atom_reply(conn, cookie, NULL);
+ if (!reply)
+ return warn("do_intern_atom: no reply");
+
+ xcb_atom_t atom = reply->atom;
+ free(reply);
+ return atom;
+}
+
+static char *do_get_atom_name(xcb_atom_t atom)
+{
+ xcb_get_atom_name_cookie_t cookie =
+ xcb_get_atom_name(conn, atom);
+ if (!cookie.sequence)
+ return warn("do_get_atom_name: bad cookie"), NULL;
+
+ xcb_get_atom_name_reply_t *reply =
+ xcb_get_atom_name_reply(conn, cookie, NULL);
+ if (!reply)
+ return warn("do_get_atom_name: no reply"), NULL;
+
+ char *name = xcb_get_atom_name_name(reply);
+ int len = xcb_get_atom_name_name_length(reply);
+ char *str = strndup(name, len);
+ free(reply);
+ return str;
+}
+
+static int do_ewmh_init_atoms(void)
+{
+ xcb_intern_atom_cookie_t *cookies =
+ xcb_ewmh_init_atoms(conn, &ewmh);
+ if (!cookies)
+ return warn("do_ewmh_init_atoms: no cookies");
+
+ int status =
+ xcb_ewmh_init_atoms_replies(&ewmh, cookies, NULL);
+ if (!status)
+ return warn("do_ewmh_init_atoms: no status");
+ return status;
+}
+
+static int do_get_type(xcb_window_t xcb, type_t *type)
+{
+ xcb_get_property_cookie_t cookie =
+ xcb_ewmh_get_wm_window_type(&ewmh, xcb);
+ if (!cookie.sequence)
+ return warn("do_get_type: bad cookie");
+
+ xcb_ewmh_get_atoms_reply_t reply;
+ if (!xcb_ewmh_get_wm_window_type_reply(&ewmh, cookie, &reply, NULL))
+ return warn("do_get_type: no reply");
+
+ type_t prev = *type;
+ for (int i = 0; i < reply.atoms_len; i++) {
+ if (reply.atoms[i] == ewmh._NET_WM_WINDOW_TYPE_DOCK)
+ *type = TYPE_TOOLBAR;
+ if (reply.atoms[i] == ewmh._NET_WM_WINDOW_TYPE_TOOLBAR)
+ *type = TYPE_TOOLBAR;
+ if (reply.atoms[i] == ewmh._NET_WM_WINDOW_TYPE_DIALOG)
+ *type = TYPE_DIALOG;
+ }
+ printf("do_get_type: %d -> %d\n", prev, *type);
+ return 1;
+}
+
+static int do_get_icccm_state(xcb_window_t xcb, state_t *state)
+{
+ xcb_get_property_cookie_t cookie;
+
+ cookie = xcb_icccm_get_wm_normal_hints(conn, xcb);
+ if (!cookie.sequence)
+ return warn("do_get_icccm_state: bad cookie1");
+
+ xcb_size_hints_t sizes;
+ if (!xcb_icccm_get_wm_normal_hints_reply(conn, cookie, &sizes, NULL))
+ return warn("do_get_icccm_state: no sizes");
+
+ state_t prev = *state;
+ printf("do_get_icccm_state: %s -> %s\n",
+ state_map[prev], state_map[*state]);
+ return 1;
+}
+
+static int do_get_ewmh_state(xcb_window_t xcb, state_t *state)
+{
+ xcb_get_property_cookie_t cookie;
+
+ cookie = xcb_ewmh_get_wm_state(&ewmh, xcb);
+ if (!cookie.sequence)
+ return warn("do_get_ewmh_state: bad cookie2");
+
+ xcb_ewmh_get_atoms_reply_t states;
+ if (!xcb_ewmh_get_wm_state_reply(&ewmh, cookie, &states, NULL))
+ return warn("do_get_ewmh_state: no reply2");
+
+ state_t prev = *state;
+ for (int i = 0; i < states.atoms_len; i++)
+ if (states.atoms[i] == ewmh._NET_WM_STATE_FULLSCREEN)
+ *state = ST_FULL;
+
+ printf("do_get_ewmh_state: %s -> %s\n",
+ state_map[prev], state_map[*state]);
+ return 1;
+}
+
+static int do_get_strut(xcb_window_t xcb, strut_t *strut)
+{
+ xcb_get_property_cookie_t cookie =
+ xcb_ewmh_get_wm_strut(&ewmh, xcb);
+ if (!cookie.sequence)
+ return warn("do_get_strut: bad cookie");
+
+ xcb_ewmh_get_extents_reply_t ext = {};
+ int status =
+ xcb_ewmh_get_wm_strut_reply(&ewmh, cookie, &ext, NULL);
+ if (!status)
+ return warn("do_get_strut: no status");
+
+ strut->left = ext.left;
+ strut->right = ext.right;
+ strut->top = ext.top;
+ strut->bottom = ext.bottom;
+
+ return ext.left || ext.right || ext.top || ext.bottom;
+}
+
+static int do_get_transient(xcb_window_t xcb, xcb_window_t *parent)
+{
+ xcb_get_property_cookie_t cookie;
+
+ cookie = xcb_icccm_get_wm_transient_for(conn, xcb);
+ if (!cookie.sequence)
+ return warn("do_get_transient: bad cookie");
+
+ if (!xcb_icccm_get_wm_transient_for_reply(conn, cookie, parent, NULL))
+ return warn("do_get_transient: no sizes");
+
+ printf("do_get_transient: %d -> %d\n", xcb, *parent);
+ return 1;