aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorKonstantin Pospelov <kupospelov@gmail.com>2019-02-19 16:35:35 +0300
committerSimon Ser <contact@emersion.fr>2019-04-26 20:56:48 +0300
commitf1609abe4c20a04b0b57f797b0e864b29840eda8 (patch)
treebe675820914ecad26516e7deb49d7bea9dc79d89 /sway
parenta09c144b8b5f9d0518e7239a27e2fb86e00644b3 (diff)
config: simplify keysym translation fields
Do not store `xkb_keymap` since it can be retrieved from `xkb_state`.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/bind.c5
-rw-r--r--sway/config.c26
2 files changed, 14 insertions, 17 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index e5fd4433..ea8179bb 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -604,7 +604,7 @@ struct keycode_matches {
static void find_keycode(struct xkb_keymap *keymap,
xkb_keycode_t keycode, void *data) {
xkb_keysym_t keysym = xkb_state_key_get_one_sym(
- config->keysym_translation.xkb_state, keycode);
+ config->keysym_translation_state, keycode);
if (keysym == XKB_KEY_NoSymbol) {
return;
@@ -627,7 +627,8 @@ static struct keycode_matches get_keycode_for_keysym(xkb_keysym_t keysym) {
.count = 0,
};
- xkb_keymap_key_for_each(config->keysym_translation.xkb_keymap,
+ xkb_keymap_key_for_each(
+ xkb_state_get_keymap(config->keysym_translation_state),
find_keycode, &matches);
return matches;
}
diff --git a/sway/config.c b/sway/config.c
index 45d16758..c5d892f3 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -33,7 +33,7 @@
struct sway_config *config = NULL;
-static struct keysym_translation_data new_keysym_translation_data(
+static struct xkb_state *keysym_translation_state_create(
const char *layout) {
struct xkb_rule_names rules = {
.layout = layout,
@@ -44,18 +44,13 @@ static struct keysym_translation_data new_keysym_translation_data(
&rules,
XKB_KEYMAP_COMPILE_NO_FLAGS);
- struct keysym_translation_data result = {
- .xkb_keymap = xkb_keymap,
- .xkb_state = xkb_state_new(xkb_keymap),
- };
-
- return result;
+ return xkb_state_new(xkb_keymap);
}
-static void free_keysym_translation_data(
- struct keysym_translation_data config) {
- xkb_state_unref(config.xkb_state);
- xkb_keymap_unref(config.xkb_keymap);
+static void keysym_translation_state_destroy(
+ struct xkb_state *state) {
+ xkb_keymap_unref(xkb_state_get_keymap(state));
+ xkb_state_unref(state);
}
static void free_mode(struct sway_mode *mode) {
@@ -171,7 +166,7 @@ void free_config(struct sway_config *config) {
free(config->swaynag_command);
free((char *)config->current_config_path);
free((char *)config->current_config);
- free_keysym_translation_data(config->keysym_translation);
+ keysym_translation_state_destroy(config->keysym_translation_state);
free(config);
}
@@ -344,7 +339,8 @@ static void config_defaults(struct sway_config *config) {
if (!(config->ipc_policies = create_list())) goto cleanup;
// The keysym to keycode translation
- config->keysym_translation = new_keysym_translation_data(getenv("XKB_DEFAULT_LAYOUT"));
+ config->keysym_translation_state =
+ keysym_translation_state_create(getenv("XKB_DEFAULT_LAYOUT"));
return;
cleanup:
@@ -992,8 +988,8 @@ static void translate_binding_list(list_t *bindings, list_t *bindsyms,
}
void translate_keysyms(const char *layout) {
- free_keysym_translation_data(config->keysym_translation);
- config->keysym_translation = new_keysym_translation_data(layout);
+ keysym_translation_state_destroy(config->keysym_translation_state);
+ config->keysym_translation_state = keysym_translation_state_create(layout);
for (int i = 0; i < config->modes->length; ++i) {
struct sway_mode *mode = config->modes->items[i];