i3 - improved tiling WM


Move check_for_duplicate_bindings to bindings.[ch]

Patch status: merged

Patch by Tony Crisci

Long description:

Additionally add a check for the same input_type (mouse or keyboard).
Bindings with different input types cannot be duplicates.

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

b/include/bindings.h

17
@@ -48,3 +48,12 @@ void translate_keysyms(void);
18
  *
19
  */
20
 void switch_mode(const char *new_mode);
21
+
22
+/**
23
+ * Checks for duplicate key bindings (the same keycode or keysym is configured
24
+ * more than once). If a duplicate binding is found, a message is printed to
25
+ * stderr and the has_errors variable is set to true, which will start
26
+ * i3-nagbar.
27
+ *
28
+ */
29
+void check_for_duplicate_bindings(struct context *context);

b/src/bindings.c

34
@@ -259,3 +259,56 @@ void switch_mode(const char *new_mode) {
35
 
36
     ELOG("ERROR: Mode not found\n");
37
 }
38
+
39
+/*
40
+ * Checks for duplicate key bindings (the same keycode or keysym is configured
41
+ * more than once). If a duplicate binding is found, a message is printed to
42
+ * stderr and the has_errors variable is set to true, which will start
43
+ * i3-nagbar.
44
+ *
45
+ */
46
+void check_for_duplicate_bindings(struct context *context) {
47
+    Binding *bind, *current;
48
+    TAILQ_FOREACH(current, bindings, bindings) {
49
+        TAILQ_FOREACH(bind, bindings, bindings) {
50
+            /* Abort when we reach the current keybinding, only check the
51
+             * bindings before */
52
+            if (bind == current)
53
+                break;
54
+
55
+            /* Check if the input types are different */
56
+            if (bind->input_type != current->input_type)
57
+                continue;
58
+
59
+            /* Check if one is using keysym while the other is using bindsym.
60
+             * If so, skip. */
61
+            /* XXX: It should be checked at a later place (when translating the
62
+             * keysym to keycodes) if there are any duplicates */
63
+            if ((bind->symbol == NULL && current->symbol != NULL) ||
64
+                (bind->symbol != NULL && current->symbol == NULL))
65
+                continue;
66
+
67
+            /* If bind is NULL, current has to be NULL, too (see above).
68
+             * If the keycodes differ, it can't be a duplicate. */
69
+            if (bind->symbol != NULL &&
70
+                strcasecmp(bind->symbol, current->symbol) != 0)
71
+                continue;
72
+
73
+            /* Check if the keycodes or modifiers are different. If so, they
74
+             * can't be duplicate */
75
+            if (bind->keycode != current->keycode ||
76
+                bind->mods != current->mods ||
77
+                bind->release != current->release)
78
+                continue;
79
+
80
+            context->has_errors = true;
81
+            if (current->keycode != 0) {
82
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keycode %d, command \"%s\"\n",
83
+                     current->mods, current->keycode, current->command);
84
+            } else {
85
+                ELOG("Duplicate keybinding in config file:\n  modmask %d with keysym %s, command \"%s\"\n",
86
+                     current->mods, current->symbol, current->command);
87
+            }
88
+        }
89
+    }
90
+}

b/src/config_parser.c

95
@@ -844,55 +844,6 @@ static char *migrate_config(char *input, off_t size) {
96
 }
97
 
98
 /*
99
- * Checks for duplicate key bindings (the same keycode or keysym is configured
100
- * more than once). If a duplicate binding is found, a message is printed to
101
- * stderr and the has_errors variable is set to true, which will start
102
- * i3-nagbar.
103
- *
104
- */
105
-static void check_for_duplicate_bindings(struct context *context) {
106
-    Binding *bind, *current;
107
-    TAILQ_FOREACH(current, bindings, bindings) {
108
-        TAILQ_FOREACH(bind, bindings, bindings) {
109
-            /* Abort when we reach the current keybinding, only check the
110
-             * bindings before */
111
-            if (bind == current)
112
-                break;
113
-
114
-            /* Check if one is using keysym while the other is using bindsym.
115
-             * If so, skip. */
116
-            /* XXX: It should be checked at a later place (when translating the
117
-             * keysym to keycodes) if there are any duplicates */
118
-            if ((bind->symbol == NULL && current->symbol != NULL) ||
119
-                (bind->symbol != NULL && current->symbol == NULL))
120
-                continue;
121
-
122
-            /* If bind is NULL, current has to be NULL, too (see above).
123
-             * If the keycodes differ, it can't be a duplicate. */
124
-            if (bind->symbol != NULL &&
125
-                strcasecmp(bind->symbol, current->symbol) != 0)
126
-                continue;
127
-
128
-            /* Check if the keycodes or modifiers are different. If so, they
129
-             * can't be duplicate */
130
-            if (bind->keycode != current->keycode ||
131
-                bind->mods != current->mods ||
132
-                bind->release != current->release)
133
-                continue;
134
-
135
-            context->has_errors = true;
136
-            if (current->keycode != 0) {
137
-                ELOG("Duplicate keybinding in config file:\n  modmask %d with keycode %d, command \"%s\"\n",
138
-                     current->mods, current->keycode, current->command);
139
-            } else {
140
-                ELOG("Duplicate keybinding in config file:\n  modmask %d with keysym %s, command \"%s\"\n",
141
-                     current->mods, current->symbol, current->command);
142
-            }
143
-        }
144
-    }
145
-}
146
-
147
-/*
148
  * Parses the given file by first replacing the variables, then calling
149
  * parse_config and possibly launching i3-nagbar.
150
  *