From dffacea831b6e7277920e885984d9c7c9b281d6c Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Wed, 6 Jan 2016 16:59:54 +0100 Subject: [PATCH] Add function for getting list of modifier names. Get an array of modifier names from modifier masks. --- common/util.c | 14 ++++++++++++++ include/util.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/common/util.c b/common/util.c index b5037d35..243f90a8 100644 --- a/common/util.c +++ b/common/util.c @@ -51,3 +51,17 @@ const char *get_modifier_name_by_mask(uint32_t modifier) { 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; +} diff --git a/include/util.h b/include/util.h index 4bbb64c8..dc47e343 100644 --- a/include/util.h +++ b/include/util.h @@ -29,4 +29,11 @@ uint32_t get_modifier_mask_by_name(const char *name); */ 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); + #endif