From be3cc0ff7acf249b4e8ed6b91770870449ed45b6 Mon Sep 17 00:00:00 2001 From: extra-salad <87635414+extra-salad@users.noreply.github.com> Date: Wed, 13 May 2026 01:18:18 +0100 Subject: [PATCH] refactor(wayland): factor portal barrier creation Move repeated InputCapture pointer barrier construction into a helper and add a small side-to-name utility for logging. This keeps the existing barrier geometry and activation handling unchanged while making later barrier metadata changes easier to review. --- src/lib/platform/PortalInputCapture.cpp | 108 +++++++++++++++--------- src/lib/platform/PortalInputCapture.h | 17 +++- 2 files changed, 82 insertions(+), 43 deletions(-) diff --git a/src/lib/platform/PortalInputCapture.cpp b/src/lib/platform/PortalInputCapture.cpp index 0a063cf40..3981651ab 100644 --- a/src/lib/platform/PortalInputCapture.cpp +++ b/src/lib/platform/PortalInputCapture.cpp @@ -1,6 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers + * SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers * SPDX-FileCopyrightText: (C) 2024 Symless Ltd. * SPDX-FileCopyrightText: (C) 2022 Red Hat, Inc. * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -21,6 +21,24 @@ namespace deskflow { +const char *PortalInputCapture::barrierSideName(BarrierSide side) +{ + using enum BarrierSide; + + switch (side) { + case Left: + return "left"; + case Right: + return "right"; + case Top: + return "top"; + case Bottom: + return "bottom"; + } + + return "unknown"; +} + PortalInputCapture::PortalInputCapture(EiScreen *screen, IEventQueue *events) : m_screen{screen}, m_events{events}, @@ -182,6 +200,49 @@ void PortalInputCapture::handleSetPointerBarriers(const GObject *, GAsyncResult enable(); } +void PortalInputCapture::addBarrier( + guint id, BarrierSide side, gint zoneX, gint zoneY, guint zoneWidth, guint zoneHeight +) +{ + gint x1 = 0; + gint x2 = 0; + gint y1 = 0; + gint y2 = 0; + + using enum BarrierSide; + switch (side) { + case Left: + x1 = zoneX; + y1 = zoneY; + x2 = zoneX; + y2 = zoneY + static_cast(zoneHeight) - 1; + break; + case Right: + x1 = zoneX + static_cast(zoneWidth); + y1 = zoneY; + x2 = x1; + y2 = zoneY + static_cast(zoneHeight) - 1; + break; + case Top: + x1 = zoneX; + y1 = zoneY; + x2 = zoneX + static_cast(zoneWidth) - 1; + y2 = zoneY; + break; + case Bottom: + x1 = zoneX; + y1 = zoneY + static_cast(zoneHeight); + x2 = zoneX + static_cast(zoneWidth) - 1; + y2 = y1; + break; + } + + LOG_DEBUG("barrier (%s) %u at %d,%d-%d,%d", barrierSideName(side), id, x1, y1, x2, y2); + m_barriers.push_back(XDP_INPUT_CAPTURE_POINTER_BARRIER( + g_object_new(XDP_TYPE_INPUT_CAPTURE_POINTER_BARRIER, "id", id, "x1", x1, "y1", y1, "x2", x2, "y2", y2, nullptr) + )); +} + gboolean PortalInputCapture::initSession() { LOG_DEBUG("setting up input capture session"); @@ -364,59 +425,22 @@ void PortalInputCapture::handleZonesChanged(XdpInputCaptureSession *session, con LOG_DEBUG("input capture zone, %dx%d@%d,%d", w, h, x, y); - int x1; - int x2; - int y1; - int y2; - auto id = 0; if (activeSides & static_cast(LeftMask)) { - id++; - x1 = x; - y1 = y; - x2 = x; - y2 = y + h - 1; - LOG_DEBUG("barrier (left) %zd at %d,%d-%d,%d", id, x1, y1, x2, y2); - m_barriers.push_back(XDP_INPUT_CAPTURE_POINTER_BARRIER(g_object_new( - XDP_TYPE_INPUT_CAPTURE_POINTER_BARRIER, "id", id, "x1", x1, "y1", y1, "x2", x2, "y2", y2, nullptr - ))); + addBarrier(++id, BarrierSide::Left, x, y, w, h); } if (activeSides & static_cast(RightMask)) { - id++; - x1 = x + w; - y1 = y; - x2 = x + w; - y2 = y + h - 1; - LOG_DEBUG("barrier (right) %zd at %d,%d-%d,%d", id, x1, y1, x2, y2); - m_barriers.push_back(XDP_INPUT_CAPTURE_POINTER_BARRIER(g_object_new( - XDP_TYPE_INPUT_CAPTURE_POINTER_BARRIER, "id", id, "x1", x1, "y1", y1, "x2", x2, "y2", y2, nullptr - ))); + addBarrier(++id, BarrierSide::Right, x, y, w, h); } if (activeSides & static_cast(TopMask)) { - id++; - x1 = x; - y1 = y; - x2 = x + w - 1; - y2 = y; - LOG_DEBUG("barrier (top) %zd at %d,%d-%d,%d", id, x1, y1, x2, y2); - m_barriers.push_back(XDP_INPUT_CAPTURE_POINTER_BARRIER(g_object_new( - XDP_TYPE_INPUT_CAPTURE_POINTER_BARRIER, "id", id, "x1", x1, "y1", y1, "x2", x2, "y2", y2, nullptr - ))); + addBarrier(++id, BarrierSide::Top, x, y, w, h); } if (activeSides & static_cast(BottomMask)) { - id++; - x1 = x; - y1 = y + h; - x2 = x + w - 1; - y2 = y + h; - LOG_DEBUG("barrier (bottom) %zd at %d,%d-%d,%d", id, x1, y1, x2, y2); - m_barriers.push_back(XDP_INPUT_CAPTURE_POINTER_BARRIER(g_object_new( - XDP_TYPE_INPUT_CAPTURE_POINTER_BARRIER, "id", id, "x1", x1, "y1", y1, "x2", x2, "y2", y2, nullptr - ))); + addBarrier(++id, BarrierSide::Bottom, x, y, w, h); } zones = zones->next; } diff --git a/src/lib/platform/PortalInputCapture.h b/src/lib/platform/PortalInputCapture.h index 5237186ef..e3572b304 100644 --- a/src/lib/platform/PortalInputCapture.h +++ b/src/lib/platform/PortalInputCapture.h @@ -1,6 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers + * SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers * SPDX-FileCopyrightText: (C) 2024 Symless Ltd. * SPDX-FileCopyrightText: (C) 2022 Red Hat, Inc. * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -15,6 +15,10 @@ #include #include +#include +#include +#include + namespace deskflow { class PortalInputCapture @@ -83,6 +87,17 @@ private: ZonesChanged }; + enum class BarrierSide : uint8_t + { + Left, + Right, + Top, + Bottom + }; + + static const char *barrierSideName(BarrierSide side); + void addBarrier(guint id, BarrierSide side, gint zoneX, gint zoneY, guint zoneWidth, guint zoneHeight); + EiScreen *m_screen = nullptr; IEventQueue *m_events = nullptr; int m_portalVersion = 0;