summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-07-19 20:09:49 +0200
committerGitHub <noreply@github.com>2023-07-19 20:09:49 +0200
commit89b87158dbf100e4177f4a010190ba5f80252eb2 (patch)
treecacff8d4257c0e4a1f95937c969075df0b07c280 /src/helpers
parentce9896204a2ab1eb4f8960d44b876cbc9d0955ac (diff)
internal: Wrap regions (#2750)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Monitor.cpp6
-rw-r--r--src/helpers/Monitor.hpp4
-rw-r--r--src/helpers/Region.cpp93
-rw-r--r--src/helpers/Region.hpp53
-rw-r--r--src/helpers/WLClasses.hpp3
5 files changed, 155 insertions, 4 deletions
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 390bd3c4..a860585d 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -10,12 +10,10 @@ int ratHandler(void* data) {
CMonitor::CMonitor() {
wlr_damage_ring_init(&damage);
- pixman_region32_init(&lastFrameDamage);
}
CMonitor::~CMonitor() {
wlr_damage_ring_finish(&damage);
- pixman_region32_fini(&lastFrameDamage);
hyprListener_monitorDestroy.removeCallback();
hyprListener_monitorFrame.removeCallback();
@@ -331,6 +329,10 @@ void CMonitor::addDamage(const pixman_region32_t* rg) {
g_pCompositor->scheduleFrameForMonitor(this);
}
+void CMonitor::addDamage(const CRegion* rg) {
+ addDamage(const_cast<CRegion*>(rg)->pixman());
+}
+
void CMonitor::addDamage(const wlr_box* box) {
static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue;
if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) {
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index 08fe5f2b..b453bc8c 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -8,6 +8,7 @@
#include <memory>
#include <xf86drmMode.h>
#include "Timer.hpp"
+#include "Region.hpp"
struct SMonitorRule;
@@ -61,7 +62,7 @@ class CMonitor {
CMonitor* pMirrorOf = nullptr;
std::vector<CMonitor*> mirrors;
- pixman_region32_t lastFrameDamage; // stores last frame damage
+ CRegion lastFrameDamage; // stores last frame damage
// for the special workspace. 0 means not open.
int specialWorkspaceID = 0;
@@ -84,6 +85,7 @@ class CMonitor {
void onConnect(bool noRule);
void onDisconnect();
void addDamage(const pixman_region32_t* rg);
+ void addDamage(const CRegion* rg);
void addDamage(const wlr_box* box);
void setMirror(const std::string&);
bool isMirror();
diff --git a/src/helpers/Region.cpp b/src/helpers/Region.cpp
new file mode 100644
index 00000000..3a210d06
--- /dev/null
+++ b/src/helpers/Region.cpp
@@ -0,0 +1,93 @@
+#include "Region.hpp"
+#include <wlr/util/box.h>
+
+CRegion::CRegion() {
+ pixman_region32_init(&m_rRegion);
+}
+
+CRegion::CRegion(pixman_region32_t* ref) {
+ pixman_region32_init(&m_rRegion);
+ pixman_region32_copy(&m_rRegion, ref);
+}
+
+CRegion::CRegion(double x, double y, double w, double h) {
+ pixman_region32_init_rect(&m_rRegion, x, y, w, h);
+}
+
+CRegion::CRegion(wlr_box* box) {
+ pixman_region32_init_rect(&m_rRegion, box->x, box->y, box->width, box->height);
+}
+
+CRegion::CRegion(const CRegion& other) {
+ pixman_region32_init(&m_rRegion);
+ pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
+}
+
+CRegion::CRegion(CRegion&& other) {
+ pixman_region32_init(&m_rRegion);
+ pixman_region32_copy(&m_rRegion, other.pixman());
+}
+
+CRegion::~CRegion() {
+ pixman_region32_fini(&m_rRegion);
+}
+
+CRegion& CRegion::clear() {
+ pixman_region32_clear(&m_rRegion);
+ return *this;
+}
+
+CRegion& CRegion::set(const CRegion& other) {
+ pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
+ return *this;
+}
+
+CRegion& CRegion::add(const CRegion& other) {
+ pixman_region32_union(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
+ return *this;
+}
+
+CRegion& CRegion::add(double x, double y, double w, double h) {
+ pixman_region32_union_rect(&m_rRegion, &m_rRegion, x, y, w, h);
+ return *this;
+}
+
+CRegion& CRegion::subtract(const CRegion& other) {
+ pixman_region32_subtract(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
+ return *this;
+}
+
+CRegion& CRegion::intersect(const CRegion& other) {
+ pixman_region32_intersect(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
+ return *this;
+}
+
+CRegion& CRegion::intersect(double x, double y, double w, double h) {
+ pixman_region32_intersect_rect(&m_rRegion, &m_rRegion, x, y, w, h);
+ return *this;
+}
+
+CRegion& CRegion::invert(pixman_box32_t* box) {
+ pixman_region32_inverse(&m_rRegion, &m_rRegion, box);
+ return *this;
+}
+
+CRegion& CRegion::translate(const Vector2D& vec) {
+ pixman_region32_translate(&m_rRegion, vec.x, vec.y);
+ return *this;
+}
+
+std::vector<pixman_box32_t> CRegion::getRects() const {
+ std::vector<pixman_box32_t> result;
+
+ int rectsNum = 0;
+ const auto RECTSARR = pixman_region32_rectangles(&m_rRegion, &rectsNum);
+
+ result.assign(RECTSARR, RECTSARR + rectsNum);
+
+ return result;
+}
+
+bool CRegion::empty() {
+ return !pixman_region32_not_empty(&m_rRegion);
+}
diff --git a/src/helpers/Region.hpp b/src/helpers/Region.hpp
new file mode 100644
index 00000000..5c700fa5
--- /dev/null
+++ b/src/helpers/Region.hpp
@@ -0,0 +1,53 @@
+#pragma once
+#include <pixman.h>
+#include <vector>
+#include "Vector2D.hpp"
+
+struct wlr_box;
+
+class CRegion {
+ public:
+ /* Create an empty region */
+ CRegion();
+ /* Create from a reference. Copies, does not own. */
+ CRegion(pixman_region32_t* ref);
+ /* Create from a box */
+ CRegion(double x, double y, double w, double h);
+ /* Create from a wlr_box */
+ CRegion(wlr_box* box);
+
+ CRegion(const CRegion&);
+ CRegion(CRegion&&);
+
+ ~CRegion();
+
+ CRegion& operator=(CRegion&& other) {
+ pixman_region32_copy(&m_rRegion, other.pixman());
+ return *this;
+ }
+
+ CRegion& operator=(CRegion& other) {
+ pixman_region32_copy(&m_rRegion, other.pixman());
+ return *this;
+ }
+
+ CRegion& clear();
+ CRegion& set(const CRegion& other);
+ CRegion& add(const CRegion& other);
+ CRegion& add(double x, double y, double w, double h);
+ CRegion& subtract(const CRegion& other);
+ CRegion& intersect(const CRegion& other);
+ CRegion& intersect(double x, double y, double w, double h);
+ CRegion& translate(const Vector2D& vec);
+ CRegion& invert(pixman_box32_t* box);
+ bool empty();
+
+ std::vector<pixman_box32_t> getRects() const;
+
+ pixman_region32_t* pixman() {
+ return &m_rRegion;
+ }
+
+ private:
+ pixman_region32_t m_rRegion;
+}; \ No newline at end of file
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index b7cd6e34..18e223b6 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -7,6 +7,7 @@
#include "SubsurfaceTree.hpp"
#include "AnimatedVariable.hpp"
#include "WLSurface.hpp"
+#include "Region.hpp"
struct SLayerRule {
std::string targetNamespace = "";
@@ -144,7 +145,7 @@ struct SMouse {
wlr_pointer_constraint_v1* currentConstraint = nullptr;
bool constraintActive = false;
- pixman_region32_t confinedTo;
+ CRegion confinedTo;
std::string name = "";