136 lines
4.8 KiB
Diff
136 lines
4.8 KiB
Diff
|
From 00e76d7ab7be57c8f514a8aa9d2337e55cd67b47 Mon Sep 17 00:00:00 2001
|
||
|
From: Guido Cella <guido@guidocella.xyz>
|
||
|
Date: Sat, 12 Feb 2022 20:29:09 +0100
|
||
|
Subject: [PATCH] =?UTF-8?q?Hide=20the=20mouse=20cursor=20if=20it=20isn?=
|
||
|
=?UTF-8?q?=E2=80=99t=20being=20used?=
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: text/plain; charset=UTF-8
|
||
|
Content-Transfer-Encoding: 8bit
|
||
|
|
||
|
---
|
||
|
config.def.h | 2 ++
|
||
|
dwl.c | 41 +++++++++++++++++++++++++++++++++++++----
|
||
|
2 files changed, 39 insertions(+), 4 deletions(-)
|
||
|
|
||
|
diff --git a/config.def.h b/config.def.h
|
||
|
index 84086594..10b463e1 100644
|
||
|
--- a/config.def.h
|
||
|
+++ b/config.def.h
|
||
|
@@ -51,6 +51,8 @@ static const int repeat_delay = 600;
|
||
|
static const int tap_to_click = 1;
|
||
|
static const int natural_scrolling = 0;
|
||
|
|
||
|
+static const int cursor_timeout = 5;
|
||
|
+
|
||
|
#define MODKEY WLR_MODIFIER_ALT
|
||
|
#define TAGKEYS(KEY,SKEY,TAG) \
|
||
|
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||
|
diff --git a/dwl.c b/dwl.c
|
||
|
index 01f51ad9..e6a5382b 100644
|
||
|
--- a/dwl.c
|
||
|
+++ b/dwl.c
|
||
|
@@ -232,6 +232,8 @@ static void focusmon(const Arg *arg);
|
||
|
static void focusstack(const Arg *arg);
|
||
|
static void fullscreennotify(struct wl_listener *listener, void *data);
|
||
|
static Client *focustop(Monitor *m);
|
||
|
+static void handlecursoractivity();
|
||
|
+static int hidecursor(void *data);
|
||
|
static void incnmaster(const Arg *arg);
|
||
|
static void inputdevice(struct wl_listener *listener, void *data);
|
||
|
static int keybinding(uint32_t mods, xkb_keysym_t sym);
|
||
|
@@ -310,6 +312,8 @@ static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
|
||
|
|
||
|
static struct wlr_cursor *cursor;
|
||
|
static struct wlr_xcursor_manager *cursor_mgr;
|
||
|
+static struct wl_event_source *hide_source;
|
||
|
+static bool cursor_hidden = false;
|
||
|
|
||
|
static struct wlr_seat *seat;
|
||
|
static struct wl_list keyboards;
|
||
|
@@ -603,6 +607,7 @@ axisnotify(struct wl_listener *listener, void *data)
|
||
|
* for example when you move the scroll wheel. */
|
||
|
struct wlr_event_pointer_axis *event = data;
|
||
|
wlr_idle_notify_activity(idle, seat);
|
||
|
+ handlecursoractivity();
|
||
|
/* Notify the client with pointer focus of the axis event. */
|
||
|
wlr_seat_pointer_notify_axis(seat,
|
||
|
event->time_msec, event->orientation, event->delta,
|
||
|
@@ -619,6 +624,7 @@ buttonpress(struct wl_listener *listener, void *data)
|
||
|
const Button *b;
|
||
|
|
||
|
wlr_idle_notify_activity(idle, seat);
|
||
|
+ handlecursoractivity();
|
||
|
|
||
|
switch (event->state) {
|
||
|
case WLR_BUTTON_PRESSED:
|
||
|
@@ -1191,6 +1197,25 @@ focustop(Monitor *m)
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
+void
|
||
|
+handlecursoractivity()
|
||
|
+{
|
||
|
+ wl_event_source_timer_update(hide_source, cursor_timeout * 1000);
|
||
|
+ if (cursor_hidden) {
|
||
|
+ wlr_xcursor_manager_set_cursor_image(cursor_mgr, "left_ptr", cursor);
|
||
|
+ cursor_hidden = false;
|
||
|
+ }
|
||
|
+}
|
||
|
+
|
||
|
+int
|
||
|
+hidecursor(void *data)
|
||
|
+{
|
||
|
+ wlr_cursor_set_image(cursor, NULL, 0, 0, 0, 0, 0, 0);
|
||
|
+ wlr_seat_pointer_notify_clear_focus(seat);
|
||
|
+ cursor_hidden = true;
|
||
|
+ return 1;
|
||
|
+}
|
||
|
+
|
||
|
void
|
||
|
incnmaster(const Arg *arg)
|
||
|
{
|
||
|
@@ -1401,6 +1426,7 @@ motionnotify(uint32_t time)
|
||
|
/* time is 0 in internal calls meant to restore pointer focus. */
|
||
|
if (time) {
|
||
|
wlr_idle_notify_activity(idle, seat);
|
||
|
+ handlecursoractivity();
|
||
|
|
||
|
/* Update selmon (even while dragging a window) */
|
||
|
if (sloppyfocus)
|
||
|
@@ -1558,10 +1584,13 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
|
||
|
time = now.tv_sec * 1000 + now.tv_nsec / 1000000;
|
||
|
}
|
||
|
|
||
|
- /* Let the client know that the mouse cursor has entered one
|
||
|
- * of its surfaces, and make keyboard focus follow if desired.
|
||
|
- * wlroots makes this a no-op if surface is already focused */
|
||
|
- wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
||
|
+ if (!cursor_hidden)
|
||
|
+ wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
||
|
+ // wlr_seat_pointer_notify_enter seems to always show the cursor when
|
||
|
+ // calling this to restore pointer focus while mapping and unmapping layer
|
||
|
+ // surfaces. Not sure how sway makes it work, but you're unlikely to care
|
||
|
+ // about which surface has pointer focus in this case as you don't know
|
||
|
+ // where you're clicking until you show the cursor again.
|
||
|
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
||
|
|
||
|
}
|
||
|
@@ -1711,6 +1740,7 @@ run(char *startup_cmd)
|
||
|
* monitor when displayed here */
|
||
|
wlr_cursor_warp_closest(cursor, NULL, cursor->x, cursor->y);
|
||
|
wlr_xcursor_manager_set_cursor_image(cursor_mgr, "left_ptr", cursor);
|
||
|
+ handlecursoractivity();
|
||
|
|
||
|
/* Run the Wayland event loop. This does not return until you exit the
|
||
|
* compositor. Starting the backend rigged up all of the necessary event
|
||
|
@@ -1959,6 +1989,9 @@ setup(void)
|
||
|
wl_signal_add(&cursor->events.axis, &cursor_axis);
|
||
|
wl_signal_add(&cursor->events.frame, &cursor_frame);
|
||
|
|
||
|
+ hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy),
|
||
|
+ hidecursor, cursor);
|
||
|
+
|
||
|
/*
|
||
|
* Configures a seat, which is a single "seat" at which a user sits and
|
||
|
* operates the computer. This conceptually includes up to one keyboard,
|