diff options
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index cb142a5e..5ea94f48 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -71,6 +71,40 @@ float parse_float(const char *value) { | |||
71 | return flt; | 71 | return flt; |
72 | } | 72 | } |
73 | 73 | ||
74 | enum movement_unit parse_movement_unit(const char *unit) { | ||
75 | if (strcasecmp(unit, "px") == 0) { | ||
76 | return MOVEMENT_UNIT_PX; | ||
77 | } | ||
78 | if (strcasecmp(unit, "ppt") == 0) { | ||
79 | return MOVEMENT_UNIT_PPT; | ||
80 | } | ||
81 | if (strcasecmp(unit, "default") == 0) { | ||
82 | return MOVEMENT_UNIT_DEFAULT; | ||
83 | } | ||
84 | return MOVEMENT_UNIT_INVALID; | ||
85 | } | ||
86 | |||
87 | int parse_movement_amount(int argc, char **argv, | ||
88 | struct movement_amount *amount) { | ||
89 | char *err; | ||
90 | amount->amount = (int)strtol(argv[0], &err, 10); | ||
91 | if (*err) { | ||
92 | // e.g. 10px | ||
93 | amount->unit = parse_movement_unit(err); | ||
94 | return 1; | ||
95 | } | ||
96 | if (argc == 1) { | ||
97 | amount->unit = MOVEMENT_UNIT_DEFAULT; | ||
98 | return 1; | ||
99 | } | ||
100 | // Try the second argument | ||
101 | amount->unit = parse_movement_unit(argv[1]); | ||
102 | if (amount->unit == MOVEMENT_UNIT_INVALID) { | ||
103 | amount->unit = MOVEMENT_UNIT_DEFAULT; | ||
104 | return 1; | ||
105 | } | ||
106 | return 2; | ||
107 | } | ||
74 | 108 | ||
75 | const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel) { | 109 | const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel) { |
76 | switch (subpixel) { | 110 | switch (subpixel) { |