From c61085dc2e28cb7d737c9b049499b4433916b194 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 14 Jun 2021 12:44:36 +0300 Subject: [PATCH] Remove Toplevel::compositing() and Workspace::compositing() It is error-prone to have multiple sources for the same data. If the base implementation (Compositor::compositing()) changes, other helpers can get out of sync. --- autotests/mock_workspace.h | 4 ---- src/events.cpp | 4 ++-- src/tabbox/tabbox.cpp | 6 ++++-- src/toplevel.cpp | 15 +++++---------- src/toplevel.h | 4 ---- src/workspace.cpp | 7 +------ src/workspace.h | 4 ---- src/x11client.cpp | 26 +++++++++++++------------- 8 files changed, 25 insertions(+), 45 deletions(-) diff --git a/autotests/mock_workspace.h b/autotests/mock_workspace.h index 11c01232ec..11e183a39d 100644 --- a/autotests/mock_workspace.h +++ b/autotests/mock_workspace.h @@ -40,10 +40,6 @@ public: void registerEventFilter(X11EventFilter *filter); void unregisterEventFilter(X11EventFilter *filter); - bool compositing() const { - return false; - } - static Workspace *self(); Q_SIGNALS: diff --git a/src/events.cpp b/src/events.cpp index 06b68dceb6..f92a8cae68 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -351,7 +351,7 @@ bool X11Client::windowEvent(xcb_generic_event_t *e) if ((dirtyProperties2 & NET::WM2StartupId) != 0) startupIdChanged(); if (dirtyProperties2 & NET::WM2Opacity) { - if (compositing()) { + if (Compositor::compositing()) { setOpacity(info->opacityF()); } else { // forward to the frame if there's possibly another compositing manager running @@ -1183,7 +1183,7 @@ bool Unmanaged::windowEvent(xcb_generic_event_t *e) NET::Properties2 dirtyProperties2; info->event(e, &dirtyProperties, &dirtyProperties2); // pass through the NET stuff if (dirtyProperties2 & NET::WM2Opacity) { - if (compositing()) { + if (Compositor::compositing()) { setOpacity(info->opacityF()); } } diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index a1536d3182..d945469237 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -23,6 +23,7 @@ #ifdef KWIN_BUILD_ACTIVITIES #include "activities.h" #endif +#include "composite.h" #include "x11client.h" #include "effects.h" #include "input.h" @@ -282,8 +283,9 @@ TabBoxClientList TabBoxHandlerImpl::stackingOrder() const return ret; } -bool TabBoxHandlerImpl::isKWinCompositing() const { - return Workspace::self()->compositing(); +bool TabBoxHandlerImpl::isKWinCompositing() const +{ + return Compositor::compositing(); } void TabBoxHandlerImpl::raiseClient(TabBoxClient* c) const diff --git a/src/toplevel.cpp b/src/toplevel.cpp index 7479c0f096..7ada48d145 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -255,7 +255,7 @@ void Toplevel::setOpacity(qreal opacity) } const qreal oldOpacity = m_opacity; m_opacity = opacity; - if (compositing()) { + if (Compositor::compositing()) { addRepaintFull(); Q_EMIT opacityChanged(this, oldOpacity); } @@ -263,7 +263,7 @@ void Toplevel::setOpacity(qreal opacity) bool Toplevel::setupCompositing() { - if (!compositing()) + if (!Compositor::compositing()) return false; effect_window = new EffectWindowImpl(this); @@ -283,11 +283,6 @@ void Toplevel::finishCompositing(ReleaseReason) } } -bool Toplevel::compositing() const -{ - return Compositor::compositing(); -} - void Toplevel::addRepaint(const QRect &rect) { addRepaint(QRegion(rect)); @@ -332,14 +327,14 @@ void Toplevel::addWorkspaceRepaint(int x, int y, int w, int h) void Toplevel::addWorkspaceRepaint(const QRect& r2) { - if (!compositing()) + if (!Compositor::compositing()) return; Compositor::self()->addRepaint(r2); } void Toplevel::addWorkspaceRepaint(const QRegion ®ion) { - if (compositing()) { + if (Compositor::compositing()) { Compositor::self()->addRepaint(region); } } @@ -348,7 +343,7 @@ void Toplevel::setReadyForPainting() { if (!ready_for_painting) { ready_for_painting = true; - if (compositing()) { + if (Compositor::compositing()) { addRepaintFull(); Q_EMIT windowShown(this); } diff --git a/src/toplevel.h b/src/toplevel.h index 5f5616016b..e0500abe65 100644 --- a/src/toplevel.h +++ b/src/toplevel.h @@ -671,10 +671,6 @@ protected: void readWmClientLeader(Xcb::Property &p); void getWmClientLeader(); void getWmClientMachine(); - /** - * @returns Whether there is a compositor and it is active. - */ - bool compositing() const; /** * This function fetches the opaque region from this Toplevel. diff --git a/src/workspace.cpp b/src/workspace.cpp index 13d89df7ec..27c9e8340a 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -1214,7 +1214,7 @@ void Workspace::updateCurrentActivity(const QString &new_activity) //if ( effects != NULL && old_desktop != 0 && old_desktop != new_desktop ) // static_cast( effects )->desktopChanged( old_desktop ); - if (compositing() && m_compositor) + if (Compositor::compositing() && m_compositor) m_compositor->addRepaintFull(); #else Q_UNUSED(new_activity) @@ -1889,11 +1889,6 @@ Toplevel *Workspace::findInternal(QWindow *w) const return nullptr; } -bool Workspace::compositing() const -{ - return Compositor::compositing(); -} - void Workspace::markXStackingOrderAsDirty() { m_xStackingDirty = true; diff --git a/src/workspace.h b/src/workspace.h index 163be79abe..f146602f7e 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -369,10 +369,6 @@ public: return movingClient; } - /** - * @returns Whether we have a Compositor and it is active (Scene created) - */ - bool compositing() const; void markXStackingOrderAsDirty(); void quickTileWindow(QuickTileMode mode); diff --git a/src/x11client.cpp b/src/x11client.cpp index e2536642b9..58e1b8ab10 100644 --- a/src/x11client.cpp +++ b/src/x11client.cpp @@ -839,7 +839,7 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) workspace()->restoreSessionStackingOrder(this); } - if (compositing()) + if (Compositor::compositing()) // Sending ConfigureNotify is done when setting mapping state below, // Getting the first sync response means window is ready for compositing sendSyncRequest(); @@ -1135,7 +1135,7 @@ void X11Client::destroyDecoration() maybeDestroyX11DecorationRenderer(); resize(adjustedSize()); move(grav); - if (compositing()) + if (Compositor::compositing()) discardWindowPixmap(); if (!isZombie()) { Q_EMIT geometryShapeChanged(this, oldgeom); @@ -1149,7 +1149,7 @@ void X11Client::maybeCreateX11DecorationRenderer() if (kwinApp()->operationMode() != Application::OperationModeX11) { return; } - if (!compositing() && decoratedClient()) { + if (!Compositor::compositing() && decoratedClient()) { m_decorationRenderer.reset(new X11DecorationRenderer(decoratedClient())); decoration()->update(); } @@ -1170,7 +1170,7 @@ void X11Client::layoutDecorationRects(QRect &left, QRect &top, QRect &right, QRe NETStrut strut = info->frameOverlap(); // Ignore the overlap strut when compositing is disabled - if (!compositing()) + if (!Compositor::compositing()) strut.left = strut.top = strut.right = strut.bottom = 0; else if (strut.left == -1 && strut.top == -1 && strut.right == -1 && strut.bottom == -1) { top = QRect(r.x(), r.y(), r.width(), r.height() / 3); @@ -1196,7 +1196,7 @@ QRect X11Client::transparentRect() const NETStrut strut = info->frameOverlap(); // Ignore the strut when compositing is disabled or the decoration doesn't support it - if (!compositing()) + if (!Compositor::compositing()) strut.left = strut.top = strut.right = strut.bottom = 0; else if (strut.left == -1 && strut.top == -1 && strut.right == -1 && strut.bottom == -1) return QRect(); @@ -1374,7 +1374,7 @@ void X11Client::updateShape() // Decoration mask (i.e. 'else' here) setting is done in setMask() // when the decoration calls it or when the decoration is created/destroyed updateInputShape(); - if (compositing()) { + if (Compositor::compositing()) { addRepaintFull(); addWorkspaceRepaint(visibleGeometry()); // In case shape change removes part of this window } @@ -1592,7 +1592,7 @@ void X11Client::updateVisibility() if (hidden) { info->setState(NET::Hidden, NET::Hidden); setSkipTaskbar(true); // Also hide from taskbar - if (compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) + if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) internalKeep(); else internalHide(); @@ -1601,7 +1601,7 @@ void X11Client::updateVisibility() setSkipTaskbar(originalSkipTaskbar()); // Reset from 'hidden' if (isMinimized()) { info->setState(NET::Hidden, NET::Hidden); - if (compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) + if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) internalKeep(); else internalHide(); @@ -1609,14 +1609,14 @@ void X11Client::updateVisibility() } info->setState(NET::States(), NET::Hidden); if (!isOnCurrentDesktop()) { - if (compositing() && options->hiddenPreviews() != HiddenPreviewsNever) + if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) internalKeep(); else internalHide(); return; } if (!isOnCurrentActivity()) { - if (compositing() && options->hiddenPreviews() != HiddenPreviewsNever) + if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) internalKeep(); else internalHide(); @@ -1678,7 +1678,7 @@ void X11Client::internalHide() void X11Client::internalKeep() { - Q_ASSERT(compositing()); + Q_ASSERT(Compositor::compositing()); if (mapping_state == Kept) return; MappingState old = mapping_state; @@ -1703,7 +1703,7 @@ void X11Client::map() // XComposite invalidates backing pixmaps on unmap (minimize, different // virtual desktop, etc.). We kept the last known good pixmap around // for use in effects, but now we want to have access to the new pixmap - if (compositing()) + if (Compositor::compositing()) discardWindowPixmap(); m_frame.map(); if (!isShade()) { @@ -4133,7 +4133,7 @@ void X11Client::updateServerGeometry() updateShape(); } else { if (isInteractiveMoveResize()) { - if (compositing()) { // Defer the X update until we leave this mode + if (Compositor::compositing()) { // Defer the X update until we leave this mode needsXWindowMove = true; } else { m_frame.move(m_bufferGeometry.topLeft()); // sendSyntheticConfigureNotify() on finish shall be sufficient