-
Notifications
You must be signed in to change notification settings - Fork 4
/
mouselock.patch
336 lines (302 loc) · 13.3 KB
/
mouselock.patch
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
From 1843de52f50347728e5ed76d99b026cbaf2c108e Mon Sep 17 00:00:00 2001
From: Giraffe1966 <35208168+Giraffe1966@users.noreply.github.com>
Date: Sun, 10 Dec 2023 06:34:51 +0000
Subject: [PATCH 1/4] Make roblox cursor lock properly.
---
dlls/winewayland.drv/wayland_pointer.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_pointer.c b/dlls/winewayland.drv/wayland_pointer.c
index c20ba170285..fb13399d22c 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -748,7 +748,7 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
BOOL covers_vscreen)
{
struct wayland_pointer *pointer = &process_wayland.pointer;
- BOOL needs_relative, needs_lock, needs_confine;
+ BOOL needs_relative, needs_lock, needs_confine, is_one_pixel;;
static unsigned int once;
if (!process_wayland.zwp_pointer_constraints_v1)
@@ -758,9 +758,10 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
return;
}
+ is_one_pixel = confine_rect && (int)(confine_rect->right - confine_rect->left)==1 && (int)(confine_rect->bottom - confine_rect->top)==1;
needs_lock = wl_surface && (confine_rect || covers_vscreen) &&
- !pointer->cursor.wl_surface;
- needs_confine = wl_surface && confine_rect && pointer->cursor.wl_surface;
+ (!pointer->cursor.wl_surface || is_one_pixel);
+ needs_confine = wl_surface && confine_rect && pointer->cursor.wl_surface && !is_one_pixel;
if (!needs_confine && pointer->zwp_confined_pointer_v1)
{
@@ -842,7 +843,7 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
return;
}
- needs_relative = !pointer->cursor.wl_surface &&
+ needs_relative = (!pointer->cursor.wl_surface || is_one_pixel) &&
pointer->constraint_hwnd &&
pointer->constraint_hwnd == pointer->focused_hwnd;
--
2.46.2
From 115603da061bbbaa73fa1b4540f9f146aff453f0 Mon Sep 17 00:00:00 2001
From: Giraffe1966 <35208168+Giraffe1966@users.noreply.github.com>
Date: Sun, 10 Dec 2023 10:27:18 +0000
Subject: [PATCH 2/4] Make relative motion smoother at lower mouse movement
speeds.
---
dlls/winewayland.drv/wayland_pointer.c | 19 ++++++++++++++++---
dlls/winewayland.drv/waylanddrv.h | 2 ++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_pointer.c b/dlls/winewayland.drv/wayland_pointer.c
index fb13399d22c..f6788db6f75 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -261,17 +261,30 @@ static void relative_pointer_v1_relative_motion(void *private,
HWND hwnd;
POINT screen;
struct wayland_win_data *data;
+ struct wayland_surface *surface;
+ struct wayland_pointer *pointer = &process_wayland.pointer;
if (!(hwnd = wayland_pointer_get_focused_hwnd())) return;
if (!(data = wayland_win_data_get(hwnd))) return;
+ if (!(surface = data->wayland_surface))
+ {
+ wayland_win_data_release(data);
+ return;
+ }
+ pthread_mutex_lock(&pointer->mutex);
wayland_surface_coords_to_window(data->wayland_surface,
- wl_fixed_to_double(dx),
- wl_fixed_to_double(dy),
+ wl_fixed_to_double(dx)+pointer->pendingX,
+ wl_fixed_to_double(dy)+pointer->pendingY,
(int *)&screen.x, (int *)&screen.y);
- wayland_win_data_release(data);
+ double actualDx = (double)screen.x / (double)(surface->window.scale);
+ pointer->pendingX = wl_fixed_to_double(dx)+pointer->pendingX-actualDx;
+ double actualDy = (double)screen.y / (double)(surface->window.scale);
+ pointer->pendingY = wl_fixed_to_double(dy)+pointer->pendingY-actualDy;
+ pthread_mutex_unlock(&pointer->mutex);
+ wayland_win_data_release(data);
input.type = INPUT_MOUSE;
input.mi.dx = screen.x;
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h
index 3dee8e432df..cd89f4959b1 100644
--- a/dlls/winewayland.drv/waylanddrv.h
+++ b/dlls/winewayland.drv/waylanddrv.h
@@ -100,6 +100,8 @@ struct wayland_pointer
HWND constraint_hwnd;
uint32_t enter_serial;
uint32_t button_serial;
+ double pendingX;
+ double pendingY;
struct wayland_cursor cursor;
pthread_mutex_t mutex;
};
--
2.46.2
From df76baa7b2371b9fa668c299d701395ae8f12c8d Mon Sep 17 00:00:00 2001
From: Giraffe1966 <35208168+Giraffe1966@users.noreply.github.com>
Date: Mon, 11 Dec 2023 20:31:26 +0000
Subject: [PATCH 3/4] Prevent left click from disabling cursor lock.
---
dlls/win32u/input.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c
index 14862e9a8a4..6f903a84acd 100644
--- a/dlls/win32u/input.c
+++ b/dlls/win32u/input.c
@@ -2568,7 +2568,7 @@ BOOL clip_fullscreen_window( HWND hwnd, BOOL reset )
if (!is_window_rect_full_screen( &rect, dpi )) return FALSE;
if (is_captured_by_system()) return FALSE;
if (NtGetTickCount() - thread_info->clipping_reset < 1000) return FALSE;
- if (!reset && clipping_cursor && thread_info->clipping_cursor) return FALSE; /* already clipping */
+ if (!reset && clipping_cursor) return FALSE; /* already clipping */
ctx = set_thread_dpi_awareness_context( NTUSER_DPI_PER_MONITOR_AWARE );
monitor_info = monitor_info_from_window( hwnd, MONITOR_DEFAULTTONEAREST );
--
2.46.2
From b9abcc45748807c36d3c2b9a48e96e2047ebc1f7 Mon Sep 17 00:00:00 2001
From: Giraffe1966 <35208168+Giraffe1966@users.noreply.github.com>
Date: Sun, 17 Dec 2023 06:37:18 +0000
Subject: [PATCH 4/4] Ensure the pointer is warped to the confinement region
when WAYLAND_ClipCursor is called.
---
dlls/winewayland.drv/wayland_pointer.c | 132 +++++++++++++++++++------
dlls/winewayland.drv/waylanddrv.h | 2 +
2 files changed, 102 insertions(+), 32 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_pointer.c b/dlls/winewayland.drv/wayland_pointer.c
index f6788db6f75..fb851318432 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -92,11 +92,84 @@ static void pointer_handle_motion_internal(wl_fixed_t sx, wl_fixed_t sy)
NtUserSendHardwareInput(hwnd, 0, &input, 0);
}
+// Calling thread should hold pointer lock
+static void update_pointer_surface_coords(wl_fixed_t sx, wl_fixed_t sy)
+{
+ struct wayland_pointer *pointer = &process_wayland.pointer;
+
+ pointer->sx = wl_fixed_to_double(sx);
+ pointer->sy = wl_fixed_to_double(sy);
+}
+
+/*
+ Try to warp the pointer to the specified confines.
+ This is necessary since pointer warping won't necessarily happen
+ when making a call to zwp_pointer_constraints_v1_{confine_pointer/lock_pointer} with the region set.
+ In fact, most compositors won't warp the pointer when the region is set on a constraint.
+
+ This method of warping done by this function isn't guaranteed to warp the pointer either (the spec doesn't provide any guarentees that it will,
+ only that warping may occur), but this method seems to work in more compositors than setting the region of a constraint.
+
+ Calling thread should own the pointer mutex. This function warps the pointer
+ to the confinement's nearest edge.
+ There should also be no currently acive cursor constraint--if there is one, it should be destroyed and then recreated aftewards
+*/
+static void warp_to_confines(struct wl_surface *wl_surface, RECT *confine_rect)
+{
+ double sx, sy;
+ struct wayland_pointer *pointer = &process_wayland.pointer;
+
+ sx = pointer->sx;
+ sy = pointer->sy;
+
+ if (!confine_rect || (confine_rect->top<=sy && confine_rect->bottom >= sy && confine_rect->left <= sx && confine_rect->right >= sx))
+ {
+ // cursor is already in the confinement area
+ return;
+ }
+
+ if (confine_rect->top>sy)
+ {
+ sy = confine_rect->top;
+ }
+ if (confine_rect->bottom<sy)
+ {
+ sy = confine_rect->bottom;
+ }
+ if (confine_rect->left>sx)
+ {
+ sx = confine_rect->left;
+ }
+ if (confine_rect->right<sx)
+ {
+ sx = confine_rect->right;
+ }
+
+ struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1 =
+ zwp_pointer_constraints_v1_lock_pointer(
+ process_wayland.zwp_pointer_constraints_v1,
+ wl_surface,
+ pointer->wl_pointer,
+ NULL,
+ ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+
+ zwp_locked_pointer_v1_set_cursor_position_hint(zwp_locked_pointer_v1, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
+ wl_surface_commit(wl_surface);
+
+ zwp_locked_pointer_v1_destroy(zwp_locked_pointer_v1);
+
+ TRACE("Warping cursor to: (%f,%f)\n", sx, sy);
+}
+
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{
struct wayland_pointer *pointer = &process_wayland.pointer;
+ pthread_mutex_lock(&pointer->mutex);
+ update_pointer_surface_coords(sx, sy);
+ pthread_mutex_unlock(&pointer->mutex);
+
/* Ignore absolute motion events if in relative mode. */
if (pointer->zwp_relative_pointer_v1) return;
@@ -122,6 +195,8 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
pthread_mutex_lock(&pointer->mutex);
pointer->focused_hwnd = hwnd;
pointer->enter_serial = serial;
+
+ update_pointer_surface_coords(sx, sy);
pthread_mutex_unlock(&pointer->mutex);
/* The cursor is undefined at every enter, so we set it again with
@@ -802,24 +877,18 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
confine_rect->right - confine_rect->left,
confine_rect->bottom - confine_rect->top);
- if (!pointer->zwp_confined_pointer_v1 || pointer->constraint_hwnd != hwnd)
- {
- if (pointer->zwp_confined_pointer_v1)
- zwp_confined_pointer_v1_destroy(pointer->zwp_confined_pointer_v1);
- pointer->zwp_confined_pointer_v1 =
- zwp_pointer_constraints_v1_confine_pointer(
- process_wayland.zwp_pointer_constraints_v1,
- wl_surface,
- pointer->wl_pointer,
- region,
- ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
- pointer->constraint_hwnd = hwnd;
- }
- else
- {
- zwp_confined_pointer_v1_set_region(pointer->zwp_confined_pointer_v1,
- region);
- }
+ if (pointer->zwp_confined_pointer_v1)
+ zwp_confined_pointer_v1_destroy(pointer->zwp_confined_pointer_v1);
+ if (confine_rect)
+ warp_to_confines(wl_surface, confine_rect);
+ pointer->zwp_confined_pointer_v1 =
+ zwp_pointer_constraints_v1_confine_pointer(
+ process_wayland.zwp_pointer_constraints_v1,
+ wl_surface,
+ pointer->wl_pointer,
+ region,
+ ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+ pointer->constraint_hwnd = hwnd;
TRACE("Confining to hwnd=%p wayland=%d,%d+%d,%d\n",
pointer->constraint_hwnd,
@@ -833,20 +902,19 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
{
HWND hwnd = wl_surface_get_user_data(wl_surface);
- if (!pointer->zwp_locked_pointer_v1 || pointer->constraint_hwnd != hwnd)
- {
- if (pointer->zwp_locked_pointer_v1)
- zwp_locked_pointer_v1_destroy(pointer->zwp_locked_pointer_v1);
- pointer->zwp_locked_pointer_v1 =
- zwp_pointer_constraints_v1_lock_pointer(
- process_wayland.zwp_pointer_constraints_v1,
- wl_surface,
- pointer->wl_pointer,
- NULL,
- ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
- pointer->constraint_hwnd = hwnd;
- TRACE("Locking to hwnd=%p\n", pointer->constraint_hwnd);
- }
+ if (pointer->zwp_locked_pointer_v1)
+ zwp_locked_pointer_v1_destroy(pointer->zwp_locked_pointer_v1);
+ if (confine_rect)
+ warp_to_confines(wl_surface, confine_rect);
+ pointer->zwp_locked_pointer_v1 =
+ zwp_pointer_constraints_v1_lock_pointer(
+ process_wayland.zwp_pointer_constraints_v1,
+ wl_surface,
+ pointer->wl_pointer,
+ NULL,
+ ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+ pointer->constraint_hwnd = hwnd;
+ TRACE("Locking to hwnd=%p\n", pointer->constraint_hwnd);
}
if (!process_wayland.zwp_relative_pointer_manager_v1)
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h
index cd89f4959b1..52b963968a7 100644
--- a/dlls/winewayland.drv/waylanddrv.h
+++ b/dlls/winewayland.drv/waylanddrv.h
@@ -102,6 +102,8 @@ struct wayland_pointer
uint32_t button_serial;
double pendingX;
double pendingY;
+ double sx;
+ double sy;
struct wayland_cursor cursor;
pthread_mutex_t mutex;
};
--
2.46.2