summaryrefslogtreecommitdiff
path: root/src/protocols/XDGShell.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-06-08 10:07:59 +0200
committerGitHub <noreply@github.com>2024-06-08 10:07:59 +0200
commit6967a31450441fc5605c05db6f65505dace4b263 (patch)
tree255a3cff7f3e2eb8a50c952eab9b270a7937561d /src/protocols/XDGShell.cpp
parentc31d9ef4172452f6f219f91d9b87a24d91f0cf3a (diff)
wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
Diffstat (limited to 'src/protocols/XDGShell.cpp')
-rw-r--r--src/protocols/XDGShell.cpp108
1 files changed, 52 insertions, 56 deletions
diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp
index 80e3487d..97de49f6 100644
--- a/src/protocols/XDGShell.cpp
+++ b/src/protocols/XDGShell.cpp
@@ -3,6 +3,7 @@
#include "../Compositor.hpp"
#include "../managers/SeatManager.hpp"
#include "core/Seat.hpp"
+#include "core/Compositor.hpp"
#define LOGM PROTO::xdgShell->protoLog
@@ -288,7 +289,8 @@ void CXDGToplevelResource::close() {
resource->sendClose();
}
-CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBase> owner_, wlr_surface* surface_) : owner(owner_), surface(surface_), resource(resource_) {
+CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBase> owner_, SP<CWLSurfaceResource> surface_) :
+ owner(owner_), surface(surface_), resource(resource_) {
if (!good())
return;
@@ -307,56 +309,50 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas
PROTO::xdgShell->destroyResource(this);
});
- hyprListener_surfaceDestroy.initCallback(
- &surface->events.destroy,
- [this](void* owner, void* data) {
- LOGM(WARN, "wl_surface destroyed before its xdg_surface role object");
- hyprListener_surfaceDestroy.removeCallback();
- hyprListener_surfaceCommit.removeCallback();
-
- if (mapped)
- events.unmap.emit();
-
- mapped = false;
- surface = nullptr;
- events.destroy.emit();
- },
- nullptr, "CXDGSurfaceResource");
-
- hyprListener_surfaceCommit.initCallback(
- &surface->events.commit,
- [this](void* owner, void* data) {
- current = pending;
+ listeners.surfaceDestroy = surface->events.destroy.registerListener([this](std::any d) {
+ LOGM(WARN, "wl_surface destroyed before its xdg_surface role object");
+ listeners.surfaceDestroy.reset();
+ listeners.surfaceCommit.reset();
+
+ if (mapped)
+ events.unmap.emit();
+
+ mapped = false;
+ surface.reset();
+ events.destroy.emit();
+ });
+
+ listeners.surfaceCommit = surface->events.commit.registerListener([this](std::any d) {
+ current = pending;
+ if (toplevel)
+ toplevel->current = toplevel->pending;
+
+ if (initialCommit && surface->pending.buffer) {
+ resource->error(-1, "Buffer attached before initial commit");
+ return;
+ }
+
+ if (surface->current.buffer && !mapped) {
+ // this forces apps to not draw CSD.
if (toplevel)
- toplevel->current = toplevel->pending;
-
- if (initialCommit && surface->pending.buffer_width > 0 && surface->pending.buffer_height > 0) {
- resource->error(-1, "Buffer attached before initial commit");
- return;
- }
-
- if (surface->pending.buffer_width > 0 && surface->pending.buffer_height > 0 && !mapped) {
- // this forces apps to not draw CSD.
- if (toplevel)
- toplevel->setMaximized(true);
-
- mapped = true;
- wlr_surface_map(surface);
- events.map.emit();
- return;
- }
-
- if (surface->pending.buffer_width <= 0 && surface->pending.buffer_height <= 0 && mapped) {
- mapped = false;
- wlr_surface_unmap(surface);
- events.unmap.emit();
- return;
- }
-
- events.commit.emit();
- initialCommit = false;
- },
- nullptr, "CXDGSurfaceResource");
+ toplevel->setMaximized(true);
+
+ mapped = true;
+ surface->map();
+ events.map.emit();
+ return;
+ }
+
+ if (!surface->current.buffer && mapped) {
+ mapped = false;
+ surface->unmap();
+ events.unmap.emit();
+ return;
+ }
+
+ events.commit.emit();
+ initialCommit = false;
+ });
resource->setGetToplevel([this](CXdgSurface* r, uint32_t id) {
const auto RESOURCE = PROTO::xdgShell->m_vToplevels.emplace_back(makeShared<CXDGToplevelResource>(makeShared<CXdgToplevel>(r->client(), r->version(), id), self.lock()));
@@ -649,7 +645,7 @@ CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
resource->setGetXdgSurface([this](CXdgWmBase* r, uint32_t id, wl_resource* surf) {
const auto RESOURCE = PROTO::xdgShell->m_vSurfaces.emplace_back(
- makeShared<CXDGSurfaceResource>(makeShared<CXdgSurface>(r->client(), r->version(), id), self.lock(), wlr_surface_from_resource(surf)));
+ makeShared<CXDGSurfaceResource>(makeShared<CXdgSurface>(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surf)));
if (!RESOURCE->good()) {
r->noMemory();
@@ -724,9 +720,9 @@ void CXDGShellProtocol::addOrStartGrab(SP<CXDGPopupResource> popup) {
grabOwner = popup;
grabbed.clear();
grab->clear();
- grab->add(popup->surface->surface);
+ grab->add(popup->surface->surface.lock());
if (popup->parent)
- grab->add(popup->parent->surface);
+ grab->add(popup->parent->surface.lock());
g_pSeatManager->setGrab(grab);
grabbed.emplace_back(popup);
return;
@@ -734,10 +730,10 @@ void CXDGShellProtocol::addOrStartGrab(SP<CXDGPopupResource> popup) {
grabbed.emplace_back(popup);
- grab->add(popup->surface->surface);
+ grab->add(popup->surface->surface.lock());
if (popup->parent)
- grab->add(popup->parent->surface);
+ grab->add(popup->parent->surface.lock());
}
void CXDGShellProtocol::onPopupDestroy(WP<CXDGPopupResource> popup) {
@@ -752,5 +748,5 @@ void CXDGShellProtocol::onPopupDestroy(WP<CXDGPopupResource> popup) {
std::erase(grabbed, popup);
if (popup->surface)
- grab->remove(popup->surface->surface);
+ grab->remove(popup->surface->surface.lock());
}