Skip to content

Commit

Permalink
wl: Add safe-guards for touch and pointer events
Browse files Browse the repository at this point in the history
In some unstable compositors it could be possible these 2 cases:

* to receive touch up/motion events immediatelly after a touch up
  (touch deinit the touch target).
* to receive pointer motion/leave event immediatelly after a touch
  leave (deinit the touch target).
  • Loading branch information
psaavedra authored and aperezdc committed Mar 27, 2024
1 parent e13c995 commit c0ef309
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion platform/wayland/cog-platform-wl.c
Expand Up @@ -271,8 +271,14 @@ pointer_on_enter(void *data,
static void
pointer_on_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
{
if (data == NULL || pointer == NULL)
return;

CogWlSeat *seat = data;

if (seat->pointer_target == NULL || seat->pointer.surface == NULL)
return;

if (pointer != seat->pointer_obj) {
g_critical("%s: Got pointer %p, expected %p.", G_STRFUNC, pointer, seat->pointer_obj);
return;
Expand All @@ -286,7 +292,14 @@ pointer_on_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct
static void
pointer_on_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y)
{
CogWlSeat *seat = data;
if (data == NULL || pointer == NULL)
return;

CogWlSeat *seat = data;

if (seat->pointer_target == NULL || seat->pointer.surface == NULL)
return;

CogWlDisplay *display = seat->display;

if (pointer != seat->pointer_obj) {
Expand Down Expand Up @@ -783,8 +796,14 @@ touch_on_down(void *data,
static void
touch_on_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, int32_t id)
{
if (data == NULL || touch == NULL)
return;

CogWlSeat *seat = data;

if (seat->touch_target == NULL || seat->touch.surface == NULL)
return;

if (touch != seat->touch_obj) {
g_critical("%s: Got touch %p, expected %p.", G_STRFUNC, touch, seat->touch_obj);
return;
Expand Down Expand Up @@ -833,9 +852,15 @@ touch_on_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time,
static void
touch_on_motion(void *data, struct wl_touch *touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
{
if (data == NULL || touch == NULL)
return;

CogWlSeat *seat = data;
CogWlDisplay *display = seat->display;

if (seat->touch_target == NULL || seat->touch.surface == NULL)
return;

if (touch != seat->touch_obj) {
g_critical("%s: Got touch %p, expected %p.", G_STRFUNC, touch, seat->touch_obj);
return;
Expand Down

0 comments on commit c0ef309

Please sign in to comment.