diff options
-rw-r--r-- | common/util.c | 38 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/input_state.h | 20 | ||||
-rw-r--r-- | include/ipc-server.h | 6 | ||||
-rw-r--r-- | include/ipc.h | 1 | ||||
-rw-r--r-- | include/util.h | 18 | ||||
-rw-r--r-- | sway/commands.c | 58 | ||||
-rw-r--r-- | sway/config.c | 33 | ||||
-rw-r--r-- | sway/handlers.c | 18 | ||||
-rw-r--r-- | sway/input_state.c | 24 | ||||
-rw-r--r-- | sway/ipc-server.c | 18 |
11 files changed, 197 insertions, 43 deletions
diff --git a/common/util.c b/common/util.c index ed6d033f..b5037d35 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -13,3 +13,41 @@ int numlen(int n) { | |||
13 | if (n >= 10) return 2; | 13 | if (n >= 10) return 2; |
14 | return 1; | 14 | return 1; |
15 | } | 15 | } |
16 | |||
17 | static struct modifier_key { | ||
18 | char *name; | ||
19 | uint32_t mod; | ||
20 | } modifiers[] = { | ||
21 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | ||
22 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | ||
23 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | ||
24 | { "Ctrl", WLC_BIT_MOD_CTRL }, | ||
25 | { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, | ||
26 | { "Alt", WLC_BIT_MOD_ALT }, | ||
27 | { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, | ||
28 | { "Mod3", WLC_BIT_MOD_MOD3 }, | ||
29 | { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, | ||
30 | { "Mod5", WLC_BIT_MOD_MOD5 }, | ||
31 | }; | ||
32 | |||
33 | uint32_t get_modifier_mask_by_name(const char *name) { | ||
34 | int i; | ||
35 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
36 | if (strcasecmp(modifiers[i].name, name) == 0) { | ||
37 | return modifiers[i].mod; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | const char *get_modifier_name_by_mask(uint32_t modifier) { | ||
45 | int i; | ||
46 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
47 | if (modifiers[i].mod == modifier) { | ||
48 | return modifiers[i].name; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | return NULL; | ||
53 | } | ||
diff --git a/include/config.h b/include/config.h index a915fbed..5e1c39f3 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -135,6 +135,7 @@ struct sway_config { | |||
135 | list_t *workspace_outputs; | 135 | list_t *workspace_outputs; |
136 | list_t *output_configs; | 136 | list_t *output_configs; |
137 | list_t *criteria; | 137 | list_t *criteria; |
138 | list_t *active_bar_modifiers; | ||
138 | struct sway_mode *current_mode; | 139 | struct sway_mode *current_mode; |
139 | struct bar_config *current_bar; | 140 | struct bar_config *current_bar; |
140 | uint32_t floating_mod; | 141 | uint32_t floating_mod; |
@@ -176,6 +177,11 @@ void merge_output_config(struct output_config *dst, struct output_config *src); | |||
176 | void apply_output_config(struct output_config *oc, swayc_t *output); | 177 | void apply_output_config(struct output_config *oc, swayc_t *output); |
177 | void free_output_config(struct output_config *oc); | 178 | void free_output_config(struct output_config *oc); |
178 | 179 | ||
180 | /** | ||
181 | * Updates the list of active bar modifiers | ||
182 | */ | ||
183 | void update_active_bar_modifiers(void); | ||
184 | |||
179 | int workspace_output_cmp_workspace(const void *a, const void *b); | 185 | int workspace_output_cmp_workspace(const void *a, const void *b); |
180 | 186 | ||
181 | int sway_binding_cmp(const void *a, const void *b); | 187 | int sway_binding_cmp(const void *a, const void *b); |
diff --git a/include/input_state.h b/include/input_state.h index a1f238e1..79e27d91 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -60,6 +60,12 @@ extern struct pointer_state { | |||
60 | int mode; | 60 | int mode; |
61 | } pointer_state; | 61 | } pointer_state; |
62 | 62 | ||
63 | enum modifier_state { | ||
64 | MOD_STATE_UNCHANGED = 0, | ||
65 | MOD_STATE_PRESSED = 1, | ||
66 | MOD_STATE_RELEASED = 2 | ||
67 | }; | ||
68 | |||
63 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); | 69 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); |
64 | void center_pointer_on(swayc_t *view); | 70 | void center_pointer_on(swayc_t *view); |
65 | 71 | ||
@@ -75,5 +81,19 @@ void pointer_mode_reset(void); | |||
75 | 81 | ||
76 | void input_init(void); | 82 | void input_init(void); |
77 | 83 | ||
84 | /** | ||
85 | * Check if state of mod changed from current state to new_state. | ||
86 | * | ||
87 | * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if | ||
88 | * the state changed to pressed and MOD_STATE_RELEASED if the state changed to | ||
89 | * released. | ||
90 | */ | ||
91 | uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod); | ||
92 | |||
93 | /** | ||
94 | * Update the current modifiers state to new_state. | ||
95 | */ | ||
96 | void modifiers_state_update(uint32_t new_state); | ||
97 | |||
78 | #endif | 98 | #endif |
79 | 99 | ||
diff --git a/include/ipc-server.h b/include/ipc-server.h index 04975093..47026bfd 100644 --- a/include/ipc-server.h +++ b/include/ipc-server.h | |||
@@ -15,6 +15,12 @@ void ipc_event_barconfig_update(struct bar_config *bar); | |||
15 | * Send IPC mode event to all listening clients | 15 | * Send IPC mode event to all listening clients |
16 | */ | 16 | */ |
17 | void ipc_event_mode(const char *mode); | 17 | void ipc_event_mode(const char *mode); |
18 | /** | ||
19 | * Sends an IPC modifier event to all listening clients. The modifier event | ||
20 | * includes a key 'change' with the value of state and a key 'modifier' with | ||
21 | * the name of that modifier. | ||
22 | */ | ||
23 | void ipc_event_modifier(uint32_t modifier, const char *state); | ||
18 | const char *swayc_type_string(enum swayc_types type); | 24 | const char *swayc_type_string(enum swayc_types type); |
19 | 25 | ||
20 | #endif | 26 | #endif |
diff --git a/include/ipc.h b/include/ipc.h index e0b3b736..56593529 100644 --- a/include/ipc.h +++ b/include/ipc.h | |||
@@ -17,6 +17,7 @@ enum ipc_command_type { | |||
17 | IPC_EVENT_WINDOW = (1 << 31 | 3), | 17 | IPC_EVENT_WINDOW = (1 << 31 | 3), |
18 | IPC_EVENT_BARCONFIG_UPDATE = (1 << 31 | 4), | 18 | IPC_EVENT_BARCONFIG_UPDATE = (1 << 31 | 4), |
19 | IPC_EVENT_BINDING = (1 << 31 | 5), | 19 | IPC_EVENT_BINDING = (1 << 31 | 5), |
20 | IPC_EVENT_MODIFIER = (1 << 31 | 6), | ||
20 | IPC_SWAY_GET_PIXELS = 0x81 | 21 | IPC_SWAY_GET_PIXELS = 0x81 |
21 | }; | 22 | }; |
22 | 23 | ||
diff --git a/include/util.h b/include/util.h index 9cb861dd..4bbb64c8 100644 --- a/include/util.h +++ b/include/util.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #ifndef _SWAY_UTIL_H | 1 | #ifndef _SWAY_UTIL_H |
2 | #define _SWAY_UTIL_H | 2 | #define _SWAY_UTIL_H |
3 | 3 | ||
4 | #include <stdint.h> | ||
5 | #include <wlc/wlc.h> | ||
6 | #include <xkbcommon/xkbcommon.h> | ||
7 | |||
4 | /** | 8 | /** |
5 | * Wrap i into the range [0, max[ | 9 | * Wrap i into the range [0, max[ |
6 | */ | 10 | */ |
@@ -11,4 +15,18 @@ int wrap(int i, int max); | |||
11 | */ | 15 | */ |
12 | int numlen(int n); | 16 | int numlen(int n); |
13 | 17 | ||
18 | /** | ||
19 | * Get modifier mask from modifier name. | ||
20 | * | ||
21 | * Returns the modifer mask or 0 if the name isn't found. | ||
22 | */ | ||
23 | uint32_t get_modifier_mask_by_name(const char *name); | ||
24 | |||
25 | /** | ||
26 | * Get modifier name from modifier mask. | ||
27 | * | ||
28 | * Returns the modifier name or NULL if it isn't found. | ||
29 | */ | ||
30 | const char *get_modifier_name_by_mask(uint32_t modifier); | ||
31 | |||
14 | #endif | 32 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index 9cc33b9c..4e5bc712 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -99,22 +99,6 @@ static sway_cmd bar_colors_cmd_urgent_workspace; | |||
99 | swayc_t *sp_view; | 99 | swayc_t *sp_view; |
100 | int sp_index = 0; | 100 | int sp_index = 0; |
101 | 101 | ||
102 | static struct modifier_key { | ||
103 | char *name; | ||
104 | uint32_t mod; | ||
105 | } modifiers[] = { | ||
106 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | ||
107 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | ||
108 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | ||
109 | { "Ctrl", WLC_BIT_MOD_CTRL }, | ||
110 | { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, | ||
111 | { "Alt", WLC_BIT_MOD_ALT }, | ||
112 | { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, | ||
113 | { "Mod3", WLC_BIT_MOD_MOD3 }, | ||
114 | { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, | ||
115 | { "Mod5", WLC_BIT_MOD_MOD5 }, | ||
116 | }; | ||
117 | |||
118 | static char *bg_options[] = { | 102 | static char *bg_options[] = { |
119 | "stretch", | 103 | "stretch", |
120 | "center", | 104 | "center", |
@@ -187,16 +171,11 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
187 | list_t *split = split_string(argv[0], "+"); | 171 | list_t *split = split_string(argv[0], "+"); |
188 | for (int i = 0; i < split->length; ++i) { | 172 | for (int i = 0; i < split->length; ++i) { |
189 | // Check for a modifier key | 173 | // Check for a modifier key |
190 | int j; | 174 | uint32_t mod; |
191 | bool is_mod = false; | 175 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { |
192 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 176 | binding->modifiers |= mod; |
193 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | 177 | continue; |
194 | binding->modifiers |= modifiers[j].mod; | ||
195 | is_mod = true; | ||
196 | break; | ||
197 | } | ||
198 | } | 178 | } |
199 | if (is_mod) continue; | ||
200 | // Check for xkb key | 179 | // Check for xkb key |
201 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | 180 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); |
202 | if (!sym) { | 181 | if (!sym) { |
@@ -408,17 +387,13 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) { | |||
408 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { | 387 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { |
409 | return error; | 388 | return error; |
410 | } | 389 | } |
411 | int i, j; | 390 | int i; |
412 | list_t *split = split_string(argv[0], "+"); | 391 | list_t *split = split_string(argv[0], "+"); |
413 | config->floating_mod = 0; | 392 | config->floating_mod = 0; |
414 | 393 | ||
415 | // set modifier keys | 394 | // set modifier keys |
416 | for (i = 0; i < split->length; ++i) { | 395 | for (i = 0; i < split->length; ++i) { |
417 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 396 | config->floating_mod |= get_modifier_mask_by_name(split->items[i]); |
418 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | ||
419 | config->floating_mod |= modifiers[j].mod; | ||
420 | } | ||
421 | } | ||
422 | } | 397 | } |
423 | free_flat_list(split); | 398 | free_flat_list(split); |
424 | if (!config->floating_mod) { | 399 | if (!config->floating_mod) { |
@@ -1776,6 +1751,9 @@ static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | |||
1776 | } | 1751 | } |
1777 | } | 1752 | } |
1778 | 1753 | ||
1754 | // active bar modifiers might have changed. | ||
1755 | update_active_bar_modifiers(); | ||
1756 | |||
1779 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1757 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
1780 | } | 1758 | } |
1781 | 1759 | ||
@@ -1800,6 +1778,9 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode | |||
1800 | if (strcmp(old_mode, bar->mode) != 0) { | 1778 | if (strcmp(old_mode, bar->mode) != 0) { |
1801 | if (!config->reading) { | 1779 | if (!config->reading) { |
1802 | ipc_event_barconfig_update(bar); | 1780 | ipc_event_barconfig_update(bar); |
1781 | |||
1782 | // active bar modifiers might have changed. | ||
1783 | update_active_bar_modifiers(); | ||
1803 | } | 1784 | } |
1804 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); | 1785 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); |
1805 | } | 1786 | } |
@@ -1893,16 +1874,11 @@ static struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | |||
1893 | 1874 | ||
1894 | list_t *split = split_string(argv[0], "+"); | 1875 | list_t *split = split_string(argv[0], "+"); |
1895 | for (int i = 0; i < split->length; ++i) { | 1876 | for (int i = 0; i < split->length; ++i) { |
1896 | int j; | 1877 | uint32_t tmp_mod; |
1897 | bool is_mod = false; | 1878 | if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { |
1898 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 1879 | mod |= tmp_mod; |
1899 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | 1880 | continue; |
1900 | mod |= modifiers[j].mod; | 1881 | } else { |
1901 | is_mod = true; | ||
1902 | break; | ||
1903 | } | ||
1904 | } | ||
1905 | if (!is_mod) { | ||
1906 | free_flat_list(split); | 1882 | free_flat_list(split); |
1907 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); | 1883 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); |
1908 | } | 1884 | } |
diff --git a/sway/config.c b/sway/config.c index 1973de02..95d8f339 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -103,6 +103,8 @@ static void free_config(struct sway_config *config) { | |||
103 | free_output_config(config->output_configs->items[i]); | 103 | free_output_config(config->output_configs->items[i]); |
104 | } | 104 | } |
105 | list_free(config->output_configs); | 105 | list_free(config->output_configs); |
106 | |||
107 | list_free(config->active_bar_modifiers); | ||
106 | free(config); | 108 | free(config); |
107 | } | 109 | } |
108 | 110 | ||
@@ -145,6 +147,33 @@ static void config_defaults(struct sway_config *config) { | |||
145 | config->edge_gaps = true; | 147 | config->edge_gaps = true; |
146 | config->gaps_inner = 0; | 148 | config->gaps_inner = 0; |
147 | config->gaps_outer = 0; | 149 | config->gaps_outer = 0; |
150 | |||
151 | config->active_bar_modifiers = create_list(); | ||
152 | } | ||
153 | |||
154 | static int compare_modifiers(const void *left, const void *right) { | ||
155 | uint32_t a = *(uint32_t *)left; | ||
156 | uint32_t b = *(uint32_t *)right; | ||
157 | |||
158 | return a - b; | ||
159 | } | ||
160 | |||
161 | void update_active_bar_modifiers() { | ||
162 | if (config->active_bar_modifiers->length > 0) { | ||
163 | list_free(config->active_bar_modifiers); | ||
164 | config->active_bar_modifiers = create_list(); | ||
165 | } | ||
166 | |||
167 | struct bar_config *bar; | ||
168 | int i; | ||
169 | for (i = 0; i < config->bars->length; ++i) { | ||
170 | bar = config->bars->items[i]; | ||
171 | if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) { | ||
172 | if (list_seq_find(config->active_bar_modifiers, compare_modifiers, &bar->modifier) < 0) { | ||
173 | list_add(config->active_bar_modifiers, &bar->modifier); | ||
174 | } | ||
175 | } | ||
176 | } | ||
148 | } | 177 | } |
149 | 178 | ||
150 | static char *get_config_path(void) { | 179 | static char *get_config_path(void) { |
@@ -215,6 +244,8 @@ bool load_config(const char *file) { | |||
215 | } | 244 | } |
216 | fclose(f); | 245 | fclose(f); |
217 | 246 | ||
247 | update_active_bar_modifiers(); | ||
248 | |||
218 | return config_load_success; | 249 | return config_load_success; |
219 | } | 250 | } |
220 | 251 | ||
@@ -695,7 +726,7 @@ struct bar_config *default_bar_config(void) { | |||
695 | bar = malloc(sizeof(struct bar_config)); | 726 | bar = malloc(sizeof(struct bar_config)); |
696 | bar->mode = strdup("dock"); | 727 | bar->mode = strdup("dock"); |
697 | bar->hidden_state = strdup("hide"); | 728 | bar->hidden_state = strdup("hide"); |
698 | bar->modifier = 0; | 729 | bar->modifier = WLC_BIT_MOD_LOGO; |
699 | bar->outputs = NULL; | 730 | bar->outputs = NULL; |
700 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | 731 | bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; |
701 | bar->bindings = create_list(); | 732 | bar->bindings = create_list(); |
diff --git a/sway/handlers.c b/sway/handlers.c index 3cc5cf3e..470f3c95 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "resize.h" | 20 | #include "resize.h" |
21 | #include "extensions.h" | 21 | #include "extensions.h" |
22 | #include "criteria.h" | 22 | #include "criteria.h" |
23 | #include "ipc-server.h" | ||
23 | 24 | ||
24 | // Event should be sent to client | 25 | // Event should be sent to client |
25 | #define EVENT_PASSTHROUGH false | 26 | #define EVENT_PASSTHROUGH false |
@@ -391,6 +392,23 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
391 | } | 392 | } |
392 | } | 393 | } |
393 | } | 394 | } |
395 | |||
396 | // handle bar modifiers pressed/released | ||
397 | uint32_t modifier; | ||
398 | for (i = 0; i < config->active_bar_modifiers->length; ++i) { | ||
399 | modifier = *(uint32_t *)config->active_bar_modifiers->items[i]; | ||
400 | |||
401 | switch (modifier_state_changed(modifiers->mods, modifier)) { | ||
402 | case MOD_STATE_PRESSED: | ||
403 | ipc_event_modifier(modifier, "pressed"); | ||
404 | break; | ||
405 | case MOD_STATE_RELEASED: | ||
406 | ipc_event_modifier(modifier, "released"); | ||
407 | break; | ||
408 | } | ||
409 | } | ||
410 | // update modifiers state | ||
411 | modifiers_state_update(modifiers->mods); | ||
394 | return EVENT_PASSTHROUGH; | 412 | return EVENT_PASSTHROUGH; |
395 | } | 413 | } |
396 | 414 | ||
diff --git a/sway/input_state.c b/sway/input_state.c index 58619d1f..2f40b6c2 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -22,12 +22,36 @@ struct key_state { | |||
22 | 22 | ||
23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; | 23 | static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; |
24 | 24 | ||
25 | static uint32_t modifiers_state; | ||
26 | |||
25 | void input_init(void) { | 27 | void input_init(void) { |
26 | int i; | 28 | int i; |
27 | for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { | 29 | for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { |
28 | struct key_state none = { 0, 0, 0 }; | 30 | struct key_state none = { 0, 0, 0 }; |
29 | key_state_array[i] = none; | 31 | key_state_array[i] = none; |
30 | } | 32 | } |
33 | |||
34 | modifiers_state = 0; | ||
35 | } | ||
36 | |||
37 | uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod) { | ||
38 | if ((new_state & mod) != 0) { // pressed | ||
39 | if ((modifiers_state & mod) != 0) { // already pressed | ||
40 | return MOD_STATE_UNCHANGED; | ||
41 | } else { // pressed | ||
42 | return MOD_STATE_PRESSED; | ||
43 | } | ||
44 | } else { // not pressed | ||
45 | if ((modifiers_state & mod) != 0) { // released | ||
46 | return MOD_STATE_RELEASED; | ||
47 | } else { // already released | ||
48 | return MOD_STATE_UNCHANGED; | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | void modifiers_state_update(uint32_t new_state) { | ||
54 | modifiers_state = new_state; | ||
31 | } | 55 | } |
32 | 56 | ||
33 | static uint8_t find_key(uint32_t key_sym, uint32_t key_code, bool update) { | 57 | static uint8_t find_key(uint32_t key_sym, uint32_t key_code, bool update) { |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index ed3977d5..f3a4647b 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "commands.h" | 19 | #include "commands.h" |
20 | #include "list.h" | 20 | #include "list.h" |
21 | #include "stringop.h" | 21 | #include "stringop.h" |
22 | #include "util.h" | ||
22 | 23 | ||
23 | static int ipc_socket = -1; | 24 | static int ipc_socket = -1; |
24 | static struct wlc_event_source *ipc_event_source = NULL; | 25 | static struct wlc_event_source *ipc_event_source = NULL; |
@@ -295,6 +296,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
295 | client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE; | 296 | client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE; |
296 | } else if (strcmp(event_type, "mode") == 0) { | 297 | } else if (strcmp(event_type, "mode") == 0) { |
297 | client->subscribed_events |= IPC_EVENT_MODE; | 298 | client->subscribed_events |= IPC_EVENT_MODE; |
299 | } else if (strcmp(event_type, "modifier") == 0) { | ||
300 | client->subscribed_events |= IPC_EVENT_MODIFIER; | ||
298 | } else { | 301 | } else { |
299 | ipc_send_reply(client, "{\"success\": false}", 18); | 302 | ipc_send_reply(client, "{\"success\": false}", 18); |
300 | ipc_client_disconnect(client); | 303 | ipc_client_disconnect(client); |
@@ -508,7 +511,7 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
508 | json_object_object_add(json, "tray_output", NULL); | 511 | json_object_object_add(json, "tray_output", NULL); |
509 | json_object_object_add(json, "mode", json_object_new_string(bar->mode)); | 512 | json_object_object_add(json, "mode", json_object_new_string(bar->mode)); |
510 | json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); | 513 | json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); |
511 | //json_object_object_add(json, "modifier", json_object_new_string(bar->modifier)); // TODO: Fix modifier | 514 | json_object_object_add(json, "modifier", json_object_new_string(get_modifier_name_by_mask(bar->modifier))); |
512 | switch (bar->position) { | 515 | switch (bar->position) { |
513 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | 516 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
514 | json_object_object_add(json, "position", json_object_new_string("top")); | 517 | json_object_object_add(json, "position", json_object_new_string("top")); |
@@ -617,3 +620,16 @@ void ipc_event_mode(const char *mode) { | |||
617 | 620 | ||
618 | json_object_put(obj); // free | 621 | json_object_put(obj); // free |
619 | } | 622 | } |
623 | |||
624 | void ipc_event_modifier(uint32_t modifier, const char *state) { | ||
625 | json_object *obj = json_object_new_object(); | ||
626 | json_object_object_add(obj, "change", json_object_new_string(state)); | ||
627 | |||
628 | const char *modifier_name = get_modifier_name_by_mask(modifier); | ||
629 | json_object_object_add(obj, "modifier", json_object_new_string(modifier_name)); | ||
630 | |||
631 | const char *json_string = json_object_to_json_string(obj); | ||
632 | ipc_send_event(json_string, IPC_EVENT_MODIFIER); | ||
633 | |||
634 | json_object_put(obj); // free | ||
635 | } | ||