summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroutfoxxed <outfoxxed@outfoxxed.me>2025-01-01 15:34:02 -0800
committerGitHub <noreply@github.com>2025-01-01 23:34:02 +0000
commitdde3e082c96cd6987420556bfc430cd5b8e0980c (patch)
treeeb034fbc2fa747637758f09fc276887477633bfc /src
parent9f3c9ac01a9a6ecef74429dc9a1dea250ef43c50 (diff)
protocols: add hyprland_surface_v1 implementation (#8877)
Diffstat (limited to 'src')
-rw-r--r--src/desktop/WLSurface.hpp5
-rw-r--r--src/managers/ProtocolManager.cpp4
-rw-r--r--src/protocols/HyprlandSurface.cpp111
-rw-r--r--src/protocols/HyprlandSurface.hpp54
-rw-r--r--src/render/OpenGL.cpp7
-rw-r--r--src/render/OpenGL.hpp3
-rw-r--r--src/render/pass/SurfacePassElement.cpp13
7 files changed, 186 insertions, 11 deletions
diff --git a/src/desktop/WLSurface.hpp b/src/desktop/WLSurface.hpp
index a962b882..346fc935 100644
--- a/src/desktop/WLSurface.hpp
+++ b/src/desktop/WLSurface.hpp
@@ -86,6 +86,9 @@ class CWLSurface {
// used by the alpha-modifier protocol
float m_pAlphaModifier = 1.F;
+ // used by the hyprland-surface protocol
+ float m_fOverallOpacity = 1.F;
+
struct {
CSignal destroy;
} events;
@@ -116,4 +119,4 @@ class CWLSurface {
} listeners;
friend class CPointerConstraint;
-}; \ No newline at end of file
+};
diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp
index cf517b22..0e1c21f5 100644
--- a/src/managers/ProtocolManager.cpp
+++ b/src/managers/ProtocolManager.cpp
@@ -47,6 +47,7 @@
#include "../protocols/SinglePixel.hpp"
#include "../protocols/SecurityContext.hpp"
#include "../protocols/CTMControl.hpp"
+#include "../protocols/HyprlandSurface.hpp"
#include "../protocols/core/Seat.hpp"
#include "../protocols/core/DataDevice.hpp"
@@ -159,6 +160,7 @@ CProtocolManager::CProtocolManager() {
PROTO::singlePixel = std::make_unique<CSinglePixelProtocol>(&wp_single_pixel_buffer_manager_v1_interface, 1, "SinglePixel");
PROTO::securityContext = std::make_unique<CSecurityContextProtocol>(&wp_security_context_manager_v1_interface, 1, "SecurityContext");
PROTO::ctm = std::make_unique<CHyprlandCTMControlProtocol>(&hyprland_ctm_control_manager_v1_interface, 1, "CTMControl");
+ PROTO::hyprlandSurface = std::make_unique<CHyprlandSurfaceProtocol>(&hyprland_surface_manager_v1_interface, 1, "HyprlandSurface");
for (auto const& b : g_pCompositor->m_pAqBackend->getImplementations()) {
if (b->type() != Aquamarine::AQ_BACKEND_DRM)
@@ -232,6 +234,7 @@ CProtocolManager::~CProtocolManager() {
PROTO::singlePixel.reset();
PROTO::securityContext.reset();
PROTO::ctm.reset();
+ PROTO::hyprlandSurface.reset();
PROTO::lease.reset();
PROTO::sync.reset();
@@ -282,6 +285,7 @@ bool CProtocolManager::isGlobalPrivileged(const wl_global* global) {
PROTO::xdgDialog->getGlobal(),
PROTO::singlePixel->getGlobal(),
PROTO::primarySelection->getGlobal(),
+ PROTO::hyprlandSurface->getGlobal(),
PROTO::sync ? PROTO::sync->getGlobal() : nullptr,
PROTO::mesaDRM ? PROTO::mesaDRM->getGlobal() : nullptr,
PROTO::linuxDma ? PROTO::linuxDma->getGlobal() : nullptr,
diff --git a/src/protocols/HyprlandSurface.cpp b/src/protocols/HyprlandSurface.cpp
new file mode 100644
index 00000000..ce6fc77a
--- /dev/null
+++ b/src/protocols/HyprlandSurface.cpp
@@ -0,0 +1,111 @@
+#include "HyprlandSurface.hpp"
+#include "../desktop/WLSurface.hpp"
+#include "../render/Renderer.hpp"
+#include "core/Compositor.hpp"
+#include "hyprland-surface-v1.hpp"
+
+CHyprlandSurface::CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface) : m_pSurface(surface) {
+ setResource(std::move(resource));
+}
+
+bool CHyprlandSurface::good() const {
+ return m_pResource->resource();
+}
+
+void CHyprlandSurface::setResource(SP<CHyprlandSurfaceV1> resource) {
+ m_pResource = std::move(resource);
+
+ if (!m_pResource->resource())
+ return;
+
+ m_pResource->setDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
+ m_pResource->setOnDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
+
+ m_pResource->setSetOpacity([this](CHyprlandSurfaceV1* resource, uint32_t opacity) {
+ if (!m_pSurface) {
+ m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE, "set_opacity called for destroyed wl_surface");
+ return;
+ }
+
+ auto fOpacity = wl_fixed_to_double(opacity);
+ if (fOpacity < 0.0 || fOpacity > 1.0) {
+ m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE, "set_opacity called with an opacity value larger than 1.0 or smaller than 0.0.");
+ return;
+ }
+
+ m_fOpacity = fOpacity;
+ });
+
+ listeners.surfaceCommitted = m_pSurface->events.commit.registerListener([this](std::any data) {
+ auto surface = CWLSurface::fromResource(m_pSurface.lock());
+
+ if (surface && surface->m_fOverallOpacity != m_fOpacity) {
+ surface->m_fOverallOpacity = m_fOpacity;
+ auto box = surface->getSurfaceBoxGlobal();
+
+ if (box.has_value())
+ g_pHyprRenderer->damageBox(&*box);
+
+ if (!m_pResource)
+ PROTO::hyprlandSurface->destroySurface(this);
+ }
+ });
+
+ listeners.surfaceDestroyed = m_pSurface->events.destroy.registerListener([this](std::any data) {
+ if (!m_pResource)
+ PROTO::hyprlandSurface->destroySurface(this);
+ });
+}
+
+void CHyprlandSurface::destroy() {
+ m_pResource.reset();
+ m_fOpacity = 1.F;
+
+ if (!m_pSurface)
+ PROTO::hyprlandSurface->destroySurface(this);
+}
+
+CHyprlandSurfaceProtocol::CHyprlandSurfaceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
+ ;
+}
+
+void CHyprlandSurfaceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ auto manager = m_vManagers.emplace_back(std::make_unique<CHyprlandSurfaceManagerV1>(client, ver, id)).get();
+ manager->setOnDestroy([this](CHyprlandSurfaceManagerV1* manager) { destroyManager(manager); });
+
+ manager->setDestroy([this](CHyprlandSurfaceManagerV1* manager) { destroyManager(manager); });
+ manager->setGetHyprlandSurface(
+ [this](CHyprlandSurfaceManagerV1* manager, uint32_t id, wl_resource* surface) { getSurface(manager, id, CWLSurfaceResource::fromResource(surface)); });
+}
+
+void CHyprlandSurfaceProtocol::destroyManager(CHyprlandSurfaceManagerV1* manager) {
+ std::erase_if(m_vManagers, [&](const auto& p) { return p.get() == manager; });
+}
+
+void CHyprlandSurfaceProtocol::destroySurface(CHyprlandSurface* surface) {
+ std::erase_if(m_mSurfaces, [&](const auto& entry) { return entry.second.get() == surface; });
+}
+
+void CHyprlandSurfaceProtocol::getSurface(CHyprlandSurfaceManagerV1* manager, uint32_t id, SP<CWLSurfaceResource> surface) {
+ CHyprlandSurface* hyprlandSurface = nullptr;
+ auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [&](const auto& entry) { return entry.second->m_pSurface == surface; });
+
+ if (iter != m_mSurfaces.end()) {
+ if (iter->second->m_pResource) {
+ LOGM(ERR, "HyprlandSurface already present for surface {:x}", (uintptr_t)surface.get());
+ manager->error(HYPRLAND_SURFACE_MANAGER_V1_ERROR_ALREADY_CONSTRUCTED, "HyprlandSurface already present");
+ return;
+ } else {
+ iter->second->setResource(makeShared<CHyprlandSurfaceV1>(manager->client(), manager->version(), id));
+ hyprlandSurface = iter->second.get();
+ }
+ } else {
+ hyprlandSurface = m_mSurfaces.emplace(surface, std::make_unique<CHyprlandSurface>(makeShared<CHyprlandSurfaceV1>(manager->client(), manager->version(), id), surface))
+ .first->second.get();
+ }
+
+ if (!hyprlandSurface->good()) {
+ manager->noMemory();
+ m_mSurfaces.erase(surface);
+ }
+}
diff --git a/src/protocols/HyprlandSurface.hpp b/src/protocols/HyprlandSurface.hpp
new file mode 100644
index 00000000..f67de115
--- /dev/null
+++ b/src/protocols/HyprlandSurface.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+#include <unordered_map>
+#include "WaylandProtocol.hpp"
+#include "hyprland-surface-v1.hpp"
+#include "../helpers/signal/Signal.hpp"
+
+class CWLSurfaceResource;
+class CHyprlandSurfaceProtocol;
+
+class CHyprlandSurface {
+ public:
+ CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface);
+
+ bool good() const;
+ void setResource(SP<CHyprlandSurfaceV1> resource);
+
+ private:
+ SP<CHyprlandSurfaceV1> m_pResource;
+ WP<CWLSurfaceResource> m_pSurface;
+ float m_fOpacity = 1.0;
+
+ void destroy();
+
+ struct {
+ CHyprSignalListener surfaceCommitted;
+ CHyprSignalListener surfaceDestroyed;
+ } listeners;
+
+ friend class CHyprlandSurfaceProtocol;
+};
+
+class CHyprlandSurfaceProtocol : public IWaylandProtocol {
+ public:
+ CHyprlandSurfaceProtocol(const wl_interface* iface, const int& ver, const std::string& name);
+
+ virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
+
+ private:
+ void destroyManager(CHyprlandSurfaceManagerV1* res);
+ void destroySurface(CHyprlandSurface* surface);
+ void getSurface(CHyprlandSurfaceManagerV1* manager, uint32_t id, SP<CWLSurfaceResource> surface);
+
+ std::vector<UP<CHyprlandSurfaceManagerV1>> m_vManagers;
+ std::unordered_map<WP<CWLSurfaceResource>, UP<CHyprlandSurface>> m_mSurfaces;
+
+ friend class CHyprlandSurface;
+};
+
+namespace PROTO {
+ inline UP<CHyprlandSurfaceProtocol> hyprlandSurface;
+}
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index d9f19fea..93bd129a 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -2045,7 +2045,8 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWin
return false;
}
-void CHyprOpenGLImpl::renderTextureWithBlur(SP<CTexture> tex, CBox* pBox, float a, SP<CWLSurfaceResource> pSurface, int round, bool blockBlurOptimization, float blurA) {
+void CHyprOpenGLImpl::renderTextureWithBlur(SP<CTexture> tex, CBox* pBox, float a, SP<CWLSurfaceResource> pSurface, int round, bool blockBlurOptimization, float blurA,
+ float overallA) {
RASSERT(m_RenderData.pMonitor, "Tried to render texture with blur without begin()!");
static auto PNOBLUROVERSIZED = CConfigValue<Hyprlang::INT>("decoration:no_blur_on_oversized");
@@ -2126,7 +2127,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(SP<CTexture> tex, CBox* pBox, float
setMonitorTransformEnabled(true);
if (!USENEWOPTIMIZE)
setRenderModifEnabled(false);
- renderTextureInternalWithDamage(POUTFB->getTexture(), &MONITORBOX, *PBLURIGNOREOPACITY ? blurA : a * blurA, texDamage, 0, false, false, false);
+ renderTextureInternalWithDamage(POUTFB->getTexture(), &MONITORBOX, (*PBLURIGNOREOPACITY ? blurA : a * blurA) * overallA, texDamage, 0, false, false, false);
if (!USENEWOPTIMIZE)
setRenderModifEnabled(true);
setMonitorTransformEnabled(false);
@@ -2137,7 +2138,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(SP<CTexture> tex, CBox* pBox, float
// draw window
glDisable(GL_STENCIL_TEST);
- renderTextureInternalWithDamage(tex, pBox, a, texDamage, round, false, false, true, true);
+ renderTextureInternalWithDamage(tex, pBox, a * overallA, texDamage, round, false, false, true, true);
glStencilMask(0xFF);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp
index 4fceabc5..95ac41be 100644
--- a/src/render/OpenGL.hpp
+++ b/src/render/OpenGL.hpp
@@ -176,7 +176,8 @@ class CHyprOpenGLImpl {
void renderTexture(SP<CTexture>, CBox*, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false);
void renderTextureWithDamage(SP<CTexture>, CBox*, const CRegion& damage, float a, int round = 0, bool discardActive = false, bool allowCustomUV = false,
SP<CSyncTimeline> waitTimeline = nullptr, uint64_t waitPoint = 0);
- void renderTextureWithBlur(SP<CTexture>, CBox*, float a, SP<CWLSurfaceResource> pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f);
+ void renderTextureWithBlur(SP<CTexture>, CBox*, float a, SP<CWLSurfaceResource> pSurface, int round = 0, bool blockBlurOptimization = false, float blurA = 1.f,
+ float overallA = 1.f);
void renderRoundedShadow(CBox*, int round, int range, const CHyprColor& color, float a = 1.0);
void renderBorder(CBox*, const CGradientValueData&, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */);
void renderBorder(CBox*, const CGradientValueData&, const CGradientValueData&, float lerp, int round, int borderSize, float a = 1.0, int outerRound = -1 /* use round */);
diff --git a/src/render/pass/SurfacePassElement.cpp b/src/render/pass/SurfacePassElement.cpp
index 38de5210..89d4301c 100644
--- a/src/render/pass/SurfacePassElement.cpp
+++ b/src/render/pass/SurfacePassElement.cpp
@@ -58,8 +58,9 @@ void CSurfacePassElement::draw(const CRegion& damage) {
auto PSURFACE = CWLSurface::fromResource(data.surface);
- const float ALPHA = data.alpha * data.fadeAlpha * (PSURFACE ? PSURFACE->m_pAlphaModifier : 1.F);
- const bool BLUR = data.blur && (!TEXTURE->m_bOpaque || ALPHA < 1.F);
+ const float ALPHA = data.alpha * data.fadeAlpha * (PSURFACE ? PSURFACE->m_pAlphaModifier : 1.F);
+ const float OVERALL_ALPHA = PSURFACE ? PSURFACE->m_fOverallOpacity : 1.F;
+ const bool BLUR = data.blur && (!TEXTURE->m_bOpaque || ALPHA < 1.F || OVERALL_ALPHA < 1.F);
auto windowBox = getTexBox();
@@ -107,14 +108,14 @@ void CSurfacePassElement::draw(const CRegion& damage) {
// to what we do for misaligned surfaces (blur the entire thing and then render shit without blur)
if (data.surfaceCounter == 0 && !data.popup) {
if (BLUR)
- g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, data.surface, rounding, data.blockBlurOptimization, data.fadeAlpha);
+ g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, data.surface, rounding, data.blockBlurOptimization, data.fadeAlpha, OVERALL_ALPHA);
else
- g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA, rounding, false, true);
+ g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA * OVERALL_ALPHA, rounding, false, true);
} else {
if (BLUR && data.popup)
- g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, data.surface, rounding, true, data.fadeAlpha);
+ g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, ALPHA, data.surface, rounding, true, data.fadeAlpha, OVERALL_ALPHA);
else
- g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA, rounding, false, true);
+ g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, ALPHA * OVERALL_ALPHA, rounding, false, true);
}
if (!g_pHyprRenderer->m_bBlockSurfaceFeedback)