From b7b41a7bf21ccb543735e3ed2492e197a3aa50d2 Mon Sep 17 00:00:00 2001 From: Jason Aunkst Date: Fri, 25 Nov 2022 14:03:55 -0500 Subject: [PATCH] fix issue with sdl touch_ids being out of range --- src/wlserver.cpp | 40 ++++++++-------------------------------- src/wlserver.hpp | 4 ++-- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/wlserver.cpp b/src/wlserver.cpp index c1d7132..8b45605 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -59,7 +59,9 @@ extern "C" { static LogScope wl_log("wlserver"); -static struct wlserver_t wlserver = {}; +static struct wlserver_t wlserver = { + .touch_down_ids = {} +}; struct wlserver_content_override { struct wlr_surface *surface; @@ -70,7 +72,6 @@ struct wlserver_content_override { enum wlserver_touch_click_mode g_nDefaultTouchClickMode = WLSERVER_TOUCH_CLICK_LEFT; enum wlserver_touch_click_mode g_nTouchClickMode = g_nDefaultTouchClickMode; -static std::set wlserver_touch_down_ids = {}; static struct wl_list pending_surfaces = {0}; @@ -1113,26 +1114,6 @@ void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time ) bump_input_counter(); } - -void wlserver_capture_touch_down( int touch_id ) -{ - if ( wlserver_touch_down_ids.size() < WLSERVER_TOUCH_COUNT ) - { - wlserver_touch_down_ids.insert( touch_id ); - } -} - -void wlserver_release_touch_down( int touch_id ) -{ - wlserver_touch_down_ids.erase( touch_id ); -} - -bool wlserver_touch_is_down( int touch_id ) -{ - return wlserver_touch_down_ids.find( touch_id ) != wlserver_touch_down_ids.end(); -} - - void wlserver_touchdown( double x, double y, int touch_id, uint32_t time ) { if ( wlserver.mouse_focus_surface != NULL ) @@ -1153,14 +1134,10 @@ void wlserver_touchdown( double x, double y, int touch_id, uint32_t time ) if ( g_nTouchClickMode == WLSERVER_TOUCH_CLICK_PASSTHROUGH ) { - int wlserver_touch_down_count = wlserver_touch_down_ids.size(); - if (wlserver_touch_down_count >= 0 && wlserver_touch_down_count < WLSERVER_TOUCH_COUNT ) - { - wlr_seat_touch_notify_down( wlserver.wlr.seat, wlserver.mouse_focus_surface, time, touch_id, - wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory ); + wlr_seat_touch_notify_down( wlserver.wlr.seat, wlserver.mouse_focus_surface, time, touch_id, + wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory ); - wlserver_capture_touch_down( touch_id ); - } + wlserver.touch_down_ids.insert( touch_id ); } else if ( g_nTouchClickMode == WLSERVER_TOUCH_CLICK_DISABLED ) { @@ -1214,11 +1191,10 @@ void wlserver_touchup( int touch_id, uint32_t time ) wlr_seat_pointer_notify_frame( wlserver.wlr.seat ); } - int wlserver_touch_down_count = wlserver_touch_down_ids.size(); - if ( wlserver_touch_down_count >= 0 && wlserver_touch_down_count < WLSERVER_TOUCH_COUNT && wlserver_touch_is_down(touch_id) ) + if ( wlserver.touch_down_ids.count( touch_id ) > 0 ) { wlr_seat_touch_notify_up( wlserver.wlr.seat, time, touch_id ); - wlserver_release_touch_down( touch_id ); + wlserver.touch_down_ids.erase( touch_id ); } } diff --git a/src/wlserver.hpp b/src/wlserver.hpp index e1d8c74..042e7d6 100644 --- a/src/wlserver.hpp +++ b/src/wlserver.hpp @@ -8,9 +8,9 @@ #include #include #include +#include #define WLSERVER_BUTTON_COUNT 4 -#define WLSERVER_TOUCH_COUNT 11 // Ten fingers + nose ought to be enough for anyone struct _XDisplay; struct xwayland_ctx_t; @@ -94,7 +94,7 @@ struct wlserver_t { double mouse_surface_cursory; bool button_held[ WLSERVER_BUTTON_COUNT ]; - bool touch_down[ WLSERVER_TOUCH_COUNT ]; + std::set touch_down_ids; struct { char *name;