diff --git a/common/util.c b/common/util.c index 839811608..b52e7448d 100644 --- a/common/util.c +++ b/common/util.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "log.h" #include "readline.h" #include "util.h" @@ -25,58 +24,6 @@ int numlen(int n) { return log10(n) + 1; } -static struct modifier_key { - char *name; - uint32_t mod; -} modifiers[] = { - { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, - { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, - { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, - { "Ctrl", WLR_MODIFIER_CTRL }, - { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, - { "Alt", WLR_MODIFIER_ALT }, - { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, - { "Mod3", WLR_MODIFIER_MOD3 }, - { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, - { "Mod5", WLR_MODIFIER_MOD5 }, -}; - -uint32_t get_modifier_mask_by_name(const char *name) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (strcasecmp(modifiers[i].name, name) == 0) { - return modifiers[i].mod; - } - } - - return 0; -} - -const char *get_modifier_name_by_mask(uint32_t modifier) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (modifiers[i].mod == modifier) { - return modifiers[i].name; - } - } - - return NULL; -} - -int get_modifier_names(const char **names, uint32_t modifier_masks) { - int length = 0; - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if ((modifier_masks & modifiers[i].mod) != 0) { - names[length] = modifiers[i].name; - ++length; - modifier_masks ^= modifiers[i].mod; - } - } - - return length; -} - pid_t get_parent_pid(pid_t child) { pid_t parent = -1; char file_name[100]; diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h index 8ec3eb356..6f9ace863 100644 --- a/include/sway/input/keyboard.h +++ b/include/sway/input/keyboard.h @@ -5,6 +5,28 @@ #define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32 +/** + * Get modifier mask from modifier name. + * + * Returns the modifer mask or 0 if the name isn't found. + */ +uint32_t get_modifier_mask_by_name(const char *name); + +/** + * Get modifier name from modifier mask. + * + * Returns the modifier name or NULL if it isn't found. + */ +const char *get_modifier_name_by_mask(uint32_t modifier); + +/** + * Get an array of modifier names from modifier_masks + * + * Populates the names array and return the number of names added. + */ +int get_modifier_names(const char **names, uint32_t modifier_masks); + + struct sway_keyboard { struct sway_seat_device *seat_device; diff --git a/include/util.h b/include/util.h index f68deae84..02519c93a 100644 --- a/include/util.h +++ b/include/util.h @@ -16,27 +16,6 @@ int wrap(int i, int max); */ int numlen(int n); -/** - * Get modifier mask from modifier name. - * - * Returns the modifer mask or 0 if the name isn't found. - */ -uint32_t get_modifier_mask_by_name(const char *name); - -/** - * Get modifier name from modifier mask. - * - * Returns the modifier name or NULL if it isn't found. - */ -const char *get_modifier_name_by_mask(uint32_t modifier); - -/** - * Get an array of modifier names from modifier_masks - * - * Populates the names array and return the number of names added. - */ -int get_modifier_names(const char **names, uint32_t modifier_masks); - /** * Get the pid of a parent process given the pid of a child process. * diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c index 43907007a..5e2316df5 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c @@ -2,7 +2,7 @@ #include "sway/commands.h" #include "log.h" #include "stringop.h" -#include "util.h" +#include "sway/input/keyboard.h" struct cmd_results *bar_cmd_modifier(int argc, char **argv) { struct cmd_results *error = NULL; diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 791214041..d3ce731cf 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -11,7 +11,7 @@ #include "list.h" #include "log.h" #include "stringop.h" -#include "util.h" +#include "sway/input/keyboard.h" int binding_order = 0; diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 8bf5abff6..e1a516dc0 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -9,6 +10,58 @@ #include "sway/commands.h" #include "log.h" +static struct modifier_key { + char *name; + uint32_t mod; +} modifiers[] = { + { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, + { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, + { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, + { "Ctrl", WLR_MODIFIER_CTRL }, + { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, + { "Alt", WLR_MODIFIER_ALT }, + { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, + { "Mod3", WLR_MODIFIER_MOD3 }, + { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, + { "Mod5", WLR_MODIFIER_MOD5 }, +}; + +uint32_t get_modifier_mask_by_name(const char *name) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (strcasecmp(modifiers[i].name, name) == 0) { + return modifiers[i].mod; + } + } + + return 0; +} + +const char *get_modifier_name_by_mask(uint32_t modifier) { + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if (modifiers[i].mod == modifier) { + return modifiers[i].name; + } + } + + return NULL; +} + +int get_modifier_names(const char **names, uint32_t modifier_masks) { + int length = 0; + int i; + for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { + if ((modifier_masks & modifiers[i].mod) != 0) { + names[length] = modifiers[i].name; + ++length; + modifier_masks ^= modifiers[i].mod; + } + } + + return length; +} + static bool keysym_is_modifier(xkb_keysym_t keysym) { switch (keysym) { case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: