diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-08-05 19:58:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-05 19:58:21 +0200 |
| commit | 0e86808e5912823f1c6bea1b6d5fcae297fc9f57 (patch) | |
| tree | 261ff4c9a108ef9d2de1c151685d52d85405497d /src/managers/XCursorManager.hpp | |
| parent | 2b520571e897be2a0e88c8692da607b062000038 (diff) | |
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.
Diffstat (limited to 'src/managers/XCursorManager.hpp')
| -rw-r--r-- | src/managers/XCursorManager.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/managers/XCursorManager.hpp b/src/managers/XCursorManager.hpp new file mode 100644 index 00000000..9ced076f --- /dev/null +++ b/src/managers/XCursorManager.hpp @@ -0,0 +1,46 @@ +#pragma once +#include <string> +#include <vector> +#include <array> +#include <cstdint> +#include <hyprutils/math/Vector2D.hpp> +#include "helpers/memory/Memory.hpp" + +extern "C" { +#include <X11/Xcursor/Xcursor.h> +} + +// gangsta bootleg XCursor impl. adidas balkanized +struct SXCursorImage { + Vector2D size; + Vector2D hotspot; + std::vector<uint32_t> pixels; // XPixel is a u32 + uint32_t delay; // animation delay to next frame (ms) +}; + +struct SXCursors { + std::vector<SXCursorImage> images; + std::string shape; +}; + +class CXCursorManager { + public: + CXCursorManager(); + ~CXCursorManager() = default; + + void loadTheme(const std::string& name, int size); + SP<SXCursors> getShape(std::string const& shape, int size); + + private: + SP<SXCursors> createCursor(std::string const& shape, XcursorImages* xImages); + std::vector<std::string> themePaths(std::string const& theme); + std::string getLegacyShapeName(std::string const& shape); + std::vector<SP<SXCursors>> loadStandardCursors(std::string const& name, int size); + std::vector<SP<SXCursors>> loadAllFromDir(std::string const& path, int size); + + int lastLoadSize = 0; + std::string themeName = ""; + SP<SXCursors> defaultCursor; + SP<SXCursors> hyprCursor; + std::vector<SP<SXCursors>> cursors; +};
\ No newline at end of file |
