1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
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 */
|