Move switch_mode to bindings.[ch]
Patch status: merged
Patch by Tony Crisci
To apply this patch, use:
curl http://cr.i3wm.org/patch/504/raw.patch | git am
b/include/bindings.h
16 |
@@ -42,3 +42,9 @@ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_
|
17 |
*
|
18 |
*/
|
19 |
void translate_keysyms(void);
|
20 |
+
|
21 |
+/**
|
22 |
+ * Switches the key bindings to the given mode, if the mode exists
|
23 |
+ *
|
24 |
+ */
|
25 |
+void switch_mode(const char *new_mode);
|
b/include/config.h
30 |
@@ -316,12 +316,6 @@ void load_configuration(xcb_connection_t *conn, const char *override_configfile,
|
31 |
void ungrab_all_keys(xcb_connection_t *conn);
|
32 |
|
33 |
/**
|
34 |
- * Switches the key bindings to the given mode, if the mode exists
|
35 |
- *
|
36 |
- */
|
37 |
-void switch_mode(const char *new_mode);
|
38 |
-
|
39 |
-/**
|
40 |
* Sends the current bar configuration as an event to all barconfig_update listeners.
|
41 |
* This update mechnism currently only includes the hidden_state and the mode in the config.
|
42 |
*
|
b/src/bindings.c
47 |
@@ -229,3 +229,33 @@ void translate_keysyms(void) {
|
48 |
bind->number_keycodes);
|
49 |
}
|
50 |
}
|
51 |
+
|
52 |
+/*
|
53 |
+ * Switches the key bindings to the given mode, if the mode exists
|
54 |
+ *
|
55 |
+ */
|
56 |
+void switch_mode(const char *new_mode) {
|
57 |
+ struct Mode *mode;
|
58 |
+
|
59 |
+ DLOG("Switching to mode %s\n", new_mode);
|
60 |
+
|
61 |
+ SLIST_FOREACH(mode, &modes, modes) {
|
62 |
+ if (strcasecmp(mode->name, new_mode) != 0)
|
63 |
+ continue;
|
64 |
+
|
65 |
+ ungrab_all_keys(conn);
|
66 |
+ bindings = mode->bindings;
|
67 |
+ translate_keysyms();
|
68 |
+ grab_all_keys(conn, false);
|
69 |
+
|
70 |
+ char *event_msg;
|
71 |
+ sasprintf(&event_msg, "{\"change\":\"%s\"}", mode->name);
|
72 |
+
|
73 |
+ ipc_send_event("mode", I3_IPC_EVENT_MODE, event_msg);
|
74 |
+ FREE(event_msg);
|
75 |
+
|
76 |
+ return;
|
77 |
+ }
|
78 |
+
|
79 |
+ ELOG("ERROR: Mode not found\n");
|
80 |
+}
|
b/src/config.c
85 |
@@ -31,36 +31,6 @@ void ungrab_all_keys(xcb_connection_t *conn) {
|
86 |
}
|
87 |
|
88 |
/*
|
89 |
- * Switches the key bindings to the given mode, if the mode exists
|
90 |
- *
|
91 |
- */
|
92 |
-void switch_mode(const char *new_mode) {
|
93 |
- struct Mode *mode;
|
94 |
-
|
95 |
- LOG("Switching to mode %s\n", new_mode);
|
96 |
-
|
97 |
- SLIST_FOREACH(mode, &modes, modes) {
|
98 |
- if (strcasecmp(mode->name, new_mode) != 0)
|
99 |
- continue;
|
100 |
-
|
101 |
- ungrab_all_keys(conn);
|
102 |
- bindings = mode->bindings;
|
103 |
- translate_keysyms();
|
104 |
- grab_all_keys(conn, false);
|
105 |
-
|
106 |
- char *event_msg;
|
107 |
- sasprintf(&event_msg, "{\"change\":\"%s\"}", mode->name);
|
108 |
-
|
109 |
- ipc_send_event("mode", I3_IPC_EVENT_MODE, event_msg);
|
110 |
- FREE(event_msg);
|
111 |
-
|
112 |
- return;
|
113 |
- }
|
114 |
-
|
115 |
- ELOG("ERROR: Mode not found\n");
|
116 |
-}
|
117 |
-
|
118 |
-/*
|
119 |
* Sends the current bar configuration as an event to all barconfig_update listeners.
|
120 |
* This update mechnism currently only includes the hidden_state and the mode in the config.
|
121 |
*
|