[client] ds: detect when the cursor exits into an overlapping window

This adds a new method to the display server interface to allow the
application to notify the ds when there is a guest cursor position
update along with the translated local guest cursor position. This makes
it possible for the display server to keep the local cursor position in
sync with the guest cursor so that window leave events can be detected
when the cursor would move into an overlapping window.

Wayland currently just has a stub for this, and the X11 implementation
still needs some minor tweaking.
This commit is contained in:
Geoffrey McRae 2021-05-04 06:35:36 +10:00
parent cd56321e65
commit d0a12f6097
11 changed files with 122 additions and 54 deletions

View File

@ -106,3 +106,7 @@ void waylandShowPointer(bool show)
wlWm.showPointer = show; wlWm.showPointer = show;
wl_pointer_set_cursor(wlWm.pointer, wlWm.pointerEnterSerial, show ? wlWm.cursor : NULL, 0, 0); wl_pointer_set_cursor(wlWm.pointer, wlWm.pointerEnterSerial, show ? wlWm.cursor : NULL, 0, 0);
} }
void waylandGuestPointerUpdated(double x, double y, int localX, int localY)
{
}

View File

@ -160,7 +160,7 @@ struct LG_DisplayServerOps LGDS_Wayland =
.glSetSwapInterval = waylandGLSetSwapInterval, .glSetSwapInterval = waylandGLSetSwapInterval,
.glSwapBuffers = waylandGLSwapBuffers, .glSwapBuffers = waylandGLSwapBuffers,
#endif #endif
.guestPointerUpdated = waylandGuestPointerUpdated,
.showPointer = waylandShowPointer, .showPointer = waylandShowPointer,
.grabPointer = waylandGrabPointer, .grabPointer = waylandGrabPointer,
.ungrabPointer = waylandUngrabPointer, .ungrabPointer = waylandUngrabPointer,

View File

@ -190,6 +190,7 @@ void waylandCBRelease(void);
// cursor module // cursor module
bool waylandCursorInit(void); bool waylandCursorInit(void);
void waylandCursorFree(void); void waylandCursorFree(void);
void waylandGuestPointerUpdated(double x, double y, int localX, int localY);
void waylandShowPointer(bool show); void waylandShowPointer(bool show);
// gl module // gl module

View File

