Skip to content

Commit

Permalink
Option to hide cursor on keyboard key press. (#85)
Browse files Browse the repository at this point in the history
* Option to hide cursor on keyboard key press.

* Added missing initialisation.

* Made suggested changes.

---------

Co-authored-by: Penguin-Guru <[email protected]>
  • Loading branch information
Penguin-Guru and Penguin-Guru authored Nov 25, 2024
1 parent 5260108 commit 0eb7a8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct Config {
bool ignore_matches;
match_t *matches;
bool start_hidden;
bool hide_on_kbd;
} Config;

typedef struct coordinates_t {
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_] [*--no-timeout*] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--ignore-buttons* _buttons_] [*--hide-on-touch*] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*] [*--start-hidden*]
unclutter [*--timeout* _seconds_] [*--no-timeout*] [*--jitter* _radius_] [*--exclude-root*] [*--ignore-scrolling*] [*--ignore-buttons* _buttons_] [*--hide-on-touch*] [*--hide-on-key-press*] [*--fork*|*-b*] [*--help*|*-h*] [*--version*|*-v*] [*--start-hidden*]

Compatibility arguments:

Expand Down Expand Up @@ -53,6 +53,9 @@ pass multiple button numbers by separating them with ','.
*--hide-on-touch*::
Hides the mouse cursor on touch events.

*--hide-on-key-press*::
Hides the mouse cursor on (keyboard) key press events.

*--start-hidden*::
Starts the cursor hidden.

Expand Down
9 changes: 8 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ static void x_check_cb(EV_P_ ev_check *w, int revents) {
last_cursor_pos.y = root_y;
}

if (config.hide_on_touch && (cookie->evtype == XI_RawTouchBegin || cookie->evtype == XI_RawTouchUpdate)) {
bool should_hide = false;
should_hide |= config.hide_on_touch && (cookie->evtype == XI_RawTouchBegin || cookie->evtype == XI_RawTouchUpdate);
should_hide |= config.hide_on_kbd && cookie->evtype == XI_RawKeyPress;

if (should_hide) {
cursor_hide();
} else {
/* We don't bother checking the exact event since we only select events that interest us. */
Expand Down Expand Up @@ -193,6 +197,9 @@ static void event_select_xi(void) {
XISetMask(mask, XI_RawTouchBegin);
XISetMask(mask, XI_RawTouchUpdate);
}
if (config.hide_on_kbd) {
XISetMask(mask, XI_RawKeyPress);
}

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 @@ -39,6 +39,7 @@ Config config = {
.ignore_buttons.count = 0,
.ignore_buttons.buttons = NULL,
.hide_on_touch = false,
.hide_on_kbd = false,
.fork = false,
.debug = false,
.onescreen = false,
Expand Down Expand Up @@ -102,6 +103,7 @@ static void parse_args(int argc, char *argv[]) {
{ "ignore-scrolling", no_argument, 0, 0 },
{ "ignore-buttons", required_argument, 0, 0 },
{ "hide-on-touch", no_argument, 0, 0 },
{ "hide-on-key-press", no_argument, 0, 0},
{ "fork", no_argument, 0, 'b' },
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
Expand Down Expand Up @@ -147,6 +149,9 @@ static void parse_args(int argc, char *argv[]) {
} else if (OPT_NAME_IS("hide-on-touch")) {
config.hide_on_touch = true;
break;
} else if (OPT_NAME_IS("hide-on-key-press")) {
config.hide_on_kbd = true;
break;
} else if (OPT_NAME_IS("root")) {
config.exclude_root = false;
break;
Expand Down Expand Up @@ -208,7 +213,7 @@ static void parse_args(int argc, char *argv[]) {
}

static void print_usage(char *argv[]) {
fprintf(stderr, "Usage: %s [--timeout <n>] [--no-timeout] [--jitter <radius>] [--exclude-root] [--ignore-scrolling] [--ignore-buttons <buttons>] [--hide-on-touch] [-b|--fork] [-v|--version] [-h|--help] [--start-hidden]", argv[0]);
fprintf(stderr, "Usage: %s [--timeout <n>] [--no-timeout] [--jitter <radius>] [--exclude-root] [--ignore-scrolling] [--ignore-buttons <buttons>] [--hide-on-touch] [-b|--fork] [-v|--version] [-h|--help] [--start-hidden] [--hide-on-key-press]", argv[0]);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 0eb7a8f

Please sign in to comment.