Skip to content

Commit

Permalink
cursormgr: use eventloopmgr for animation
Browse files Browse the repository at this point in the history
use EvenloopManager for timers instead of adding it directly to
m_sWLEventLoop and using its related wl_* functions.
  • Loading branch information
gulafaran committed Aug 4, 2024
1 parent f014695 commit d72a3ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/managers/CursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "PointerManager.hpp"
#include "../xwayland/XWayland.hpp"

static int cursorAnimTimer(void* data) {
g_pCursorManager->tickAnimatedCursor();
static int cursorAnimTimer(SP<CEventLoopTimer> self, void* data) {
const auto cursorMgr = reinterpret_cast<CCursorManager*>(data);
cursorMgr->tickAnimatedCursor();
return 1;
}

Expand Down Expand Up @@ -51,16 +52,19 @@ CCursorManager::CCursorManager() {
m_pXcursor->loadTheme(getenv("XCURSOR_THEME") ? getenv("XCURSOR_THEME") : "default", m_iSize * std::ceil(m_fCursorScale));
}

m_pAnimationTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ::cursorAnimTimer, nullptr);
m_pAnimationTimer = makeShared<CEventLoopTimer>(std::nullopt, cursorAnimTimer, this);
g_pEventLoopManager->addTimer(m_pAnimationTimer);

updateTheme();

static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateTheme(); });
}

CCursorManager::~CCursorManager() {
if (m_pAnimationTimer)
wl_event_source_remove(m_pAnimationTimer);
if (m_pAnimationTimer && g_pEventLoopManager) {
g_pEventLoopManager->removeTimer(m_pAnimationTimer);
m_pAnimationTimer.reset();
}
}

void CCursorManager::dropBufferRef(CCursorManager::CCursorBuffer* ref) {
Expand Down Expand Up @@ -149,11 +153,11 @@ void CCursorManager::setXCursor(const std::string& name) {

if (m_currentXcursor->images.size() > 1) {
// animated
wl_event_source_timer_update(m_pAnimationTimer, m_currentXcursor->images[0].delay);
m_pAnimationTimer->updateTimeout(std::chrono::milliseconds(m_currentXcursor->images[0].delay));
m_iCurrentAnimationFrame = 0;
} else {
// disarm
wl_event_source_timer_update(m_pAnimationTimer, 0);
m_pAnimationTimer->updateTimeout(std::nullopt);
}
}

Expand Down Expand Up @@ -207,11 +211,11 @@ void CCursorManager::setCursorFromName(const std::string& name) {

if (m_sCurrentCursorShapeData.images.size() > 1) {
// animated
wl_event_source_timer_update(m_pAnimationTimer, m_sCurrentCursorShapeData.images[0].delay);
m_pAnimationTimer->updateTimeout(std::chrono::milliseconds(m_sCurrentCursorShapeData.images[0].delay));
m_iCurrentAnimationFrame = 0;
} else {
// disarm
wl_event_source_timer_update(m_pAnimationTimer, 0);
m_pAnimationTimer->updateTimeout(std::nullopt);
}
}

Expand All @@ -231,7 +235,7 @@ void CCursorManager::tickAnimatedCursor() {
if (m_vCursorBuffers.size() > 1)
dropBufferRef(m_vCursorBuffers.at(0).get());

wl_event_source_timer_update(m_pAnimationTimer, m_currentXcursor->images[m_iCurrentAnimationFrame].delay);
m_pAnimationTimer->updateTimeout(std::chrono::milliseconds(m_currentXcursor->images[m_iCurrentAnimationFrame].delay));

return;
}
Expand All @@ -256,7 +260,7 @@ void CCursorManager::tickAnimatedCursor() {
if (m_vCursorBuffers.size() > 1)
dropBufferRef(m_vCursorBuffers.at(0).get());

wl_event_source_timer_update(m_pAnimationTimer, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].delay);
m_pAnimationTimer->updateTimeout(std::chrono::milliseconds(m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].delay));
}

SCursorImageData CCursorManager::dataFor(const std::string& name) {
Expand Down
3 changes: 2 additions & 1 deletion src/managers/CursorManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../helpers/math/Math.hpp"
#include "../helpers/memory/Memory.hpp"
#include "../macros.hpp"
#include "managers/eventLoop/EventLoopManager.hpp"
#include "managers/XCursorManager.hpp"
#include <aquamarine/buffer/Buffer.hpp>

Expand Down Expand Up @@ -73,7 +74,7 @@ class CCursorManager {

Hyprcursor::SCursorStyleInfo m_sCurrentStyleInfo;

wl_event_source* m_pAnimationTimer = nullptr;
SP<CEventLoopTimer> m_pAnimationTimer;
int m_iCurrentAnimationFrame = 0;
Hyprcursor::SCursorShapeData m_sCurrentCursorShapeData;
};
Expand Down

0 comments on commit d72a3ce

Please sign in to comment.