From e106f2096ba9fc17c0c62d8823b957fd6ea3370d Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 17 Jan 2021 14:23:51 +1100 Subject: [PATCH] [client] app: add and expose new app_handleButtonPress/Release methods --- client/include/app.h | 2 ++ client/src/main.c | 36 ++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/client/include/app.h b/client/include/app.h index 55415921..72d92744 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -35,6 +35,8 @@ void app_handleResizeEvent(int w, int h); void app_handleMouseGrabbed(double ex, double ey); void app_handleMouseNormal(double ex, double ey); void app_handleMouseBasic(void); +void app_handleButtonPress(int button); +void app_handleButtonRelease(int button); void app_handleWindowEnter(void); void app_handleWindowLeave(void); void app_handleFocusEvent(bool focused); diff --git a/client/src/main.c b/client/src/main.c index 38ee02c7..ca5db704 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1015,6 +1015,24 @@ void app_handleMouseGrabbed(double ex, double ey) DEBUG_ERROR("failed to send mouse motion message"); } +void app_handleButtonPress(int button) +{ + if (!app_inputEnabled() || !g_cursor.inView) + return; + + if (!spice_mouse_press(button)) + DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message"); +} + +void app_handleButtonRelease(int button) +{ + if (!app_inputEnabled()) + return; + + if (!spice_mouse_release(button)) + DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message"); +} + static void guestCurToLocal(struct DoublePoint *local) { local->x = g_state.dstRect.x + @@ -1444,35 +1462,21 @@ int eventFilter(void * userdata, SDL_Event * event) case SDL_MOUSEBUTTONDOWN: { - if (!app_inputEnabled() || !g_cursor.inView) - break; - int button = event->button.button; if (button > 3) button += 2; - if (!spice_mouse_press(button)) - { - DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message"); - break; - } + app_handleButtonPress(button); break; } case SDL_MOUSEBUTTONUP: { - if (!app_inputEnabled()) - break; - int button = event->button.button; if (button > 3) button += 2; - if (!spice_mouse_release(button)) - { - DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message"); - break; - } + app_handleButtonRelease(button); break; } }