mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-10 23:07:04 +00:00
[client] spice: x11 use xinput2 raw mode if possible for captured mouse
This commit is contained in:
parent
27a5a0811b
commit
974b409e91
@ -85,6 +85,7 @@ struct WarpInfo
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void handleMouseMoveEvent(int ex, int ey);
|
static void handleMouseMoveEvent(int ex, int ey);
|
||||||
|
static void handleMouseRawEvent(int ex, int ey);
|
||||||
|
|
||||||
static void lgInit()
|
static void lgInit()
|
||||||
{
|
{
|
||||||
@ -828,6 +829,12 @@ static bool isValidCursorLocation(int x, int y)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleMouseRawEvent(int ex, int ey)
|
||||||
|
{
|
||||||
|
if (!spice_mouse_motion(ex, ey))
|
||||||
|
DEBUG_ERROR("failed to send mouse motion message");
|
||||||
|
}
|
||||||
|
|
||||||
static void handleMouseMoveEvent(int ex, int ey)
|
static void handleMouseMoveEvent(int ex, int ey)
|
||||||
{
|
{
|
||||||
if (!params.useSpiceInput)
|
if (!params.useSpiceInput)
|
||||||
@ -1084,6 +1091,59 @@ static void processWarp(int serial, int x, int y)
|
|||||||
g_cursor.warpState = WARP_STATE_ON;
|
g_cursor.warpState = WARP_STATE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setGrab(bool enable)
|
||||||
|
{
|
||||||
|
if (g_cursor.grab == enable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_cursor.grab = enable;
|
||||||
|
|
||||||
|
if (g_state.wminfo.subsystem != SDL_SYSWM_X11)
|
||||||
|
SDL_SetWindowGrab(g_state.window, g_cursor.grab);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (g_cursor.grab)
|
||||||
|
{
|
||||||
|
XGrabPointer(
|
||||||
|
g_state.wminfo.info.x11.display,
|
||||||
|
g_state.wminfo.info.x11.window,
|
||||||
|
true,
|
||||||
|
None,
|
||||||
|
GrabModeAsync,
|
||||||
|
GrabModeAsync,
|
||||||
|
g_state.wminfo.info.x11.window,
|
||||||
|
None,
|
||||||
|
CurrentTime);
|
||||||
|
|
||||||
|
XGrabKeyboard(
|
||||||
|
g_state.wminfo.info.x11.display,
|
||||||
|
g_state.wminfo.info.x11.window,
|
||||||
|
true,
|
||||||
|
GrabModeAsync,
|
||||||
|
GrabModeAsync,
|
||||||
|
CurrentTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
XUngrabKeyboard(g_state.wminfo.info.x11.display, CurrentTime);
|
||||||
|
XUngrabPointer(g_state.wminfo.info.x11.display, CurrentTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if exiting grab move the pointer back to the center of the window */
|
||||||
|
if (!g_cursor.grab && g_cursor.inWindow)
|
||||||
|
{
|
||||||
|
warpMouse(g_state.windowCX, g_state.windowCY, false);
|
||||||
|
g_cursor.delta.x = 0;
|
||||||
|
g_cursor.delta.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
app_alert(
|
||||||
|
g_cursor.grab ? LG_ALERT_SUCCESS : LG_ALERT_WARNING,
|
||||||
|
g_cursor.grab ? "Capture Enabled" : "Capture Disabled"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
int eventFilter(void * userdata, SDL_Event * event)
|
int eventFilter(void * userdata, SDL_Event * event)
|
||||||
{
|
{
|
||||||
switch(event->type)
|
switch(event->type)
|
||||||
@ -1169,6 +1229,19 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
XIDeviceEvent *device = cookie->data;
|
XIDeviceEvent *device = cookie->data;
|
||||||
|
|
||||||
|
if (g_cursor.grab)
|
||||||
|
{
|
||||||
|
if (device->evtype != XI_RawMotion)
|
||||||
|
break;
|
||||||
|
|
||||||
|
XIRawEvent *raw = cookie->data;
|
||||||
|
const int x = raw->raw_values[0];
|
||||||
|
const int y = raw->raw_values[1];
|
||||||
|
handleMouseRawEvent(x, y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (device->evtype != XI_Motion)
|
if (device->evtype != XI_Motion)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1177,6 +1250,7 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
|
|
||||||
processWarp(xe.xany.serial, x, y);
|
processWarp(xe.xany.serial, x, y);
|
||||||
handleMouseMoveEvent(x, y);
|
handleMouseMoveEvent(x, y);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1234,7 +1308,12 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
|
|
||||||
if (xe.xfocus.mode == NotifyNormal ||
|
if (xe.xfocus.mode == NotifyNormal ||
|
||||||
xe.xfocus.mode == NotifyWhileGrabbed)
|
xe.xfocus.mode == NotifyWhileGrabbed)
|
||||||
|
{
|
||||||
|
if (g_cursor.grab)
|
||||||
|
setGrab(false);
|
||||||
|
else
|
||||||
keyboardUngrab();
|
keyboardUngrab();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@ -1316,46 +1395,7 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
if (g_state.escapeAction == -1)
|
if (g_state.escapeAction == -1)
|
||||||
{
|
{
|
||||||
if (params.useSpiceInput)
|
if (params.useSpiceInput)
|
||||||
{
|
setGrab(!g_cursor.grab);
|
||||||
g_cursor.grab = !g_cursor.grab;
|
|
||||||
|
|
||||||
if (g_state.wminfo.subsystem != SDL_SYSWM_X11)
|
|
||||||
SDL_SetWindowGrab(g_state.window, g_cursor.grab);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (g_cursor.grab)
|
|
||||||
{
|
|
||||||
XGrabPointer(
|
|
||||||
g_state.wminfo.info.x11.display,
|
|
||||||
g_state.wminfo.info.x11.window,
|
|
||||||
true,
|
|
||||||
None,
|
|
||||||
GrabModeAsync,
|
|
||||||
GrabModeAsync,
|
|
||||||
g_state.wminfo.info.x11.window,
|
|
||||||
None,
|
|
||||||
CurrentTime);
|
|
||||||
|
|
||||||
XGrabKeyboard(
|
|
||||||
g_state.wminfo.info.x11.display,
|
|
||||||
g_state.wminfo.info.x11.window,
|
|
||||||
true,
|
|
||||||
GrabModeAsync,
|
|
||||||
GrabModeAsync,
|
|
||||||
CurrentTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
XUngrabKeyboard(g_state.wminfo.info.x11.display, CurrentTime);
|
|
||||||
XUngrabPointer(g_state.wminfo.info.x11.display, CurrentTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app_alert(
|
|
||||||
g_cursor.grab ? LG_ALERT_SUCCESS : LG_ALERT_WARNING,
|
|
||||||
g_cursor.grab ? "Capture Enabled" : "Capture Disabled"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user