mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 15:45:57 +01:00
surface: unify owners
This commit is contained in:
parent
bcec082a1c
commit
6916d0a6a3
8 changed files with 124 additions and 28 deletions
|
@ -481,8 +481,7 @@ void CWindow::onUnmap() {
|
|||
|
||||
void CWindow::onMap() {
|
||||
|
||||
m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this));
|
||||
m_pWLSurface.m_pOwner = this;
|
||||
m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this), this);
|
||||
|
||||
// JIC, reset the callbacks. If any are set, we'll make sure they are cleared so we don't accidentally unset them. (In case a window got remapped)
|
||||
m_vRealPosition.resetAllCallbacks();
|
||||
|
|
|
@ -10,7 +10,7 @@ CPopup::CPopup(SLayerSurface* pOwner) : m_pLayerOwner(pOwner) {
|
|||
|
||||
CPopup::CPopup(wlr_xdg_popup* popup, CPopup* pOwner) : m_pParent(pOwner), m_pWLR(popup) {
|
||||
m_pWLR->base->data = this;
|
||||
m_sWLSurface.assign(popup->base->surface);
|
||||
m_sWLSurface.assign(popup->base->surface, this);
|
||||
|
||||
m_pLayerOwner = pOwner->m_pLayerOwner;
|
||||
m_pWindowOwner = pOwner->m_pWindowOwner;
|
||||
|
@ -222,4 +222,8 @@ void CPopup::recheckChildrenRecursive() {
|
|||
c->onCommit();
|
||||
c->recheckChildrenRecursive();
|
||||
}
|
||||
}
|
||||
|
||||
Vector2D CPopup::size() {
|
||||
return m_vLastSize;
|
||||
}
|
|
@ -20,6 +20,8 @@ class CPopup {
|
|||
Vector2D coordsRelativeToParent();
|
||||
Vector2D coordsGlobal();
|
||||
|
||||
Vector2D size();
|
||||
|
||||
void onNewPopup(wlr_xdg_popup* popup);
|
||||
void onDestroy();
|
||||
void onMap();
|
||||
|
|
|
@ -29,13 +29,13 @@ CSubsurface::CSubsurface(CPopup* pOwner) : m_pPopupParent(pOwner) {
|
|||
}
|
||||
|
||||
CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) {
|
||||
m_sWLSurface.assign(pSubsurface->surface);
|
||||
m_sWLSurface.assign(pSubsurface->surface, this);
|
||||
initSignals();
|
||||
initExistingSubsurfaces();
|
||||
}
|
||||
|
||||
CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CPopup* pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) {
|
||||
m_sWLSurface.assign(pSubsurface->surface);
|
||||
m_sWLSurface.assign(pSubsurface->surface, this);
|
||||
initSignals();
|
||||
initExistingSubsurfaces();
|
||||
}
|
||||
|
@ -254,4 +254,8 @@ void CSubsurface::initExistingSubsurfaces() {
|
|||
wl_list_for_each(wlrSubsurface, &m_sWLSurface.wlr()->current.subsurfaces_above, current.link) {
|
||||
::onNewSubsurface(this, wlrSubsurface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector2D CSubsurface::size() {
|
||||
return {m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height};
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ class CSubsurface {
|
|||
Vector2D coordsRelativeToParent();
|
||||
Vector2D coordsGlobal();
|
||||
|
||||
Vector2D size();
|
||||
|
||||
void onCommit();
|
||||
void onDestroy();
|
||||
void onNewSubsurface(wlr_subsurface* pSubsurface);
|
||||
|
|
|
@ -1,14 +1,38 @@
|
|||
#include "WLSurface.hpp"
|
||||
#include "../Compositor.hpp"
|
||||
|
||||
CWLSurface::CWLSurface(wlr_surface* pSurface) {
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
}
|
||||
|
||||
void CWLSurface::assign(wlr_surface* pSurface) {
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
m_bInert = false;
|
||||
}
|
||||
|
||||
void CWLSurface::assign(wlr_surface* pSurface, CWindow* pOwner) {
|
||||
m_pWindowOwner = pOwner;
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
m_bInert = false;
|
||||
}
|
||||
|
||||
void CWLSurface::assign(wlr_surface* pSurface, SLayerSurface* pOwner) {
|
||||
m_pLayerOwner = pOwner;
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
m_bInert = false;
|
||||
}
|
||||
|
||||
void CWLSurface::assign(wlr_surface* pSurface, CSubsurface* pOwner) {
|
||||
m_pSubsurfaceOwner = pOwner;
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
m_bInert = false;
|
||||
}
|
||||
|
||||
void CWLSurface::assign(wlr_surface* pSurface, CPopup* pOwner) {
|
||||
m_pPopupOwner = pOwner;
|
||||
m_pWLRSurface = pSurface;
|
||||
init();
|
||||
m_bInert = false;
|
||||
}
|
||||
|
||||
void CWLSurface::unassign() {
|
||||
|
@ -28,20 +52,20 @@ wlr_surface* CWLSurface::wlr() const {
|
|||
}
|
||||
|
||||
bool CWLSurface::small() const {
|
||||
if (!m_pOwner || !exists())
|
||||
if (!m_pWindowOwner || !exists())
|
||||
return false;
|
||||
|
||||
return m_pOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
|
||||
return m_pWindowOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pWindowOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
|
||||
}
|
||||
|
||||
Vector2D CWLSurface::correctSmallVec() const {
|
||||
if (!m_pOwner || !exists() || !small() || m_bFillIgnoreSmall)
|
||||
if (!m_pWindowOwner || !exists() || !small() || m_bFillIgnoreSmall)
|
||||
return {};
|
||||
|
||||
const auto SIZE = getViewporterCorrectedSize();
|
||||
|
||||
return Vector2D{(m_pOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) *
|
||||
(m_pOwner->m_vRealSize.vec() / m_pOwner->m_vReportedSize);
|
||||
return Vector2D{(m_pWindowOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pWindowOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) *
|
||||
(m_pWindowOwner->m_vRealSize.vec() / m_pWindowOwner->m_vReportedSize);
|
||||
}
|
||||
|
||||
Vector2D CWLSurface::getViewporterCorrectedSize() const {
|
||||
|
@ -81,7 +105,11 @@ void CWLSurface::destroy() {
|
|||
|
||||
hyprListener_destroy.removeCallback();
|
||||
m_pWLRSurface->data = nullptr;
|
||||
m_pOwner = nullptr;
|
||||
m_pWindowOwner = nullptr;
|
||||
m_pLayerOwner = nullptr;
|
||||
m_pPopupOwner = nullptr;
|
||||
m_pSubsurfaceOwner = nullptr;
|
||||
m_bInert = true;
|
||||
|
||||
if (g_pCompositor && g_pCompositor->m_pLastFocus == m_pWLRSurface)
|
||||
g_pCompositor->m_pLastFocus = nullptr;
|
||||
|
@ -107,4 +135,40 @@ void CWLSurface::init() {
|
|||
&m_pWLRSurface->events.destroy, [&](void* owner, void* data) { destroy(); }, this, "CWLSurface");
|
||||
|
||||
Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this);
|
||||
}
|
||||
|
||||
CWindow* CWLSurface::getWindow() {
|
||||
return m_pWindowOwner;
|
||||
}
|
||||
|
||||
SLayerSurface* CWLSurface::getLayer() {
|
||||
return m_pLayerOwner;
|
||||
}
|
||||
|
||||
CPopup* CWLSurface::getPopup() {
|
||||
return m_pPopupOwner;
|
||||
}
|
||||
|
||||
CSubsurface* CWLSurface::getSubsurface() {
|
||||
return m_pSubsurfaceOwner;
|
||||
}
|
||||
|
||||
bool CWLSurface::desktopComponent() {
|
||||
return m_pLayerOwner || m_pWindowOwner || m_pSubsurfaceOwner || m_pPopupOwner;
|
||||
}
|
||||
|
||||
std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() {
|
||||
if (!desktopComponent())
|
||||
return {};
|
||||
|
||||
if (m_pWindowOwner)
|
||||
return m_pWindowOwner->getWindowMainSurfaceBox();
|
||||
if (m_pLayerOwner)
|
||||
return m_pLayerOwner->geometry;
|
||||
if (m_pPopupOwner)
|
||||
return CBox{m_pPopupOwner->coordsGlobal(), m_pPopupOwner->size()};
|
||||
if (m_pSubsurfaceOwner)
|
||||
return CBox{m_pSubsurfaceOwner->coordsGlobal(), m_pSubsurfaceOwner->size()};
|
||||
|
||||
return {};
|
||||
}
|
|
@ -4,14 +4,21 @@
|
|||
#include "../helpers/Region.hpp"
|
||||
|
||||
class CWindow;
|
||||
struct SLayerSurface;
|
||||
class CSubsurface;
|
||||
class CPopup;
|
||||
|
||||
class CWLSurface {
|
||||
public:
|
||||
CWLSurface() = default;
|
||||
CWLSurface(wlr_surface* pSurface);
|
||||
~CWLSurface();
|
||||
|
||||
// anonymous surfaces are non-desktop components, e.g. a cursor surface or a DnD
|
||||
void assign(wlr_surface* pSurface);
|
||||
void assign(wlr_surface* pSurface, CWindow* pOwner);
|
||||
void assign(wlr_surface* pSurface, SLayerSurface* pOwner);
|
||||
void assign(wlr_surface* pSurface, CSubsurface* pOwner);
|
||||
void assign(wlr_surface* pSurface, CPopup* pOwner);
|
||||
void unassign();
|
||||
|
||||
CWLSurface(const CWLSurface&) = delete;
|
||||
|
@ -26,12 +33,18 @@ class CWLSurface {
|
|||
Vector2D getViewporterCorrectedSize() const;
|
||||
CRegion logicalDamage() const;
|
||||
|
||||
// getters for owners.
|
||||
CWindow* getWindow();
|
||||
SLayerSurface* getLayer();
|
||||
CPopup* getPopup();
|
||||
CSubsurface* getSubsurface();
|
||||
|
||||
// desktop components misc utils
|
||||
std::optional<CBox> getSurfaceBoxGlobal();
|
||||
|
||||
// allow stretching. Useful for plugins.
|
||||
bool m_bFillIgnoreSmall = false;
|
||||
|
||||
// if present, means this is a base surface of a window. Cleaned on unassign()
|
||||
CWindow* m_pOwner = nullptr;
|
||||
|
||||
// track surface data and avoid dupes
|
||||
float m_fLastScale = 0;
|
||||
int m_iLastScale = 0;
|
||||
|
@ -63,10 +76,18 @@ class CWLSurface {
|
|||
}
|
||||
|
||||
private:
|
||||
wlr_surface* m_pWLRSurface = nullptr;
|
||||
bool m_bInert = true;
|
||||
|
||||
void destroy();
|
||||
void init();
|
||||
wlr_surface* m_pWLRSurface = nullptr;
|
||||
|
||||
CWindow* m_pWindowOwner = nullptr;
|
||||
SLayerSurface* m_pLayerOwner = nullptr;
|
||||
CPopup* m_pPopupOwner = nullptr;
|
||||
CSubsurface* m_pSubsurfaceOwner = nullptr;
|
||||
|
||||
void destroy();
|
||||
void init();
|
||||
bool desktopComponent();
|
||||
|
||||
DYNLISTENER(destroy);
|
||||
};
|
|
@ -70,7 +70,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data)
|
|||
// however, if surface buffer w / h < box, we need to adjust them
|
||||
auto* const PSURFACE = CWLSurface::surfaceFromWlr(surface);
|
||||
|
||||
if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees m_pOwner */) {
|
||||
if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees m_pWindowOwner */) {
|
||||
const auto CORRECT = PSURFACE->correctSmallVec();
|
||||
const auto SIZE = PSURFACE->getViewporterCorrectedSize();
|
||||
|
||||
|
@ -78,8 +78,8 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data)
|
|||
windowBox.x += CORRECT.x;
|
||||
windowBox.y += CORRECT.y;
|
||||
|
||||
windowBox.width = SIZE.x * (PSURFACE->m_pOwner->m_vRealSize.vec().x / PSURFACE->m_pOwner->m_vReportedSize.x);
|
||||
windowBox.height = SIZE.y * (PSURFACE->m_pOwner->m_vRealSize.vec().y / PSURFACE->m_pOwner->m_vReportedSize.y);
|
||||
windowBox.width = SIZE.x * (PSURFACE->getWindow()->m_vRealSize.vec().x / PSURFACE->getWindow()->m_vReportedSize.x);
|
||||
windowBox.height = SIZE.y * (PSURFACE->getWindow()->m_vRealSize.vec().y / PSURFACE->getWindow()->m_vReportedSize.y);
|
||||
} else {
|
||||
windowBox.width = SIZE.x;
|
||||
windowBox.height = SIZE.y;
|
||||
|
@ -1590,7 +1590,7 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou
|
|||
return;
|
||||
|
||||
auto* const PSURFACE = CWLSurface::surfaceFromWlr(pSurface);
|
||||
if (PSURFACE && PSURFACE->m_pOwner && PSURFACE->small()) {
|
||||
if (PSURFACE && PSURFACE->small()) {
|
||||
const auto CORRECTION = PSURFACE->correctSmallVec();
|
||||
x += CORRECTION.x;
|
||||
y += CORRECTION.y;
|
||||
|
|
Loading…
Reference in a new issue