-void reparent_window(xcb_connection_t *conn, xcb_window_t child,
- xcb_visualid_t visual, xcb_window_t root, uint8_t depth,
- int16_t x, int16_t y, uint16_t width, uint16_t height) {
-
- xcb_get_property_cookie_t wm_type_cookie, strut_cookie;
- uint32_t mask = 0;
- uint32_t values[3];
-
- /* We are interested in property changes */
- mask = XCB_CW_EVENT_MASK;
- values[0] = CHILD_EVENT_MASK;
- xcb_change_window_attributes(conn, child, mask, values);
-
- /* Map the window first to avoid flickering */
- xcb_map_window(conn, child);
-
- /* Place requests for properties ASAP */
- wm_type_cookie = xcb_get_any_property_unchecked(conn, false, child, atoms[_NET_WM_WINDOW_TYPE], UINT32_MAX);
- strut_cookie = xcb_get_any_property_unchecked(conn, false, child, atoms[_NET_WM_STRUT_PARTIAL], UINT32_MAX);
-
- Client *new = table_get(byChild, child);
-
- /* Events for already managed windows should already be filtered in manage_window() */
- assert(new == NULL);
-
- LOG("reparenting new client\n");
- new = calloc(sizeof(Client), 1);
- new->force_reconfigure = true;
-
- /* Update the data structures */
- Client *old_focused = CUR_CELL->currently_focused;
-
- new->container = CUR_CELL;
- new->workspace = new->container->workspace;
-
- new->frame = xcb_generate_id(conn);
- new->child = child;
- new->rect.width = width;
- new->rect.height = height;
-
- mask = 0;
-
- /* Don’t generate events for our new window, it should *not* be managed */
- mask |= XCB_CW_OVERRIDE_REDIRECT;
- values[0] = 1;
-
- /* We want to know when… */
- mask |= XCB_CW_EVENT_MASK;
- values[1] = FRAME_EVENT_MASK;
-
- LOG("Reparenting 0x%08x under 0x%08x.\n", child, new->frame);
-
- i3Font *font = load_font(conn, config.font);
- width = min(width, c_ws->rect.x + c_ws->rect.width);
- height = min(height, c_ws->rect.y + c_ws->rect.height);
-
- Rect framerect = {x, y,
- width + 2 + 2, /* 2 px border at each side */
- height + 2 + 2 + font->height}; /* 2 px border plus font’s height */
-
- /* Yo dawg, I heard you like windows, so I create a window around your window… */
- new->frame = create_window(conn, framerect, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_CURSOR_LEFT_PTR, mask, values);
-
- /* Put the client inside the save set. Upon termination (whether killed or normal exit
- does not matter) of the window manager, these clients will be correctly reparented
- to their most closest living ancestor (= cleanup) */
- xcb_change_save_set(conn, XCB_SET_MODE_INSERT, child);
+static void xkb_got_event(EV_P_ struct ev_io *w, int revents) {
+ DLOG("Handling XKB event\n");
+ XkbEvent ev;
+
+ /* When using xmodmap, every change (!) gets an own event.
+ * Therefore, we just read all events and only handle the
+ * mapping_notify once. */
+ bool mapping_changed = false;
+ while (XPending(xkbdpy)) {
+ XNextEvent(xkbdpy, (XEvent*)&ev);
+ /* While we should never receive a non-XKB event,
+ * better do sanity checking */
+ if (ev.type != xkb_event_base)
+ continue;
+
+ if (ev.any.xkb_type == XkbMapNotify) {
+ mapping_changed = true;
+ continue;
+ }