summaryrefslogtreecommitdiff
path: root/src/desktop/Popup.hpp
blob: 964b36b6c16791abe663bb6304def345c7502ccc (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once

#include <vector>
#include "Subsurface.hpp"
#include "../helpers/signal/Signal.hpp"
#include "../helpers/memory/Memory.hpp"
#include "../helpers/AnimatedVariable.hpp"

class CXDGPopupResource;

class CPopup {
  public:
    // dummy head nodes
    static UP<CPopup> create(PHLWINDOW pOwner);
    static UP<CPopup> create(PHLLS pOwner);

    // real nodes
    static UP<CPopup> create(SP<CXDGPopupResource> popup, WP<CPopup> pOwner);

    ~CPopup();

    SP<CWLSurface> getT1Owner();
    Vector2D       coordsRelativeToParent();
    Vector2D       coordsGlobal();
    PHLMONITOR     getMonitor();

    Vector2D       size();

    void           onNewPopup(SP<CXDGPopupResource> popup);
    void           onDestroy();
    void           onMap();
    void           onUnmap();
    void           onCommit(bool ignoreSiblings = false);
    void           onReposition();

    void           recheckTree();

    bool           visible();
    bool           inert() const;

    // will also loop over this node
    void       breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data);
    WP<CPopup> at(const Vector2D& globalCoords, bool allowsInput = false);

    //
    SP<CWLSurface> m_wlSurface;
    WP<CPopup>     m_self;
    bool           m_mapped = false;

    // fade in-out
    PHLANIMVAR<float> m_alpha;
    bool              m_fadingOut = false;

  private:
    CPopup() = default;

    // T1 owners, each popup has to have one of these
    PHLWINDOWREF m_windowOwner;
    PHLLSREF     m_layerOwner;

    // T2 owners
    WP<CPopup>            m_parent;

    WP<CXDGPopupResource> m_resource;

    Vector2D              m_lastSize = {};
    Vector2D              m_lastPos  = {};

    bool                  m_requestedReposition = false;

    bool                  m_inert = false;

    //
    std::vector<UP<CPopup>> m_children;
    UP<CSubsurface>         m_subsurfaceHead;

    struct {
        CHyprSignalListener newPopup;
        CHyprSignalListener destroy;
        CHyprSignalListener map;
        CHyprSignalListener unmap;
        CHyprSignalListener commit;
        CHyprSignalListener dismissed;
        CHyprSignalListener reposition;
    } m_listeners;

    void        initAllSignals();
    void        reposition();
    void        recheckChildrenRecursive();
    void        sendScale();
    void        fullyDestroy();

    Vector2D    localToGlobal(const Vector2D& rel);
    Vector2D    t1ParentCoords();
    static void bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(WP<CPopup>, void*)> fn, void* data);
};