diff options
author | Ingo Bürk <admin@airblader.de> | 2019-04-07 13:09:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-07 13:09:28 +0200 |
commit | 1c410949e2d488d26e41cf0e534272e15fbcd9dc (patch) | |
tree | 717b3cfed364e6403cb4086541275698724ef9d2 | |
parent | 04e2a940a3c7714dbc690e9ed974e4b68dc614d3 (diff) | |
parent | 45ae983255058ed9e32763d819ec1857ca5806ac (diff) |
Merge pull request #41 from chelovechishko/ignore_butt
add --ignore-buttons option
-rw-r--r-- | include/types.h | 6 | ||||
-rw-r--r-- | include/util.h | 2 | ||||
-rw-r--r-- | man/unclutter-xfixes.man | 8 | ||||
-rw-r--r-- | src/event.c | 18 | ||||
-rw-r--r-- | src/unclutter.c | 8 | ||||
-rw-r--r-- | src/util.c | 29 |
6 files changed, 66 insertions, 5 deletions
diff --git a/include/types.h b/include/types.h index d10818b..86fe36b 100644 --- a/include/types.h +++ b/include/types.h @@ -6,11 +6,17 @@ typedef struct match_t { int len; } match_t; +typedef struct ignore_buttons_t { + unsigned char count; + unsigned int *buttons; +} ignore_buttons_t; + typedef struct Config { long timeout; long jitter; bool exclude_root; bool ignore_scrolling; + ignore_buttons_t ignore_buttons; bool fork; bool debug; bool onescreen; diff --git a/include/util.h b/include/util.h index 35431ee..195afa1 100644 --- a/include/util.h +++ b/include/util.h @@ -27,3 +27,5 @@ void bail(char *message); long int parse_int(char *str); + +void parse_buttons_numbers(char *str, ignore_buttons_t *ignore_buttons); diff --git a/man/unclutter-xfixes.man b/man/unclutter-xfixes.man index 4028797..ed8e95c 100644 --- a/man/unclutter-xfixes.man +++ b/man/unclutter-xfixes.man @@ -8,7 +8,7 @@ unclutter-xfixes - rewrite of unclutter using the X11-Xfixes extension == SYNOPSIS -unclutter [*--timeout* _seconds_] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*] +unclutter [*--timeout* _seconds_] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--ignore-buttons* _buttons_] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*] Compatibility arguments: @@ -30,7 +30,11 @@ rather just the desktop background. *--ignore-scrolling*:: Ignore mouse scroll events (buttons 4 and 5) so that scrolling doesn't unhide -the cursor. +the cursor. This is a shortcut for *--ignore-buttons* '4,5'. + +*--ignore-buttons*:: +Defines the mouse buttons which do not unhide the cursor when clicked. You can +pass multiple button numbers by separating them with ','. *--fork*|*-b*:: Fork unclutter to the background. diff --git a/src/event.c b/src/event.c index c31cecd..f79887e 100644 --- a/src/event.c +++ b/src/event.c @@ -46,6 +46,20 @@ static void x_cb(EV_P_ ev_io *w, int revents) { /* Deliberately empty. */ } +static bool is_button_ignored(const XIRawEvent *data) { + if (config.ignore_scrolling && (data->detail == 4 || data->detail == 5)) { + return true; + } + + for (int i = 0; i < config.ignore_buttons.count; ++i) { + if (data->detail == config.ignore_buttons.buttons[i]) { + return true; + } + } + + return false; +} + static void x_check_cb(EV_P_ ev_check *w, int revents) { XEvent ev; while (XPending(display) > 0) { @@ -57,9 +71,9 @@ static void x_check_cb(EV_P_ ev_check *w, int revents) { continue; } - if (config.ignore_scrolling && cookie->evtype == XI_RawButtonPress) { + if (cookie->evtype == XI_RawButtonPress) { const XIRawEvent *data = (const XIRawEvent *) cookie->data; - if (data->detail == 4 || data->detail == 5) { + if (is_button_ignored(data)) { XFreeEventData(display, cookie); continue; } diff --git a/src/unclutter.c b/src/unclutter.c index 1d7a021..ddc999d 100644 --- a/src/unclutter.c +++ b/src/unclutter.c @@ -36,6 +36,8 @@ Config config = { .jitter = 0, .exclude_root = false, .ignore_scrolling = false, + .ignore_buttons.count = 0, + .ignore_buttons.buttons = NULL, .fork = false, .debug = false, .onescreen = false, @@ -93,6 +95,7 @@ static void parse_args(int argc, char *argv[]) { { "jitter", required_argument, 0, 0 }, { "exclude-root", no_argument, 0, 0 }, { "ignore-scrolling", no_argument, 0, 0 }, + { "ignore-buttons", required_argument, 0, 0 }, { "fork", no_argument, 0, 'b' }, { "version", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' }, @@ -142,6 +145,9 @@ static void parse_args(int argc, char *argv[]) { } else if (OPT_NAME_IS("ignore-scrolling")) { config.ignore_scrolling = true; break; + } else if (OPT_NAME_IS("ignore-buttons")) { + parse_buttons_numbers(optarg, &config.ignore_buttons); + break; } else if (OPT_NAME_IS("debug")) { config.debug = true; break; @@ -185,7 +191,7 @@ static void parse_args(int argc, char *argv[]) { } static void print_usage(char *argv[]) { - fprintf(stderr, "Usage: %s [--timeout <n>] [--jitter <radius>] [--exclude-root] [--ignore-scrolling] [-b|--fork] [-v|--version] [-h|--help]", argv[0]); + fprintf(stderr, "Usage: %s [--timeout <n>] [--jitter <radius>] [--exclude-root] [--ignore-scrolling] [--ignore-buttons <buttons>] [-b|--fork] [-v|--version] [-h|--help]", argv[0]); fprintf(stderr, "\n"); exit(EXIT_FAILURE); } @@ -17,3 +17,32 @@ long parse_int(char *str) { return parsed; } + +void parse_buttons_numbers(char *str, ignore_buttons_t *ignore_buttons) { + char *button = strtok(str, ","); + while (button != NULL) { + long number = atol(button); + button = strtok(NULL, ","); + if (number < 0 || number > UINT_MAX) { + continue; + } + + ignore_buttons->count++; + if (ignore_buttons->count == UCHAR_MAX) { + bail("Too much buttons numbers"); + } + unsigned int *buttons = (unsigned int *)realloc(ignore_buttons->buttons, + ignore_buttons->count * sizeof(unsigned int)); + if (buttons == NULL) { + free(ignore_buttons->buttons); + bail("Cannot reallocate memory for ignore-buttons"); + } else { + ignore_buttons->buttons = buttons; + } + ignore_buttons->buttons[ignore_buttons->count - 1] = number; + } + + if (!ignore_buttons->count) { + bail("Amount of buttons to ignore = 0"); + } +} |