From c191902026ee32d5e4bac8ee7826b8d3f40e453b Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 2 Mar 2023 17:02:09 +0200 Subject: [PATCH] wayland: Setup compositing when window is mapped ready for painting This prevents creating a WindowItem until we know that the window is actually going to be visible on the screen. --- src/composite.cpp | 20 ++++---------------- src/inputpanelv1window.cpp | 2 +- src/layershellv1window.cpp | 2 +- src/waylandwindow.cpp | 9 ++++++++- src/waylandwindow.h | 1 + src/xdgshellwindow.cpp | 6 +----- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/composite.cpp b/src/composite.cpp index ca2d389965..88d3bcd87b 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -384,7 +384,8 @@ void Compositor::startupWithWorkspace() m_state = State::On; - for (X11Window *window : Workspace::self()->clientList()) { + const auto windows = workspace()->allClientList(); + for (Window *window : windows) { window->setupCompositing(); } for (Unmanaged *window : Workspace::self()->unmanagedList()) { @@ -394,13 +395,6 @@ void Compositor::startupWithWorkspace() window->setupCompositing(); } - if (auto *server = waylandServer()) { - const auto windows = server->windows(); - for (Window *window : windows) { - window->setupCompositing(); - } - } - // Sets also the 'effects' pointer. kwinApp()->createEffectsHandler(this, m_scene.get()); @@ -515,7 +509,8 @@ void Compositor::stop() effects = nullptr; if (Workspace::self()) { - for (X11Window *window : Workspace::self()->clientList()) { + const auto windows = workspace()->allClientList(); + for (Window *window : windows) { window->finishCompositing(); } for (Unmanaged *window : Workspace::self()->unmanagedList()) { @@ -536,13 +531,6 @@ void Compositor::stop() disconnect(workspace(), &Workspace::outputRemoved, this, &Compositor::removeOutput); } - if (waylandServer()) { - const QList toFinishCompositing = waylandServer()->windows(); - for (Window *window : toFinishCompositing) { - window->finishCompositing(); - } - } - const auto superlayers = m_superlayers; for (auto it = superlayers.begin(); it != superlayers.end(); ++it) { removeSuperLayer(*it); diff --git a/src/inputpanelv1window.cpp b/src/inputpanelv1window.cpp index 14a7a306db..da437d86ef 100644 --- a/src/inputpanelv1window.cpp +++ b/src/inputpanelv1window.cpp @@ -189,7 +189,7 @@ void InputPanelV1Window::maybeShow() { const bool shouldShow = m_mode == Mode::Overlay || (m_mode == Mode::VirtualKeyboard && m_allowed && m_virtualKeyboardShouldBeShown); if (shouldShow && !isZombie() && surface()->isMapped()) { - setReadyForPainting(); + markAsMapped(); reposition(); showClient(); } diff --git a/src/layershellv1window.cpp b/src/layershellv1window.cpp index 6f1a0fa2ae..6b60ff47e8 100644 --- a/src/layershellv1window.cpp +++ b/src/layershellv1window.cpp @@ -250,7 +250,7 @@ void LayerShellV1Window::handleUnmapped() void LayerShellV1Window::handleCommitted() { if (surface()->buffer()) { - setReadyForPainting(); + markAsMapped(); } } diff --git a/src/waylandwindow.cpp b/src/waylandwindow.cpp index b9d98d3085..b27b86d21d 100644 --- a/src/waylandwindow.cpp +++ b/src/waylandwindow.cpp @@ -38,7 +38,6 @@ WaylandWindow::WaylandWindow(SurfaceInterface *surface) { setSurface(surface); setDepth(32); - setupCompositing(); connect(surface, &SurfaceInterface::shadowChanged, this, &WaylandWindow::updateShadow); @@ -323,4 +322,12 @@ void WaylandWindow::updateGeometry(const QRectF &rect) Q_EMIT geometryShapeChanged(oldFrameGeometry); } +void WaylandWindow::markAsMapped() +{ + if (Q_UNLIKELY(!ready_for_painting)) { + setupCompositing(); + setReadyForPainting(); + } +} + } // namespace KWin diff --git a/src/waylandwindow.h b/src/waylandwindow.h index 2df94dbd96..2be051eed5 100644 --- a/src/waylandwindow.h +++ b/src/waylandwindow.h @@ -47,6 +47,7 @@ protected: void cleanGrouping(); void updateGeometry(const QRectF &rect); + void markAsMapped(); private: void updateClientOutputs(); diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 377cbbebfe..4078a8c652 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -52,10 +52,6 @@ XdgSurfaceWindow::XdgSurfaceWindow(XdgSurfaceInterface *shellSurface) this, &XdgSurfaceWindow::destroyWindow); connect(shellSurface->surface(), &SurfaceInterface::committed, this, &XdgSurfaceWindow::handleCommit); -#if 0 // TODO: Refactor kwin core in order to uncomment this code. - connect(shellSurface->surface(), &SurfaceInterface::mapped, - this, &XdgSurfaceWindow::setReadyForPainting); -#endif connect(shellSurface, &XdgSurfaceInterface::aboutToBeDestroyed, this, &XdgSurfaceWindow::destroyWindow); connect(shellSurface->surface(), &SurfaceInterface::aboutToBeDestroyed, @@ -174,7 +170,7 @@ void XdgSurfaceWindow::handleCommit() m_lastAcknowledgedConfigure.reset(); m_lastAcknowledgedConfigureSerial.reset(); - setReadyForPainting(); + markAsMapped(); } void XdgSurfaceWindow::handleRolePrecommit()