diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c index 89dd0936..6e2a79f6 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <xkbcommon/xkbcommon.h> | 1 | #include <xkbcommon/xkbcommon.h> |
2 | #include <xkbcommon/xkbcommon-names.h> | 2 | #include <xkbcommon/xkbcommon-names.h> |
3 | #include <wlc/wlc.h> | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
4 | #include <stdlib.h> | 5 | #include <stdlib.h> |
5 | #include <string.h> | 6 | #include <string.h> |
@@ -22,6 +23,32 @@ int cmd_set(struct sway_config *config, int argc, char **argv) { | |||
22 | return 0; | 23 | return 0; |
23 | } | 24 | } |
24 | 25 | ||
26 | int cmd_exit(struct sway_config *config, int argc, char **argv) { | ||
27 | if (argc != 0) { | ||
28 | sway_log(L_ERROR, "Invalid exit command (expected 1 arguments, got %d)", argc); | ||
29 | return 1; | ||
30 | } | ||
31 | // TODO: Some kind of clean up is probably in order | ||
32 | exit(0); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | struct modifier_key { | ||
37 | char *name; | ||
38 | uint32_t mod; | ||
39 | }; | ||
40 | |||
41 | struct modifier_key modifiers[] = { | ||
42 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | ||
43 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | ||
44 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | ||
45 | { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, | ||
46 | { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, | ||
47 | { "Mod3", WLC_BIT_MOD_MOD3 }, | ||
48 | { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, | ||
49 | { "Mod5", WLC_BIT_MOD_MOD5 }, | ||
50 | }; | ||
51 | |||
25 | int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | 52 | int cmd_bindsym(struct sway_config *config, int argc, char **argv) { |
26 | if (argc < 2) { | 53 | if (argc < 2) { |
27 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | 54 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); |
@@ -37,12 +64,22 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
37 | list_t *split = split_string(argv[0], "+"); | 64 | list_t *split = split_string(argv[0], "+"); |
38 | int i; | 65 | int i; |
39 | for (i = 0; i < split->length; ++i) { | 66 | for (i = 0; i < split->length; ++i) { |
40 | // TODO: Parse modifier keys | 67 | // Check for a modifier key |
68 | int j; | ||
69 | bool is_mod = false; | ||
70 | for (j = 0; j < sizeof(modifiers) / sizeof(struct modifier_key); ++j) { | ||
71 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | ||
72 | binding->modifiers |= modifiers[j].mod; | ||
73 | is_mod = true; | ||
74 | break; | ||
75 | } | ||
76 | } | ||
77 | if (is_mod) continue; | ||
78 | // Check for xkb key | ||
41 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | 79 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); |
42 | if (!sym) { | 80 | if (!sym) { |
43 | sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]); | 81 | sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]); |
44 | // Ignore for now, we need to deal with modifier keys | 82 | return 1; |
45 | // return 1; | ||
46 | } | 83 | } |
47 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | 84 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); |
48 | *key = sym; | 85 | *key = sym; |
@@ -60,7 +97,8 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
60 | /* Keep alphabetized */ | 97 | /* Keep alphabetized */ |
61 | struct cmd_handler handlers[] = { | 98 | struct cmd_handler handlers[] = { |
62 | { "bindsym", cmd_bindsym }, | 99 | { "bindsym", cmd_bindsym }, |
63 | { "set", cmd_set } | 100 | { "exit", cmd_exit }, |
101 | { "set", cmd_set }, | ||
64 | }; | 102 | }; |
65 | 103 | ||
66 | char **split_directive(char *line, int *argc) { | 104 | char **split_directive(char *line, int *argc) { |
@@ -128,10 +166,11 @@ struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *lin | |||
128 | } | 166 | } |
129 | 167 | ||
130 | int handle_command(struct sway_config *config, char *exec) { | 168 | int handle_command(struct sway_config *config, char *exec) { |
169 | sway_log(L_INFO, "Handling command '%s'", exec); | ||
131 | char *ptr, *cmd; | 170 | char *ptr, *cmd; |
132 | if ((ptr = strchr(exec, ' ')) == NULL) { | 171 | if ((ptr = strchr(exec, ' ')) == NULL) { |
133 | cmd = malloc(strlen(exec) + 1); | 172 | cmd = malloc(strlen(exec) + 1); |
134 | strcpy(exec, cmd); | 173 | strcpy(cmd, exec); |
135 | } else { | 174 | } else { |
136 | int index = ptr - exec; | 175 | int index = ptr - exec; |
137 | cmd = malloc(index + 1); | 176 | cmd = malloc(index + 1); |