Skip to content

Commit

Permalink
Merge pull request #52 from nowrep/hide-on-touch
Browse files Browse the repository at this point in the history
Add touch option to hide cursor on any touch input
  • Loading branch information
Airblader authored Sep 24, 2019
2 parents b450d78 + 13d6742 commit d965307
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct Config {
bool exclude_root;
bool ignore_scrolling;
ignore_buttons_t ignore_buttons;
bool hide_on_touch;
bool fork;
bool debug;
bool onescreen;
Expand Down
5 changes: 4 additions & 1 deletion man/unclutter-xfixes.man
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ unclutter-xfixes - rewrite of unclutter using the X11-Xfixes extension

== SYNOPSIS

unclutter [*--timeout* _seconds_] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--ignore-buttons* _buttons_] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*]
unclutter [*--timeout* _seconds_] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--ignore-buttons* _buttons_] [*--hide-on-touch*] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*]

Compatibility arguments:

Expand Down Expand Up @@ -36,6 +36,9 @@ the cursor. This is a shortcut for *--ignore-buttons* '4,5'.
Defines the mouse buttons which do not unhide the cursor when clicked. You can
pass multiple button numbers by separating them with ','.

*--hide-on-touch*::
Hides the mouse cursor on touch events.

*--fork*|*-b*::
Fork unclutter to the background.

Expand Down
12 changes: 10 additions & 2 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ static void x_check_cb(EV_P_ ev_check *w, int revents) {
last_cursor_pos.y = root_y;
}

/* We don't bother checking the exact event since we only select events that interest us. */
cursor_show();
if (config.hide_on_touch && (cookie->evtype == XI_RawTouchBegin || cookie->evtype == XI_RawTouchUpdate)) {
cursor_hide();
} else {
/* We don't bother checking the exact event since we only select events that interest us. */
cursor_show();
}
ev_timer_again(loop, idle_watcher);
}
}
Expand Down Expand Up @@ -178,6 +182,10 @@ static void event_select_xi(void) {
XISetMask(mask, XI_RawMotion);
XISetMask(mask, XI_RawButtonPress);
XISetMask(mask, XI_RawTouchUpdate);
if (config.hide_on_touch) {
XISetMask(mask, XI_RawTouchBegin);
XISetMask(mask, XI_RawTouchUpdate);
}

masks[0].deviceid = XIAllMasterDevices;
masks[0].mask_len = sizeof(mask);
Expand Down
7 changes: 6 additions & 1 deletion src/unclutter.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Config config = {
.ignore_scrolling = false,
.ignore_buttons.count = 0,
.ignore_buttons.buttons = NULL,
.hide_on_touch = false,
.fork = false,
.debug = false,
.onescreen = false,
Expand Down Expand Up @@ -96,6 +97,7 @@ static void parse_args(int argc, char *argv[]) {
{ "exclude-root", no_argument, 0, 0 },
{ "ignore-scrolling", no_argument, 0, 0 },
{ "ignore-buttons", required_argument, 0, 0 },
{ "hide-on-touch", no_argument, 0, 0 },
{ "fork", no_argument, 0, 'b' },
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
Expand Down Expand Up @@ -133,6 +135,9 @@ static void parse_args(int argc, char *argv[]) {
} else if (OPT_NAME_IS("exclude-root")) {
config.exclude_root = true;
break;
} else if (OPT_NAME_IS("hide-on-touch")) {
config.hide_on_touch = true;
break;
} else if (OPT_NAME_IS("root")) {
config.exclude_root = false;
break;
Expand Down Expand Up @@ -191,7 +196,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] [--ignore-buttons <buttons>] [-b|--fork] [-v|--version] [-h|--help]", argv[0]);
fprintf(stderr, "Usage: %s [--timeout <n>] [--jitter <radius>] [--exclude-root] [--ignore-scrolling] [--ignore-buttons <buttons>] [--hide-on-touch] [-b|--fork] [-v|--version] [-h|--help]", argv[0]);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit d965307

Please sign in to comment.