Skip to content

Commit

Permalink
Merge pull request #54 from marza91/decimal_timeout
Browse files Browse the repository at this point in the history
Changed timeout to support double values
  • Loading branch information
Airblader authored Oct 11, 2019
2 parents d965307 + 706d068 commit e9d1b24
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/externals.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include <err.h>
#include <ev.h>
#include <float.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
Expand Down
2 changes: 1 addition & 1 deletion include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
7 changes: 4 additions & 3 deletions src/unclutter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")) {
Expand Down
12 changes: 12 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e9d1b24

Please sign in to comment.