diff options
-rw-r--r-- | common/util.c | 14 | ||||
-rw-r--r-- | include/util.h | 7 |
2 files changed, 21 insertions, 0 deletions
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) { | |||
51 | 51 | ||
52 | return NULL; | 52 | return NULL; |
53 | } | 53 | } |
54 | |||
55 | int get_modifier_names(const char **names, uint32_t modifier_masks) { | ||
56 | int length = 0; | ||
57 | int i; | ||
58 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
59 | if ((modifier_masks & modifiers[i].mod) != 0) { | ||
60 | names[length] = modifiers[i].name; | ||
61 | ++length; | ||
62 | modifier_masks ^= modifiers[i].mod; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return length; | ||
67 | } | ||
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); | |||
29 | */ | 29 | */ |
30 | const char *get_modifier_name_by_mask(uint32_t modifier); | 30 | const char *get_modifier_name_by_mask(uint32_t modifier); |
31 | 31 | ||
32 | /** | ||
33 | * Get an array of modifier names from modifier_masks | ||
34 | * | ||
35 | * Populates the names array and return the number of names added. | ||
36 | */ | ||
37 | int get_modifier_names(const char **names, uint32_t modifier_masks); | ||
38 | |||
32 | #endif | 39 | #endif |