dwl/patches/cursor_warp.patch

146 lines
4.2 KiB
Diff
Raw Normal View History

From 8703fcdeac789425fbea768c3efa30884518e72e Mon Sep 17 00:00:00 2001
From: Faerryn <alexandre.liao@gmail.com>
Date: Thu, 26 May 2022 23:18:59 -0400
Subject: [PATCH 1/3] cursor wrap
---
dwl.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/dwl.c b/dwl.c
index d0f5afc8..7427fa06 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1107,6 +1107,16 @@ focusclient(Client *c, int lift)
struct wlr_keyboard *kb;
int i;
+ /* Warp cursor to center of client if it is outside */
+ 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);
+
/* Raise client in stacking order if requested */
if (c && lift)
wlr_scene_node_raise_to_top(c->scene);
From 9cd5b806a96823fc10784a39c86d57156e749d11 Mon Sep 17 00:00:00 2001
From: Faerryn <alexandre.liao@gmail.com>
Date: Fri, 27 May 2022 14:51:09 -0400
Subject: [PATCH 2/3] both focusclient and arrange will warp cursor
---
dwl.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/dwl.c b/dwl.c
index 7427fa06..2bdcaa56 100644
--- a/dwl.c
+++ b/dwl.c
@@ -290,6 +290,7 @@ static void updatetitle(struct wl_listener *listener, void *data);
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 warpcursor(const Client *c);
static Monitor *xytomon(double x, double y);
static struct wlr_scene_node *xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
@@ -489,6 +490,9 @@ arrange(Monitor *m)
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
/* TODO recheck pointer focus here... or in resize()? */
+ c = selclient();
+ if (c)
+ warpcursor(c);
}
void
@@ -1108,14 +1112,8 @@ focusclient(Client *c, int lift)
int i;
/* Warp cursor to center of client if it is outside */
- 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);
+ if (c)
+ warpcursor(c);
/* Raise client in stacking order if requested */
if (c && lift)
@@ -2375,6 +2373,18 @@ virtualkeyboard(struct wl_listener *listener, void *data)
createkeyboard(device);
}
+void
+warpcursor(const Client *c) {
+ if (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)
{
From 95a8e2c3372b2dc245533001164b1e427751d394 Mon Sep 17 00:00:00 2001
From: Faerryn <alexandre.liao@gmail.com>
Date: Sat, 28 May 2022 12:35:32 -0400
Subject: [PATCH 3/3] add an option to config.h for cursor_warp
---
config.def.h | 3 +++
dwl.c | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 4f131dda..f82dd582 100644
--- a/config.def.h
+++ b/config.def.h
@@ -6,6 +6,9 @@ static const float rootcolor[] = {0.3, 0.3, 0.3, 1.0};
static const float bordercolor[] = {0.5, 0.5, 0.5, 1.0};
static const float focuscolor[] = {1.0, 0.0, 0.0, 1.0};
+/* cursor warping */
+static const bool cursor_warp = true;
+
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
diff --git a/dwl.c b/dwl.c
index 2bdcaa56..e593b152 100644
--- a/dwl.c
+++ b/dwl.c
@@ -491,7 +491,7 @@ arrange(Monitor *m)
m->lt[m->sellt]->arrange(m);
/* TODO recheck pointer focus here... or in resize()? */
c = selclient();
- if (c)
+ if (cursor_warp && c)
warpcursor(c);
}
@@ -1112,7 +1112,7 @@ focusclient(Client *c, int lift)
int i;
/* Warp cursor to center of client if it is outside */
- if (c)
+ if (cursor_warp && c)
warpcursor(c);
/* Raise client in stacking order if requested */