xwayland: Delay cursor visibility update

Xwayland won't emulate XWarpPointer requests if the cursor is visible,
this is to avoid having the cursor jumping on screen and preventing
random X11 clients from controlling the pointer in Wayland, while
allowing games which use that mechanism with a hidden cursor to work in
Xwayland.

There are, however, games which tend to do it in the wrong order, i.e.
show the cursor before moving the pointer, and because Xwayland will not
allow an X11 client to move the pointer while the cursor is visible, the
requests will fail.

Add a workaround for such X11 clients, when the cursor is being shown,
keep it invisible until the cursor is actually moved. This way, X11
clients which show their cursor just before moving it would still have a
chance to succeed.

v2: Add a timeout to show the cursor for well behaved clients.
v3: Some cleanup (Michel)
v4: Do not cancel cursor delay when updating the cursor to avoid
    delaying cursor visibility indefinitely if the client keeps
    settings different cursors (Michel)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Tested-by: Jaap Buurman jaapbuurman@gmail.com
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/734
This commit is contained in:
Olivier Fourdan 2020-12-18 17:53:33 +01:00
parent 9d329a0fb1
commit 97ed0048e4
2 changed files with 91 additions and 10 deletions

View File

@ -41,6 +41,8 @@
#include "tablet-unstable-v2-client-protocol.h"
#define DELAYED_X_CURSOR_TIMEOUT 5 /* ms */
static DevPrivateKeyRec xwl_cursor_private_key;
static void
@ -255,12 +257,69 @@ xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *xwl_tablet_tool)
xwl_cursor_attach_pixmap(xwl_seat, xwl_cursor, pixmap);
}
static void
xwl_seat_update_cursor(struct xwl_seat *xwl_seat)
{
struct xwl_tablet_tool *xwl_tablet_tool;
xwl_seat_set_cursor(xwl_seat);
xorg_list_for_each_entry(xwl_tablet_tool, &xwl_seat->tablet_tools, link) {
if (xwl_tablet_tool->proximity_in_serial != 0)
xwl_tablet_tool_set_cursor(xwl_tablet_tool);
}
/* Clear delayed cursor if any */
xwl_seat->pending_x_cursor = NULL;
}
static void
xwl_seat_update_cursor_visibility(struct xwl_seat *xwl_seat)
{
xwl_seat->x_cursor = xwl_seat->pending_x_cursor;
xwl_seat_cursor_visibility_changed(xwl_seat);
xwl_seat_update_cursor(xwl_seat);
}
static void
xwl_set_cursor_free_timer(struct xwl_seat *xwl_seat)
{
if (xwl_seat->x_cursor_timer) {
TimerFree(xwl_seat->x_cursor_timer);
xwl_seat->x_cursor_timer = NULL;
}
}
static CARD32
xwl_set_cursor_timer_callback(OsTimerPtr timer, CARD32 time, void *arg)
{
struct xwl_seat *xwl_seat = arg;
xwl_set_cursor_free_timer(xwl_seat);
xwl_seat_update_cursor_visibility(xwl_seat);
/* Don't re-arm the timer */
return 0;
}
static void
xwl_set_cursor_delayed(struct xwl_seat *xwl_seat, CursorPtr cursor)
{
xwl_seat->pending_x_cursor = cursor;
if (xwl_seat->x_cursor_timer == NULL) {
xwl_seat->x_cursor_timer = TimerSet(xwl_seat->x_cursor_timer,
0, DELAYED_X_CURSOR_TIMEOUT,
&xwl_set_cursor_timer_callback,
xwl_seat);
}
}
static void
xwl_set_cursor(DeviceIntPtr device,
ScreenPtr screen, CursorPtr cursor, int x, int y)
{
struct xwl_seat *xwl_seat;
struct xwl_tablet_tool *xwl_tablet_tool;
Bool cursor_visibility_changed;
xwl_seat = device->public.devicePrivate;
@ -269,22 +328,37 @@ xwl_set_cursor(DeviceIntPtr device,
cursor_visibility_changed = !!xwl_seat->x_cursor ^ !!cursor;
xwl_seat->x_cursor = cursor;
if (!cursor_visibility_changed) {
/* Cursor remains shown or hidden, apply the change immediately */
xwl_set_cursor_free_timer(xwl_seat);
xwl_seat->x_cursor = cursor;
xwl_seat_update_cursor(xwl_seat);
return;
}
if (cursor_visibility_changed)
xwl_seat_cursor_visibility_changed(xwl_seat);
xwl_seat_set_cursor(xwl_seat);
xorg_list_for_each_entry(xwl_tablet_tool, &xwl_seat->tablet_tools, link) {
if (xwl_tablet_tool->proximity_in_serial != 0)
xwl_tablet_tool_set_cursor(xwl_tablet_tool);
xwl_seat->pending_x_cursor = cursor;
if (cursor) {
/* Cursor is being shown, delay the change until moved or timed out */
xwl_set_cursor_delayed(xwl_seat, cursor);
} else {
/* Cursor is being hidden, apply the change immediately */
xwl_seat_update_cursor_visibility(xwl_seat);
}
}
static void
xwl_move_cursor(DeviceIntPtr device, ScreenPtr screen, int x, int y)
{
struct xwl_seat *xwl_seat;
xwl_seat = device->public.devicePrivate;
if (xwl_seat == NULL)
return;
xwl_set_cursor_free_timer(xwl_seat);
if (xwl_seat->pending_x_cursor)
xwl_seat_update_cursor_visibility(xwl_seat);
}
static Bool
@ -296,6 +370,11 @@ xwl_device_cursor_initialize(DeviceIntPtr device, ScreenPtr screen)
static void
xwl_device_cursor_cleanup(DeviceIntPtr device, ScreenPtr screen)
{
struct xwl_seat *xwl_seat;
xwl_seat = device->public.devicePrivate;
if (xwl_seat)
xwl_set_cursor_free_timer(xwl_seat);
}
static miPointerSpriteFuncRec xwl_pointer_sprite_funcs = {

View File

@ -75,6 +75,8 @@ struct xwl_seat {
uint32_t pointer_enter_serial;
struct xorg_list link;
CursorPtr x_cursor;
OsTimerPtr x_cursor_timer;
CursorPtr pending_x_cursor;
struct xwl_cursor cursor;
WindowPtr last_xwindow;