From e9457e08ca3ff16dc5a815be62baf9e18b539197 Mon Sep 17 00:00:00 2001 From: Mathis H Date: Thu, 11 Apr 2024 11:47:36 +0000 Subject: [PATCH] Hyprexpo: support touchscreen taps for workspace selection (#136) * feat(hyprexpo): also monitor touches for selecting workspace * refactor(hyprexpo): use same callbacks for hooks --- hyprexpo/overview.cpp | 16 ++++++++++++---- hyprexpo/overview.hpp | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/hyprexpo/overview.cpp b/hyprexpo/overview.cpp index 18ae932..56f0787 100644 --- a/hyprexpo/overview.cpp +++ b/hyprexpo/overview.cpp @@ -17,6 +17,8 @@ static void removeOverview(void*) { COverview::~COverview() { g_pHyprRenderer->makeEGLCurrent(); images.clear(); // otherwise we get a vram leak + g_pHookSystem->unhook(touchUpHook); + g_pHookSystem->unhook(touchMoveHook); g_pHookSystem->unhook(mouseButtonHook); g_pHookSystem->unhook(mouseMoveHook); g_pInputManager->unsetCursorImage(); @@ -184,15 +186,15 @@ COverview::COverview(PHLWORKSPACE startedOn_, bool swipe_) : startedOn(startedOn lastMousePosLocal = g_pInputManager->getMouseCoordsInternal() - pMonitor->vecPosition; - mouseMoveHook = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any param) { + auto onCursorMove = [this](void* self, SCallbackInfo& info, std::any param) { if (closing) return; info.cancelled = true; lastMousePosLocal = g_pInputManager->getMouseCoordsInternal() - pMonitor->vecPosition; - }); + }; - mouseButtonHook = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any param) { + auto onCursorSelect = [this](void* self, SCallbackInfo& info, std::any param) { if (closing) return; @@ -205,7 +207,13 @@ COverview::COverview(PHLWORKSPACE startedOn_, bool swipe_) : startedOn(startedOn closeOnID = x + y * SIDE_LENGTH; close(); - }); + }; + + mouseMoveHook = g_pHookSystem->hookDynamic("mouseMove", onCursorMove); + touchMoveHook = g_pHookSystem->hookDynamic("touchMove", onCursorMove); + + mouseButtonHook = g_pHookSystem->hookDynamic("mouseButton", onCursorSelect); + touchUpHook = g_pHookSystem->hookDynamic("touchUp", onCursorSelect); } void COverview::redrawID(int id, bool forcelowres) { diff --git a/hyprexpo/overview.hpp b/hyprexpo/overview.hpp index 4e75c02..8bd9972 100644 --- a/hyprexpo/overview.hpp +++ b/hyprexpo/overview.hpp @@ -70,6 +70,8 @@ class COverview { HOOK_CALLBACK_FN* mouseMoveHook = nullptr; HOOK_CALLBACK_FN* mouseButtonHook = nullptr; + HOOK_CALLBACK_FN* touchMoveHook = nullptr; + HOOK_CALLBACK_FN* touchUpHook = nullptr; bool swipe = false; bool swipeWasCommenced = false;