@ -41,6 +41,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include "app.h" #include "app.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/time.h"
#define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1 #define _NET_WM_STATE_ADD 1
@ -105,7 +106,8 @@ static bool x11Init(const LG_DSInitParams params)
.event_mask = .event_mask =
StructureNotifyMask | StructureNotifyMask |
PropertyChangeMask | PropertyChangeMask |
ExposureMask ExposureMask |
PointerMotionMask
}; };
unsigned long swaMask = CWEventMask; unsigned long swaMask = CWEventMask;
@ -677,6 +679,8 @@ static int x11EventThread(void * unused)
static void x11GenericEvent(XGenericEventCookie *cookie) static void x11GenericEvent(XGenericEventCookie *cookie)
{ {
static int button_state = 0;
if (cookie->extension != x11.xinputOp) if (cookie->extension != x11.xinputOp)
return; return;
@ -718,10 +722,10 @@ static void x11GenericEvent(XGenericEventCookie *cookie)
case XI_Enter: case XI_Enter:
{ {
if (x11.entered) XIEnterEvent *xie = cookie->data;
if (x11.entered || xie->event != x11.window)
return; return;
XIEnterEvent *xie = cookie->data;
app_updateCursorPos(xie->event_x, xie->event_y); app_updateCursorPos(xie->event_x, xie->event_y);
app_handleEnterEvent(true); app_handleEnterEvent(true);
x11.entered = true; x11.entered = true;
@ -730,10 +734,11 @@ static void x11GenericEvent(XGenericEventCookie *cookie)
case XI_Leave: case XI_Leave:
{ {
if (!x11.entered) XILeaveEvent *xie = cookie->data;
if (!x11.entered || xie->event != x11.window ||
button_state != 0 || app_isCaptureMode())
return; return;
XILeaveEvent *xie = cookie->data;
app_updateCursorPos(xie->event_x, xie->event_y); app_updateCursorPos(xie->event_x, xie->event_y);
app_handleEnterEvent(false); app_handleEnterEvent(false);
x11.entered = false; x11.entered = false;
@ -795,6 +800,7 @@ static void x11GenericEvent(XGenericEventCookie *cookie)
prev_time = raw->time; prev_time = raw->time;
prev_detail = raw->detail; prev_detail = raw->detail;
button_state |= (1 << raw->detail);
app_handleButtonPress( app_handleButtonPress(
raw->detail > 5 ? raw->detail - 2 : raw->detail); raw->detail > 5 ? raw->detail - 2 : raw->detail);
@ -816,6 +822,7 @@ static void x11GenericEvent(XGenericEventCookie *cookie)
prev_time = raw->time; prev_time = raw->time;
prev_detail = raw->detail; prev_detail = raw->detail;
button_state &= ~(1 << raw->detail);
app_handleButtonRelease( app_handleButtonRelease(
raw->detail > 5 ? raw->detail - 2 : raw->detail); raw->detail > 5 ? raw->detail - 2 : raw->detail);
@ -957,6 +964,29 @@ static void x11GLSwapBuffers(void)
} }
#endif #endif
static void x11GuestPointerUpdated(double x, double y, int localX, int localY)
{
if (app_isCaptureMode() || !x11.entered)
return;
// avoid running too often
static uint64_t last_warp = 0;
uint64_t now = microtime();
if (now - last_warp < 10000)
return;
last_warp = now;
XIWarpPointer(
x11.display,
x11.pointerDev,
None,
x11.window,
0, 0, 0, 0,
localX, localY);
XSync(x11.display, False);
}
static void x11ShowPointer(bool show) static void x11ShowPointer(bool show)
{ {
if (show) if (show)
@ -1000,6 +1030,8 @@ static void x11GrabPointer(void)
XISetMask(mask.mask, XI_RawButtonRelease); XISetMask(mask.mask, XI_RawButtonRelease);
XISetMask(mask.mask, XI_RawMotion ); XISetMask(mask.mask, XI_RawMotion );
XISetMask(mask.mask, XI_Motion ); XISetMask(mask.mask, XI_Motion );
XISetMask(mask.mask, XI_Enter );
XISetMask(mask.mask, XI_Leave );
Status ret = XIGrabDevice( Status ret = XIGrabDevice(
x11.display, x11.display,
@ -1189,6 +1221,7 @@ struct LG_DisplayServerOps LGDS_X11 =
.glSetSwapInterval = x11GLSetSwapInterval, .glSetSwapInterval = x11GLSetSwapInterval,
.glSwapBuffers = x11GLSwapBuffers, .glSwapBuffers = x11GLSwapBuffers,
#endif #endif
.guestPointerUpdated = x11GuestPointerUpdated,
.showPointer = x11ShowPointer, .showPointer = x11ShowPointer,
.grabPointer = x11GrabPointer, .grabPointer = x11GrabPointer,
.ungrabPointer = x11UngrabPointer, .ungrabPointer = x11UngrabPointer,

View File

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

View File

@ -129,6 +129,7 @@ struct LG_DisplayServerOps
#endif #endif
/* dm specific cursor implementations */ /* dm specific cursor implementations */
void (*guestPointerUpdated)(double x, double y, int localX, int localY);
void (*showPointer)(bool show); void (*showPointer)(bool show);
void (*grabPointer)(); void (*grabPointer)();
void (*ungrabPointer)(); void (*ungrabPointer)();
@ -194,6 +195,7 @@ struct LG_DisplayServerOps
ASSERT_OPENGL_FN((x)->glMakeCurrent ); \ ASSERT_OPENGL_FN((x)->glMakeCurrent ); \
ASSERT_OPENGL_FN((x)->glSetSwapInterval); \ ASSERT_OPENGL_FN((x)->glSetSwapInterval); \
ASSERT_OPENGL_FN((x)->glSwapBuffers ); \ ASSERT_OPENGL_FN((x)->glSwapBuffers ); \
assert((x)->guestPointerUpdated); \
assert((x)->showPointer ); \ assert((x)->showPointer ); \
assert((x)->grabPointer ); \ assert((x)->grabPointer ); \
assert((x)->ungrabPointer ); \ assert((x)->ungrabPointer ); \

View File

@ -33,4 +33,11 @@ bool util_guestCurToLocal(struct DoublePoint *local);
void util_localCurToGuest(struct DoublePoint *guest); void util_localCurToGuest(struct DoublePoint *guest);
void util_rotatePoint(struct DoublePoint *point); void util_rotatePoint(struct DoublePoint *point);
static inline double util_clamp(double x, double min, double max)
{
if (x < min) return min;
if (x > max) return max;
return x;
}
#endif #endif

View File

@ -41,6 +41,11 @@ bool app_isRunning(void)
g_state.state == APP_STATE_RESTART; g_state.state == APP_STATE_RESTART;
} }
bool app_isCaptureMode(void)
{
return g_cursor.grab;
}
void app_updateCursorPos(double x, double y) void app_updateCursorPos(double x, double y)
{ {
g_cursor.pos.x = x; g_cursor.pos.x = x;

View File

@ -326,6 +326,17 @@ void core_stopFrameThread(void)
g_state.frameThread = NULL; g_state.frameThread = NULL;
} }
void core_handleGuestMouseUpdate(void)
{
int x, y;
struct DoublePoint localPos;
util_guestCurToLocal(&localPos);
localPos.x = util_clamp(localPos.x, 0.0, g_state.dstRect.w);
localPos.y = util_clamp(localPos.y, 0.0, g_state.dstRect.h);
util_cursorToInt(localPos.x, localPos.y, &x, &y);
g_state.ds->guestPointerUpdated(g_cursor.guest.x, g_cursor.guest.y, x, y);
}
void core_handleMouseGrabbed(double ex, double ey) void core_handleMouseGrabbed(double ex, double ey)
{ {
if (!core_inputEnabled()) if (!core_inputEnabled())

View File

@ -32,6 +32,7 @@ void core_alignToGuest(void);
bool core_isValidPointerPos(int x, int y); bool core_isValidPointerPos(int x, int y);
bool core_startFrameThread(void); bool core_startFrameThread(void);
void core_stopFrameThread(void); void core_stopFrameThread(void);
void core_handleGuestMouseUpdate(void);
void core_handleMouseGrabbed(double ex, double ey); void core_handleMouseGrabbed(double ex, double ey);
void core_handleMouseNormal(double ex, double ey); void core_handleMouseNormal(double ex, double ey);

View File

@ -306,6 +306,9 @@ static int cursorThread(void * unused)
core_alignToGuest(); core_alignToGuest();
app_resyncMouseBasic(); app_resyncMouseBasic();
} }
// tell the DS there was an update
core_handleGuestMouseUpdate();
} }
lgmpClientMessageDone(queue); lgmpClientMessageDone(queue);