aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/xwayland
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-06-08 10:07:59 +0200
committerGitHub <[email protected]>2024-06-08 10:07:59 +0200
commit6967a31450441fc5605c05db6f65505dace4b263 (patch)
tree255a3cff7f3e2eb8a50c952eab9b270a7937561d /src/xwayland
parentc31d9ef4172452f6f219f91d9b87a24d91f0cf3a (diff)
downloadHyprland-6967a31450441fc5605c05db6f65505dace4b263.tar.gz
Hyprland-6967a31450441fc5605c05db6f65505dace4b263.zip
wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
Diffstat (limited to 'src/xwayland')
-rw-r--r--src/xwayland/XSurface.cpp66
-rw-r--r--src/xwayland/XSurface.hpp9
-rw-r--r--src/xwayland/XWM.cpp21
-rw-r--r--src/xwayland/XWM.hpp7
4 files changed, 48 insertions, 55 deletions
diff --git a/src/xwayland/XSurface.cpp b/src/xwayland/XSurface.cpp
index 8994e975..07cac832 100644
--- a/src/xwayland/XSurface.cpp
+++ b/src/xwayland/XSurface.cpp
@@ -1,6 +1,7 @@
#include "XSurface.hpp"
#include "XWayland.hpp"
#include "../protocols/XWaylandShell.hpp"
+#include "../protocols/core/Compositor.hpp"
#ifndef NO_XWAYLAND
@@ -44,46 +45,41 @@ CXWaylandSurface::CXWaylandSurface(uint32_t xID_, CBox geometry_, bool OR) : xID
}
void CXWaylandSurface::ensureListeners() {
- bool connected = hyprListener_surfaceDestroy.isConnected();
+ bool connected = listeners.destroySurface;
if (connected && !surface) {
- hyprListener_surfaceDestroy.removeCallback();
- hyprListener_surfaceCommit.removeCallback();
+ listeners.destroySurface.reset();
+ listeners.commitSurface.reset();
} else if (!connected && surface) {
- hyprListener_surfaceDestroy.initCallback(
- &surface->events.destroy,
- [this](void* owner, void* data) {
- if (mapped)
- unmap();
-
- surface = nullptr;
- hyprListener_surfaceDestroy.removeCallback();
- hyprListener_surfaceCommit.removeCallback();
- events.resourceChange.emit();
- },
- nullptr, "CXWaylandSurface");
- hyprListener_surfaceCommit.initCallback(
- &surface->events.commit,
- [this](void* owner, void* data) {
- if (surface->pending.buffer_width > 0 && surface->pending.buffer_height > 0 && !mapped) {
- map();
- return;
- }
-
- if (surface->pending.buffer_width <= 0 && surface->pending.buffer_height <= 0 && mapped) {
- unmap();
- return;
- }
-
- events.commit.emit();
- },
- nullptr, "CXWaylandSurface");
+ listeners.destroySurface = surface->events.destroy.registerListener([this](std::any d) {
+ if (mapped)
+ unmap();
+
+ surface.reset();
+ listeners.destroySurface.reset();
+ listeners.commitSurface.reset();
+ events.resourceChange.emit();
+ });
+
+ listeners.commitSurface = surface->events.commit.registerListener([this](std::any d) {
+ if (surface->pending.buffer && !mapped) {
+ map();
+ return;
+ }
+
+ if (!surface->pending.buffer && mapped) {
+ unmap();
+ return;
+ }
+
+ events.commit.emit();
+ });
}
if (resource) {
listeners.destroyResource = resource->events.destroy.registerListener([this](std::any d) {
unmap();
- surface = nullptr;
+ surface.reset();
events.resourceChange.emit();
});
}
@@ -99,7 +95,7 @@ void CXWaylandSurface::map() {
g_pXWayland->pWM->mappedSurfacesStacking.emplace_back(self);
mapped = true;
- wlr_surface_map(surface);
+ surface->map();
Debug::log(LOG, "XWayland surface {:x} mapping", (uintptr_t)this);
@@ -118,7 +114,7 @@ void CXWaylandSurface::unmap() {
std::erase(g_pXWayland->pWM->mappedSurfacesStacking, self);
mapped = false;
- wlr_surface_unmap(surface);
+ surface->unmap();
Debug::log(LOG, "XWayland surface {:x} unmapping", (uintptr_t)this);
@@ -136,7 +132,7 @@ void CXWaylandSurface::considerMap() {
return;
}
- if (surface->pending.buffer_width > 0 && surface->pending.buffer_height > 0) {
+ if (surface->pending.buffer) {
Debug::log(LOG, "XWayland surface: considerMap, sure, we have a buffer");
map();
return;
diff --git a/src/xwayland/XSurface.hpp b/src/xwayland/XSurface.hpp
index 73cb89a5..0cdac1d5 100644
--- a/src/xwayland/XSurface.hpp
+++ b/src/xwayland/XSurface.hpp
@@ -5,7 +5,7 @@
#include "../helpers/Box.hpp"
#include <vector>
-struct wlr_surface;
+class CWLSurfaceResource;
class CXWaylandSurfaceResource;
#ifdef NO_XWAYLAND
@@ -39,7 +39,7 @@ typedef struct {
class CXWaylandSurface {
public:
- wlr_surface* surface = nullptr;
+ WP<CWLSurfaceResource> surface;
WP<CXWaylandSurfaceResource> resource;
struct {
@@ -109,11 +109,10 @@ class CXWaylandSurface {
void considerMap();
void setWithdrawn(bool withdrawn);
- DYNLISTENER(surfaceDestroy);
- DYNLISTENER(surfaceCommit);
-
struct {
CHyprSignalListener destroyResource;
+ CHyprSignalListener destroySurface;
+ CHyprSignalListener commitSurface;
} listeners;
friend class CXWM;
diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp
index 5dfd4839..7af1d506 100644
--- a/src/xwayland/XWM.cpp
+++ b/src/xwayland/XWM.cpp
@@ -6,6 +6,7 @@
#include <unordered_map>
#include "../Compositor.hpp"
#include "../protocols/XWaylandShell.hpp"
+#include "../protocols/core/Compositor.hpp"
#include "../managers/SeatManager.hpp"
#include "../protocols/core/Seat.hpp"
#include <ranges>
@@ -296,7 +297,7 @@ void CXWM::handleClientMessage(xcb_client_message_event_t* e) {
auto id = e->data.data32[0];
auto resource = wl_client_get_object(g_pXWayland->pServer->xwaylandClient, id);
if (resource) {
- auto wlrSurface = wlr_surface_from_resource(resource);
+ auto wlrSurface = CWLSurfaceResource::fromResource(resource);
associate(XSURF, wlrSurface);
}
} else if (e->type == HYPRATOMS["WL_SURFACE_SERIAL"]) {
@@ -318,7 +319,7 @@ void CXWM::handleClientMessage(xcb_client_message_event_t* e) {
if (res->serial != XSURF->wlSerial || !XSURF->wlSerial)
continue;
- associate(XSURF, res->surface);
+ associate(XSURF, res->surface.lock());
break;
}
@@ -827,9 +828,7 @@ CXWM::CXWM() {
initSelection();
- hyprListener_newSurface.initCallback(
- &g_pCompositor->m_sWLRCompositor->events.new_surface, [this](void* owner, void* data) { onNewSurface((wlr_surface*)data); }, nullptr, "XWM");
-
+ listeners.newWLSurface = PROTO::compositor->events.newSurface.registerListener([this](std::any d) { onNewSurface(std::any_cast<SP<CWLSurfaceResource>>(d)); });
listeners.newXShellSurface = PROTO::xwaylandShell->events.newSurface.registerListener([this](std::any d) { onNewResource(std::any_cast<SP<CXWaylandSurfaceResource>>(d)); });
createWMWindow();
@@ -903,13 +902,13 @@ void CXWM::sendState(SP<CXWaylandSurface> surf) {
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, surf->xID, HYPRATOMS["_NET_WM_STATE"], XCB_ATOM_ATOM, 32, props.size(), props.data());
}
-void CXWM::onNewSurface(wlr_surface* surf) {
- if (wl_resource_get_client(surf->resource) != g_pXWayland->pServer->xwaylandClient)
+void CXWM::onNewSurface(SP<CWLSurfaceResource> surf) {
+ if (surf->client() != g_pXWayland->pServer->xwaylandClient)
return;
Debug::log(LOG, "[xwm] New XWayland surface at {:x}", (uintptr_t)surf);
- const auto WLID = wl_resource_get_id(surf->resource);
+ const auto WLID = surf->id();
for (auto& sr : surfaces) {
if (sr->surface || sr->wlID != WLID)
@@ -932,7 +931,7 @@ void CXWM::onNewResource(SP<CXWaylandSurfaceResource> resource) {
if (surf->resource || surf->wlSerial != resource->serial)
continue;
- associate(surf, resource->surface);
+ associate(surf, resource->surface.lock());
break;
}
}
@@ -955,7 +954,7 @@ void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
}
}
-void CXWM::associate(SP<CXWaylandSurface> surf, wlr_surface* wlSurf) {
+void CXWM::associate(SP<CXWaylandSurface> surf, SP<CWLSurfaceResource> wlSurf) {
if (surf->surface)
return;
@@ -981,7 +980,7 @@ void CXWM::dissociate(SP<CXWaylandSurface> surf) {
if (surf->mapped)
surf->unmap();
- surf->surface = nullptr;
+ surf->surface.reset();
surf->events.resourceChange.emit();
Debug::log(LOG, "Dissociate for {:x}", (uintptr_t)surf.get());
diff --git a/src/xwayland/XWM.hpp b/src/xwayland/XWM.hpp
index 1d695a15..bdf4fac2 100644
--- a/src/xwayland/XWM.hpp
+++ b/src/xwayland/XWM.hpp
@@ -73,7 +73,7 @@ class CXWM {
void createWMWindow();
void initSelection();
- void onNewSurface(wlr_surface* surf);
+ void onNewSurface(SP<CWLSurfaceResource> surf);
void onNewResource(SP<CXWaylandSurfaceResource> resource);
void setActiveWindow(xcb_window_t window);
@@ -87,7 +87,7 @@ class CXWM {
SP<CXWaylandSurface> windowForXID(xcb_window_t wid);
void readWindowData(SP<CXWaylandSurface> surf);
- void associate(SP<CXWaylandSurface> surf, wlr_surface* wlSurf);
+ void associate(SP<CXWaylandSurface> surf, SP<CWLSurfaceResource> wlSurf);
void dissociate(SP<CXWaylandSurface> surf);
void updateClientList();
@@ -147,9 +147,8 @@ class CXWM {
SXSelection clipboard;
- DYNLISTENER(newSurface);
-
struct {
+ CHyprSignalListener newWLSurface;
CHyprSignalListener newXShellSurface;
} listeners;