From fc72df8e58bc127442a245f2f29a3246acf77cce Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 11 May 2024 01:02:57 +0100 Subject: seatmgr: Add a grab class --- src/managers/SeatManager.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/managers/SeatManager.hpp') diff --git a/src/managers/SeatManager.hpp b/src/managers/SeatManager.hpp index ef114024..16f11ffd 100644 --- a/src/managers/SeatManager.hpp +++ b/src/managers/SeatManager.hpp @@ -14,6 +14,37 @@ class CWLSeatResource; class IPointer; class IKeyboard; +/* + A seat grab defines a restricted set of surfaces that can be focused. + Only one grab can be active at a time + + when a grab is removed, refocus() will happen + + Different from a constraint. + + When first set with setGrab, SeatManager will try to find a surface that is at the mouse pointer to focus, + from first added to last added. If none are, first is focused. +*/ +class CSeatGrab { + public: + bool accepts(wlr_surface* surf); + void add(wlr_surface* surf); + void remove(wlr_surface* surf); + void setCallback(std::function onEnd_); + void clear(); + + bool keyboard = false; + bool pointer = false; + bool touch = false; + + bool removeOnInput = true; // on hard input e.g. click outside, remove + + private: + std::vector surfs; // read-only + std::function onEnd; + friend class CSeatManager; +}; + class CSeatManager { public: CSeatManager(); @@ -76,6 +107,9 @@ class CSeatManager { WP mouse; WP keyboard; + void setGrab(SP grab); // nullptr removes + SP seatGrab; + private: struct SSeatResourceContainer { SSeatResourceContainer(SP); @@ -92,6 +126,8 @@ class CSeatManager { void onNewSeatResource(SP resource); SP containerForResource(SP seatResource); + void refocusGrab(); + struct { CHyprSignalListener newSeatResource; } listeners; @@ -101,6 +137,7 @@ class CSeatManager { DYNLISTENER(touchSurfaceDestroy); friend struct SSeatResourceContainer; + friend class CSeatGrab; }; inline UP g_pSeatManager; -- cgit v1.2.3