diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-15 05:22:51 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-15 05:22:51 -0500 |
commit | 9eecbb5d8a988a0dded57ead1982dd0121071454 (patch) | |
tree | 3b02befcc78d300a0fd84b5962b323d015369398 | |
parent | basic configuration (diff) | |
download | sway-9eecbb5d8a988a0dded57ead1982dd0121071454.tar.gz sway-9eecbb5d8a988a0dded57ead1982dd0121071454.tar.zst sway-9eecbb5d8a988a0dded57ead1982dd0121071454.zip |
xkb config
-rw-r--r-- | include/sway/commands.h | 5 | ||||
-rw-r--r-- | include/sway/config.h | 6 | ||||
-rw-r--r-- | sway/commands.c | 5 | ||||
-rw-r--r-- | sway/commands/input/xkb_layout.c | 24 | ||||
-rw-r--r-- | sway/commands/input/xkb_model.c | 24 | ||||
-rw-r--r-- | sway/commands/input/xkb_options.c | 24 | ||||
-rw-r--r-- | sway/commands/input/xkb_rules.c | 24 | ||||
-rw-r--r-- | sway/commands/input/xkb_variant.c | 24 | ||||
-rw-r--r-- | sway/config.c | 20 | ||||
-rw-r--r-- | sway/input/keyboard.c | 38 | ||||
-rw-r--r-- | sway/main.c | 1 | ||||
-rw-r--r-- | sway/meson.build | 5 |
12 files changed, 195 insertions, 5 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index ce74e1ed..61950d0d 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -195,6 +195,11 @@ sway_cmd input_cmd_natural_scroll; | |||
195 | sway_cmd input_cmd_pointer_accel; | 195 | sway_cmd input_cmd_pointer_accel; |
196 | sway_cmd input_cmd_scroll_method; | 196 | sway_cmd input_cmd_scroll_method; |
197 | sway_cmd input_cmd_tap; | 197 | sway_cmd input_cmd_tap; |
198 | sway_cmd input_cmd_xkb_layout; | ||
199 | sway_cmd input_cmd_xkb_model; | ||
200 | sway_cmd input_cmd_xkb_options; | ||
201 | sway_cmd input_cmd_xkb_rules; | ||
202 | sway_cmd input_cmd_xkb_variant; | ||
198 | 203 | ||
199 | sway_cmd seat_cmd_attach; | 204 | sway_cmd seat_cmd_attach; |
200 | 205 | ||
diff --git a/include/sway/config.h b/include/sway/config.h index 5df5d61e..9bfda259 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -67,6 +67,12 @@ struct input_config { | |||
67 | int send_events; | 67 | int send_events; |
68 | int tap; | 68 | int tap; |
69 | 69 | ||
70 | char *xkb_layout; | ||
71 | char *xkb_model; | ||
72 | char *xkb_options; | ||
73 | char *xkb_rules; | ||
74 | char *xkb_variant; | ||
75 | |||
70 | bool capturable; | 76 | bool capturable; |
71 | struct wlr_box region; | 77 | struct wlr_box region; |
72 | }; | 78 | }; |
diff --git a/sway/commands.c b/sway/commands.c index e003e06d..b8948fb7 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -154,6 +154,11 @@ static struct cmd_handler input_handlers[] = { | |||
154 | { "pointer_accel", input_cmd_pointer_accel }, | 154 | { "pointer_accel", input_cmd_pointer_accel }, |
155 | { "scroll_method", input_cmd_scroll_method }, | 155 | { "scroll_method", input_cmd_scroll_method }, |
156 | { "tap", input_cmd_tap }, | 156 | { "tap", input_cmd_tap }, |
157 | { "xkb_layout", input_cmd_xkb_layout }, | ||
158 | { "xkb_model", input_cmd_xkb_model }, | ||
159 | { "xkb_options", input_cmd_xkb_options }, | ||
160 | { "xkb_rules", input_cmd_xkb_rules }, | ||
161 | { "xkb_variant", input_cmd_xkb_variant }, | ||
157 | }; | 162 | }; |
158 | 163 | ||
159 | // must be in order for the bsearch | 164 | // must be in order for the bsearch |
diff --git a/sway/commands/input/xkb_layout.c b/sway/commands/input/xkb_layout.c new file mode 100644 index 00000000..9a9ce044 --- /dev/null +++ b/sway/commands/input/xkb_layout.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/input/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) { | ||
7 | sway_log(L_DEBUG, "xkb layout for device: %s", current_input_config->identifier); | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xkb_layout", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (!current_input_config) { | ||
13 | return cmd_results_new(CMD_FAILURE, "xkb_layout", "No input device defined."); | ||
14 | } | ||
15 | struct input_config *new_config = | ||
16 | new_input_config(current_input_config->identifier); | ||
17 | |||
18 | new_config->xkb_layout = strdup(argv[0]); | ||
19 | |||
20 | sway_log(L_DEBUG, "apply-xkb_layout for device: %s", | ||
21 | current_input_config->identifier); | ||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/xkb_model.c b/sway/commands/input/xkb_model.c new file mode 100644 index 00000000..14a50ffb --- /dev/null +++ b/sway/commands/input/xkb_model.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/input/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_xkb_model(int argc, char **argv) { | ||
7 | sway_log(L_DEBUG, "xkb model for device: %s", current_input_config->identifier); | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xkb_model", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (!current_input_config) { | ||
13 | return cmd_results_new(CMD_FAILURE, "xkb_model", "No input device defined."); | ||
14 | } | ||
15 | struct input_config *new_config = | ||
16 | new_input_config(current_input_config->identifier); | ||
17 | |||
18 | new_config->xkb_model = strdup(argv[0]); | ||
19 | |||
20 | sway_log(L_DEBUG, "apply-xkb_model for device: %s", | ||
21 | current_input_config->identifier); | ||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/xkb_options.c b/sway/commands/input/xkb_options.c new file mode 100644 index 00000000..67eb5342 --- /dev/null +++ b/sway/commands/input/xkb_options.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/input/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_xkb_options(int argc, char **argv) { | ||
7 | sway_log(L_DEBUG, "xkb options for device: %s", current_input_config->identifier); | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xkb_options", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (!current_input_config) { | ||
13 | return cmd_results_new(CMD_FAILURE, "xkb_options", "No input device defined."); | ||
14 | } | ||
15 | struct input_config *new_config = | ||
16 | new_input_config(current_input_config->identifier); | ||
17 | |||
18 | new_config->xkb_options = strdup(argv[0]); | ||
19 | |||
20 | sway_log(L_DEBUG, "apply-xkb_options for device: %s", | ||
21 | current_input_config->identifier); | ||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/xkb_rules.c b/sway/commands/input/xkb_rules.c new file mode 100644 index 00000000..3eda0bdd --- /dev/null +++ b/sway/commands/input/xkb_rules.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/input/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) { | ||
7 | sway_log(L_DEBUG, "xkb rules for device: %s", current_input_config->identifier); | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xkb_rules", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (!current_input_config) { | ||
13 | return cmd_results_new(CMD_FAILURE, "xkb_rules", "No input device defined."); | ||
14 | } | ||
15 | struct input_config *new_config = | ||
16 | new_input_config(current_input_config->identifier); | ||
17 | |||
18 | new_config->xkb_rules = strdup(argv[0]); | ||
19 | |||
20 | sway_log(L_DEBUG, "apply-xkb_rules for device: %s", | ||
21 | current_input_config->identifier); | ||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/xkb_variant.c b/sway/commands/input/xkb_variant.c new file mode 100644 index 00000000..c7f93ad4 --- /dev/null +++ b/sway/commands/input/xkb_variant.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/input/input-manager.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) { | ||
7 | sway_log(L_DEBUG, "xkb variant for device: %s", current_input_config->identifier); | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "xkb_variant", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (!current_input_config) { | ||
13 | return cmd_results_new(CMD_FAILURE, "xkb_variant", "No input device defined."); | ||
14 | } | ||
15 | struct input_config *new_config = | ||
16 | new_input_config(current_input_config->identifier); | ||
17 | |||
18 | new_config->xkb_variant = strdup(argv[0]); | ||
19 | |||
20 | sway_log(L_DEBUG, "apply-xkb_variant for device: %s", | ||
21 | current_input_config->identifier); | ||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/config.c b/sway/config.c index 52633ad8..4e34aa8c 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -292,6 +292,26 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { | |||
292 | if (src->tap != INT_MIN) { | 292 | if (src->tap != INT_MIN) { |
293 | dst->tap = src->tap; | 293 | dst->tap = src->tap; |
294 | } | 294 | } |
295 | if (src->xkb_layout) { | ||
296 | free(dst->xkb_layout); | ||
297 | dst->xkb_layout = strdup(src->xkb_layout); | ||
298 | } | ||
299 | if (src->xkb_model) { | ||
300 | free(dst->xkb_model); | ||
301 | dst->xkb_model = strdup(src->xkb_model); | ||
302 | } | ||
303 | if (src->xkb_options) { | ||
304 | free(dst->xkb_options); | ||
305 | dst->xkb_options = strdup(src->xkb_options); | ||
306 | } | ||
307 | if (src->xkb_rules) { | ||
308 | free(dst->xkb_rules); | ||
309 | dst->xkb_rules = strdup(src->xkb_rules); | ||
310 | } | ||
311 | if (src->xkb_variant) { | ||
312 | free(dst->xkb_variant); | ||
313 | dst->xkb_variant = strdup(src->xkb_variant); | ||
314 | } | ||
295 | } | 315 | } |
296 | 316 | ||
297 | void free_input_config(struct input_config *ic) { | 317 | void free_input_config(struct input_config *ic) { |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 53db3270..2ab0206a 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "sway/input/seat.h" | 1 | #include "sway/input/seat.h" |
2 | #include "sway/input/keyboard.h" | 2 | #include "sway/input/keyboard.h" |
3 | #include "sway/input/input-manager.h" | ||
3 | #include "log.h" | 4 | #include "log.h" |
4 | 5 | ||
5 | static void handle_keyboard_key(struct wl_listener *listener, void *data) { | 6 | static void handle_keyboard_key(struct wl_listener *listener, void *data) { |
@@ -47,17 +48,44 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
47 | void sway_keyboard_configure(struct sway_keyboard *keyboard) { | 48 | void sway_keyboard_configure(struct sway_keyboard *keyboard) { |
48 | struct xkb_rule_names rules; | 49 | struct xkb_rule_names rules; |
49 | memset(&rules, 0, sizeof(rules)); | 50 | memset(&rules, 0, sizeof(rules)); |
50 | rules.rules = getenv("XKB_DEFAULT_RULES"); | 51 | struct input_config *input_config = |
51 | rules.model = getenv("XKB_DEFAULT_MODEL"); | 52 | keyboard->seat_device->input_device->config; |
52 | rules.layout = getenv("XKB_DEFAULT_LAYOUT"); | 53 | |
53 | rules.variant = getenv("XKB_DEFAULT_VARIANT"); | 54 | if (input_config && input_config->xkb_layout) { |
54 | rules.options = getenv("XKB_DEFAULT_OPTIONS"); | 55 | rules.layout = input_config->xkb_layout; |
56 | } else { | ||
57 | rules.layout = getenv("XKB_DEFAULT_LAYOUT"); | ||
58 | } | ||
59 | if (input_config && input_config->xkb_model) { | ||
60 | rules.model = input_config->xkb_model; | ||
61 | } else { | ||
62 | rules.model = getenv("XKB_DEFAULT_MODEL"); | ||
63 | } | ||
64 | |||
65 | if (input_config && input_config->xkb_options) { | ||
66 | rules.options = input_config->xkb_options; | ||
67 | } else { | ||
68 | rules.options = getenv("XKB_DEFAULT_OPTIONS"); | ||
69 | } | ||
70 | |||
71 | if (input_config && input_config->xkb_rules) { | ||
72 | rules.rules = input_config->xkb_rules; | ||
73 | } else { | ||
74 | rules.rules = getenv("XKB_DEFAULT_RULES"); | ||
75 | } | ||
76 | |||
77 | if (input_config && input_config->xkb_variant) { | ||
78 | rules.variant = input_config->xkb_variant; | ||
79 | } else { | ||
80 | rules.variant = getenv("XKB_DEFAULT_VARIANT"); | ||
81 | } | ||
55 | 82 | ||
56 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); | 83 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); |
57 | if (!sway_assert(context, "cannot create XKB context")) { | 84 | if (!sway_assert(context, "cannot create XKB context")) { |
58 | return; | 85 | return; |
59 | } | 86 | } |
60 | 87 | ||
88 | xkb_keymap_unref(keyboard->keymap); | ||
61 | keyboard->keymap = | 89 | keyboard->keymap = |
62 | xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); | 90 | xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); |
63 | wlr_keyboard_set_keymap(keyboard->seat_device->input_device->wlr_device->keyboard, keyboard->keymap); | 91 | wlr_keyboard_set_keymap(keyboard->seat_device->input_device->wlr_device->keyboard, keyboard->keymap); |
diff --git a/sway/main.c b/sway/main.c index 363f4d96..25032aa0 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -158,6 +158,7 @@ static void log_distro() { | |||
158 | } | 158 | } |
159 | 159 | ||
160 | static void log_kernel() { | 160 | static void log_kernel() { |
161 | return; | ||
161 | FILE *f = popen("uname -a", "r"); | 162 | FILE *f = popen("uname -a", "r"); |
162 | if (!f) { | 163 | if (!f) { |
163 | sway_log(L_INFO, "Unable to determine kernel version"); | 164 | sway_log(L_INFO, "Unable to determine kernel version"); |
diff --git a/sway/meson.build b/sway/meson.build index ad8160eb..c81e1c2c 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -24,6 +24,11 @@ sway_sources = files( | |||
24 | 'commands/input/pointer_accel.c', | 24 | 'commands/input/pointer_accel.c', |
25 | 'commands/input/scroll_method.c', | 25 | 'commands/input/scroll_method.c', |
26 | 'commands/input/tap.c', | 26 | 'commands/input/tap.c', |
27 | 'commands/input/xkb_layout.c', | ||
28 | 'commands/input/xkb_model.c', | ||
29 | 'commands/input/xkb_options.c', | ||
30 | 'commands/input/xkb_rules.c', | ||
31 | 'commands/input/xkb_variant.c', | ||
27 | 'config.c', | 32 | 'config.c', |
28 | 'ipc-json.c', | 33 | 'ipc-json.c', |
29 | 'ipc-server.c', | 34 | 'ipc-server.c', |