-
-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protocols: add hyprland_surface_v1 implementation
- Loading branch information
Showing
10 changed files
with
166 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#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_pResource(resource), m_pSurface(surface) { | ||
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_SET_OPACITY_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); | ||
} | ||
}); | ||
|
||
listeners.surfaceDestroyed = m_pSurface->events.destroy.registerListener([this](std::any data) { m_pSurface.reset(); }); | ||
} | ||
|
||
bool CHyprlandSurface::good() const { | ||
return m_pResource->resource(); | ||
} | ||
|
||
void CHyprlandSurface::destroy() { | ||
auto surface = CWLSurface::fromResource(m_pSurface.lock()); | ||
|
||
if (surface) | ||
surface->m_fOverallOpacity = 1.F; | ||
|
||
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) { | ||
if (m_mSurfaces.contains(surface)) { | ||
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; | ||
} | ||
|
||
auto 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#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 CHyprlandSurface { | ||
public: | ||
CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface); | ||
|
||
bool good() const; | ||
|
||
private: | ||
SP<CHyprlandSurfaceV1> m_pResource; | ||
WP<CWLSurfaceResource> m_pSurface; | ||
float m_fOpacity = 1.0; | ||
|
||
void destroy(); | ||
|
||
struct { | ||
CHyprSignalListener surfaceCommitted; | ||
CHyprSignalListener surfaceDestroyed; | ||
} listeners; | ||
}; | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule hyprland-protocols
updated
3 files
+2 −0 | README.md | |
+1 −0 | meson.build | |
+103 −0 | protocols/hyprland-surface-v1.xml |