i3 - improved tiling WM


Move translate_keysyms to bindings.[ch]

Patch status: merged

Patch by Tony Crisci

Long description:

Additionally add a check so the function only handles bindings of type
B_KEYBOARD to prepare for the new bindmouse feature.

To apply this patch, use:
curl http://cr.i3wm.org/patch/466/raw.patch | git am

b/include/bindings.h

18
@@ -36,3 +36,9 @@ void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch);
19
  *
20
  */
21
 Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_t keycode);
22
+
23
+/**
24
+ * Translates keysymbols to keycodes for all bindings which use keysyms.
25
+ *
26
+ */
27
+void translate_keysyms(void);

b/include/config.h

32
@@ -309,12 +309,6 @@ struct Barconfig {
33
 void load_configuration(xcb_connection_t *conn, const char *override_configfile, bool reload);
34
 
35
 /**
36
- * Translates keysymbols to keycodes for all bindings which use keysyms.
37
- *
38
- */
39
-void translate_keysyms(void);
40
-
41
-/**
42
  * Ungrabs all keys, to be called before re-grabbing the keys because of a
43
  * mapping_notify event or a configuration file reload
44
  *

b/src/bindings.c

49
@@ -179,3 +179,53 @@ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_
50
 
51
     return (bind == TAILQ_END(bindings) ? NULL : bind);
52
 }
53
+
54
+/*
55
+ * Translates keysymbols to keycodes for all bindings which use keysyms.
56
+ *
57
+ */
58
+void translate_keysyms(void) {
59
+    Binding *bind;
60
+    xcb_keysym_t keysym;
61
+    int col;
62
+    xcb_keycode_t i, min_keycode, max_keycode;
63
+
64
+    min_keycode = xcb_get_setup(conn)->min_keycode;
65
+    max_keycode = xcb_get_setup(conn)->max_keycode;
66
+
67
+    TAILQ_FOREACH(bind, bindings, bindings) {
68
+        if (bind->input_type != B_KEYBOARD || bind->keycode > 0)
69
+            continue;
70
+
71
+        /* We need to translate the symbol to a keycode */
72
+        keysym = XStringToKeysym(bind->symbol);
73
+        if (keysym == NoSymbol) {
74
+            ELOG("Could not translate string to key symbol: \"%s\"\n",
75
+                 bind->symbol);
76
+            continue;
77
+        }
78
+
79
+        /* Base column we use for looking up key symbols. We always consider
80
+         * the base column and the corresponding shift column, so without
81
+         * mode_switch, we look in 0 and 1, with mode_switch we look in 2 and
82
+         * 3. */
83
+        col = (bind->mods & BIND_MODE_SWITCH ? 2 : 0);
84
+
85
+        FREE(bind->translated_to);
86
+        bind->number_keycodes = 0;
87
+
88
+        for (i = min_keycode; i && i <= max_keycode; i++) {
89
+            if ((xcb_key_symbols_get_keysym(keysyms, i, col) != keysym) &&
90
+                (xcb_key_symbols_get_keysym(keysyms, i, col+1) != keysym))
91
+                continue;
92
+            bind->number_keycodes++;
93
+            bind->translated_to = srealloc(bind->translated_to,
94
+                                           (sizeof(xcb_keycode_t) *
95
+                                            bind->number_keycodes));
96
+            bind->translated_to[bind->number_keycodes-1] = i;
97
+        }
98
+
99
+        DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol,
100
+             bind->number_keycodes);
101
+    }
102
+}

b/src/config.c

107
@@ -31,55 +31,6 @@ void ungrab_all_keys(xcb_connection_t *conn) {
108
 }
109
 
110
 /*
111
- * Translates keysymbols to keycodes for all bindings which use keysyms.
112
- *
113
- */
114
-void translate_keysyms(void) {
115
-    Binding *bind;
116
-    xcb_keysym_t keysym;
117
-    int col;
118
-    xcb_keycode_t i,
119
-                  min_keycode = xcb_get_setup(conn)->min_keycode,
120
-                  max_keycode = xcb_get_setup(conn)->max_keycode;
121
-
122
-    TAILQ_FOREACH(bind, bindings, bindings) {
123
-        if (bind->keycode > 0)
124
-            continue;
125
-
126
-        /* We need to translate the symbol to a keycode */
127
-        keysym = XStringToKeysym(bind->symbol);
128
-        if (keysym == NoSymbol) {
129
-            ELOG("Could not translate string to key symbol: \"%s\"\n",
130
-                 bind->symbol);
131
-            continue;
132
-        }
133
-
134
-        /* Base column we use for looking up key symbols. We always consider
135
-         * the base column and the corresponding shift column, so without
136
-         * mode_switch, we look in 0 and 1, with mode_switch we look in 2 and
137
-         * 3. */
138
-        col = (bind->mods & BIND_MODE_SWITCH ? 2 : 0);
139
-
140
-        FREE(bind->translated_to);
141
-        bind->number_keycodes = 0;
142
-
143
-        for (i = min_keycode; i && i <= max_keycode; i++) {
144
-            if ((xcb_key_symbols_get_keysym(keysyms, i, col) != keysym) &&
145
-                (xcb_key_symbols_get_keysym(keysyms, i, col+1) != keysym))
146
-                continue;
147
-            bind->number_keycodes++;
148
-            bind->translated_to = srealloc(bind->translated_to,
149
-                                           (sizeof(xcb_keycode_t) *
150
-                                            bind->number_keycodes));
151
-            bind->translated_to[bind->number_keycodes-1] = i;
152
-        }
153
-
154
-        DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol,
155
-             bind->number_keycodes);
156
-    }
157
-}
158
-
159
-/*
160
  * Switches the key bindings to the given mode, if the mode exists
161
  *
162
  */