@@ -912,7 +912,7 @@ static void pointer_handle_button_common(SDL_WaylandSeat *seat, uint32_t serial,
912
912
*
913
913
* The mouse is not captured in relative mode.
914
914
*/
915
- if (!seat -> display -> relative_mode_enabled || ! Wayland_SeatHasRelativePointerFocus ( seat ) ) {
915
+ if (!seat -> pointer . relative_pointer ) {
916
916
if (seat -> pointer .buttons_pressed != 0 ) {
917
917
window -> sdlwindow -> flags |= SDL_WINDOW_MOUSE_CAPTURE ;
918
918
} else {
@@ -1164,30 +1164,23 @@ static void relative_pointer_handle_relative_motion(void *data,
1164
1164
wl_fixed_t dy_unaccel_w )
1165
1165
{
1166
1166
SDL_WaylandSeat * seat = data ;
1167
+ SDL_WindowData * window = seat -> pointer .focus ;
1168
+ SDL_Mouse * mouse = SDL_GetMouse ();
1167
1169
1168
- if (seat -> display -> relative_mode_enabled ) {
1169
- SDL_WindowData * window = seat -> pointer .focus ;
1170
-
1171
- // Relative motion follows keyboard focus.
1172
- if (Wayland_SeatHasRelativePointerFocus (seat )) {
1173
- SDL_Mouse * mouse = SDL_GetMouse ();
1174
-
1175
- // Relative pointer event times are in microsecond granularity.
1176
- const Uint64 timestamp = Wayland_AdjustEventTimestampBase (SDL_US_TO_NS (((Uint64 )time_hi << 32 ) | (Uint64 )time_lo ));
1170
+ // Relative pointer event times are in microsecond granularity.
1171
+ const Uint64 timestamp = Wayland_AdjustEventTimestampBase (SDL_US_TO_NS (((Uint64 )time_hi << 32 ) | (Uint64 )time_lo ));
1177
1172
1178
- double dx ;
1179
- double dy ;
1180
- if (mouse -> InputTransform || !mouse -> enable_relative_system_scale ) {
1181
- dx = wl_fixed_to_double (dx_unaccel_w );
1182
- dy = wl_fixed_to_double (dy_unaccel_w );
1183
- } else {
1184
- dx = wl_fixed_to_double (dx_w ) * window -> pointer_scale .x ;
1185
- dy = wl_fixed_to_double (dy_w ) * window -> pointer_scale .y ;
1186
- }
1187
-
1188
- SDL_SendMouseMotion (timestamp , window -> sdlwindow , seat -> pointer .sdl_id , true, (float )dx , (float )dy );
1189
- }
1173
+ double dx ;
1174
+ double dy ;
1175
+ if (mouse -> InputTransform || !mouse -> enable_relative_system_scale ) {
1176
+ dx = wl_fixed_to_double (dx_unaccel_w );
1177
+ dy = wl_fixed_to_double (dy_unaccel_w );
1178
+ } else {
1179
+ dx = wl_fixed_to_double (dx_w ) * window -> pointer_scale .x ;
1180
+ dy = wl_fixed_to_double (dy_w ) * window -> pointer_scale .y ;
1190
1181
}
1182
+
1183
+ SDL_SendMouseMotion (timestamp , window -> sdlwindow , seat -> pointer .sdl_id , true, (float )dx , (float )dy );
1191
1184
}
1192
1185
1193
1186
static const struct zwp_relative_pointer_v1_listener relative_pointer_listener = {
@@ -2077,26 +2070,6 @@ static const struct wl_keyboard_listener keyboard_listener = {
2077
2070
keyboard_handle_repeat_info , // Version 4
2078
2071
};
2079
2072
2080
- static void Wayland_SeatCreateRelativePointer (SDL_WaylandSeat * seat )
2081
- {
2082
- if (seat -> display -> relative_pointer_manager ) {
2083
- if (seat -> pointer .wl_pointer && !seat -> pointer .relative_pointer ) {
2084
- seat -> pointer .relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer (seat -> display -> relative_pointer_manager , seat -> pointer .wl_pointer );
2085
- zwp_relative_pointer_v1_add_listener (seat -> pointer .relative_pointer ,
2086
- & relative_pointer_listener ,
2087
- seat );
2088
- }
2089
- }
2090
- }
2091
-
2092
- void Wayland_DisplayInitRelativePointerManager (SDL_VideoData * display )
2093
- {
2094
- SDL_WaylandSeat * seat ;
2095
- wl_list_for_each (seat , & display -> seat_list , link ) {
2096
- Wayland_SeatCreateRelativePointer (seat );
2097
- }
2098
- }
2099
-
2100
2073
static void Wayland_SeatDestroyPointer (SDL_WaylandSeat * seat , bool send_event )
2101
2074
{
2102
2075
// Make sure focus is removed from a surface before the pointer is destroyed.
@@ -2239,8 +2212,6 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum w
2239
2212
wl_pointer_set_user_data (seat -> pointer .wl_pointer , seat );
2240
2213
wl_pointer_add_listener (seat -> pointer .wl_pointer , & pointer_listener , seat );
2241
2214
2242
- Wayland_SeatCreateRelativePointer (seat );
2243
-
2244
2215
seat -> pointer .sdl_id = SDL_GetNextObjectID ();
2245
2216
2246
2217
if (seat -> name ) {
@@ -3490,16 +3461,36 @@ void Wayland_SeatDestroy(SDL_WaylandSeat *seat, bool send_events)
3490
3461
SDL_free (seat );
3491
3462
}
3492
3463
3493
- bool Wayland_SeatHasRelativePointerFocus (SDL_WaylandSeat * seat )
3464
+ static void Wayland_SeatUpdateRelativePointer (SDL_WaylandSeat * seat )
3494
3465
{
3495
- /* If a seat has both keyboard and pointer capabilities, relative focus will follow the keyboard
3496
- * attached to that seat. Otherwise, relative focus will be gained if any other seat has keyboard
3497
- * focus on the window with pointer focus.
3498
- */
3499
- if (seat -> keyboard .wl_keyboard ) {
3500
- return seat -> keyboard .focus && seat -> keyboard .focus == seat -> pointer .focus ;
3501
- } else {
3502
- return seat -> pointer .focus && seat -> pointer .focus -> keyboard_focus_count != 0 ;
3466
+ if (seat -> display -> relative_pointer_manager ) {
3467
+ bool relative_focus = false;
3468
+
3469
+ if (seat -> pointer .focus ) {
3470
+ /* If a seat has both keyboard and pointer capabilities, relative focus will follow the keyboard
3471
+ * attached to that seat. Otherwise, relative focus will be gained if any other seat has keyboard
3472
+ * focus on the window with pointer focus.
3473
+ */
3474
+ if (seat -> pointer .focus -> sdlwindow -> flags & SDL_WINDOW_MOUSE_RELATIVE_MODE ) {
3475
+ if (seat -> keyboard .wl_keyboard ) {
3476
+ relative_focus = seat -> keyboard .focus == seat -> pointer .focus ;
3477
+ } else {
3478
+ relative_focus = seat -> pointer .focus -> keyboard_focus_count != 0 ;
3479
+ }
3480
+ } else {
3481
+ relative_focus = SDL_GetMouse ()-> warp_emulation_active ;
3482
+ }
3483
+ }
3484
+
3485
+ if (relative_focus ) {
3486
+ if (!seat -> pointer .relative_pointer ) {
3487
+ seat -> pointer .relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer (seat -> display -> relative_pointer_manager , seat -> pointer .wl_pointer );
3488
+ zwp_relative_pointer_v1_add_listener (seat -> pointer .relative_pointer , & relative_pointer_listener , seat );
3489
+ }
3490
+ } else if (seat -> pointer .relative_pointer ) {
3491
+ zwp_relative_pointer_v1_destroy (seat -> pointer .relative_pointer );
3492
+ seat -> pointer .relative_pointer = NULL ;
3493
+ }
3503
3494
}
3504
3495
}
3505
3496
@@ -3532,11 +3523,10 @@ static void Wayland_SeatUpdateKeyboardGrab(SDL_WaylandSeat *seat)
3532
3523
void Wayland_SeatUpdatePointerGrab (SDL_WaylandSeat * seat )
3533
3524
{
3534
3525
SDL_VideoData * display = seat -> display ;
3526
+ Wayland_SeatUpdateRelativePointer (seat );
3535
3527
3536
3528
if (display -> pointer_constraints ) {
3537
- const bool has_relative_focus = Wayland_SeatHasRelativePointerFocus (seat );
3538
-
3539
- if (seat -> pointer .locked_pointer && (!display -> relative_mode_enabled || !has_relative_focus )) {
3529
+ if (seat -> pointer .locked_pointer && !seat -> pointer .relative_pointer ) {
3540
3530
zwp_locked_pointer_v1_destroy (seat -> pointer .locked_pointer );
3541
3531
seat -> pointer .locked_pointer = NULL ;
3542
3532
@@ -3546,7 +3536,7 @@ void Wayland_SeatUpdatePointerGrab(SDL_WaylandSeat *seat)
3546
3536
3547
3537
if (seat -> pointer .wl_pointer ) {
3548
3538
// If relative mode is active, and the pointer focus matches the keyboard focus, lock it.
3549
- if (seat -> display -> relative_mode_enabled && has_relative_focus ) {
3539
+ if (seat -> pointer . relative_pointer ) {
3550
3540
if (!seat -> pointer .locked_pointer ) {
3551
3541
// Creating a lock on a surface with an active confinement region on the same seat is a protocol error.
3552
3542
if (seat -> pointer .confined_pointer ) {
0 commit comments