From 005b098707c277f2d108d72bfe88dbd289116df9 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 28 Mar 2023 22:12:37 +0300 Subject: [PATCH] Move xwayland surface association logic to X11Window --- src/events.cpp | 36 ++++++++++++++++-------------------- src/window.cpp | 1 - src/window.h | 15 --------------- src/x11window.cpp | 2 ++ src/x11window.h | 17 ++++++++++++++++- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index 4004ab119a..ca5f5a8171 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -649,7 +649,22 @@ void X11Window::destroyNotifyEvent(xcb_destroy_notify_event_t *e) */ void X11Window::clientMessageEvent(xcb_client_message_event_t *e) { - Window::clientMessageEvent(e); + if (e->type == atoms->wl_surface_serial) { + m_surfaceSerial = (uint64_t(e->data.data32[1]) << 32) | e->data.data32[0]; + if (auto w = waylandServer()) { + if (KWaylandServer::XwaylandSurfaceV1Interface *xwaylandSurface = w->xwaylandShell()->findSurface(m_surfaceSerial)) { + setSurface(xwaylandSurface->surface()); + } + } + } else if (e->type == atoms->wl_surface_id) { + m_pendingSurfaceId = e->data.data32[0]; + if (auto w = waylandServer()) { + if (auto s = KWaylandServer::SurfaceInterface::get(m_pendingSurfaceId, w->xWaylandConnection())) { + setSurface(s); + } + } + } + if (e->window != window()) { return; // ignore frame/wrapper } @@ -1319,23 +1334,4 @@ void Window::propertyNotifyEvent(xcb_property_notify_event_t *e) } } -void Window::clientMessageEvent(xcb_client_message_event_t *e) -{ - if (e->type == atoms->wl_surface_serial) { - m_surfaceSerial = (uint64_t(e->data.data32[1]) << 32) | e->data.data32[0]; - if (auto w = waylandServer()) { - if (KWaylandServer::XwaylandSurfaceV1Interface *xwaylandSurface = w->xwaylandShell()->findSurface(m_surfaceSerial)) { - setSurface(xwaylandSurface->surface()); - } - } - } else if (e->type == atoms->wl_surface_id) { - m_pendingSurfaceId = e->data.data32[0]; - if (auto w = waylandServer()) { - if (auto s = KWaylandServer::SurfaceInterface::get(m_pendingSurfaceId, w->xWaylandConnection())) { - setSurface(s); - } - } - } -} - } // namespace diff --git a/src/window.cpp b/src/window.cpp index f75d0621cb..d531f74773 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -531,7 +531,6 @@ void Window::setSurface(KWaylandServer::SurfaceInterface *surface) return; } m_surface = surface; - m_pendingSurfaceId = 0; Q_EMIT surfaceChanged(); } diff --git a/src/window.h b/src/window.h index a542375ce7..2a0a85f253 100644 --- a/src/window.h +++ b/src/window.h @@ -728,8 +728,6 @@ public: bool skipsCloseAnimation() const; void setSkipCloseAnimation(bool set); - quint64 surfaceSerial() const; - quint32 pendingSurfaceId() const; KWaylandServer::SurfaceInterface *surface() const; void setSurface(KWaylandServer::SurfaceInterface *surface); @@ -1494,7 +1492,6 @@ protected: void setWindowHandles(xcb_window_t client); void detectShape(xcb_window_t id); virtual void propertyNotifyEvent(xcb_property_notify_event_t *e); - virtual void clientMessageEvent(xcb_client_message_event_t *e); Xcb::Property fetchWmClientLeader() const; void readWmClientLeader(Xcb::Property &p); void getWmClientLeader(); @@ -1839,8 +1836,6 @@ private: mutable QVector m_shapeRegion; mutable bool m_shapeRegionIsValid = false; bool m_skipCloseAnimation; - quint32 m_pendingSurfaceId = 0; - quint64 m_surfaceSerial = 0; QPointer m_surface; // when adding new data members, check also copyToDeleted() qreal m_opacity = 1.0; @@ -2206,16 +2201,6 @@ inline const ClientMachine *Window::clientMachine() const return m_clientMachine; } -inline quint64 Window::surfaceSerial() const -{ - return m_surfaceSerial; -} - -inline quint32 Window::pendingSurfaceId() const -{ - return m_pendingSurfaceId; -} - template inline T *Window::findInList(const QList &list, std::function func) { diff --git a/src/x11window.cpp b/src/x11window.cpp index de8b5fa621..c7e04f46ae 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -5024,6 +5024,8 @@ void X11Window::associate() // the associated surface item has processed the new surface state. connect(surface(), &KWaylandServer::SurfaceInterface::mapped, this, handleMapped, Qt::QueuedConnection); } + + m_pendingSurfaceId = 0; } QWindow *X11Window::findInternalWindow() const diff --git a/src/x11window.h b/src/x11window.h index 3bc77ac7c9..45af0c85fb 100644 --- a/src/x11window.h +++ b/src/x11window.h @@ -294,6 +294,9 @@ public: static void cleanupX11(); + quint64 surfaceSerial() const; + quint32 pendingSurfaceId() const; + public Q_SLOTS: void closeWindow() override; void updateCaption() override; @@ -306,7 +309,7 @@ private: void configureNotifyEvent(xcb_configure_notify_event_t *e); void configureRequestEvent(xcb_configure_request_event_t *e); void propertyNotifyEvent(xcb_property_notify_event_t *e) override; - void clientMessageEvent(xcb_client_message_event_t *e) override; + void clientMessageEvent(xcb_client_message_event_t *e); void enterNotifyEvent(xcb_enter_notify_event_t *e); void leaveNotifyEvent(xcb_leave_notify_event_t *e); void focusInEvent(xcb_focus_in_event_t *e); @@ -502,6 +505,8 @@ private: bool m_unmanaged = false; bool m_outline = false; + quint32 m_pendingSurfaceId = 0; + quint64 m_surfaceSerial = 0; }; inline xcb_window_t X11Window::wrapperId() const @@ -599,6 +604,16 @@ inline bool X11Window::hiddenPreview() const return mapping_state == Kept; } +inline quint64 X11Window::surfaceSerial() const +{ + return m_surfaceSerial; +} + +inline quint32 X11Window::pendingSurfaceId() const +{ + return m_pendingSurfaceId; +} + } // namespace Q_DECLARE_METATYPE(KWin::X11Window *) Q_DECLARE_METATYPE(QList)