mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-25 14:17:03 +00:00
[client] spice: detect end of warp based on serial and x & y match
x11 serials are per server command, not per event, as such several events may be processed by the server before a new event is received causing the existing logic to fail. This changes the logic to check for a larger serial instead of an exact match, and confirms the completion of the warp by matching the target x/y.
This commit is contained in:
parent
d6bb518992
commit
27a5a0811b
@ -80,12 +80,8 @@ struct AppParams params = { 0 };
|
|||||||
|
|
||||||
struct WarpInfo
|
struct WarpInfo
|
||||||
{
|
{
|
||||||
int x, y;
|
SDL_Point from, to;
|
||||||
union
|
unsigned long serial;
|
||||||
{
|
|
||||||
unsigned long serial;
|
|
||||||
SDL_Point p;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void handleMouseMoveEvent(int ex, int ey);
|
static void handleMouseMoveEvent(int ex, int ey);
|
||||||
@ -793,8 +789,10 @@ static void warpMouse(int x, int y, bool disable)
|
|||||||
g_cursor.warpState = WARP_STATE_OFF;
|
g_cursor.warpState = WARP_STATE_OFF;
|
||||||
|
|
||||||
struct WarpInfo * warp = malloc(sizeof(struct WarpInfo));
|
struct WarpInfo * warp = malloc(sizeof(struct WarpInfo));
|
||||||
warp->x = g_cursor.pos.x;
|
warp->from.x = g_cursor.pos.x;
|
||||||
warp->y = g_cursor.pos.y;
|
warp->from.y = g_cursor.pos.y;
|
||||||
|
warp->to.x = x;
|
||||||
|
warp->to.y = y;
|
||||||
|
|
||||||
if (g_state.wminfo.subsystem == SDL_SYSWM_X11)
|
if (g_state.wminfo.subsystem == SDL_SYSWM_X11)
|
||||||
{
|
{
|
||||||
@ -810,8 +808,7 @@ static void warpMouse(int x, int y, bool disable)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
warp->p.x = x;
|
warp->serial = 0;
|
||||||
warp->p.y = y;
|
|
||||||
ll_push(g_cursor.warpList, warp);
|
ll_push(g_cursor.warpList, warp);
|
||||||
SDL_WarpMouseInWindow(g_state.window, x, y);
|
SDL_WarpMouseInWindow(g_state.window, x, y);
|
||||||
}
|
}
|
||||||
@ -1070,34 +1067,17 @@ static void keyboardUngrab()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processWarp(int x, int y)
|
static void processWarp(int serial, int x, int y)
|
||||||
{
|
{
|
||||||
struct WarpInfo * warp;
|
struct WarpInfo * warp;
|
||||||
if (!ll_peek_head(g_cursor.warpList, (void **)&warp) ||
|
if (!ll_peek_head(g_cursor.warpList, (void **)&warp) ||
|
||||||
warp->p.x != x || warp->p.y != y)
|
serial < warp->serial || warp->to.x != x || warp->to.y != y)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ll_shift(g_cursor.warpList, NULL);
|
ll_shift(g_cursor.warpList, NULL);
|
||||||
|
|
||||||
g_cursor.pos.x = x + (warp->x - g_cursor.pos.x);
|
g_cursor.pos.x = x + (warp->from.x - g_cursor.pos.x);
|
||||||
g_cursor.pos.y = y + (warp->y - g_cursor.pos.y);
|
g_cursor.pos.y = y + (warp->from.y - g_cursor.pos.y);
|
||||||
free(warp);
|
|
||||||
|
|
||||||
if (ll_count(g_cursor.warpList) == 0 && g_cursor.inWindow)
|
|
||||||
g_cursor.warpState = WARP_STATE_ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void processXWarp(const XEvent xe, int x, int y)
|
|
||||||
{
|
|
||||||
struct WarpInfo * warp;
|
|
||||||
if (!ll_peek_head(g_cursor.warpList, (void **)&warp) ||
|
|
||||||
xe.xany.serial != warp->serial)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ll_shift(g_cursor.warpList, NULL);
|
|
||||||
|
|
||||||
g_cursor.pos.x = x + (warp->x - g_cursor.pos.x);
|
|
||||||
g_cursor.pos.y = y + (warp->y - g_cursor.pos.y);
|
|
||||||
free(warp);
|
free(warp);
|
||||||
|
|
||||||
if (ll_count(g_cursor.warpList) == 0 && g_cursor.inWindow)
|
if (ll_count(g_cursor.warpList) == 0 && g_cursor.inWindow)
|
||||||
@ -1195,7 +1175,7 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
const int x = round(device->event_x);
|
const int x = round(device->event_x);
|
||||||
const int y = round(device->event_y);
|
const int y = round(device->event_y);
|
||||||
|
|
||||||
processXWarp(xe, x, y);
|
processWarp(xe.xany.serial, x, y);
|
||||||
handleMouseMoveEvent(x, y);
|
handleMouseMoveEvent(x, y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1205,7 +1185,7 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
* motion events when a button is held */
|
* motion events when a button is held */
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
{
|
{
|
||||||
processXWarp(xe, xe.xmotion.x, xe.xmotion.y);
|
processWarp(xe.xany.serial, xe.xmotion.x, xe.xmotion.y);
|
||||||
handleMouseMoveEvent(xe.xmotion.x, xe.xmotion.y);
|
handleMouseMoveEvent(xe.xmotion.x, xe.xmotion.y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1213,25 +1193,25 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
/* key press/release events can be the end of a warp also */
|
/* key press/release events can be the end of a warp also */
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
case KeyRelease:
|
case KeyRelease:
|
||||||
processXWarp(xe, xe.xkey.x, xe.xkey.y);
|
processWarp(xe.xany.serial, xe.xkey.x, xe.xkey.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* button press/release events can be the end of a warp also */
|
/* button press/release events can be the end of a warp also */
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
processXWarp(xe, xe.xbutton.x, xe.xbutton.y);
|
processWarp(xe.xany.serial, xe.xbutton.x, xe.xbutton.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EnterNotify:
|
case EnterNotify:
|
||||||
{
|
{
|
||||||
handleWindowEnter();
|
handleWindowEnter();
|
||||||
processXWarp(xe, xe.xcrossing.x, xe.xcrossing.y);
|
processWarp(xe.xany.serial, xe.xcrossing.x, xe.xcrossing.y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LeaveNotify:
|
case LeaveNotify:
|
||||||
{
|
{
|
||||||
processXWarp(xe, xe.xcrossing.x, xe.xcrossing.y);
|
processWarp(xe.xany.serial, xe.xcrossing.x, xe.xcrossing.y);
|
||||||
if (xe.xcrossing.mode != NotifyNormal)
|
if (xe.xcrossing.mode != NotifyNormal)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1282,8 +1262,7 @@ int eventFilter(void * userdata, SDL_Event * event)
|
|||||||
if (g_state.wminfo.subsystem == SDL_SYSWM_X11)
|
if (g_state.wminfo.subsystem == SDL_SYSWM_X11)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* detect and filter out warp events */
|
processWarp(0, event->motion.x, event->motion.y);
|
||||||
processWarp(event->motion.x, event->motion.y);
|
|
||||||
handleMouseMoveEvent(event->motion.x, event->motion.y);
|
handleMouseMoveEvent(event->motion.x, event->motion.y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user