Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed timeout to support double values #54

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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