aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers/WLSurface.hpp
blob: e3325f9977c60645589ce13165f8420dd75f6f95 (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
#pragma once

#include "../defines.hpp"

class CWLSurface {
  public:
    CWLSurface() = default;
    CWLSurface(wlr_surface* pSurface);
    ~CWLSurface();

    void assign(wlr_surface* pSurface);
    void unassign();

    CWLSurface(const CWLSurface&) = delete;
    CWLSurface(CWLSurface&&)      = delete;
    CWLSurface&  operator=(const CWLSurface&) = delete;
    CWLSurface&  operator=(CWLSurface&&) = delete;

    wlr_surface* wlr() const;
    bool         exists() const;

    CWLSurface&  operator=(wlr_surface* pSurface) {
        destroy();
        m_pWLRSurface = pSurface;
        init();

        return *this;
    }

    bool operator==(const CWLSurface& other) const {
        return other.wlr() == wlr();
    }

    bool operator==(const wlr_surface* other) const {
        return other == wlr();
    }

    explicit operator bool() const {
        return exists();
    }

  private:
    wlr_surface* m_pWLRSurface = nullptr;

    void         destroy();
    void         init();

    DYNLISTENER(destroy);
};