warpcursor patch

This commit is contained in:
Ben Collerson 2024-05-16 11:21:44 +10:00
parent 4021b0d41c
commit b014e0e41e
3 changed files with 93 additions and 8 deletions

View File

@ -1,8 +0,0 @@
### Description
When focus is changed, warp the cursor the the center of the new focused client (if it wasn't already within the client's geometry).
### Download
- [2022-05-26](https://github.com/djpohly/dwl/compare/main...faerryn:cursor_warp.patch)
### Authors
- [Faerryn](https://github.com/faerryn)

View File

@ -0,0 +1,15 @@
### Description
Warp cursor to the centre of newly focused clients.
Only moves the cursor if the cursor is currently not on the new client.
This is my version of the orphaned cursorwarp patch except I left out the
config flag as I think it is unnecessary.
### Download
- [git branch](https://codeberg.org/bencc/dwl/src/branch/warpcursor)
- [2024-05-16](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/warpcursor/warpcursor.patch)
### Authors
- [Faerryn](https://github.com/faerryn)
- [Ben Collerson](https://codeberg.org/bencc)

View File

@ -0,0 +1,78 @@
From 8fd10973586e774fb83cc540e3b7a033bec2ca73 Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Thu, 4 Jan 2024 20:30:01 +1000
Subject: [PATCH] warpcursor
---
dwl.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/dwl.c b/dwl.c
index bf763dfc..6bad7d51 100644
--- a/dwl.c
+++ b/dwl.c
@@ -343,6 +343,7 @@ static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static void virtualpointer(struct wl_listener *listener, void *data);
+static void warpcursor(const Client *c);
static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
@@ -497,6 +498,7 @@ arrange(Monitor *m)
m->lt[m->sellt]->arrange(m);
motionnotify(0, NULL, 0, 0, 0, 0);
checkidleinhibitor(NULL);
+ warpcursor(c);
}
void
@@ -1244,6 +1246,9 @@ focusclient(Client *c, int lift)
if (locked)
return;
+ /* Warp cursor to center of client if it is outside */
+ warpcursor(c);
+
/* Raise client in stacking order if requested */
if (c && lift)
wlr_scene_node_raise_to_top(&c->scene->node);
@@ -1344,6 +1349,7 @@ focusstack(const Arg *arg)
}
/* If only one client is visible on selmon, then c == sel */
focusclient(c, 1);
+ warpcursor(focustop(selmon));
}
/* We probably should change the name of this, it sounds like
@@ -2858,6 +2864,27 @@ virtualpointer(struct wl_listener *listener, void *data)
wlr_cursor_map_input_to_output(cursor, &pointer.base, event->suggested_output);
}
+void
+warpcursor(const Client *c) {
+ if (cursor_mode != CurNormal) {
+ return;
+ }
+ if (!c && selmon) {
+ wlr_cursor_warp_closest(cursor,
+ NULL,
+ selmon->w.x + selmon->w.width / 2.0 ,
+ selmon->w.y + selmon->w.height / 2.0);
+ }
+ else if ( c && (cursor->x < c->geom.x ||
+ cursor->x > c->geom.x + c->geom.width ||
+ cursor->y < c->geom.y ||
+ cursor->y > c->geom.y + c->geom.height))
+ wlr_cursor_warp_closest(cursor,
+ NULL,
+ c->geom.x + c->geom.width / 2.0,
+ c->geom.y + c->geom.height / 2.0);
+}
+
Monitor *
xytomon(double x, double y)
{
--
2.43.0