summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Fourdan <ofourdan@redhat.com>2021-03-03 17:56:55 +0100
committerMichel Dänzer <mdaenzer@redhat.com>2021-03-03 17:56:55 +0100
commit15f8b789049eb3cfab0f811d29b9c8d377ae941d (patch)
tree9f65dbd35067d49b896bc19c4a2ebe1bdef374b1
parentefd546cd1eff8a205ecf43a318d3ec38e02eaa40 (diff)
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 (cherry picked from commit 97ed0048e45f4909a0c164b27e768af8c9364068)
-rw-r--r--hw/xwayland/xwayland-cursor.c99
-rw-r--r--hw/xwayland/xwayland-input.h2
2 files changed, 91 insertions, 10 deletions
diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c
index 91cc18464..fac8840e6 100644
--- a/hw/xwayland/xwayland-cursor.c
+++ b/hw/xwayland/xwayland-cursor.c
@@ -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
@@ -256,11 +258,68 @@ xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *xwl_tablet_tool)
}
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)
- xwl_seat_cursor_visibility_changed(xwl_seat);
-
- xwl_seat_set_cursor(xwl_seat);
+ 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;
+ }
- 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 = {
diff --git a/hw/xwayland/xwayland-input.h b/hw/xwayland/xwayland-input.h
index e7e21fcfd..0c6591b5e 100644
--- a/hw/xwayland/xwayland-input.h
+++ b/hw/xwayland/xwayland-input.h
@@ -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;