diff options
author | Nils Schulte <git@nilsschulte.de> | 2020-07-16 10:23:24 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-07-21 10:07:01 +0200 |
commit | 6898d1963f7a7f6dcc0bff5d4c484818f38cdacf (patch) | |
tree | d8fd7ba5347f23e24cfa470727b2b6bd5b693342 /common | |
parent | 36c3c222d2418b30fea02c28ea21652ec90238c4 (diff) |
moved and renamed movement-unit parsing to common
Diffstat (limited to 'common')
-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) { return flt; } +enum movement_unit parse_movement_unit(const char *unit) { + if (strcasecmp(unit, "px") == 0) { + return MOVEMENT_UNIT_PX; + } + if (strcasecmp(unit, "ppt") == 0) { + return MOVEMENT_UNIT_PPT; + } + if (strcasecmp(unit, "default") == 0) { + return MOVEMENT_UNIT_DEFAULT; + } + return MOVEMENT_UNIT_INVALID; +} + +int parse_movement_amount(int argc, char **argv, + struct movement_amount *amount) { + char *err; + amount->amount = (int)strtol(argv[0], &err, 10); + if (*err) { + // e.g. 10px + amount->unit = parse_movement_unit(err); + return 1; + } + if (argc == 1) { + amount->unit = MOVEMENT_UNIT_DEFAULT; + return 1; + } + // Try the second argument + amount->unit = parse_movement_unit(argv[1]); + if (amount->unit == MOVEMENT_UNIT_INVALID) { + amount->unit = MOVEMENT_UNIT_DEFAULT; + return 1; + } + return 2; +} const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel) { switch (subpixel) { |