From cb45fe7034746dd1e9f9bf21289ae8d16ef77e5d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 11 Dec 2022 19:14:35 +0900 Subject: [PATCH] [x11] Warp the mouse when it touches a barrier It seems that the mouse escaping the barriers requires some combination of hitting two at once, and holding your mouth just right (something about sliding the mouse up and down one barrier near the other). However, sending the mouse back to the center of the screen when it touches a barrier makes such sliding impossible. This seems to fix #38 --- libs/video/targets/in_x11.c | 65 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/libs/video/targets/in_x11.c b/libs/video/targets/in_x11.c index aaaac8d31..2b8d547e2 100644 --- a/libs/video/targets/in_x11.c +++ b/libs/video/targets/in_x11.c @@ -688,32 +688,6 @@ in_x11_send_focus_event (int gain) IE_Send_Event (&event); } -static void -event_focusout (XEvent *event) -{ - if (x_have_focus) { - x_have_focus = false; - in_x11_send_focus_event (0); - if (in_snd_block) { - S_BlockSound (); - CDAudio_Pause (); - } - X11_RestoreGamma (); - } -} - -static void -event_focusin (XEvent *event) -{ - in_x11_send_focus_event (1); - x_have_focus = true; - if (in_snd_block) { - S_UnblockSound (); - CDAudio_Resume (); - } - VID_UpdateGamma (); -} - static void center_pointer (void) { @@ -1044,9 +1018,7 @@ xi_barrier_hit (void *event) return; } - if (!x11_have_pointer || !input_grabbed) { - XIBarrierReleasePointer (x_disp, be.deviceid, be.barrier, be.eventid); - } + center_pointer (); } static void @@ -1157,6 +1129,41 @@ in_x11_setup_barriers (int xpos, int ypos, int xlen, int ylen) } #endif +static void +event_focusout (XEvent *event) +{ + if (x_have_focus) { + x_have_focus = false; +#ifdef HAVE_XFIXES + in_x11_remove_barriers (); +#endif + in_x11_send_focus_event (0); + if (in_snd_block) { + S_BlockSound (); + CDAudio_Pause (); + } + X11_RestoreGamma (); + } +} + +static void +event_focusin (XEvent *event) +{ + in_x11_send_focus_event (1); + x_have_focus = true; + if (in_snd_block) { + S_UnblockSound (); + CDAudio_Resume (); + } + if (input_grabbed) { +#ifdef HAVE_XFIXES + in_x11_setup_barriers (x11_aw.xpos, x11_aw.ypos, + x11_aw.xlen, x11_aw.ylen); +#endif + } + VID_UpdateGamma (); +} + static void in_x11_grab_input (void *data, int grab) {