Implement bindsym --to-code

* `bindsym --to-code` enables keysym to keycode translation.
* If there are no `xkb_layout` commands in the config file, the translation
uses the XKB_DEFAULT_LAYOUT value.
* It there is one or more `xkb_layout` command, the translation uses
the first one.
* If the translation is unsuccessful, a message is logged and the binding
is stored as BINDING_KEYSYM.
* The binding keysyms are stored and re-translated when a change in the input
configuration may affect the translated bindings.
This commit is contained in:
Konstantin Pospelov 2019-02-17 19:08:22 +03:00 committed by Simon Ser
parent bd32b300fb
commit a09c144b8b
4 changed files with 274 additions and 26 deletions

View file

@ -24,7 +24,6 @@ struct sway_variable {
char *value;
};
enum binding_input_type {
BINDING_KEYCODE,
BINDING_KEYSYM,
@ -39,6 +38,7 @@ enum binding_flags {
BINDING_BORDER=4, // mouse only; trigger on container border
BINDING_CONTENTS=8, // mouse only; trigger on container contents
BINDING_TITLEBAR=16, // mouse only; trigger on container titlebar
BINDING_CODE=32, // keyboard only; convert keysyms into keycodes
};
/**
@ -50,6 +50,7 @@ struct sway_binding {
char *input;
uint32_t flags;
list_t *keys; // sorted in ascending order
list_t *syms; // sorted in ascending order; NULL if BINDING_CODE is not set
uint32_t modifiers;
char *command;
};
@ -406,6 +407,14 @@ enum alignment {
ALIGN_RIGHT
};
/**
* The keysym to keycode translation.
*/
struct keysym_translation_data {
struct xkb_keymap *xkb_keymap;
struct xkb_state *xkb_state;
};
/**
* The configuration struct. The result of loading a config file.
*/
@ -508,6 +517,9 @@ struct sway_config {
list_t *feature_policies;
list_t *ipc_policies;
// The keysym to keycode translation
struct keysym_translation_data keysym_translation;
// Context for command handlers
struct {
struct input_config *input_config;
@ -617,12 +629,6 @@ bool spawn_swaybg(void);
int workspace_output_cmp_workspace(const void *a, const void *b);
int sway_binding_cmp(const void *a, const void *b);
int sway_binding_cmp_qsort(const void *a, const void *b);
int sway_binding_cmp_keys(const void *a, const void *b);
void free_sway_binding(struct sway_binding *sb);
void free_switch_binding(struct sway_switch_binding *binding);
@ -651,6 +657,16 @@ void free_workspace_config(struct workspace_config *wsc);
*/
void config_update_font_height(bool recalculate);
/**
* Convert bindsym into bindcode using the first configured layout.
* Return false in case the conversion is unsuccessful.
*/
bool translate_binding(struct sway_binding *binding);
void translate_keysyms(const char *layout);
void binding_add_translated(struct sway_binding *binding, list_t *bindings);
/* Global config singleton. */
extern struct sway_config *config;