]> git.sur5r.net Git - i3/i3/blobdiff - i3-config-wizard/xcb.c
Merge branch 'master' into next
[i3/i3] / i3-config-wizard / xcb.c
index 9a9bf615cd920775f11fab6733a0da6da2d7cc89..461dfd529b7dbbe3bd731dd21b94bd8205684746 100644 (file)
 
 #include <X11/keysym.h>
 
+#include "xcb.h"
+
 extern xcb_window_t root;
+unsigned int xcb_numlock_mask;
 
 /*
  * Convenience-wrapper around xcb_change_gc which saves us declaring a variable
@@ -106,11 +109,9 @@ xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t
         mask |= XCB_CW_BACK_PIXEL;
         values[0] = 0;
 
-        mask |= XCB_CW_OVERRIDE_REDIRECT;
-        values[1] = 1;
-
        mask |= XCB_CW_EVENT_MASK;
-       values[2] = XCB_EVENT_MASK_EXPOSURE;
+       values[1] = XCB_EVENT_MASK_EXPOSURE |
+                    XCB_EVENT_MASK_BUTTON_PRESS;
 
         xcb_create_window(conn,
                           XCB_COPY_FROM_PARENT,
@@ -164,3 +165,58 @@ int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
 
         return result;
 }
+
+/*
+ * Finds out which modifier mask is the one for numlock, as the user may change this.
+ *
+ */
+void xcb_get_numlock_mask(xcb_connection_t *conn) {
+    xcb_key_symbols_t *keysyms;
+    xcb_get_modifier_mapping_cookie_t cookie;
+    xcb_get_modifier_mapping_reply_t *reply;
+    xcb_keycode_t *modmap;
+    int mask, i;
+    const int masks[8] = { XCB_MOD_MASK_SHIFT,
+                           XCB_MOD_MASK_LOCK,
+                           XCB_MOD_MASK_CONTROL,
+                           XCB_MOD_MASK_1,
+                           XCB_MOD_MASK_2,
+                           XCB_MOD_MASK_3,
+                           XCB_MOD_MASK_4,
+                           XCB_MOD_MASK_5 };
+
+    /* Request the modifier map */
+    cookie = xcb_get_modifier_mapping_unchecked(conn);
+
+    /* Get the keysymbols */
+    keysyms = xcb_key_symbols_alloc(conn);
+
+    if ((reply = xcb_get_modifier_mapping_reply(conn, cookie, NULL)) == NULL) {
+        xcb_key_symbols_free(keysyms);
+        return;
+    }
+
+    modmap = xcb_get_modifier_mapping_keycodes(reply);
+
+    /* Get the keycode for numlock */
+#ifdef OLD_XCB_KEYSYMS_API
+    xcb_keycode_t numlock = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
+#else
+    /* For now, we only use the first keysymbol. */
+    xcb_keycode_t *numlock_syms = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
+    if (numlock_syms == NULL)
+        return;
+    xcb_keycode_t numlock = *numlock_syms;
+    free(numlock_syms);
+#endif
+
+    /* Check all modifiers (Mod1-Mod5, Shift, Control, Lock) */
+    for (mask = 0; mask < 8; mask++)
+        for (i = 0; i < reply->keycodes_per_modifier; i++)
+            if (modmap[(mask * reply->keycodes_per_modifier) + i] == numlock)
+                xcb_numlock_mask = masks[mask];
+
+    xcb_key_symbols_free(keysyms);
+    free(reply);
+}
+