From 4e5d23daa9b4d70bf8b614d5375ee1ccdab6771f Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 19:59:32 +0200 Subject: Per-keyboard configuration --- include/rootston/config.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'include/rootston/config.h') diff --git a/include/rootston/config.h b/include/rootston/config.h index 5fa4890f..792146fb 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -26,6 +26,17 @@ struct binding_config { struct wl_list link; }; +struct keyboard_config { + char *name; + uint32_t meta_key; + char *rules; + char *model; + char *layout; + char *variant; + char *options; + struct wl_list link; +}; + struct roots_config { bool xwayland; // TODO: Multiple cursors, multiseat @@ -34,13 +45,10 @@ struct roots_config { struct wlr_box *mapped_box; } cursor; - struct { - uint32_t meta_key; - } keyboard; - struct wl_list outputs; struct wl_list devices; struct wl_list bindings; + struct wl_list keyboards; char *config_path; char *startup_cmd; }; @@ -54,13 +62,20 @@ void roots_config_destroy(struct roots_config *config); * NULL. */ struct output_config *config_get_output(struct roots_config *config, - struct wlr_output *output); + struct wlr_output *output); /** * Get configuration for the device. If the device is not configured, returns * NULL. */ struct device_config *config_get_device(struct roots_config *config, - struct wlr_input_device *device); + struct wlr_input_device *device); + +/** + * Get configuration for the keyboard. If the keyboard is not configured, + * returns NULL. + */ +struct keyboard_config *config_get_keyboard(struct roots_config *config, + struct wlr_input_device *device); #endif -- cgit v1.2.3 From c0c4816b132649d1ffc5435720578286d83a19ef Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 22:38:03 +0200 Subject: Fix fallback when there are two config blocks for a keyboard --- include/rootston/config.h | 2 +- rootston/config.c | 8 +++--- rootston/cursor.c | 8 +++--- rootston/keyboard.c | 64 +++++++++++++++++++++++++++++------------------ 4 files changed, 49 insertions(+), 33 deletions(-) (limited to 'include/rootston/config.h') diff --git a/include/rootston/config.h b/include/rootston/config.h index 792146fb..ecbdd88b 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -73,7 +73,7 @@ struct device_config *config_get_device(struct roots_config *config, /** * Get configuration for the keyboard. If the keyboard is not configured, - * returns NULL. + * returns NULL. A NULL device returns the default config for keyboards. */ struct keyboard_config *config_get_keyboard(struct roots_config *config, struct wlr_input_device *device); diff --git a/rootston/config.c b/rootston/config.c index 863adc60..7a443151 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -417,14 +417,12 @@ struct device_config *config_get_device(struct roots_config *config, struct keyboard_config *config_get_keyboard(struct roots_config *config, struct wlr_input_device *device) { struct keyboard_config *kc; - struct keyboard_config *default_kc = NULL; wl_list_for_each(kc, &config->keyboards, link) { - if (strcmp(kc->name, "*") == 0) { - default_kc = kc; - } else if (strcmp(kc->name, device->name) == 0) { + if ((device != NULL && strcmp(kc->name, device->name) == 0) || + (device == NULL && strcmp(kc->name, "*") == 0)) { return kc; } } - return default_kc; + return NULL; } diff --git a/rootston/cursor.c b/rootston/cursor.c index 0cbca9f8..7d2548eb 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -217,10 +217,12 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { static bool is_meta_pressed(struct roots_input *input, struct wlr_input_device *device) { - struct keyboard_config *config = config_get_keyboard(input->server->config, - device); uint32_t meta_key = 0; - if (config != NULL) { + struct keyboard_config *config; + if ((config = config_get_keyboard(input->server->config, device))) { + meta_key = config->meta_key; + } else if (!meta_key && (config = config_get_keyboard(input->server->config, + NULL))) { meta_key = config->meta_key; } if (meta_key == 0) { diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 008fba2d..142e9c71 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -125,6 +125,28 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { } } +static void keyboard_config_merge(struct keyboard_config *config, + struct keyboard_config *fallback) { + if (fallback == NULL) { + return; + } + if (config->rules == NULL) { + config->rules = fallback->rules; + } + if (config->model == NULL) { + config->model = fallback->model; + } + if (config->layout == NULL) { + config->layout = fallback->layout; + } + if (config->variant == NULL) { + config->variant = fallback->variant; + } + if (config->options == NULL) { + config->options = fallback->options; + } +} + void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1); if (keyboard == NULL) { @@ -137,33 +159,27 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_list_insert(&input->keyboards, &keyboard->link); - struct keyboard_config *config = config_get_keyboard(input->config, - device); + struct keyboard_config config; + memset(&config, 0, sizeof(config)); + keyboard_config_merge(&config, config_get_keyboard(input->config, device)); + keyboard_config_merge(&config, config_get_keyboard(input->config, NULL)); + + struct keyboard_config env_config = { + .rules = getenv("XKB_DEFAULT_RULES"), + .model = getenv("XKB_DEFAULT_MODEL"), + .layout = getenv("XKB_DEFAULT_LAYOUT"), + .variant = getenv("XKB_DEFAULT_VARIANT"), + .options = getenv("XKB_DEFAULT_OPTIONS"), + }; + keyboard_config_merge(&config, &env_config); struct xkb_rule_names rules; memset(&rules, 0, sizeof(rules)); - if (config != NULL) { - rules.rules = config->rules; - rules.model = config->model; - rules.layout = config->layout; - rules.variant = config->variant; - rules.options = config->options; - } - if (rules.rules == NULL) { - rules.rules = getenv("XKB_DEFAULT_RULES"); - } - if (rules.model == NULL) { - rules.model = getenv("XKB_DEFAULT_MODEL"); - } - if (rules.layout == NULL) { - rules.layout = getenv("XKB_DEFAULT_LAYOUT"); - } - if (rules.variant == NULL) { - rules.variant = getenv("XKB_DEFAULT_VARIANT"); - } - if (rules.options == NULL) { - rules.options = getenv("XKB_DEFAULT_OPTIONS"); - } + rules.rules = config.rules; + rules.model = config.model; + rules.layout = config.layout; + rules.variant = config.variant; + rules.options = config.options; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (context == NULL) { wlr_log(L_ERROR, "Cannot create XKB context"); -- cgit v1.2.3