aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/managers/CursorManager.hpp
blob: 629f29e111035fe79adc444aad1f289b15c1941a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include <string>
#include <hyprcursor/hyprcursor.hpp>
#include <memory>
#include "../includes.hpp"
#include "../helpers/Vector2D.hpp"

struct wlr_buffer;
struct wlr_xcursor_manager;
struct wlr_xwayland;

class CCursorManager {
  public:
    CCursorManager();
    ~CCursorManager();

    wlr_buffer*      getCursorBuffer();

    void             setCursorFromName(const std::string& name);
    void             setCursorSurface(wlr_surface* surf, const Vector2D& hotspot);

    void             changeTheme(const std::string& name, const int size);
    void             updateTheme();
    SCursorImageData dataFor(const std::string& name); // for xwayland
    void             setXWaylandCursor(wlr_xwayland* xwayland);

    void             tickAnimatedCursor();

    class CCursorBuffer {
      public:
        CCursorBuffer(cairo_surface_t* surf, const Vector2D& size, const Vector2D& hotspot);
        ~CCursorBuffer();

        struct SCursorWlrBuffer {
            wlr_buffer       base;
            cairo_surface_t* surface = nullptr;
            bool             dropped = false;
            CCursorBuffer*   parent  = nullptr;
        } wlrBuffer;

      private:
        Vector2D size;
        Vector2D hotspot;

        friend class CCursorManager;
    };

    void dropBufferRef(CCursorBuffer* ref);

    bool m_bOurBufferConnected = false;

  private:
    std::vector<std::unique_ptr<CCursorBuffer>>     m_vCursorBuffers;

    std::unique_ptr<Hyprcursor::CHyprcursorManager> m_pHyprcursor;

    std::string                                     m_szTheme      = "";
    int                                             m_iSize        = 0;
    float                                           m_fCursorScale = 1.0;

    Hyprcursor::SCursorStyleInfo                    m_sCurrentStyleInfo;

    wl_event_source*                                m_pAnimationTimer        = nullptr;
    int                                             m_iCurrentAnimationFrame = 0;
    Hyprcursor::SCursorShapeData                    m_sCurrentCursorShapeData;

    // xcursor fallback
    wlr_xcursor_manager* m_pWLRXCursorMgr = nullptr;
};

inline std::unique_ptr<CCursorManager> g_pCursorManager;