From cec147fb09eda466385e3a50b1010fe454224508 Mon Sep 17 00:00:00 2001 From: Gwilherm Folliot Date: Mon, 21 Oct 2024 10:46:56 +0200 Subject: [PATCH] input-capture: impl force release --- src/portals/InputCapture.cpp | 24 +++++++++++++++++------- src/portals/InputCapture.hpp | 1 + subprojects/hyprland-protocols | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/portals/InputCapture.cpp b/src/portals/InputCapture.cpp index 6009760..249f9a4 100644 --- a/src/portals/InputCapture.cpp +++ b/src/portals/InputCapture.cpp @@ -16,6 +16,8 @@ CInputCapturePortal::CInputCapturePortal(SP mgr) : m_sState(mgr) { Debug::log(LOG, "[input-capture] initializing input capture portal"); + mgr->setForceRelease([this](CCHyprlandInputCaptureManagerV1* r) { onForceRelease(); }); + mgr->setMotion([this](CCHyprlandInputCaptureManagerV1* r, wl_fixed_t x, wl_fixed_t y, wl_fixed_t dx, wl_fixed_t dy) { onMotion(wl_fixed_to_double(x), wl_fixed_to_double(y), wl_fixed_to_double(dx), wl_fixed_to_double(dy)); }); @@ -102,6 +104,9 @@ void CInputCapturePortal::onCreateSession(sdbus::MethodCall& call) { session->session = createDBusSession(sessionHandle); session->session->onDestroy = [session, this]() { disable(session->sessionHandle); + session->status = STOPPED; + session->eis->stopServer(); + session->eis.reset(); Debug::log(LOG, "[input-capture] Session {} destroyed", session->sessionHandle.c_str()); @@ -250,8 +255,10 @@ void CInputCapturePortal::onEnable(sdbus::MethodCall& call) { Debug::log(LOG, "[input-capture] | {}", sessionHandle.c_str()); Debug::log(LOG, "[input-capture] | appid: {}", appID); - if (!sessionValid(sessionHandle)) + if (!sessions.contains(sessionHandle)) { + Debug::log(WARN, "[input-capture] Unknown session handle: {}", sessionHandle.c_str()); return complete(call); + } sessions[sessionHandle]->status = ENABLED; @@ -324,6 +331,12 @@ bool CInputCapturePortal::sessionValid(sdbus::ObjectPath sessionHandle) { return sessions[sessionHandle]->status != STOPPED; } +void CInputCapturePortal::onForceRelease() { + Debug::log(LOG, "[input-capture] Released every captures"); + for (auto [key, value] : sessions) + disable(key); +} + bool get_line_intersection(double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y, double* i_x, double* i_y) { float s1_x, s1_y, s2_x, s2_y; s1_x = p1_x - p0_x; @@ -510,10 +523,7 @@ void CInputCapturePortal::disable(sdbus::ObjectPath sessionHandle) { if (!session->disable()) return; - session->eis->stopServer(); - session->eis.reset(); - - auto signal = m_pObject->createSignal(INTERFACE_NAME, "Disable"); + auto signal = m_pObject->createSignal(INTERFACE_NAME, "Disabled"); signal << sessionHandle; std::unordered_map options; @@ -523,8 +533,8 @@ void CInputCapturePortal::disable(sdbus::ObjectPath sessionHandle) { } bool CInputCapturePortal::SSession::disable() { - status = STOPPED; - + status = CREATED; + barriers.clear(); Debug::log(LOG, "[input-capture] Session {} disabled", sessionHandle.c_str()); return true; } diff --git a/src/portals/InputCapture.hpp b/src/portals/InputCapture.hpp index 75091f1..16095ee 100644 --- a/src/portals/InputCapture.hpp +++ b/src/portals/InputCapture.hpp @@ -29,6 +29,7 @@ class CInputCapturePortal { void onRelease(sdbus::MethodCall& methodCall); void onConnectToEIS(sdbus::MethodCall& methodCall); + void onForceRelease(); void onMotion(double x, double y, double dx, double dy); void onKeymap(int32_t fd, uint32_t size); void onKey(uint32_t key, bool pressed); diff --git a/subprojects/hyprland-protocols b/subprojects/hyprland-protocols index d3674e1..0c7cf26 160000 --- a/subprojects/hyprland-protocols +++ b/subprojects/hyprland-protocols @@ -1 +1 @@ -Subproject commit d3674e1f4eac730efc01c08e794a988be31ec73e +Subproject commit 0c7cf263faeae9429942c6ffbc1e9b5dfd709bf4