diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2024-05-05 17:16:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-05 17:16:00 +0100 |
| commit | 1ed1ce9506e65f76fe5236194516f23d662bba0b (patch) | |
| tree | 124556baadfe27587d025913bfbdd579060ed317 /src/managers | |
| parent | 589f758d947cb4e8b888d2da00076a9fb0a6d521 (diff) | |
internal: new shared_ptr and weak_ptr implementation (#5883)
moves std::shared_ptrs to a new implementation
Advantages:
- you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired.
- this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.)
- weak_ptrs are still valid while the SP is being destroyed.
- reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection)
- this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though.
- this is useful in destructors and callbacks.
Diffstat (limited to 'src/managers')
| -rw-r--r-- | src/managers/AnimationManager.cpp | 4 | ||||
| -rw-r--r-- | src/managers/AnimationManager.hpp | 2 | ||||
| -rw-r--r-- | src/managers/HookSystemManager.cpp | 12 | ||||
| -rw-r--r-- | src/managers/HookSystemManager.hpp | 10 | ||||
| -rw-r--r-- | src/managers/KeybindManager.cpp | 28 | ||||
| -rw-r--r-- | src/managers/SessionLockManager.cpp | 8 | ||||
| -rw-r--r-- | src/managers/TokenManager.cpp | 6 | ||||
| -rw-r--r-- | src/managers/TokenManager.hpp | 13 | ||||
| -rw-r--r-- | src/managers/eventLoop/EventLoopManager.cpp | 4 | ||||
| -rw-r--r-- | src/managers/eventLoop/EventLoopManager.hpp | 9 | ||||
| -rw-r--r-- | src/managers/eventLoop/EventLoopTimer.cpp | 8 | ||||
| -rw-r--r-- | src/managers/eventLoop/EventLoopTimer.hpp | 14 | ||||
| -rw-r--r-- | src/managers/input/IdleInhibitor.cpp | 4 | ||||
| -rw-r--r-- | src/managers/input/InputManager.cpp | 21 | ||||
| -rw-r--r-- | src/managers/input/InputManager.hpp | 8 | ||||
| -rw-r--r-- | src/managers/input/InputMethodPopup.cpp | 4 | ||||
| -rw-r--r-- | src/managers/input/InputMethodRelay.cpp | 6 | ||||
| -rw-r--r-- | src/managers/input/TextInput.cpp | 14 | ||||
| -rw-r--r-- | src/managers/input/TextInput.hpp | 14 | ||||
| -rw-r--r-- | src/managers/input/Touch.cpp | 19 |
20 files changed, 103 insertions, 105 deletions
diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index c39df580..21c1055f 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -7,7 +7,7 @@ #include "../desktop/LayerSurface.hpp" #include "eventLoop/EventLoopManager.hpp" -int wlTick(std::shared_ptr<CEventLoopTimer> self, void* data) { +int wlTick(SP<CEventLoopTimer> self, void* data) { if (g_pAnimationManager) g_pAnimationManager->onTicked(); @@ -27,7 +27,7 @@ CAnimationManager::CAnimationManager() { std::vector<Vector2D> points = {Vector2D(0, 0.75f), Vector2D(0.15f, 1.f)}; m_mBezierCurves["default"].setup(&points); - m_pAnimationTimer = std::make_unique<CEventLoopTimer>(std::chrono::microseconds(500), wlTick, nullptr); + m_pAnimationTimer = SP<CEventLoopTimer>(new CEventLoopTimer(std::chrono::microseconds(500), wlTick, nullptr)); g_pEventLoopManager->addTimer(m_pAnimationTimer); } diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 5d4d0e1c..601a38b3 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -33,7 +33,7 @@ class CAnimationManager { std::vector<CBaseAnimatedVariable*> m_vAnimatedVariables; std::vector<CBaseAnimatedVariable*> m_vActiveAnimatedVariables; - std::shared_ptr<CEventLoopTimer> m_pAnimationTimer; + SP<CEventLoopTimer> m_pAnimationTimer; float m_fLastTickTime; // in ms diff --git a/src/managers/HookSystemManager.cpp b/src/managers/HookSystemManager.cpp index 11007f1a..a1920863 100644 --- a/src/managers/HookSystemManager.cpp +++ b/src/managers/HookSystemManager.cpp @@ -7,16 +7,16 @@ CHookSystemManager::CHookSystemManager() { } // returns the pointer to the function -std::shared_ptr<HOOK_CALLBACK_FN> CHookSystemManager::hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, HANDLE handle) { - std::shared_ptr<HOOK_CALLBACK_FN> hookFN = std::make_shared<HOOK_CALLBACK_FN>(fn); +SP<HOOK_CALLBACK_FN> CHookSystemManager::hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, HANDLE handle) { + SP<HOOK_CALLBACK_FN> hookFN = makeShared<HOOK_CALLBACK_FN>(fn); m_mRegisteredHooks[event].emplace_back(SCallbackFNPtr{.fn = hookFN, .handle = handle}); return hookFN; } -void CHookSystemManager::unhook(std::shared_ptr<HOOK_CALLBACK_FN> fn) { +void CHookSystemManager::unhook(SP<HOOK_CALLBACK_FN> fn) { for (auto& [k, v] : m_mRegisteredHooks) { std::erase_if(v, [&](const auto& other) { - std::shared_ptr<HOOK_CALLBACK_FN> fn_ = other.fn.lock(); + SP<HOOK_CALLBACK_FN> fn_ = other.fn.lock(); return fn_.get() == fn.get(); }); @@ -37,7 +37,7 @@ void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCal if (!cb.handle) { // we don't guard hl hooks - if (std::shared_ptr<HOOK_CALLBACK_FN> fn = cb.fn.lock()) + if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock()) (*fn)(fn.get(), info, data); else needsDeadCleanup = true; @@ -51,7 +51,7 @@ void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCal try { if (!setjmp(m_jbHookFaultJumpBuf)) { - if (std::shared_ptr<HOOK_CALLBACK_FN> fn = cb.fn.lock()) + if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock()) (*fn)(fn.get(), info, data); else needsDeadCleanup = true; diff --git a/src/managers/HookSystemManager.hpp b/src/managers/HookSystemManager.hpp index 4b27fadf..75377aaa 100644 --- a/src/managers/HookSystemManager.hpp +++ b/src/managers/HookSystemManager.hpp @@ -16,8 +16,8 @@ typedef std::function<void(void*, SCallbackInfo& info, std::any data)> HOOK_CALLBACK_FN; struct SCallbackFNPtr { - std::weak_ptr<HOOK_CALLBACK_FN> fn; - HANDLE handle = nullptr; + WP<HOOK_CALLBACK_FN> fn; + HANDLE handle = nullptr; }; #define EMIT_HOOK_EVENT(name, param) \ @@ -43,9 +43,9 @@ class CHookSystemManager { // returns the pointer to the function. // losing this pointer (letting it get destroyed) // will equal to unregistering the callback. - [[nodiscard("Losing this pointer instantly unregisters the callback")]] std::shared_ptr<HOOK_CALLBACK_FN> hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, - HANDLE handle = nullptr); - void unhook(std::shared_ptr<HOOK_CALLBACK_FN> fn); + [[nodiscard("Losing this pointer instantly unregisters the callback")]] SP<HOOK_CALLBACK_FN> hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, + HANDLE handle = nullptr); + void unhook(SP<HOOK_CALLBACK_FN> fn); void emit(std::vector<SCallbackFNPtr>* const callbacks, SCallbackInfo& info, std::any data = 0); std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 7708a77a..16b631c8 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -532,7 +532,7 @@ int repeatKeyHandler(void* data) { Debug::log(LOG, "Keybind repeat triggered, calling dispatcher."); DISPATCHER->second((*ppActiveKeybind)->arg); - wl_event_source_timer_update(g_pKeybindManager->m_pActiveKeybindEventSource, 1000 / g_pCompositor->m_sSeat.keyboard.lock()->repeatRate); + wl_event_source_timer_update(g_pKeybindManager->m_pActiveKeybindEventSource, 1000 / g_pCompositor->m_sSeat.keyboard->repeatRate); return 0; } @@ -1162,7 +1162,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace); } - if (PWINDOW == g_pCompositor->m_pLastWindow.lock()) { + if (PWINDOW == g_pCompositor->m_pLastWindow) { if (const auto PATCOORDS = g_pCompositor->vectorToWindowUnified(OLDMIDDLE, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, PWINDOW); PATCOORDS) g_pCompositor->focusWindow(PATCOORDS); else @@ -1910,7 +1910,7 @@ void CKeybindManager::pass(std::string regexp) { return; } - const auto XWTOXW = PWINDOW->m_bIsX11 && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsX11; + const auto XWTOXW = PWINDOW->m_bIsX11 && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsX11; const auto SL = Vector2D(g_pCompositor->m_sSeat.seat->pointer_state.sx, g_pCompositor->m_sSeat.seat->pointer_state.sy); uint32_t keycodes[32] = {0}; @@ -2026,9 +2026,9 @@ void CKeybindManager::swapnext(std::string arg) { const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); - const auto PLASTCYCLED = validMapped(g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow) && - g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow.lock()->m_pWorkspace == PLASTWINDOW->m_pWorkspace ? - g_pCompositor->m_pLastWindow.lock()->m_pLastCycledWindow.lock() : + const auto PLASTCYCLED = + validMapped(g_pCompositor->m_pLastWindow->m_pLastCycledWindow) && g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_pWorkspace == PLASTWINDOW->m_pWorkspace ? + g_pCompositor->m_pLastWindow->m_pLastCycledWindow.lock() : nullptr; if (arg == "last" || arg == "l" || arg == "prev" || arg == "p") @@ -2151,7 +2151,7 @@ void CKeybindManager::mouse(std::string args) { } void CKeybindManager::bringActiveToTop(std::string args) { - if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsFloating) g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow.lock(), true); } @@ -2160,7 +2160,7 @@ void CKeybindManager::alterZOrder(std::string args) { const auto POSITION = args.substr(0, args.find_first_of(',')); auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); - if (!PWINDOW && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + if (!PWINDOW && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsFloating) PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) { @@ -2183,8 +2183,8 @@ void CKeybindManager::alterZOrder(std::string args) { void CKeybindManager::fakeFullscreenActive(std::string args) { if (!g_pCompositor->m_pLastWindow.expired()) { // will also set the flag - g_pCompositor->m_pLastWindow.lock()->m_bFakeFullscreenState = !g_pCompositor->m_pLastWindow.lock()->m_bFakeFullscreenState; - g_pXWaylandManager->setWindowFullscreen(g_pCompositor->m_pLastWindow.lock(), g_pCompositor->m_pLastWindow.lock()->shouldSendFullscreenState()); + g_pCompositor->m_pLastWindow->m_bFakeFullscreenState = !g_pCompositor->m_pLastWindow->m_bFakeFullscreenState; + g_pXWaylandManager->setWindowFullscreen(g_pCompositor->m_pLastWindow.lock(), g_pCompositor->m_pLastWindow->shouldSendFullscreenState()); } } @@ -2349,7 +2349,7 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { const bool ISWINDOWGROUPSINGLE = ISWINDOWGROUP && PWINDOW->m_sGroupData.pNextWindow.lock() == PWINDOW; // note: PWINDOWINDIR is not null implies !PWINDOW->m_bIsFloating - if (PWINDOWINDIR && PWINDOWINDIR->m_sGroupData.pNextWindow.lock()) { // target is group + if (PWINDOWINDIR && PWINDOWINDIR->m_sGroupData.pNextWindow) { // target is group if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || ISWINDOWGROUPLOCKED || PWINDOW->m_sGroupData.deny)) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); g_pCompositor->warpCursorTo(PWINDOW->middle()); @@ -2416,9 +2416,9 @@ void CKeybindManager::moveGroupWindow(std::string args) { if (!PLASTWINDOW || !PLASTWINDOW->m_sGroupData.pNextWindow.lock()) return; - if ((!BACK && PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.head) || (BACK && PLASTWINDOW->m_sGroupData.head)) { - std::swap(PLASTWINDOW->m_sGroupData.head, PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.head); - std::swap(PLASTWINDOW->m_sGroupData.locked, PLASTWINDOW->m_sGroupData.pNextWindow.lock()->m_sGroupData.locked); + if ((!BACK && PLASTWINDOW->m_sGroupData.pNextWindow->m_sGroupData.head) || (BACK && PLASTWINDOW->m_sGroupData.head)) { + std::swap(PLASTWINDOW->m_sGroupData.head, PLASTWINDOW->m_sGroupData.pNextWindow->m_sGroupData.head); + std::swap(PLASTWINDOW->m_sGroupData.locked, PLASTWINDOW->m_sGroupData.pNextWindow->m_sGroupData.locked); } else PLASTWINDOW->switchWithWindowInGroup(BACK ? PLASTWINDOW->getGroupPrevious() : PLASTWINDOW->m_sGroupData.pNextWindow.lock()); diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index d1c609d3..6dd096bb 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -5,12 +5,12 @@ #include "../protocols/SessionLock.hpp" SSessionLockSurface::SSessionLockSurface(SP<CSessionLockSurface> surface_) : surface(surface_) { - pWlrSurface = surface.lock()->surface(); + pWlrSurface = surface->surface(); listeners.map = surface_->events.map.registerListener([this](std::any data) { mapped = true; - g_pCompositor->focusSurface(surface.lock()->surface()); + g_pCompositor->focusSurface(surface->surface()); const auto PMONITOR = g_pCompositor->getMonitorFromID(iMonitorID); @@ -124,7 +124,7 @@ bool CSessionLockManager::isSurfaceSessionLock(wlr_surface* pSurface) { return false; for (auto& sls : m_pSessionLock->vSessionLockSurfaces) { - if (sls->surface.lock()->surface() == pSurface) + if (sls->surface->surface() == pSurface) return true; } @@ -144,7 +144,7 @@ void CSessionLockManager::removeSessionLockSurface(SSessionLockSurface* pSLS) { if (!sls->mapped) continue; - g_pCompositor->focusSurface(sls->surface.lock()->surface()); + g_pCompositor->focusSurface(sls->surface->surface()); break; } } diff --git a/src/managers/TokenManager.cpp b/src/managers/TokenManager.cpp index 89db3256..451baac1 100644 --- a/src/managers/TokenManager.cpp +++ b/src/managers/TokenManager.cpp @@ -26,11 +26,11 @@ std::string CTokenManager::getRandomUUID() { std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_clock::duration expires) { std::string uuid = getRandomUUID(); - m_mTokens[uuid] = std::make_shared<CUUIDToken>(uuid, data, expires); + m_mTokens[uuid] = makeShared<CUUIDToken>(uuid, data, expires); return uuid; } -std::shared_ptr<CUUIDToken> CTokenManager::getToken(const std::string& uuid) { +SP<CUUIDToken> CTokenManager::getToken(const std::string& uuid) { // cleanup expired tokens const auto NOW = std::chrono::system_clock::now(); @@ -42,7 +42,7 @@ std::shared_ptr<CUUIDToken> CTokenManager::getToken(const std::string& uuid) { return m_mTokens.at(uuid); } -void CTokenManager::removeToken(std::shared_ptr<CUUIDToken> token) { +void CTokenManager::removeToken(SP<CUUIDToken> token) { if (!token) return; m_mTokens.erase(token->uuid); diff --git a/src/managers/TokenManager.hpp b/src/managers/TokenManager.hpp index ead02275..afe8c55b 100644 --- a/src/managers/TokenManager.hpp +++ b/src/managers/TokenManager.hpp @@ -1,11 +1,12 @@ #pragma once -#include <memory> #include <chrono> #include <any> #include <unordered_map> #include <string> +#include "../helpers/memory/SharedPtr.hpp" + class CUUIDToken { public: CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::system_clock::duration expires); @@ -24,14 +25,14 @@ class CUUIDToken { class CTokenManager { public: - std::string registerNewToken(std::any data, std::chrono::system_clock::duration expires); - std::string getRandomUUID(); + std::string registerNewToken(std::any data, std::chrono::system_clock::duration expires); + std::string getRandomUUID(); - std::shared_ptr<CUUIDToken> getToken(const std::string& uuid); - void removeToken(std::shared_ptr<CUUIDToken> token); + SP<CUUIDToken> getToken(const std::string& uuid); + void removeToken(SP<CUUIDToken> token); private: - std::unordered_map<std::string, std::shared_ptr<CUUIDToken>> m_mTokens; + std::unordered_map<std::string, SP<CUUIDToken>> m_mTokens; }; inline std::unique_ptr<CTokenManager> g_pTokenManager;
\ No newline at end of file diff --git a/src/managers/eventLoop/EventLoopManager.cpp b/src/managers/eventLoop/EventLoopManager.cpp index 20de570c..c78bc551 100644 --- a/src/managers/eventLoop/EventLoopManager.cpp +++ b/src/managers/eventLoop/EventLoopManager.cpp @@ -38,12 +38,12 @@ void CEventLoopManager::onTimerFire() { nudgeTimers(); } -void CEventLoopManager::addTimer(std::shared_ptr<CEventLoopTimer> timer) { +void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) { m_sTimers.timers.push_back(timer); nudgeTimers(); } -void CEventLoopManager::removeTimer(std::shared_ptr<CEventLoopTimer> timer) { +void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) { std::erase_if(m_sTimers.timers, [timer](const auto& t) { return timer == t; }); nudgeTimers(); } diff --git a/src/managers/eventLoop/EventLoopManager.hpp b/src/managers/eventLoop/EventLoopManager.hpp index ccd70123..13d74571 100644 --- a/src/managers/eventLoop/EventLoopManager.hpp +++ b/src/managers/eventLoop/EventLoopManager.hpp @@ -2,7 +2,6 @@ #include <condition_variable> #include <mutex> -#include <memory> #include <thread> #include <wayland-server.h> @@ -13,8 +12,8 @@ class CEventLoopManager { CEventLoopManager(); void enterLoop(wl_display* display, wl_event_loop* wlEventLoop); - void addTimer(std::shared_ptr<CEventLoopTimer> timer); - void removeTimer(std::shared_ptr<CEventLoopTimer> timer); + void addTimer(SP<CEventLoopTimer> timer); + void removeTimer(SP<CEventLoopTimer> timer); void onTimerFire(); @@ -28,8 +27,8 @@ class CEventLoopManager { } m_sWayland; struct { - std::vector<std::shared_ptr<CEventLoopTimer>> timers; - int timerfd = -1; + std::vector<SP<CEventLoopTimer>> timers; + int timerfd = -1; } m_sTimers; }; diff --git a/src/managers/eventLoop/EventLoopTimer.cpp b/src/managers/eventLoop/EventLoopTimer.cpp index 5ece1cac..dbb405e5 100644 --- a/src/managers/eventLoop/EventLoopTimer.cpp +++ b/src/managers/eventLoop/EventLoopTimer.cpp @@ -2,10 +2,8 @@ #include <limits> #include "EventLoopManager.hpp" -CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(std::shared_ptr<CEventLoopTimer> self, void* data)> cb_, - void* data_) : - cb(cb_), - data(data_) { +CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) : + cb(cb_), data(data_) { if (!timeout.has_value()) expires.reset(); @@ -40,7 +38,7 @@ bool CEventLoopTimer::cancelled() { return wasCancelled; } -void CEventLoopTimer::call(std::shared_ptr<CEventLoopTimer> self) { +void CEventLoopTimer::call(SP<CEventLoopTimer> self) { expires.reset(); cb(self, data); } diff --git a/src/managers/eventLoop/EventLoopTimer.hpp b/src/managers/eventLoop/EventLoopTimer.hpp index 8865d29f..fc0b2522 100644 --- a/src/managers/eventLoop/EventLoopTimer.hpp +++ b/src/managers/eventLoop/EventLoopTimer.hpp @@ -4,9 +4,11 @@ #include <functional> #include <optional> +#include "../../helpers/memory/SharedPtr.hpp" + class CEventLoopTimer { public: - CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(std::shared_ptr<CEventLoopTimer> self, void* data)> cb_, void* data_); + CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_); // if not specified, disarms. // if specified, arms. @@ -19,11 +21,11 @@ class CEventLoopTimer { bool cancelled(); // resets expires - void call(std::shared_ptr<CEventLoopTimer> self); + void call(SP<CEventLoopTimer> self); private: - std::function<void(std::shared_ptr<CEventLoopTimer> self, void* data)> cb; - void* data = nullptr; - std::optional<std::chrono::system_clock::time_point> expires; - bool wasCancelled = false; + std::function<void(SP<CEventLoopTimer> self, void* data)> cb; + void* data = nullptr; + std::optional<std::chrono::system_clock::time_point> expires; + bool wasCancelled = false; }; diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 468ea58b..a71059e4 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -5,11 +5,11 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { const auto PINHIBIT = m_vIdleInhibitors.emplace_back(std::make_unique<SIdleInhibitor>()).get(); - PINHIBIT->inhibitor = std::any_cast<std::shared_ptr<CIdleInhibitor>>(inhibitor); + PINHIBIT->inhibitor = std::any_cast<SP<CIdleInhibitor>>(inhibitor); Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface); - PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource.lock()->events.destroy.registerListener([this, PINHIBIT](std::any data) { + PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource->events.destroy.registerListener([this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); recheckIdleInhibitorStatus(); }); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 81ceae79..6d493e5b 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -250,7 +250,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (!PSLS) return; - foundSurface = PSLS->surface.lock()->surface(); + foundSurface = PSLS->surface->surface(); surfacePos = PMONITOR->vecPosition; } @@ -408,7 +408,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_pFoundSurfaceToFocus = foundSurface; } - if (currentlyDraggedWindow.lock() && pFoundWindow != currentlyDraggedWindow.lock()) { + if (currentlyDraggedWindow.lock() && pFoundWindow != currentlyDraggedWindow) { wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); return; @@ -434,8 +434,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (FOLLOWMOUSE != 1 && !refocus) { if (pFoundWindow != g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock() && - ((pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR == 2) || - (g_pCompositor->m_pLastWindow.lock()->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR != 0))) { + ((pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR == 2) || (g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR != 0))) { // enter if change floating style if (FOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); @@ -446,12 +445,12 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); } - if (pFoundWindow == g_pCompositor->m_pLastWindow.lock()) { + if (pFoundWindow == g_pCompositor->m_pLastWindow) { m_pLastMouseSurface = foundSurface; wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); } - if (FOLLOWMOUSE != 0 || pFoundWindow == g_pCompositor->m_pLastWindow.lock()) + if (FOLLOWMOUSE != 0 || pFoundWindow == g_pCompositor->m_pLastWindow) wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); m_bLastFocusOnLS = false; @@ -671,7 +670,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { } // if clicked on a floating window make it top - if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow.lock()->m_bIsFloating) + if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsFloating) g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow.lock(), true); break; @@ -1172,9 +1171,9 @@ void CInputManager::destroyKeyboard(SP<IKeyboard> pKeyboard) { std::erase_if(m_vKeyboards, [pKeyboard](const auto& other) { return other == pKeyboard; }); if (m_vKeyboards.size() > 0) { - g_pCompositor->m_sSeat.keyboard = m_vKeyboards.back(); - g_pCompositor->m_sSeat.keyboard.lock()->active = true; - wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, g_pCompositor->m_sSeat.keyboard.lock()->wlr()); + g_pCompositor->m_sSeat.keyboard = m_vKeyboards.back(); + g_pCompositor->m_sSeat.keyboard->active = true; + wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, g_pCompositor->m_sSeat.keyboard->wlr()); } else { g_pCompositor->m_sSeat.keyboard.reset(); wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, nullptr); @@ -1278,7 +1277,7 @@ bool CInputManager::shouldIgnoreVirtualKeyboard(SP<IKeyboard> pKeyboard) { CVirtualKeyboard* vk = (CVirtualKeyboard*)pKeyboard.get(); - return !pKeyboard || (!m_sIMERelay.m_pIME.expired() && m_sIMERelay.m_pIME.lock()->grabClient() == vk->getClient()); + return !pKeyboard || (!m_sIMERelay.m_pIME.expired() && m_sIMERelay.m_pIME->grabClient() == vk->getClient()); } void CInputManager::refocus() { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 329748b2..7d78c133 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -144,7 +144,7 @@ class CInputManager { std::deque<PHLLSREF> m_dExclusiveLSes; // constraints - std::vector<std::weak_ptr<CPointerConstraint>> m_vConstraints; + std::vector<WP<CPointerConstraint>> m_vConstraints; // void newTabletTool(wlr_input_device*); @@ -241,9 +241,9 @@ class CInputManager { // idle inhibitors struct SIdleInhibitor { - std::shared_ptr<CIdleInhibitor> inhibitor; - bool nonDesktop = false; - CHyprSignalListener surfaceDestroyListener; + SP<CIdleInhibitor> inhibitor; + bool nonDesktop = false; + CHyprSignalListener surfaceDestroyListener; }; std::vector<std::unique_ptr<SIdleInhibitor>> m_vIdleInhibitors; diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index f2d49ae8..9ff584e6 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -73,7 +73,7 @@ void CInputPopup::damageSurface() { } void CInputPopup::updateBox() { - if (!popup.lock()->mapped) + if (!popup->mapped) return; const auto OWNER = queryOwner(); @@ -114,7 +114,7 @@ void CInputPopup::updateBox() { popupOffset.x -= popupOverflow; CBox cursorBoxLocal({-popupOffset.x, -popupOffset.y}, cursorBoxParent.size()); - popup.lock()->sendInputRectangle(cursorBoxLocal); + popup->sendInputRectangle(cursorBoxLocal); CBox popupBoxParent(cursorBoxParent.pos() + popupOffset, currentPopupSize); if (popupBoxParent != lastBoxLocal) { diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index 778f3086..abf18fba 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -85,7 +85,7 @@ CTextInput* CInputMethodRelay::getFocusedTextInput() { } void CInputMethodRelay::onNewTextInput(std::any tiv3) { - m_vTextInputs.emplace_back(std::make_unique<CTextInput>(std::any_cast<std::weak_ptr<CTextInputV3>>(tiv3))); + m_vTextInputs.emplace_back(std::make_unique<CTextInput>(std::any_cast<WP<CTextInputV3>>(tiv3))); } void CInputMethodRelay::onNewTextInput(STextInputV1* pTIV1) { @@ -106,7 +106,7 @@ void CInputMethodRelay::activateIME(CTextInput* pInput) { if (m_pIME.expired()) return; - m_pIME.lock()->activate(); + m_pIME->activate(); commitIMEState(pInput); } @@ -114,7 +114,7 @@ void CInputMethodRelay::deactivateIME(CTextInput* pInput) { if (m_pIME.expired()) return; - m_pIME.lock()->deactivate(); + m_pIME->deactivate(); commitIMEState(pInput); } diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 77718174..b3f0b0cb 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -11,7 +11,7 @@ CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) { initCallbacks(); } -CTextInput::CTextInput(std::weak_ptr<CTextInputV3> ti) : pV3Input(ti) { +CTextInput::CTextInput(WP<CTextInputV3> ti) : pV3Input(ti) { initCallbacks(); } @@ -109,7 +109,7 @@ void CTextInput::onCommit() { return; } - if (!(isV3() ? pV3Input.lock()->current.enabled : pV1Input->active)) { + if (!(isV3() ? pV3Input->current.enabled : pV1Input->active)) { Debug::log(WARN, "Disabled TextInput commit?"); return; } @@ -180,7 +180,7 @@ void CTextInput::enter(wlr_surface* pSurface) { } if (isV3()) - pV3Input.lock()->enter(pSurface); + pV3Input->enter(pSurface); else { zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->resource); pV1Input->active = true; @@ -200,7 +200,7 @@ void CTextInput::leave() { } if (isV3() && focusedSurface()) - pV3Input.lock()->leave(focusedSurface()); + pV3Input->leave(focusedSurface()); else if (focusedSurface() && pV1Input) { zwp_text_input_v1_send_leave(pV1Input->resourceImpl); pV1Input->active = false; @@ -216,7 +216,7 @@ wlr_surface* CTextInput::focusedSurface() { } wl_client* CTextInput::client() { - return isV3() ? pV3Input.lock()->client() : pV1Input->client; + return isV3() ? pV3Input->client() : pV1Input->client; } void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) { @@ -284,9 +284,9 @@ void CTextInput::updateIMEState(SP<CInputMethodV2> ime) { } bool CTextInput::hasCursorRectangle() { - return !isV3() || pV3Input.lock()->current.box.updated; + return !isV3() || pV3Input->current.box.updated; } CBox CTextInput::cursorBox() { - return CBox{isV3() ? pV3Input.lock()->current.box.cursorBox : pV1Input->cursorRectangle}; + return CBox{isV3() ? pV3Input->current.box.cursorBox : pV1Input->cursorRectangle}; }
\ No newline at end of file diff --git a/src/managers/input/TextInput.hpp b/src/managers/input/TextInput.hpp index 481d60c1..ff21da95 100644 --- a/src/managers/input/TextInput.hpp +++ b/src/managers/input/TextInput.hpp @@ -15,7 +15,7 @@ class CInputMethodV2; class CTextInput { public: - CTextInput(std::weak_ptr<CTextInputV3> ti); + CTextInput(WP<CTextInputV3> ti); CTextInput(STextInputV1* ti); ~CTextInput(); @@ -37,13 +37,13 @@ class CTextInput { wlr_surface* focusedSurface(); private: - void setFocusedSurface(wlr_surface* pSurface); - void initCallbacks(); + void setFocusedSurface(wlr_surface* pSurface); + void initCallbacks(); - wlr_surface* pFocusedSurface = nullptr; - int enterLocks = 0; - std::weak_ptr<CTextInputV3> pV3Input; - STextInputV1* pV1Input = nullptr; + wlr_surface* pFocusedSurface = nullptr; + int enterLocks = 0; + WP<CTextInputV3> pV3Input; + STextInputV1* pV1Input = nullptr; DYNLISTENER(textInputEnable); DYNLISTENER(textInputDisable); diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 8f6e2226..7b0d6190 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -38,7 +38,7 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { if (m_sActiveSwipe.pWorkspaceBegin) { return; // TODO: Don't swipe if you touched a floating window. - } else if (*PSWIPETOUCH && (m_pFoundLSToFocus.expired() || m_pFoundLSToFocus.lock()->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) { + } else if (*PSWIPETOUCH && (m_pFoundLSToFocus.expired() || m_pFoundLSToFocus->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) { const auto PWORKSPACE = PMONITOR->activeWorkspace; const bool VERTANIMS = PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); @@ -67,16 +67,15 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { Vector2D local; if (!m_sTouchData.touchFocusWindow.expired()) { - if (m_sTouchData.touchFocusWindow.lock()->m_bIsX11) { - local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow.lock()->m_vRealPosition.goal()) * - m_sTouchData.touchFocusWindow.lock()->m_fX11SurfaceScaledBy; - m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow.lock()->m_vRealPosition.goal(); + if (m_sTouchData.touchFocusWindow->m_bIsX11) { + local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goal()) * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; + m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_vRealPosition.goal(); } else { g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow.lock(), local); m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local; } } else if (!m_sTouchData.touchFocusLS.expired()) { - local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusLS.lock()->geometry.pos(); + local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusLS->geometry.pos(); m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local; } else { @@ -130,18 +129,18 @@ void CInputManager::onTouchMove(wlr_touch_motion_event* e) { return; } if (validMapped(m_sTouchData.touchFocusWindow)) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow.lock()->m_iMonitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y); auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin; - if (m_sTouchData.touchFocusWindow.lock()->m_bIsX11) - local = local * m_sTouchData.touchFocusWindow.lock()->m_fX11SurfaceScaledBy; + if (m_sTouchData.touchFocusWindow->m_bIsX11) + local = local * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y); // wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, local.x, local.y); } else if (!m_sTouchData.touchFocusLS.expired()) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLS.lock()->monitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLS->monitorID); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y); |
