forked from vinegarhq/wine-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouselock.patch
325 lines (292 loc) · 13 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
From c5dc39997d5fa5f30be9b2eacc165e32f69a51e9 Mon Sep 17 00:00:00 2001
From: Giraffe1966 <[email protected]>
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 fad75c8506c..13942f991f5 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -767,11 +767,12 @@ 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;
+ 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)
{
@@ -846,7 +847,7 @@ static void wayland_pointer_update_constraint(struct wl_surface *wl_surface,
}
}
- 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.42.0
From 67d3c6e3fe7b80d25f0f1c6b01aa77d2bca57051 Mon Sep 17 00:00:00 2001
From: Giraffe1966 <[email protected]>
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 | 12 ++++++++++--
dlls/winewayland.drv/waylanddrv.h | 2 ++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_pointer.c b/dlls/winewayland.drv/wayland_pointer.c
index 13942f991f5..1ffe34c1852 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -258,6 +258,7 @@ static void relative_pointer_v1_relative_motion(void *data,
HWND hwnd;
POINT screen, origin;
struct wayland_surface *surface;
+ struct wayland_pointer *pointer = &process_wayland.pointer;
RECT window_rect;
if (!(hwnd = wayland_pointer_get_focused_hwnd())) return;
@@ -265,11 +266,18 @@ static void relative_pointer_v1_relative_motion(void *data,
window_rect = surface->window.rect;
+ pthread_mutex_lock(&pointer->mutex);
wayland_surface_coords_to_window(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);
+ 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);
pthread_mutex_unlock(&surface->mutex);
/* We clip the relative motion within the window rectangle so that
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h
index 0883c43f1ff..793353017d4 100644
--- a/dlls/winewayland.drv/waylanddrv.h
+++ b/dlls/winewayland.drv/waylanddrv.h
@@ -99,6 +99,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.42.0
From 0dcabe4db4f780ba3e5bd997e3bfe88e2f7dd7bf Mon Sep 17 00:00:00 2001
From: Giraffe1966 <[email protected]>
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 3ee46f0bfcf..09498c4e786 100644
--- a/dlls/win32u/input.c
+++ b/dlls/win32u/input.c
@@ -2518,7 +2518,7 @@ BOOL clip_fullscreen_window( HWND hwnd, BOOL reset )
if (!NtUserIsWindowRectFullScreen( &rect )) 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 */
if (!(monitor = NtUserMonitorFromWindow( hwnd, MONITOR_DEFAULTTONEAREST ))) return FALSE;
if (!NtUserGetMonitorInfo( monitor, &monitor_info )) return FALSE;
--
2.42.0
From 3a858c6ed009ce0aa1c82a351d79d8732a35f877 Mon Sep 17 00:00:00 2001
From: Giraffe1966 <[email protected]>
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 1ffe34c1852..b634acb0e23 100644
--- a/dlls/winewayland.drv/wayland_pointer.c
+++ b/dlls/winewayland.drv/wayland_pointer.c
@@ -89,11 +89,84 @@ static void pointer_handle_motion_internal(wl_fixed_t sx, wl_fixed_t sy)
__wine_send_input(hwnd, &input, NULL);
}
+// 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;
@@ -119,6 +192,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
@@ -808,24 +883,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,
@@ -839,20 +908,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);
}
needs_relative = (!pointer->cursor.wl_surface || is_one_pixel) &&
diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h
index 793353017d4..173b18afc24 100644
--- a/dlls/winewayland.drv/waylanddrv.h
+++ b/dlls/winewayland.drv/waylanddrv.h
@@ -101,6 +101,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.42.0