diff --git a/include/hyprutils/math/Region.hpp b/include/hyprutils/math/Region.hpp index f7589f2..fc13451 100644 --- a/include/hyprutils/math/Region.hpp +++ b/include/hyprutils/math/Region.hpp @@ -21,17 +21,21 @@ namespace Hyprutils { CRegion(pixman_box32_t* box); CRegion(const CRegion&); - CRegion(CRegion&&); + CRegion(CRegion&&) noexcept; ~CRegion(); - CRegion& operator=(CRegion&& other) { - pixman_region32_copy(&m_rRegion, other.pixman()); + CRegion& operator=(CRegion&& other) noexcept { + if (this != &other) + pixman_region32_copy(&m_rRegion, other.pixman()); + return *this; } - CRegion& operator=(CRegion& other) { - pixman_region32_copy(&m_rRegion, other.pixman()); + CRegion& operator=(const CRegion& other) { + if (this != &other) + pixman_region32_copy(&m_rRegion, other.pixman()); + return *this; } @@ -58,12 +62,24 @@ namespace Hyprutils { CRegion copy() const; std::vector getRects() const; + template + void forEachRect(T&& cb) const { + int rectsNum = 0; + const auto* rects = pixman_region32_rectangles(&m_rRegion, &rectsNum); + for (int i = 0; i < rectsNum; ++i) { + std::forward(cb)(rects[i]); + } + } // pixman_region32_t* pixman() { return &m_rRegion; } + const pixman_region32_t* pixman() const { + return &m_rRegion; + } + private: pixman_region32_t m_rRegion; }; diff --git a/src/math/Region.cpp b/src/math/Region.cpp index 6260b88..f05cfb0 100644 --- a/src/math/Region.cpp +++ b/src/math/Region.cpp @@ -28,10 +28,10 @@ Hyprutils::Math::CRegion::CRegion(pixman_box32_t* box) { Hyprutils::Math::CRegion::CRegion(const CRegion& other) { pixman_region32_init(&m_rRegion); - pixman_region32_copy(&m_rRegion, const_cast(&other)->pixman()); + pixman_region32_copy(&m_rRegion, other.pixman()); } -Hyprutils::Math::CRegion::CRegion(CRegion&& other) { +Hyprutils::Math::CRegion::CRegion(CRegion&& other) noexcept { pixman_region32_init(&m_rRegion); pixman_region32_copy(&m_rRegion, other.pixman()); } @@ -46,12 +46,12 @@ CRegion& Hyprutils::Math::CRegion::clear() { } CRegion& Hyprutils::Math::CRegion::set(const CRegion& other) { - pixman_region32_copy(&m_rRegion, const_cast(&other)->pixman()); + pixman_region32_copy(&m_rRegion, other.pixman()); return *this; } CRegion& Hyprutils::Math::CRegion::add(const CRegion& other) { - pixman_region32_union(&m_rRegion, &m_rRegion, const_cast(&other)->pixman()); + pixman_region32_union(&m_rRegion, &m_rRegion, other.pixman()); return *this; } @@ -66,12 +66,12 @@ CRegion& Hyprutils::Math::CRegion::add(const CBox& other) { } CRegion& Hyprutils::Math::CRegion::subtract(const CRegion& other) { - pixman_region32_subtract(&m_rRegion, &m_rRegion, const_cast(&other)->pixman()); + pixman_region32_subtract(&m_rRegion, &m_rRegion, other.pixman()); return *this; } CRegion& Hyprutils::Math::CRegion::intersect(const CRegion& other) { - pixman_region32_intersect(&m_rRegion, &m_rRegion, const_cast(&other)->pixman()); + pixman_region32_intersect(&m_rRegion, &m_rRegion, other.pixman()); return *this; }