summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2023-10-20 20:15:41 +0100
committerVaxry <vaxry@vaxry.net>2023-10-20 20:15:57 +0100
commit7f35f33b4ca16509e127976772db6abd9abf100b (patch)
tree557326d4214617c3459d983001d969fbe6510448 /src/helpers
parentbab2f6a664a67dfd0c2f442dbc0134ef7c6e07e2 (diff)
surface/wayland: conform to small surface requirements
do not stretch small surfaces, instead center them if they fit.
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/WLSurface.cpp17
-rw-r--r--src/helpers/WLSurface.hpp31
2 files changed, 40 insertions, 8 deletions
diff --git a/src/helpers/WLSurface.cpp b/src/helpers/WLSurface.cpp
index 8524c9a5..a34c77a1 100644
--- a/src/helpers/WLSurface.cpp
+++ b/src/helpers/WLSurface.cpp
@@ -27,12 +27,29 @@ wlr_surface* CWLSurface::wlr() const {
return m_pWLRSurface;
}
+bool CWLSurface::small() const {
+ if (!m_pOwner || !exists())
+ return false;
+
+ return m_pOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width || m_pOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height;
+}
+
+Vector2D CWLSurface::correctSmallVec() const {
+ if (!m_pOwner || !exists() || !small() || m_bFillIgnoreSmall)
+ return {};
+
+ return Vector2D{(m_pOwner->m_vReportedSize.x - m_pWLRSurface->current.buffer_width) / 2, (m_pOwner->m_vReportedSize.y - m_pWLRSurface->current.buffer_height) / 2}.clamp(
+ {}, {INFINITY, INFINITY}) *
+ (m_pOwner->m_vRealSize.vec() / m_pOwner->m_vReportedSize);
+}
+
void CWLSurface::destroy() {
if (!m_pWLRSurface)
return;
hyprListener_destroy.removeCallback();
m_pWLRSurface->data = nullptr;
+ m_pOwner = nullptr;
if (g_pCompositor->m_pLastFocus == m_pWLRSurface)
g_pCompositor->m_pLastFocus = nullptr;
diff --git a/src/helpers/WLSurface.hpp b/src/helpers/WLSurface.hpp
index c5cdd37f..ee6574de 100644
--- a/src/helpers/WLSurface.hpp
+++ b/src/helpers/WLSurface.hpp
@@ -1,6 +1,9 @@
#pragma once
#include "../defines.hpp"
+
+class CWindow;
+
class CWLSurface {
public:
CWLSurface() = default;
@@ -10,20 +13,28 @@ class CWLSurface {
void assign(wlr_surface* pSurface);
void unassign();
- CWLSurface(const CWLSurface&) = delete;
- CWLSurface(CWLSurface&&) = delete;
+ CWLSurface(const CWLSurface&) = delete;
+ CWLSurface(CWLSurface&&) = delete;
CWLSurface& operator=(const CWLSurface&) = delete;
- CWLSurface& operator=(CWLSurface&&) = delete;
+ CWLSurface& operator=(CWLSurface&&) = delete;
wlr_surface* wlr() const;
bool exists() const;
+ bool small() const; // means surface is smaller than the requested size
+ Vector2D correctSmallVec() const; // returns a corrective vector for small() surfaces
+
+ // allow stretching. Useful for plugins.
+ bool m_bFillIgnoreSmall = false;
- CWLSurface& operator=(wlr_surface* pSurface) {
- destroy();
- m_pWLRSurface = pSurface;
- init();
+ // if present, means this is a base surface of a window. Cleaned on unassign()
+ CWindow* m_pOwner = nullptr;
- return *this;
+ CWLSurface& operator=(wlr_surface* pSurface) {
+ destroy();
+ m_pWLRSurface = pSurface;
+ init();
+
+ return *this;
}
bool operator==(const CWLSurface& other) const {
@@ -38,6 +49,10 @@ class CWLSurface {
return exists();
}
+ static CWLSurface* surfaceFromWlr(wlr_surface* pSurface) {
+ return (CWLSurface*)pSurface->data;
+ }
+
private:
wlr_surface* m_pWLRSurface = nullptr;