[client] ds: separate grab and capture logic

Currently, (un)grabPointer is used both for tracking/confining the mouse
in normal mode, as well as entering/exiting capture mode. This makes it
impossible to use separate cursor logic for capture mode, which is needed
to deal with overlapping windows for the Wayland backend.

This commit creates separate (un)capturePointer for entering/exiting
capture mode. There should be no behaviour changes.
This commit is contained in:
Quantum 2021-05-03 20:16:51 -04:00 committed by Geoffrey McRae
parent 7acbc57bc7
commit 00c2773e6b
9 changed files with 65 additions and 14 deletions

View File

@ -535,6 +535,8 @@ struct LG_DisplayServerOps LGDS_SDL =
.showPointer = sdlShowPointer,
.grabPointer = sdlGrabPointer,
.ungrabPointer = sdlUngrabPointer,
.capturePointer = sdlGrabPointer,
.uncapturePointer = sdlUngrabPointer,
.grabKeyboard = sdlGrabKeyboard,
.ungrabKeyboard = sdlUngrabKeyboard,
.warpPointer = sdlWarpPointer,

View File

@ -357,6 +357,24 @@ void waylandUngrabPointer(void)
}
}
void waylandCapturePointer(void)
{
waylandGrabPointer();
}
void waylandUncapturePointer(void)
{
/* we need to ungrab the pointer on the following conditions when exiting capture mode:
* - if warp is not supported, exit via window edge detection will never work
* as the cursor can not be warped out of the window when we release it.
* - if the format is invalid as we do not know where the guest cursor is,
* which also breaks edge detection.
* - if the user has opted to use captureInputOnly mode.
*/
if (!wlWm.warpSupport || !app_isFormatValid() || app_isCaptureOnlyMode())
waylandUngrabPointer();
}
void waylandGrabKeyboard(void)
{
if (wlWm.keyboardInhibitManager && !wlWm.keyboardInhibitor)

View File

@ -164,6 +164,8 @@ struct LG_DisplayServerOps LGDS_Wayland =
.showPointer = waylandShowPointer,
.grabPointer = waylandGrabPointer,
.ungrabPointer = waylandUngrabPointer,
.capturePointer = waylandCapturePointer,
.uncapturePointer = waylandUncapturePointer,
.grabKeyboard = waylandGrabKeyboard,
.ungrabKeyboard = waylandUngrabKeyboard,
.warpPointer = waylandWarpPointer,

View File

@ -225,6 +225,8 @@ void waylandGrabKeyboard(void);
void waylandGrabPointer(void);
void waylandUngrabKeyboard(void);
void waylandUngrabPointer(void);
void waylandCapturePointer(void);
void waylandUncapturePointer(void);
void waylandRealignPointer(void);
void waylandWarpPointer(int x, int y, bool exiting);
void waylandGuestPointerUpdated(double x, double y, int localX, int localY);

View File

@ -1063,6 +1063,23 @@ static void x11UngrabPointer(void)
x11.pointerGrabbed = false;
}
static void x11CapturePointer(void)
{
x11GrabPointer();
}
static void x11UncapturePointer(void)
{
/* we need to ungrab the pointer on the following conditions when exiting capture mode:
* - if the format is invalid as we do not know where the guest cursor is,
* which breaks edge detection as the cursor can not be warped out of the
* window when we release it.
* - if the user has opted to use captureInputOnly mode.
*/
if (!app_isFormatValid() || app_isCaptureOnlyMode())
x11UngrabPointer();
}
static void x11GrabKeyboard(void)
{
if (x11.keyboardGrabbed)
@ -1224,6 +1241,8 @@ struct LG_DisplayServerOps LGDS_X11 =
.showPointer = x11ShowPointer,
.grabPointer = x11GrabPointer,
.ungrabPointer = x11UngrabPointer,
.capturePointer = x11CapturePointer,
.uncapturePointer = x11UncapturePointer,
.grabKeyboard = x11GrabKeyboard,
.ungrabKeyboard = x11UngrabKeyboard,
.warpPointer = x11WarpPointer,

View File

@ -38,6 +38,8 @@ LG_MsgAlert;
bool app_isRunning(void);
bool app_inputEnabled(void);
bool app_isCaptureMode(void);
bool app_isCaptureOnlyMode(void);
bool app_isFormatValid(void);
void app_updateCursorPos(double x, double y);
void app_updateWindowPos(int x, int y);
void app_handleResizeEvent(int w, int h, double scale, const struct Border border);

View File

@ -131,10 +131,14 @@ struct LG_DisplayServerOps
/* dm specific cursor implementations */
void (*guestPointerUpdated)(double x, double y, int localX, int localY);
void (*showPointer)(bool show);
void (*grabPointer)();
void (*ungrabPointer)();
void (*grabKeyboard)();
void (*ungrabKeyboard)();
/* (un)grabPointer is used to toggle cursor tracking/confine in normal mode */
void (*grabPointer)();
void (*ungrabPointer)();
/* (un)capturePointer is used do toggle special cursor tracking in capture mode */
void (*capturePointer)();
void (*uncapturePointer)();
/* exiting = true if the warp is to leave the window */
void (*warpPointer)(int x, int y, bool exiting);
@ -199,6 +203,8 @@ struct LG_DisplayServerOps
assert((x)->showPointer ); \
assert((x)->grabPointer ); \
assert((x)->ungrabPointer ); \
assert((x)->capturePointer ); \
assert((x)->uncapturePointer ); \
assert((x)->warpPointer ); \
assert((x)->realignPointer ); \
assert((x)->isValidPointerPos ); \

View File

@ -46,6 +46,16 @@ bool app_isCaptureMode(void)
return g_cursor.grab;
}
bool app_isCaptureOnlyMode(void)
{
return g_params.captureInputOnly;
}
bool app_isFormatValid(void)
{
return g_state.formatValid;
}
void app_updateCursorPos(double x, double y)
{
g_cursor.pos.x = x;

View File

@ -123,7 +123,7 @@ void core_setGrabQuiet(bool enable)
if (g_params.grabKeyboard)
g_state.ds->grabKeyboard();
g_state.ds->grabPointer();
g_state.ds->capturePointer();
}
else
{
@ -134,17 +134,7 @@ void core_setGrabQuiet(bool enable)
g_state.ds->ungrabKeyboard();
}
/* we need to ungrab the pointer on the following conditions
* - if the backend does not support warp as exit via window edge
* detection will never work as the cursor can not be warped out of the
* window when we release it.
* - if the format is invalid as we do not know where the guest cursor is
* which also breaks edge detection.
* - if the user has opted to use captureInputOnly mode.
*/
if (warpSupport == LG_DS_WARP_NONE || !g_state.formatValid ||
g_params.captureInputOnly)
g_state.ds->ungrabPointer();
g_state.ds->uncapturePointer();
/* if exiting capture when input on capture only we need to align the local
* cursor to the guest's location before it is shown. */