cursor: Better xcursor implementation (#7178)

* xcursor: bootleg xcursors into its own manager

implent XCursorManager and load themes based on librarypath and its
dir, now we catch all supplied theme files. and also implent animated
cursors. also refactor a bit of spaghetti regarding xcursors in
CursorManager.

* hyprcursor: fix buffer leak

animated cursors are creating a new buffer for each image, ensure we
drop the buffers so it continously doesnt build up in infinity.

* cursormgr: use eventloopmgr for animation

use EvenloopManager for timers instead of adding it directly to
m_sWLEventLoop and using its related wl_* functions.
This commit is contained in:
Tom Englund
2024-08-05 19:58:21 +02:00
committed by GitHub
parent 2b520571e8
commit 0e86808e59
4 changed files with 585 additions and 408 deletions

View File

@@ -7,6 +7,8 @@
#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>
class CWLSurface;
@@ -63,6 +65,8 @@ class CCursorManager {
std::vector<SP<CCursorBuffer>> m_vCursorBuffers;
std::unique_ptr<Hyprcursor::CHyprcursorManager> m_pHyprcursor;
std::unique_ptr<CXCursorManager> m_pXcursor;
SP<SXCursors> m_currentXcursor;
std::string m_szTheme = "";
int m_iSize = 0;
@@ -70,29 +74,9 @@ class CCursorManager {
Hyprcursor::SCursorStyleInfo m_sCurrentStyleInfo;
wl_event_source* m_pAnimationTimer = nullptr;
SP<CEventLoopTimer> m_pAnimationTimer;
int m_iCurrentAnimationFrame = 0;
Hyprcursor::SCursorShapeData m_sCurrentCursorShapeData;
// gangsta bootleg XCursor impl. Whenever Hyprland has to use
// an xcursor, just use the pointer.
struct SXCursor {
Vector2D size;
Vector2D hotspot;
std::vector<uint32_t> pixels; // XPixel is a u32
};
struct SXCursorManager {
void loadTheme(const std::string& name, int size);
std::string getLegacyShapeName(std::string const& shape);
SP<SXCursor> createDefaultCursor();
int lastLoadSize = 0;
bool themeLoaded = false;
std::string themeName = "";
SP<SXCursor> defaultCursor;
std::vector<std::pair<std::string, SP<SXCursor>>> cursors;
} xcursor;
};
inline std::unique_ptr<CCursorManager> g_pCursorManager;