From 706d068de30dffbf296c2d03e4f0a830ee7904b0 Mon Sep 17 00:00:00 2001 From: Martin Vaaden <1224973+marza91@users.noreply.github.com> Date: Thu, 9 Mar 2017 09:03:40 +0100 Subject: [PATCH] Changed timeout to support double values --- include/externals.h | 1 + include/types.h | 2 +- include/util.h | 2 ++ src/unclutter.c | 7 ++++--- src/util.c | 12 ++++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/externals.h b/include/externals.h index 9110ddc..8dbe2c8 100644 --- a/include/externals.h +++ b/include/externals.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/include/types.h b/include/types.h index 1cfc414..ccfc3c0 100644 --- a/include/types.h +++ b/include/types.h @@ -12,7 +12,7 @@ typedef struct ignore_buttons_t { } ignore_buttons_t; typedef struct Config { - long timeout; + double timeout; long jitter; bool exclude_root; bool ignore_scrolling; diff --git a/include/util.h b/include/util.h index 195afa1..9c33c49 100644 --- a/include/util.h +++ b/include/util.h @@ -28,4 +28,6 @@ void bail(char *message); long int parse_int(char *str); +double parse_double(char *str); + void parse_buttons_numbers(char *str, ignore_buttons_t *ignore_buttons); diff --git a/src/unclutter.c b/src/unclutter.c index b810633..8cac69f 100644 --- a/src/unclutter.c +++ b/src/unclutter.c @@ -107,6 +107,7 @@ static void parse_args(int argc, char *argv[]) { while ((c = getopt_long_only(argc, argv, "t:j:bvhd:", long_options, &opt_index)) != -1) { long value; + double value_double; const char *opt_name = long_options[opt_index].name; #define OPT_NAME_IS(name) (strcmp(opt_name, (name)) == 0) @@ -117,11 +118,11 @@ static void parse_args(int argc, char *argv[]) { setenv("DISPLAY", optarg, true); break; } else if (OPT_NAME_IS("timeout") || OPT_NAME_IS("idle")) { - value = parse_int(optarg); - if (value < 0) + value_double = parse_double(optarg); + if (value_double < 0) ELOG("Invalid timeout specified."); else - config.timeout = value; + config.timeout = value_double; break; } else if (OPT_NAME_IS("jitter")) { diff --git a/src/util.c b/src/util.c index b2dd392..1e61b69 100644 --- a/src/util.c +++ b/src/util.c @@ -18,6 +18,18 @@ long parse_int(char *str) { return parsed; } +double parse_double(char *str) { + char *endptr = NULL; + double parsed = strtod(str, &endptr); + if (parsed == -DBL_MAX || parsed == DBL_MAX || + parsed < 0 || endptr == str) { + + return -1; + } + + return parsed; +} + void parse_buttons_numbers(char *str, ignore_buttons_t *ignore_buttons) { char *button = strtok(str, ","); while (button != NULL) {