bindsym: consider xkb_rule_names for --to-code

This commit is contained in:
Konstantin Pospelov 2019-02-20 14:54:59 +03:00 committed by Simon Ser
parent d27a5e1cb0
commit ddf63ffabe
5 changed files with 40 additions and 31 deletions

View file

@ -577,6 +577,8 @@ void merge_input_config(struct input_config *dst, struct input_config *src);
struct input_config *store_input_config(struct input_config *ic); struct input_config *store_input_config(struct input_config *ic);
struct xkb_rule_names input_config_get_rule_names(struct input_config *ic);
void free_input_config(struct input_config *ic); void free_input_config(struct input_config *ic);
int seat_name_cmp(const void *item, const void *data); int seat_name_cmp(const void *item, const void *data);
@ -655,7 +657,7 @@ void config_update_font_height(bool recalculate);
*/ */
bool translate_binding(struct sway_binding *binding); bool translate_binding(struct sway_binding *binding);
void translate_keysyms(const char *layout); void translate_keysyms(struct input_config *input_config);
void binding_add_translated(struct sway_binding *binding, list_t *bindings); void binding_add_translated(struct sway_binding *binding, list_t *bindings);

View file

@ -48,7 +48,7 @@ static void retranslate_keysyms(struct input_config *input_config) {
if (ic->xkb_layout) { if (ic->xkb_layout) {
// this is the first config with xkb_layout // this is the first config with xkb_layout
if (ic->identifier == input_config->identifier) { if (ic->identifier == input_config->identifier) {
translate_keysyms(ic->xkb_layout); translate_keysyms(ic);
} }
return; return;

View file

@ -34,16 +34,14 @@
struct sway_config *config = NULL; struct sway_config *config = NULL;
static struct xkb_state *keysym_translation_state_create( static struct xkb_state *keysym_translation_state_create(
const char *layout) { struct xkb_rule_names rules) {
struct xkb_rule_names rules = { struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
.layout = layout,
};
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names( struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names(
xkb_context_new(XKB_CONTEXT_NO_FLAGS), context,
&rules, &rules,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_context_unref(context);
return xkb_state_new(xkb_keymap); return xkb_state_new(xkb_keymap);
} }
@ -339,8 +337,9 @@ static void config_defaults(struct sway_config *config) {
if (!(config->ipc_policies = create_list())) goto cleanup; if (!(config->ipc_policies = create_list())) goto cleanup;
// The keysym to keycode translation // The keysym to keycode translation
struct xkb_rule_names rules = {};
config->keysym_translation_state = config->keysym_translation_state =
keysym_translation_state_create(NULL); keysym_translation_state_create(rules);
return; return;
cleanup: cleanup:
@ -987,9 +986,12 @@ static void translate_binding_list(list_t *bindings, list_t *bindsyms,
} }
} }
void translate_keysyms(const char *layout) { void translate_keysyms(struct input_config *input_config) {
keysym_translation_state_destroy(config->keysym_translation_state); keysym_translation_state_destroy(config->keysym_translation_state);
config->keysym_translation_state = keysym_translation_state_create(layout);
struct xkb_rule_names rules = input_config_get_rule_names(input_config);
config->keysym_translation_state =
keysym_translation_state_create(rules);
for (int i = 0; i < config->modes->length; ++i) { for (int i = 0; i < config->modes->length; ++i) {
struct sway_mode *mode = config->modes->items[i]; struct sway_mode *mode = config->modes->items[i];
@ -1007,5 +1009,6 @@ void translate_keysyms(const char *layout) {
mode->keycode_bindings = bindcodes; mode->keycode_bindings = bindcodes;
} }
sway_log(SWAY_DEBUG, "Translated keysyms for layout %s", layout); sway_log(SWAY_DEBUG, "Translated keysyms using config for device '%s'",
input_config->identifier);
} }

View file

@ -212,6 +212,18 @@ struct input_config *store_input_config(struct input_config *ic) {
return ic; return ic;
} }
struct xkb_rule_names input_config_get_rule_names(struct input_config *ic) {
struct xkb_rule_names rules = {
.layout = ic->xkb_layout,
.model = ic->xkb_model,
.options = ic->xkb_options,
.rules = ic->xkb_rules,
.variant = ic->xkb_variant,
};
return rules;
}
void free_input_config(struct input_config *ic) { void free_input_config(struct input_config *ic) {
if (!ic) { if (!ic) {
return; return;

View file

@ -477,39 +477,31 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
} }
void sway_keyboard_configure(struct sway_keyboard *keyboard) { void sway_keyboard_configure(struct sway_keyboard *keyboard) {
struct xkb_rule_names rules;
memset(&rules, 0, sizeof(rules));
struct input_config *input_config = struct input_config *input_config =
input_device_get_config(keyboard->seat_device->input_device); input_device_get_config(keyboard->seat_device->input_device);
struct wlr_input_device *wlr_device = struct wlr_input_device *wlr_device =
keyboard->seat_device->input_device->wlr_device; keyboard->seat_device->input_device->wlr_device;
if (input_config && input_config->xkb_layout) { struct xkb_rule_names rules;
rules.layout = input_config->xkb_layout; if (input_config) {
rules = input_config_get_rule_names(input_config);
} else { } else {
memset(&rules, 0, sizeof(rules));
}
if (!rules.layout) {
rules.layout = getenv("XKB_DEFAULT_LAYOUT"); rules.layout = getenv("XKB_DEFAULT_LAYOUT");
} }
if (input_config && input_config->xkb_model) { if (!rules.model) {
rules.model = input_config->xkb_model;
} else {
rules.model = getenv("XKB_DEFAULT_MODEL"); rules.model = getenv("XKB_DEFAULT_MODEL");
} }
if (!rules.options) {
if (input_config && input_config->xkb_options) {
rules.options = input_config->xkb_options;
} else {
rules.options = getenv("XKB_DEFAULT_OPTIONS"); rules.options = getenv("XKB_DEFAULT_OPTIONS");
} }
if (!rules.rules) {
if (input_config && input_config->xkb_rules) {
rules.rules = input_config->xkb_rules;
} else {
rules.rules = getenv("XKB_DEFAULT_RULES"); rules.rules = getenv("XKB_DEFAULT_RULES");
} }
if (!rules.variant) {
if (input_config && input_config->xkb_variant) {
rules.variant = input_config->xkb_variant;
} else {
rules.variant = getenv("XKB_DEFAULT_VARIANT"); rules.variant = getenv("XKB_DEFAULT_VARIANT");
} }