From e293972eaa1e28a0e962a37a498bfbe3a47082c9 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 25 Mar 2022 14:20:32 +0200 Subject: [PATCH] Run clang-tidy with -checks=readability-braces-around-statements fixit This fixes style issues in old code. --- .../integration/keyboard_layout_test.cpp | 3 +- .../integration/no_global_shortcuts_test.cpp | 5 +- .../integration/xwayland_selections_test.cpp | 3 +- .../libkwineffects/windowquadlisttest.cpp | 24 +- data/update_default_rules.cpp | 6 +- src/abstract_client.cpp | 439 +++++++---- src/activation.cpp | 156 ++-- src/activities.cpp | 20 +- src/backends/virtual/egl_gbm_backend.cpp | 3 +- src/backends/wayland/egl_wayland_backend.cpp | 6 +- src/backends/x11/standalone/effects_x11.cpp | 3 +- src/backends/x11/standalone/glxbackend.cpp | 66 +- .../x11/standalone/overlaywindow_x11.cpp | 18 +- src/backends/x11/standalone/x11_platform.cpp | 12 +- src/composite.cpp | 3 +- src/cursor.cpp | 14 +- src/deleted.cpp | 12 +- src/effects.cpp | 107 ++- src/effects.h | 3 +- src/effects/backgroundcontrast/contrast.cpp | 27 +- .../backgroundcontrast/contrastshader.cpp | 15 +- src/effects/blur/blur.cpp | 24 +- src/effects/desktopgrid/desktopgrid.cpp | 212 +++-- src/effects/fallapart/fallapart.cpp | 33 +- .../highlightwindow/highlightwindow.cpp | 9 +- src/effects/invert/invert.cpp | 8 +- src/effects/lookingglass/lookingglass.cpp | 5 +- src/effects/magiclamp/magiclamp.cpp | 43 +- src/effects/magnifier/magnifier.cpp | 13 +- src/effects/mouseclick/mouseclick.cpp | 17 +- src/effects/mouseclick/mouseclick.h | 3 +- src/effects/mousemark/mousemark.cpp | 15 +- src/effects/overview/expolayout.cpp | 15 +- src/effects/presentwindows/presentwindows.cpp | 418 ++++++---- src/effects/showfps/showfps.cpp | 40 +- src/effects/slideback/slideback.cpp | 11 +- .../startupfeedback/startupfeedback.cpp | 39 +- src/effects/thumbnailaside/thumbnailaside.cpp | 25 +- src/effects/touchpoints/touchpoints.cpp | 11 +- src/effects/trackmouse/trackmouse.cpp | 27 +- src/effects/wobblywindows/wobblywindows.cpp | 63 +- src/effects/zoom/zoom.cpp | 69 +- src/events.cpp | 200 +++-- src/group.cpp | 4 +- src/kcmkwin/kwinscreenedges/monitor.cpp | 16 +- .../kwinscreenedges/screenpreviewwidget.cpp | 6 +- src/kcmkwin/kwintabbox/thumbnailitem.cpp | 11 +- src/layers.cpp | 115 ++- src/libkwineffects/kwinanimationeffect.cpp | 112 ++- src/libkwineffects/kwinanimationeffect.h | 5 +- src/libkwineffects/kwineffects.cpp | 59 +- src/libkwineffects/kwineffects.h | 6 +- src/libkwineffects/kwinglplatform.cpp | 192 +++-- src/libkwineffects/kwinglplatform.h | 3 +- src/libkwineffects/kwingltexture.cpp | 29 +- src/libkwineffects/kwinglutils.cpp | 130 +-- src/libkwineffects/kwinxrenderutils.cpp | 9 +- src/main_wayland.cpp | 9 +- src/main_x11.cpp | 35 +- src/netinfo.cpp | 75 +- src/options.cpp | 138 ++-- src/placement.cpp | 141 ++-- src/platform.cpp | 3 +- .../scenes/opengl/abstract_egl_backend.cpp | 3 +- .../themes/plastik/code/plastikbutton.cpp | 21 +- src/plugins/screencast/pipewirecore.cpp | 3 +- src/plugins/screencast/screencaststream.cpp | 14 +- src/rootinfo_filter.cpp | 6 +- src/rules.cpp | 173 ++-- src/rules.h | 3 +- src/scene.cpp | 27 +- src/scenes/opengl/lanczosfilter.cpp | 24 +- src/scenes/opengl/scene_opengl.cpp | 64 +- src/scenes/qpainter/scene_qpainter.cpp | 6 +- src/screenedge.cpp | 9 +- src/scripting/scriptedeffect.cpp | 10 +- src/scripting/workspace_wrapper.cpp | 3 +- src/sm.cpp | 42 +- src/tabbox/clientmodel.cpp | 21 +- src/tabbox/desktopmodel.cpp | 12 +- src/tabbox/switcheritem.cpp | 3 +- src/tabbox/tabbox.cpp | 177 +++-- src/tabbox/tabboxhandler.cpp | 61 +- src/tabbox/x11_filter.cpp | 10 +- src/toplevel.cpp | 6 +- src/unmanaged.cpp | 9 +- src/useractions.cpp | 181 +++-- src/utils/common.cpp | 57 +- src/utils/serviceutils.h | 3 +- src/utils/subsurfacemonitor.cpp | 3 +- src/utils/xcbutils.h | 6 +- src/wayland_server.cpp | 3 +- src/workspace.cpp | 232 ++++-- src/x11client.cpp | 742 +++++++++++------- src/xdgshellclient.cpp | 6 +- 95 files changed, 3421 insertions(+), 1862 deletions(-) diff --git a/autotests/integration/keyboard_layout_test.cpp b/autotests/integration/keyboard_layout_test.cpp index d021b742aa..bc16337ae1 100644 --- a/autotests/integration/keyboard_layout_test.cpp +++ b/autotests/integration/keyboard_layout_test.cpp @@ -370,8 +370,9 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy() QCOMPARE(desktops.at(desktop), VirtualDesktopManager::self()->currentDesktop()); layout = (desktop + 1) % xkb->numberOfLayouts(); QCOMPARE(xkb->currentLayout(), layout); - if (--desktop >= VirtualDesktopManager::self()->count()) // overflow + if (--desktop >= VirtualDesktopManager::self()->count()) { // overflow break; + } VirtualDesktopManager::self()->setCurrent(desktops.at(desktop)); } diff --git a/autotests/integration/no_global_shortcuts_test.cpp b/autotests/integration/no_global_shortcuts_test.cpp index 11ce7cbebc..dedbbc18d0 100644 --- a/autotests/integration/no_global_shortcuts_test.cpp +++ b/autotests/integration/no_global_shortcuts_test.cpp @@ -247,10 +247,11 @@ void NoGlobalShortcutsTest::testAxisShortcut() // try to trigger the shortcut quint32 timestamp = 1; Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++); - if (direction == Qt::Vertical) + if (direction == Qt::Vertical) { Test::pointerAxisVertical(sign * 5.0, timestamp++); - else + } else { Test::pointerAxisHorizontal(sign * 5.0, timestamp++); + } QCoreApplication::instance()->processEvents(); QCOMPARE(actionSpy.count(), 0); Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); diff --git a/autotests/integration/xwayland_selections_test.cpp b/autotests/integration/xwayland_selections_test.cpp index 67e6340fc3..55b64c2796 100644 --- a/autotests/integration/xwayland_selections_test.cpp +++ b/autotests/integration/xwayland_selections_test.cpp @@ -29,8 +29,9 @@ struct ProcessKillBeforeDeleter { static inline void cleanup(QProcess *pointer) { - if (pointer) + if (pointer) { pointer->kill(); + } delete pointer; } }; diff --git a/autotests/libkwineffects/windowquadlisttest.cpp b/autotests/libkwineffects/windowquadlisttest.cpp index 165d9cf9e3..e7c755ac67 100644 --- a/autotests/libkwineffects/windowquadlisttest.cpp +++ b/autotests/libkwineffects/windowquadlisttest.cpp @@ -96,14 +96,18 @@ void WindowQuadListTest::testMakeGrid() auto vertexTest = [actualQuad, expectedQuad](int index) { const KWin::WindowVertex &actualVertex = actualQuad[index]; const KWin::WindowVertex &expectedVertex = expectedQuad[index]; - if (actualVertex.x() != expectedVertex.x()) + if (actualVertex.x() != expectedVertex.x()) { return false; - if (actualVertex.y() != expectedVertex.y()) + } + if (actualVertex.y() != expectedVertex.y()) { return false; - if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) + } + if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) { return false; - if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) + } + if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) { return false; + } return true; }; found = vertexTest(0) && vertexTest(1) && vertexTest(2) && vertexTest(3); @@ -180,14 +184,18 @@ void WindowQuadListTest::testMakeRegularGrid() auto vertexTest = [actualQuad, expectedQuad](int index) { const KWin::WindowVertex &actualVertex = actualQuad[index]; const KWin::WindowVertex &expectedVertex = expectedQuad[index]; - if (actualVertex.x() != expectedVertex.x()) + if (actualVertex.x() != expectedVertex.x()) { return false; - if (actualVertex.y() != expectedVertex.y()) + } + if (actualVertex.y() != expectedVertex.y()) { return false; - if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) + } + if (!qFuzzyIsNull(actualVertex.u() - expectedVertex.u())) { return false; - if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) + } + if (!qFuzzyIsNull(actualVertex.v() - expectedVertex.v())) { return false; + } return true; }; found = vertexTest(0) && vertexTest(1) && vertexTest(2) && vertexTest(3); diff --git a/data/update_default_rules.cpp b/data/update_default_rules.cpp index eb29b0cef9..6399d5d680 100644 --- a/data/update_default_rules.cpp +++ b/data/update_default_rules.cpp @@ -17,8 +17,9 @@ int main(int argc, char *argv[]) { - if (argc != 2) + if (argc != 2) { return 1; + } QCoreApplication::setApplicationName("kwin_update_default_rules"); @@ -42,8 +43,9 @@ int main(int argc, char *argv[]) KConfigGroup dcg2(&dest_cfg, QString::number(pos)); for (QMap::ConstIterator it = entries.constBegin(); it != entries.constEnd(); - ++it) + ++it) { dcg2.writeEntry(it.key(), *it); + } } dcg.writeEntry("count", pos); scg.sync(); diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index e933ab9f43..1a17f70b80 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -129,8 +129,9 @@ xcb_timestamp_t AbstractClient::userTime() const void AbstractClient::setSkipSwitcher(bool set) { set = rules()->checkSkipSwitcher(set); - if (set == skipSwitcher()) + if (set == skipSwitcher()) { return; + } m_skipSwitcher = set; doSetSkipSwitcher(); updateWindowRules(Rules::SkipSwitcher); @@ -140,8 +141,9 @@ void AbstractClient::setSkipSwitcher(bool set) void AbstractClient::setSkipPager(bool b) { b = rules()->checkSkipPager(b); - if (b == skipPager()) + if (b == skipPager()) { return; + } m_skipPager = b; doSetSkipPager(); updateWindowRules(Rules::SkipPager); @@ -155,8 +157,9 @@ void AbstractClient::doSetSkipPager() void AbstractClient::setSkipTaskbar(bool b) { int was_wants_tab_focus = wantsTabFocus(); - if (b == skipTaskbar()) + if (b == skipTaskbar()) { return; + } m_skipTaskbar = b; doSetSkipTaskbar(); updateWindowRules(Rules::SkipTaskbar); @@ -201,18 +204,22 @@ void AbstractClient::setActive(bool act) setOpacity(ruledOpacity / 100.0); workspace()->setActiveClient(act ? this : nullptr); - if (!m_active) + if (!m_active) { cancelAutoRaise(); + } - if (!m_active && shadeMode() == ShadeActivated) + if (!m_active && shadeMode() == ShadeActivated) { setShade(ShadeNormal); + } StackingUpdatesBlocker blocker(workspace()); updateLayer(); // active windows may get different layer auto mainclients = mainClients(); - for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) - if ((*it)->isFullScreen()) // fullscreens go high even if their transient is active + for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) { + if ((*it)->isFullScreen()) { // fullscreens go high even if their transient is active (*it)->updateLayer(); + } + } doSetActive(); Q_EMIT activeChanged(); @@ -236,19 +243,22 @@ void AbstractClient::markAsZombie() Layer AbstractClient::layer() const { - if (m_layer == UnknownLayer) + if (m_layer == UnknownLayer) { const_cast(this)->m_layer = belongsToLayer(); + } return m_layer; } void AbstractClient::updateLayer() { - if (layer() == belongsToLayer()) + if (layer() == belongsToLayer()) { return; + } StackingUpdatesBlocker blocker(workspace()); invalidateLayer(); // invalidate, will be updated when doing restacking - for (auto it = transients().constBegin(), end = transients().constEnd(); it != end; ++it) + for (auto it = transients().constBegin(), end = transients().constEnd(); it != end; ++it) { (*it)->updateLayer(); + } } void AbstractClient::invalidateLayer() @@ -263,38 +273,51 @@ Layer AbstractClient::belongsToLayer() const // and the docks move into the NotificationLayer (which is between Above- and // ActiveLayer, so that active fullscreen windows will still cover everything) // Since the desktop is also activated, nothing should be in the ActiveLayer, though - if (isInternal()) + if (isInternal()) { return UnmanagedLayer; - if (isLockScreen()) + } + if (isLockScreen()) { return UnmanagedLayer; - if (isInputMethod()) + } + if (isInputMethod()) { return UnmanagedLayer; - if (isDesktop()) + } + if (isDesktop()) { return workspace()->showingDesktop() ? AboveLayer : DesktopLayer; - if (isSplash()) // no damn annoying splashscreens + } + if (isSplash()) { // no damn annoying splashscreens return NormalLayer; // getting in the way of everything else + } if (isDock()) { - if (workspace()->showingDesktop()) + if (workspace()->showingDesktop()) { return NotificationLayer; + } return layerForDock(); } - if (isPopupWindow()) + if (isPopupWindow()) { return PopupLayer; - if (isOnScreenDisplay()) + } + if (isOnScreenDisplay()) { return OnScreenDisplayLayer; - if (isNotification()) + } + if (isNotification()) { return NotificationLayer; - if (isCriticalNotification()) + } + if (isCriticalNotification()) { return CriticalNotificationLayer; + } if (workspace()->showingDesktop() && belongsToDesktop()) { return AboveLayer; } - if (keepBelow()) + if (keepBelow()) { return BelowLayer; - if (isActiveFullScreen()) + } + if (isActiveFullScreen()) { return ActiveLayer; - if (keepAbove()) + } + if (keepAbove()) { return AboveLayer; + } return NormalLayer; } @@ -309,18 +332,21 @@ Layer AbstractClient::layerForDock() const // slight hack for the 'allow window to cover panel' Kicker setting // don't move keepbelow docks below normal window, but only to the same // layer, so that both may be raised to cover the other - if (keepBelow()) + if (keepBelow()) { return NormalLayer; - if (keepAbove()) // slight hack for the autohiding panels + } + if (keepAbove()) { // slight hack for the autohiding panels return AboveLayer; + } return DockLayer; } void AbstractClient::setKeepAbove(bool b) { b = rules()->checkKeepAbove(b); - if (b && !rules()->checkKeepBelow(false)) + if (b && !rules()->checkKeepBelow(false)) { setKeepBelow(false); + } if (b == keepAbove()) { return; } @@ -339,8 +365,9 @@ void AbstractClient::doSetKeepAbove() void AbstractClient::setKeepBelow(bool b) { b = rules()->checkKeepBelow(b); - if (b && !rules()->checkKeepAbove(false)) + if (b && !rules()->checkKeepAbove(false)) { setKeepAbove(false); + } if (b == keepBelow()) { return; } @@ -396,10 +423,12 @@ bool AbstractClient::isSpecialWindow() const void AbstractClient::demandAttention(bool set) { - if (isActive()) + if (isActive()) { set = false; - if (m_demandsAttention == set) + } + if (m_demandsAttention == set) { return; + } m_demandsAttention = set; doSetDemandsAttention(); workspace()->clientAttentionChanged(this, set); @@ -413,8 +442,9 @@ void AbstractClient::doSetDemandsAttention() void AbstractClient::setDesktop(int desktop) { const int numberOfDesktops = VirtualDesktopManager::self()->count(); - if (desktop != NET::OnAllDesktops) // Do range check + if (desktop != NET::OnAllDesktops) { // Do range check desktop = qMax(1, qMin(numberOfDesktops, desktop)); + } QVector desktops; if (desktop != NET::OnAllDesktops) { @@ -468,8 +498,9 @@ void AbstractClient::setDesktops(QVector desktops) } auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); - for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) + for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) { (*it)->setDesktops(desktops); + } if (isModal()) // if a modal dialog is moved, move the mainwindow with it as otherwise // the (just moved) modal dialog will confusingly return to the mainwindow with @@ -590,16 +621,20 @@ void AbstractClient::setShade(bool set) void AbstractClient::setShade(ShadeMode mode) { - if (!isShadeable()) + if (!isShadeable()) { return; - if (mode == ShadeHover && isInteractiveMove()) + } + if (mode == ShadeHover && isInteractiveMove()) { return; // causes geometry breaks and is probably nasty - if (isSpecialWindow() || !isDecorated()) + } + if (isSpecialWindow() || !isDecorated()) { mode = ShadeNone; + } mode = rules()->checkShade(mode); - if (m_shadeMode == mode) + if (m_shadeMode == mode) { return; + } const bool wasShade = isShade(); const ShadeMode previousShadeMode = shadeMode(); @@ -639,8 +674,9 @@ void AbstractClient::shadeUnhover() void AbstractClient::startShadeHoverTimer() { - if (!isShade()) + if (!isShade()) { return; + } m_shadeHoverTimer = new QTimer(this); connect(m_shadeHoverTimer, &QTimer::timeout, this, &AbstractClient::shadeHover); m_shadeHoverTimer->setSingleShot(true); @@ -707,8 +743,9 @@ void AbstractClient::setMinimized(bool set) void AbstractClient::minimize(bool avoid_animation) { - if (!isMinimizable() || isMinimized()) + if (!isMinimizable() || isMinimized()) { return; + } m_minimized = true; doMinimize(); @@ -727,8 +764,9 @@ void AbstractClient::minimize(bool avoid_animation) void AbstractClient::unminimize(bool avoid_animation) { - if (!isMinimized()) + if (!isMinimized()) { return; + } if (rules()->checkMinimize(false)) { return; @@ -921,10 +959,12 @@ bool AbstractClient::startInteractiveMoveResize() Q_ASSERT(QWidget::keyboardGrabber() == nullptr); Q_ASSERT(QWidget::mouseGrabber() == nullptr); stopDelayedInteractiveMoveResize(); - if (QApplication::activePopupWidget() != nullptr) + if (QApplication::activePopupWidget() != nullptr) { return false; // popups have grab - if (isFullScreen() && (screens()->count() < 2 || !isMovableAcrossScreens())) + } + if (isFullScreen() && (screens()->count() < 2 || !isMovableAcrossScreens())) { return false; + } if (!doStartInteractiveMoveResize()) { return false; } @@ -985,8 +1025,9 @@ bool AbstractClient::startInteractiveMoveResize() updateElectricGeometryRestore(); checkUnrestrictedInteractiveMoveResize(); Q_EMIT clientStartUserMovedResized(this); - if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) + if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) { ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical | Qt::Horizontal); + } return true; } @@ -1023,8 +1064,9 @@ void AbstractClient::finishInteractiveMoveResize(bool cancel) // NOTE: Most of it is duplicated from handleMoveResize(). void AbstractClient::checkUnrestrictedInteractiveMoveResize() { - if (isUnrestrictedInteractiveMoveResize()) + if (isUnrestrictedInteractiveMoveResize()) { return; + } const QRect &moveResizeGeom = moveResizeGeometry(); QRect desktopArea = workspace()->clientArea(WorkArea, this, moveResizeGeom.center()); int left_marge, right_marge, top_marge, bottom_marge, titlebar_marge; @@ -1037,27 +1079,36 @@ void AbstractClient::checkUnrestrictedInteractiveMoveResize() top_marge = borderBottom(); bottom_marge = borderTop(); if (isInteractiveResize()) { - if (moveResizeGeom.bottom() < desktopArea.top() + top_marge) + if (moveResizeGeom.bottom() < desktopArea.top() + top_marge) { setUnrestrictedInteractiveMoveResize(true); - if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge) + } + if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge) { setUnrestrictedInteractiveMoveResize(true); - if (moveResizeGeom.right() < desktopArea.left() + left_marge) + } + if (moveResizeGeom.right() < desktopArea.left() + left_marge) { setUnrestrictedInteractiveMoveResize(true); - if (moveResizeGeom.left() > desktopArea.right() - right_marge) + } + if (moveResizeGeom.left() > desktopArea.right() - right_marge) { setUnrestrictedInteractiveMoveResize(true); - if (!isUnrestrictedInteractiveMoveResize() && moveResizeGeom.top() < desktopArea.top()) // titlebar mustn't go out + } + if (!isUnrestrictedInteractiveMoveResize() && moveResizeGeom.top() < desktopArea.top()) { // titlebar mustn't go out setUnrestrictedInteractiveMoveResize(true); + } } if (isInteractiveMove()) { - if (moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1) + if (moveResizeGeom.bottom() < desktopArea.top() + titlebar_marge - 1) { setUnrestrictedInteractiveMoveResize(true); + } // no need to check top_marge, titlebar_marge already handles it - if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge + 1) // titlebar mustn't go out + if (moveResizeGeom.top() > desktopArea.bottom() - bottom_marge + 1) { // titlebar mustn't go out setUnrestrictedInteractiveMoveResize(true); - if (moveResizeGeom.right() < desktopArea.left() + left_marge) + } + if (moveResizeGeom.right() < desktopArea.left() + left_marge) { setUnrestrictedInteractiveMoveResize(true); - if (moveResizeGeom.left() > desktopArea.right() - right_marge) + } + if (moveResizeGeom.left() > desktopArea.right() - right_marge) { setUnrestrictedInteractiveMoveResize(true); + } } } @@ -1102,8 +1153,9 @@ void AbstractClient::handleInteractiveMoveResize(const QPoint &local, const QPoi const QRect &geom_restore = geometryRestore(); setInteractiveMoveOffset(QPoint(double(interactiveMoveOffset().x()) / double(oldGeo.width()) * double(geom_restore.width()), double(interactiveMoveOffset().y()) / double(oldGeo.height()) * double(geom_restore.height()))); - if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore) + if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore) { setMoveResizeGeometry(geom_restore); + } handleInteractiveMoveResize(local.x(), local.y(), global.x(), global.y()); // fix position } else if (quickTileMode() == QuickTileMode(QuickTileFlag::None) && isResizable()) { checkQuickTilingMaximizationZones(global.x(), global.y()); @@ -1113,8 +1165,9 @@ void AbstractClient::handleInteractiveMoveResize(const QPoint &local, const QPoi void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y_root) { - if (isWaitingForInteractiveMoveResizeSync()) + if (isWaitingForInteractiveMoveResizeSync()) { return; // we're still waiting for the client or the timeout + } const Gravity gravity = interactiveMoveResizeGravity(); if ((gravity == Gravity::None && !isMovableAcrossScreens()) @@ -1131,8 +1184,9 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y return; } updateCursor(); - } else + } else { return; + } } // ShadeHover or ShadeActive, ShadeNormal was already avoided above @@ -1242,19 +1296,22 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y const QRect r = rect & titleRect; realVisiblePixels += r.width() * r.height(); if ((transposed && r.width() == titleRect.width()) || // Only the full size regions... - (!transposed && r.height() == titleRect.height())) // ...prevents long slim areas + (!transposed && r.height() == titleRect.height())) { // ...prevents long slim areas visiblePixels += r.width() * r.height(); + } } - if (visiblePixels >= requiredPixels) + if (visiblePixels >= requiredPixels) { break; // We have reached a valid position + } if (realVisiblePixels <= lastVisiblePixels) { - if (titleFailed && realVisiblePixels < lastVisiblePixels) + if (titleFailed && realVisiblePixels < lastVisiblePixels) { break; // we won't become better - else { - if (!titleFailed) + } else { + if (!titleFailed) { setMoveResizeGeometry(lastTry); + } titleFailed = true; } } @@ -1274,10 +1331,12 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y bool btmChanged = previousMoveResizeGeom.bottom() != moveResizeGeom.bottom(); auto fixChangedState = [titleFailed](bool &major, bool &counter, bool &ad1, bool &ad2) { counter = false; - if (titleFailed) + if (titleFailed) { major = false; - if (major) + } + if (major) { ad1 = ad2 = false; + } }; switch (titlebarPosition()) { default: @@ -1294,16 +1353,17 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y fixChangedState(rightChanged, leftChanged, topChanged, btmChanged); break; } - if (topChanged) + if (topChanged) { moveResizeGeom.setTop(moveResizeGeom.y() + sign(previousMoveResizeGeom.y() - moveResizeGeom.y())); - else if (leftChanged) + } else if (leftChanged) { moveResizeGeom.setLeft(moveResizeGeom.x() + sign(previousMoveResizeGeom.x() - moveResizeGeom.x())); - else if (btmChanged) + } else if (btmChanged) { moveResizeGeom.setBottom(moveResizeGeom.bottom() + sign(previousMoveResizeGeom.bottom() - moveResizeGeom.bottom())); - else if (rightChanged) + } else if (rightChanged) { moveResizeGeom.setRight(moveResizeGeom.right() + sign(previousMoveResizeGeom.right() - moveResizeGeom.right())); - else + } else { break; // no position changed - that's certainly not good + } setMoveResizeGeometry(moveResizeGeom); } } @@ -1318,23 +1378,25 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y // if aspect ratios are specified, both dimensions may change. // Therefore grow to the right/bottom if needed. // TODO it should probably obey gravity rather than always using right/bottom ? - if (sizeMode == SizeModeFixedH) + if (sizeMode == SizeModeFixedH) { orig.setRight(bottomright.x()); - else if (sizeMode == SizeModeFixedW) + } else if (sizeMode == SizeModeFixedW) { orig.setBottom(bottomright.y()); + } calculateMoveResizeGeom(); - if (moveResizeGeometry().size() != previousMoveResizeGeom.size()) + if (moveResizeGeometry().size() != previousMoveResizeGeom.size()) { update = true; + } } else if (isInteractiveMove()) { Q_ASSERT(gravity == Gravity::None); if (!isMovable()) { // isMovableAcrossScreens() must have been true to get here // Special moving of maximized windows on Xinerama screens AbstractOutput *output = kwinApp()->platform()->outputAt(globalPos); - if (isFullScreen()) + if (isFullScreen()) { setMoveResizeGeometry(workspace()->clientArea(FullScreenArea, this, output)); - else { + } else { QRect moveResizeGeom = workspace()->clientArea(MaximizeArea, this, output); QSize adjSize = constrainFrameSize(moveResizeGeom.size(), SizeModeMax); if (adjSize != moveResizeGeom.size()) { @@ -1366,11 +1428,13 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y for (const QRect &rect : availableArea) { const QRect r = rect & titleRect; if ((transposed && r.width() == titleRect.width()) || // Only the full size regions... - (!transposed && r.height() == titleRect.height())) // ...prevents long slim areas + (!transposed && r.height() == titleRect.height())) { // ...prevents long slim areas visiblePixels += r.width() * r.height(); + } } - if (visiblePixels >= requiredPixels) + if (visiblePixels >= requiredPixels) { break; // We have reached a valid position + } // (esp.) if there're more screens with different struts (panels) it the titlebar // will be movable outside the movearea (covering one of the panels) until it @@ -1400,10 +1464,11 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y int dx = sign(previousMoveResizeGeom.x() - moveResizeGeom.x()), dy = sign(previousMoveResizeGeom.y() - moveResizeGeom.y()); - if (visiblePixels && dx) // means there's no full width cap -> favor horizontally + if (visiblePixels && dx) { // means there's no full width cap -> favor horizontally dy = 0; - else if (dy) + } else if (dy) { dx = 0; + } // Move it back moveResizeGeom.translate(dx, dy); @@ -1415,14 +1480,16 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y } } } - if (moveResizeGeometry().topLeft() != previousMoveResizeGeom.topLeft()) + if (moveResizeGeometry().topLeft() != previousMoveResizeGeom.topLeft()) { update = true; + } } else { Q_UNREACHABLE(); } - if (!update) + if (!update) { return; + } if (isInteractiveMove()) { move(moveResizeGeometry().topLeft()); @@ -1697,14 +1764,16 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint // since this is a mouseOp it's however safe to use the client under the mouse instead if (isActive() && options->focusPolicyIsReasonable()) { AbstractClient *next = workspace()->clientUnderMouse(output()); - if (next && next != this) + if (next && next != this) { workspace()->requestFocus(next, false); + } } break; } case Options::MouseOperationsMenu: - if (isActive() && options->isClickRaise()) + if (isActive() && options->isClickRaise()) { autoRaise(); + } workspace()->showWindowMenu(QRect(globalPos, globalPos), this); break; case Options::MouseToggleRaiseAndLower: @@ -1718,8 +1787,9 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint begin = workspace()->stackingOrder().constBegin(); while (mustReplay && --it != begin && *it != this) { AbstractClient *c = qobject_cast(*it); - if (!c || (c->keepAbove() && !keepAbove()) || (keepBelow() && !c->keepBelow())) + if (!c || (c->keepAbove() && !keepAbove()) || (keepBelow() && !c->keepBelow())) { continue; // can never raise above "it" + } mustReplay = !(c->isOnCurrentDesktop() && c->isOnCurrentActivity() && c->frameGeometry().intersects(frameGeometry())); } } @@ -1761,18 +1831,20 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint break; case Options::MouseAbove: { StackingUpdatesBlocker blocker(workspace()); - if (keepBelow()) + if (keepBelow()) { setKeepBelow(false); - else + } else { setKeepAbove(true); + } break; } case Options::MouseBelow: { StackingUpdatesBlocker blocker(workspace()); - if (keepAbove()) + if (keepAbove()) { setKeepAbove(false); - else + } else { setKeepBelow(true); + } break; } case Options::MousePreviousDesktop: @@ -1782,12 +1854,14 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint workspace()->windowToNextDesktop(this); break; case Options::MouseOpacityMore: - if (!isDesktop()) // No point in changing the opacity of the desktop + if (!isDesktop()) { // No point in changing the opacity of the desktop setOpacity(qMin(opacity() + 0.1, 1.0)); + } break; case Options::MouseOpacityLess: - if (!isDesktop()) // No point in changing the opacity of the desktop + if (!isDesktop()) { // No point in changing the opacity of the desktop setOpacity(qMax(opacity() - 0.1, 0.1)); + } break; case Options::MouseClose: closeWindow(); @@ -1800,27 +1874,32 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint // fallthrough case Options::MouseMove: case Options::MouseUnrestrictedMove: { - if (!isMovableAcrossScreens()) + if (!isMovableAcrossScreens()) { break; - if (isInteractiveMoveResize()) + } + if (isInteractiveMoveResize()) { finishInteractiveMoveResize(false); + } setInteractiveMoveResizeGravity(Gravity::None); setInteractiveMoveResizePointerButtonDown(true); setInteractiveMoveOffset(QPoint(globalPos.x() - x(), globalPos.y() - y())); // map from global setInvertedInteractiveMoveOffset(rect().bottomRight() - interactiveMoveOffset()); setUnrestrictedInteractiveMoveResize((cmd == Options::MouseActivateRaiseAndUnrestrictedMove || cmd == Options::MouseUnrestrictedMove)); - if (!startInteractiveMoveResize()) + if (!startInteractiveMoveResize()) { setInteractiveMoveResizePointerButtonDown(false); + } updateCursor(); break; } case Options::MouseResize: case Options::MouseUnrestrictedResize: { - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { break; - if (isInteractiveMoveResize()) + } + if (isInteractiveMoveResize()) { finishInteractiveMoveResize(false); + } setInteractiveMoveResizePointerButtonDown(true); const QPoint moveOffset = QPoint(globalPos.x() - x(), globalPos.y() - y()); // map from global setInteractiveMoveOffset(moveOffset); @@ -1840,8 +1919,9 @@ bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint setInteractiveMoveResizeGravity(gravity); setInvertedInteractiveMoveOffset(rect().bottomRight() - moveOffset); setUnrestrictedInteractiveMoveResize((cmd == Options::MouseUnrestrictedResize)); - if (!startInteractiveMoveResize()) + if (!startInteractiveMoveResize()) { setInteractiveMoveResizePointerButtonDown(false); + } updateCursor(); break; } @@ -1926,8 +2006,9 @@ QList AbstractClient::allMainClients() const void AbstractClient::setModal(bool m) { // Qt-3.2 can have even modal normal windows :( - if (m_modal == m) + if (m_modal == m) { return; + } m_modal = m; Q_EMIT modalChanged(); // Changing modality for a mapped window is weird (?) @@ -1989,8 +2070,9 @@ void AbstractClient::removeTransientFromList(AbstractClient *cl) bool AbstractClient::isActiveFullScreen() const { - if (!isFullScreen()) + if (!isFullScreen()) { return false; + } const auto ac = workspace()->mostRecentlyActivatedClient(); // instead of activeClient() - avoids flicker // according to NETWM spec implementation notes suggests @@ -2020,8 +2102,9 @@ void AbstractClient::updateInitialMoveResizeGeometry() void AbstractClient::updateCursor() { Gravity gravity = interactiveMoveResizeGravity(); - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { gravity = Gravity::None; + } CursorShape c = Qt::ArrowCursor; switch (gravity) { case Gravity::TopLeft: @@ -2049,14 +2132,16 @@ void AbstractClient::updateCursor() c = KWin::ExtendedCursor::SizeEast; break; default: - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { c = Qt::SizeAllCursor; - else + } else { c = Qt::ArrowCursor; + } break; } - if (c == m_interactiveMoveResize.cursor) + if (c == m_interactiveMoveResize.cursor) { return; + } m_interactiveMoveResize.cursor = c; Q_EMIT moveResizeCursorChanged(c); } @@ -2065,8 +2150,9 @@ void AbstractClient::leaveInteractiveMoveResize() { workspace()->setMoveResizeClient(nullptr); setInteractiveMoveResize(false); - if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) + if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) { ScreenEdges::self()->reserveDesktopSwitching(false, Qt::Vertical | Qt::Horizontal); + } if (isElectricBorderMaximizing()) { outline()->hide(); elevate(false); @@ -2126,10 +2212,11 @@ void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot) } if (mode != QuickTileMode(QuickTileFlag::None)) { - if (yroot <= area.y() + area.height() * options->electricBorderCornerRatio()) + if (yroot <= area.y() + area.height() * options->electricBorderCornerRatio()) { mode |= QuickTileFlag::Top; - else if (yroot >= area.y() + area.height() - area.height() * options->electricBorderCornerRatio()) + } else if (yroot >= area.y() + area.height() - area.height() * options->electricBorderCornerRatio()) { mode |= QuickTileFlag::Bottom; + } } else if (options->electricBorderMaximize() && yroot <= area.y() + 5 && isMaximizable()) { mode = QuickTileFlag::Maximize; innerBorder = isInScreen(QPoint(xroot, area.y() - 1)); @@ -2144,8 +2231,9 @@ void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot) m_electricMaximizingDelay->setInterval(250); m_electricMaximizingDelay->setSingleShot(true); connect(m_electricMaximizingDelay, &QTimer::timeout, this, [this]() { - if (isInteractiveMove()) + if (isInteractiveMove()) { setElectricBorderMaximizing(electricBorderMode() != QuickTileMode(QuickTileFlag::None)); + } }); } m_electricMaximizingDelay->start(); @@ -2157,8 +2245,9 @@ void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot) void AbstractClient::keyPressEvent(uint key_code) { - if (!isInteractiveMove() && !isInteractiveResize()) + if (!isInteractiveMove() && !isInteractiveResize()) { return; + } bool is_control = key_code & Qt::CTRL; bool is_alt = key_code & Qt::ALT; key_code = key_code & ~Qt::KeyboardModifierMask; @@ -2205,8 +2294,9 @@ void AbstractClient::dontInteractiveMoveResize() { setInteractiveMoveResizePointerButtonDown(false); stopDelayedInteractiveMoveResize(); - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { finishInteractiveMoveResize(false); + } } Gravity AbstractClient::mouseGravity() const @@ -2341,8 +2431,9 @@ bool AbstractClient::processDecorationButtonPress(QMouseEvent *event, bool ignor { Options::MouseCommand com = Options::MouseNothing; bool active = isActive(); - if (!wantsInput()) // we cannot be active, use it anyway + if (!wantsInput()) { // we cannot be active, use it anyway active = true; + } // check whether it is a double click if (event->button() == Qt::LeftButton && titlebarPositionUnderMouse()) { @@ -2361,12 +2452,13 @@ bool AbstractClient::processDecorationButtonPress(QMouseEvent *event, bool ignor } } - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton) { com = active ? options->commandActiveTitlebar1() : options->commandInactiveTitlebar1(); - else if (event->button() == Qt::MiddleButton) + } else if (event->button() == Qt::MiddleButton) { com = active ? options->commandActiveTitlebar2() : options->commandInactiveTitlebar2(); - else if (event->button() == Qt::RightButton) + } else if (event->button() == Qt::RightButton) { com = active ? options->commandActiveTitlebar3() : options->commandInactiveTitlebar3(); + } if (event->button() == Qt::LeftButton && com != Options::MouseOperationsMenu // actions where it's not possible to get the matching && com != Options::MouseMinimize) // mouse release event @@ -2381,8 +2473,9 @@ bool AbstractClient::processDecorationButtonPress(QMouseEvent *event, bool ignor } // In the new API the decoration may process the menu action to display an inactive tab's menu. // If the event is unhandled then the core will create one for the active window in the group. - if (!ignoreMenu || com != Options::MouseOperationsMenu) + if (!ignoreMenu || com != Options::MouseOperationsMenu) { performMouseCommand(com, event->globalPos()); + } return !( // Return events that should be passed to the decoration in the new API com == Options::MouseRaise || com == Options::MouseOperationsMenu || com == Options::MouseActivateAndRaise || com == Options::MouseActivate || com == Options::MouseActivateRaiseAndPassClick || com == Options::MouseActivateAndPassClick || com == Options::MouseNothing); } @@ -2442,15 +2535,17 @@ void AbstractClient::pointerEnterEvent(const QPoint &globalPos) startShadeHoverTimer(); } - if (options->focusPolicy() == Options::ClickToFocus || workspace()->userActionsMenu()->isShown()) + if (options->focusPolicy() == Options::ClickToFocus || workspace()->userActionsMenu()->isShown()) { return; + } if (options->isAutoRaise() && !isDesktop() && !isDock() && workspace()->focusChangeEnabled() && globalPos != workspace()->focusMousePosition() && workspace()->topClientOnDesktop(VirtualDesktopManager::self()->currentDesktop(), options->isSeparateScreenFocus() ? output() : nullptr) != this) { startAutoRaise(); } - if (isDesktop() || isDock()) + if (isDesktop() || isDock()) { return; + } // for FocusFollowsMouse, change focus only if the mouse has actually been moved, not if the focus // change came because of window changes (e.g. closing a window) - #92290 if (options->focusPolicy() != Options::FocusFollowsMouse @@ -2961,10 +3056,12 @@ void AbstractClient::setElectricBorderMode(QuickTileMode mode) { if (mode != QuickTileMode(QuickTileFlag::Maximize)) { // sanitize the mode, ie. simplify "invalid" combinations - if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal)) + if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal)) { mode &= ~QuickTileMode(QuickTileFlag::Horizontal); - if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical)) + } + if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical)) { mode &= ~QuickTileMode(QuickTileFlag::Vertical); + } } m_electricMode = mode; } @@ -2972,31 +3069,35 @@ void AbstractClient::setElectricBorderMode(QuickTileMode mode) void AbstractClient::setElectricBorderMaximizing(bool maximizing) { m_electricMaximizing = maximizing; - if (maximizing) + if (maximizing) { outline()->show(quickTileGeometry(electricBorderMode(), Cursors::self()->mouse()->pos()), moveResizeGeometry()); - else + } else { outline()->hide(); + } elevate(maximizing); } QRect AbstractClient::quickTileGeometry(QuickTileMode mode, const QPoint &pos) const { if (mode == QuickTileMode(QuickTileFlag::Maximize)) { - if (maximizeMode() == MaximizeFull) + if (maximizeMode() == MaximizeFull) { return geometryRestore(); - else + } else { return workspace()->clientArea(MaximizeArea, this, pos); + } } QRect ret = workspace()->clientArea(MaximizeArea, this, pos); - if (mode & QuickTileFlag::Left) + if (mode & QuickTileFlag::Left) { ret.setRight(ret.left() + ret.width() / 2 - 1); - else if (mode & QuickTileFlag::Right) + } else if (mode & QuickTileFlag::Right) { ret.setLeft(ret.right() - (ret.width() - ret.width() / 2) + 1); - if (mode & QuickTileFlag::Top) + } + if (mode & QuickTileFlag::Top) { ret.setBottom(ret.top() + ret.height() / 2 - 1); - else if (mode & QuickTileFlag::Bottom) + } else if (mode & QuickTileFlag::Bottom) { ret.setTop(ret.bottom() - (ret.height() - ret.height() / 2) + 1); + } return ret; } @@ -3057,10 +3158,12 @@ void AbstractClient::setQuickTileMode(QuickTileMode mode, bool keyboard) } // sanitize the mode, ie. simplify "invalid" combinations - if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal)) + if ((mode & QuickTileFlag::Horizontal) == QuickTileMode(QuickTileFlag::Horizontal)) { mode &= ~QuickTileMode(QuickTileFlag::Horizontal); - if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical)) + } + if ((mode & QuickTileFlag::Vertical) == QuickTileMode(QuickTileFlag::Vertical)) { mode &= ~QuickTileMode(QuickTileFlag::Vertical); + } // restore from maximized so that it is possible to tile maximized windows with one hit or by dragging if (requestedMaximizeMode() != MaximizeRestore) { @@ -3183,10 +3286,12 @@ void AbstractClient::sendToOutput(AbstractOutput *newOutput) // so we clear the state first MaximizeMode maxMode = maximizeMode(); QuickTileMode qtMode = quickTileMode(); - if (maxMode != MaximizeRestore) + if (maxMode != MaximizeRestore) { maximize(MaximizeRestore); - if (qtMode != QuickTileMode(QuickTileFlag::None)) + } + if (qtMode != QuickTileMode(QuickTileFlag::None)) { setQuickTileMode(QuickTileFlag::None, true); + } QRect oldScreenArea = workspace()->clientArea(MaximizeArea, this); QRect screenArea = workspace()->clientArea(MaximizeArea, this, newOutput); @@ -3194,8 +3299,9 @@ void AbstractClient::sendToOutput(AbstractOutput *newOutput) // the window can have its center so that the position correction moves the new center onto // the old screen, what will tile it where it is. Ie. the screen is not changed // this happens esp. with electric border quicktiling - if (qtMode != QuickTileMode(QuickTileFlag::None)) + if (qtMode != QuickTileMode(QuickTileFlag::None)) { keepInArea(oldScreenArea); + } QRect oldGeom = moveResizeGeometry(); QRect newGeom = oldGeom; @@ -3231,14 +3337,17 @@ void AbstractClient::sendToOutput(AbstractOutput *newOutput) // finally reset special states // NOTICE that MaximizeRestore/QuickTileFlag::None checks are required. // eg. setting QuickTileFlag::None would break maximization - if (maxMode != MaximizeRestore) + if (maxMode != MaximizeRestore) { maximize(maxMode); - if (qtMode != QuickTileMode(QuickTileFlag::None) && qtMode != quickTileMode()) + } + if (qtMode != QuickTileMode(QuickTileFlag::None) && qtMode != quickTileMode()) { setQuickTileMode(qtMode, true); + } auto tso = workspace()->ensureStackingOrder(transients()); - for (auto it = tso.constBegin(), end = tso.constEnd(); it != end; ++it) + for (auto it = tso.constBegin(), end = tso.constEnd(); it != end; ++it) { (*it)->sendToOutput(newOutput); + } } void AbstractClient::updateGeometryRestoresForFullscreen(AbstractOutput *output) @@ -3298,8 +3407,9 @@ void AbstractClient::checkWorkspacePosition(QRect oldGeometry, const VirtualDesk // because the window already had its position, and if a window // with a strut altering the workarea would be managed in initialization // after this one, this window would be moved - if (!workspace() || workspace()->initializing()) + if (!workspace() || workspace()->initializing()) { return; + } VirtualDesktop *desktop = !isOnCurrentDesktop() ? desktops().constLast() : VirtualDesktopManager::self()->currentDesktop(); if (!oldDesktop) { @@ -3349,45 +3459,53 @@ void AbstractClient::checkWorkspacePosition(QRect oldGeometry, const VirtualDesk for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) { QRect rect = r & oldGeomTall; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { oldTopMax = qMax(oldTopMax, rect.y() + rect.height()); + } } for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight)) { QRect rect = r & oldGeomWide; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { oldRightMax = qMin(oldRightMax, rect.x()); + } } for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom)) { QRect rect = r & oldGeomTall; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { oldBottomMax = qMin(oldBottomMax, rect.y()); + } } for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft)) { QRect rect = r & oldGeomWide; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { oldLeftMax = qMax(oldLeftMax, rect.x() + rect.width()); + } } // These 4 compute new bounds for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaTop)) { QRect rect = r & newGeomTall; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { topMax = qMax(topMax, rect.y() + rect.height()); + } } for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaRight)) { QRect rect = r & newGeomWide; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { rightMax = qMin(rightMax, rect.x()); + } } for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaBottom)) { QRect rect = r & newGeomTall; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { bottomMax = qMin(bottomMax, rect.y()); + } } for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaLeft)) { QRect rect = r & newGeomWide; - if (!rect.isEmpty()) + if (!rect.isEmpty()) { leftMax = qMax(leftMax, rect.x() + rect.width()); + } } // Check if the sides were inside or touching but are no longer @@ -3399,25 +3517,33 @@ void AbstractClient::checkWorkspacePosition(QRect oldGeometry, const VirtualDesk }; bool keep[4] = {false, false, false, false}; bool save[4] = {false, false, false, false}; - if (oldGeometry.x() >= oldLeftMax) + if (oldGeometry.x() >= oldLeftMax) { save[Left] = newGeom.x() < leftMax; - if (oldGeometry.x() == oldLeftMax) + } + if (oldGeometry.x() == oldLeftMax) { keep[Left] = newGeom.x() != leftMax; + } - if (oldGeometry.y() >= oldTopMax) + if (oldGeometry.y() >= oldTopMax) { save[Top] = newGeom.y() < topMax; - if (oldGeometry.y() == oldTopMax) + } + if (oldGeometry.y() == oldTopMax) { keep[Top] = newGeom.y() != topMax; + } - if (oldGeometry.right() <= oldRightMax - 1) + if (oldGeometry.right() <= oldRightMax - 1) { save[Right] = newGeom.right() > rightMax - 1; - if (oldGeometry.right() == oldRightMax - 1) + } + if (oldGeometry.right() == oldRightMax - 1) { keep[Right] = newGeom.right() != rightMax - 1; + } - if (oldGeometry.bottom() <= oldBottomMax - 1) + if (oldGeometry.bottom() <= oldBottomMax - 1) { save[Bottom] = newGeom.bottom() > bottomMax - 1; - if (oldGeometry.bottom() == oldBottomMax - 1) + } + if (oldGeometry.bottom() == oldBottomMax - 1) { keep[Bottom] = newGeom.bottom() != bottomMax - 1; + } // if randomly touches opposing edges, do not favor either if (keep[Left] && keep[Right]) { @@ -3427,24 +3553,31 @@ void AbstractClient::checkWorkspacePosition(QRect oldGeometry, const VirtualDesk keep[Top] = keep[Bottom] = false; } - if (save[Left] || keep[Left]) + if (save[Left] || keep[Left]) { newGeom.moveLeft(qMax(leftMax, screenArea.x())); - if (save[Top] || keep[Top]) + } + if (save[Top] || keep[Top]) { newGeom.moveTop(qMax(topMax, screenArea.y())); - if (save[Right] || keep[Right]) + } + if (save[Right] || keep[Right]) { newGeom.moveRight(qMin(rightMax - 1, screenArea.right())); - if (save[Bottom] || keep[Bottom]) + } + if (save[Bottom] || keep[Bottom]) { newGeom.moveBottom(qMin(bottomMax - 1, screenArea.bottom())); + } - if (oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax) + if (oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax) { newGeom.setLeft(qMax(leftMax, screenArea.x())); - if (oldGeometry.y() >= oldTopMax && newGeom.y() < topMax) + } + if (oldGeometry.y() >= oldTopMax && newGeom.y() < topMax) { newGeom.setTop(qMax(topMax, screenArea.y())); + } checkOffscreenPosition(&newGeom, screenArea); // Obey size hints. TODO: We really should make sure it stays in the right place - if (!isShade()) + if (!isShade()) { newGeom.setSize(constrainFrameSize(newGeom.size())); + } moveResize(newGeom); } diff --git a/src/activation.cpp b/src/activation.cpp index 102045d7b1..a0e1b3e477 100644 --- a/src/activation.cpp +++ b/src/activation.cpp @@ -217,11 +217,13 @@ namespace KWin */ void Workspace::setActiveClient(AbstractClient *c) { - if (active_client == c) + if (active_client == c) { return; + } - if (active_popup && active_popup_client != c && set_active_client_recursion == 0) + if (active_popup && active_popup_client != c && set_active_client_recursion == 0) { closeActivePopup(); + } if (m_userActionsMenu->hasClient() && !m_userActionsMenu->isMenuClient(c) && set_active_client_recursion == 0) { m_userActionsMenu->close(); } @@ -251,10 +253,11 @@ void Workspace::setActiveClient(AbstractClient *c) } updateToolWindows(false); - if (c) + if (c) { disableGlobalShortcutsForClient(c->rules()->checkDisableGlobalShortcuts(false)); - else + } else { disableGlobalShortcutsForClient(false); + } updateStackingOrder(); // e.g. fullscreens have different layer when active/not-active @@ -299,15 +302,17 @@ void Workspace::activateClient(AbstractClient *c, bool force) --block_focus; } #endif - if (c->isMinimized()) + if (c->isMinimized()) { c->unminimize(); + } // ensure the window is really visible - could eg. be a hidden utility window, see bug #348083 c->showClient(); // TODO force should perhaps allow this only if the window already contains the mouse - if (options->focusPolicyIsReasonable() || force) + if (options->focusPolicyIsReasonable() || force) { requestFocus(c, force); + } // Don't update user time for clients that have focus stealing workaround. // As they usually belong to the current active window but fail to provide @@ -337,8 +342,9 @@ bool Workspace::requestFocus(AbstractClient *c, bool force) bool Workspace::takeActivity(AbstractClient *c, ActivityFlags flags) { // the 'if ( c == active_client ) return;' optimization mustn't be done here - if (!focusChangeEnabled() && (c != active_client)) + if (!focusChangeEnabled() && (c != active_client)) { flags &= ~ActivityFocus; + } if (!c) { focusToNull(); @@ -351,14 +357,16 @@ bool Workspace::takeActivity(AbstractClient *c, ActivityFlags flags) if (modal->desktops() != c->desktops()) { modal->setDesktops(c->desktops()); } - if (!modal->isShown() && !modal->isMinimized()) // forced desktop or utility window + if (!modal->isShown() && !modal->isMinimized()) { // forced desktop or utility window activateClient(modal); // activating a minimized blocked window will unminimize its modal implicitly + } // if the click was inside the window (i.e. handled is set), // but it has a modal, there's no need to use handled mode, because // the modal doesn't get the click anyway // raising of the original window needs to be still done - if (flags & ActivityRaise) + if (flags & ActivityRaise) { raiseClient(c); + } c = modal; } cancelDelayFocus(); @@ -385,10 +393,12 @@ bool Workspace::takeActivity(AbstractClient *c, ActivityFlags flags) bool ret = true; - if (flags & ActivityFocus) + if (flags & ActivityFocus) { ret &= c->takeFocus(); - if (flags & ActivityRaise) + } + if (flags & ActivityRaise) { workspace()->raiseClient(c); + } if (!c->isOnActiveOutput()) { setActiveOutput(c->output()); @@ -421,8 +431,9 @@ AbstractClient *Workspace::clientUnderMouse(AbstractOutput *output) const // rule out clients which are not really visible. // the screen test is rather superfluous for xrandr & twinview since the geometry would differ -> TODO: might be dropped - if (!(client->isShown() && client->isOnCurrentDesktop() && client->isOnCurrentActivity() && client->isOnOutput(output) && !client->isShade())) + if (!(client->isShown() && client->isOnCurrentDesktop() && client->isOnCurrentActivity() && client->isOnOutput(output) && !client->isShade())) { continue; + } if (client->frameGeometry().contains(Cursors::self()->mouse()->pos())) { return client; @@ -435,14 +446,16 @@ AbstractClient *Workspace::clientUnderMouse(AbstractOutput *output) const bool Workspace::activateNextClient(AbstractClient *c) { // if 'c' is not the active or the to-become active one, do nothing - if (!(c == active_client || (should_get_focus.count() > 0 && c == should_get_focus.last()))) + if (!(c == active_client || (should_get_focus.count() > 0 && c == should_get_focus.last()))) { return false; + } closeActivePopup(); if (c != nullptr) { - if (c == active_client) + if (c == active_client) { setActiveClient(nullptr); + } should_get_focus.removeAll(c); } @@ -453,15 +466,17 @@ bool Workspace::activateNextClient(AbstractClient *c) return true; } - if (!options->focusPolicyIsReasonable()) + if (!options->focusPolicyIsReasonable()) { return false; + } AbstractClient *get_focus = nullptr; VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); - if (!get_focus && showingDesktop()) + if (!get_focus && showingDesktop()) { get_focus = findDesktop(true, desktop); // to not break the state + } if (!get_focus && options->isNextFocusPrefersMouse()) { get_focus = clientUnderMouse(c ? c->output() : workspace()->activeOutput()); @@ -486,28 +501,33 @@ bool Workspace::activateNextClient(AbstractClient *c) } } - if (get_focus == nullptr) // last chance: focus the desktop + if (get_focus == nullptr) { // last chance: focus the desktop get_focus = findDesktop(true, desktop); + } - if (get_focus != nullptr) + if (get_focus != nullptr) { requestFocus(get_focus); - else + } else { focusToNull(); + } return true; } void Workspace::switchToOutput(AbstractOutput *output) { - if (!options->focusPolicyIsReasonable()) + if (!options->focusPolicyIsReasonable()) { return; + } closeActivePopup(); VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); AbstractClient *get_focus = FocusChain::self()->getForActivation(desktop, output); - if (get_focus == nullptr) + if (get_focus == nullptr) { get_focus = findDesktop(true, desktop); - if (get_focus != nullptr && get_focus != mostRecentlyActivatedClient()) + } + if (get_focus != nullptr && get_focus != mostRecentlyActivatedClient()) { requestFocus(get_focus); + } setActiveOutput(output); } @@ -516,8 +536,9 @@ void Workspace::gotFocusIn(const AbstractClient *c) if (should_get_focus.contains(const_cast(c))) { // remove also all sooner elements that should have got FocusIn, // but didn't for some reason (and also won't anymore, because they were sooner) - while (should_get_focus.first() != c) + while (should_get_focus.first() != c) { should_get_focus.pop_front(); + } should_get_focus.pop_front(); // remove 'c' } } @@ -552,37 +573,43 @@ bool Workspace::allowClientActivation(const KWin::AbstractClient *c, xcb_timesta // 3 - high - new window gets focus only if it belongs to the active application, // or when no window is currently active // 4 - extreme - no window gets focus without user intervention - if (time == -1U) + if (time == -1U) { time = c->userTime(); + } int level = c->rules()->checkFSP(options->focusStealingPreventionLevel()); if (sessionManager()->state() == SessionState::Saving && level <= FSP::Medium) { // <= normal return true; } AbstractClient *ac = mostRecentlyActivatedClient(); if (focus_in) { - if (should_get_focus.contains(const_cast(c))) + if (should_get_focus.contains(const_cast(c))) { return true; // FocusIn was result of KWin's action + } // Before getting FocusIn, the active Client already // got FocusOut, and therefore got deactivated. ac = last_active_client; } if (time == 0) { // explicitly asked not to get focus - if (!c->rules()->checkAcceptFocus(false)) + if (!c->rules()->checkAcceptFocus(false)) { return false; + } } const int protection = ac ? ac->rules()->checkFPP(2) : 0; // stealing is unconditionally allowed (NETWM behavior) - if (level == FSP::None || protection == FSP::None) + if (level == FSP::None || protection == FSP::None) { return true; + } // The active client "grabs" the focus or stealing is generally forbidden - if (level == FSP::Extreme || protection == FSP::Extreme) + if (level == FSP::Extreme || protection == FSP::Extreme) { return false; + } // Desktop switching is only allowed in the "no protection" case - if (!ignore_desktop && !c->isOnCurrentDesktop()) + if (!ignore_desktop && !c->isOnCurrentDesktop()) { return false; // allow only with level == 0 + } // No active client, it's ok to pass focus // NOTICE that extreme protection needs to be handled before to allow protection on unmanged windows @@ -600,18 +627,21 @@ bool Workspace::allowClientActivation(const KWin::AbstractClient *c, xcb_timesta return true; } - if (!c->isOnCurrentDesktop()) // we allowed explicit self-activation across virtual desktops + if (!c->isOnCurrentDesktop()) { // we allowed explicit self-activation across virtual desktops return false; // inside a client or if no client was active, but not otherwise + } // High FPS, not intr-client change. Only allow if the active client has only minor interest - if (level > FSP::Medium && protection > FSP::Low) + if (level > FSP::Medium && protection > FSP::Low) { return false; + } if (time == -1U) { // no time known qCDebug(KWIN_CORE) << "Activation: No timestamp at all"; // Only allow for Low protection unless active client has High interest in focus - if (level < FSP::Medium && protection < FSP::High) + if (level < FSP::Medium && protection < FSP::High) { return true; + } // no timestamp at all, don't activate - because there's also creation timestamp // done on CreateNotify, this case should happen only in case application // maps again already used window, i.e. this won't happen after app startup @@ -636,10 +666,12 @@ bool Workspace::allowFullClientRaising(const KWin::AbstractClient *c, xcb_timest return true; } AbstractClient *ac = mostRecentlyActivatedClient(); - if (level == 0) // none + if (level == 0) { // none return true; - if (level == 4) // extreme + } + if (level == 4) { // extreme return false; + } if (ac == nullptr || ac->isDesktop()) { qCDebug(KWIN_CORE) << "Raising: No client active, allowing"; return true; // no active client -> always allow @@ -649,8 +681,9 @@ bool Workspace::allowFullClientRaising(const KWin::AbstractClient *c, xcb_timest qCDebug(KWIN_CORE) << "Raising: Belongs to active application"; return true; } - if (level == 3) // high + if (level == 3) { // high return false; + } xcb_timestamp_t user_time = ac->userTime(); qCDebug(KWIN_CORE) << "Raising, compared:" << time << ":" << user_time << ":" << (NET::timestampCompare(time, user_time) >= 0); @@ -670,10 +703,11 @@ bool Workspace::restoreFocus() // that was used by whoever caused the focus change, and therefore // the attempt to restore the focus would fail due to old timestamp updateXTime(); - if (should_get_focus.count() > 0) + if (should_get_focus.count() > 0) { return requestFocus(should_get_focus.last()); - else if (last_active_client) + } else if (last_active_client) { return requestFocus(last_active_client); + } return true; } @@ -682,8 +716,9 @@ void Workspace::clientAttentionChanged(AbstractClient *c, bool set) if (set) { attention_chain.removeAll(c); attention_chain.prepend(c); - } else + } else { attention_chain.removeAll(c); + } Q_EMIT clientDemandsAttentionChanged(c, set); } @@ -763,16 +798,18 @@ xcb_timestamp_t X11Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id } return ret; }; - if (act->hasTransient(this, true)) + if (act->hasTransient(this, true)) { ; // is transient for currently active window, even though it's not // the same app (e.g. kcookiejar dialog) -> allow activation - else if (groupTransient() && findInList(clientMainClients(), sameApplicationActiveHackPredicate) == nullptr) + } else if (groupTransient() && findInList(clientMainClients(), sameApplicationActiveHackPredicate) == nullptr) { ; // standalone transient - else + } else { first_window = false; + } } else { - if (workspace()->findClient(sameApplicationActiveHackPredicate)) + if (workspace()->findClient(sameApplicationActiveHackPredicate)) { first_window = false; + } } // don't refuse if focus stealing prevention is turned off if (!first_window && rules()->checkFSP(options->focusStealingPreventionLevel()) > 0) { @@ -789,8 +826,9 @@ xcb_timestamp_t X11Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id // Unless it was the active window at the time // of session saving and there was no user interaction yet, // this check will be done in manage(). - if (session) + if (session) { return -1U; + } time = readUserCreationTime(); } qCDebug(KWIN_CORE) << "User timestamp, final:" << this << ":" << time; @@ -800,13 +838,15 @@ xcb_timestamp_t X11Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id xcb_timestamp_t X11Client::userTime() const { xcb_timestamp_t time = m_userTime; - if (time == 0) // doesn't want focus after showing + if (time == 0) { // doesn't want focus after showing return 0; + } Q_ASSERT(group() != nullptr); if (time == -1U || (group()->userTime() != -1U - && NET::timestampCompare(group()->userTime(), time) > 0)) + && NET::timestampCompare(group()->userTime(), time) > 0)) { time = group()->userTime(); + } return time; } @@ -821,16 +861,19 @@ void X11Client::startupIdChanged() KStartupInfoId asn_id; KStartupInfoData asn_data; bool asn_valid = workspace()->checkStartupNotification(window(), asn_id, asn_data); - if (!asn_valid) + if (!asn_valid) { return; + } // If the ASN contains desktop, move it to the desktop, otherwise move it to the current // desktop (since the new ASN should make the window act like if it's a new application // launched). However don't affect the window's desktop if it's set to be on all desktops. int desktop = VirtualDesktopManager::self()->current(); - if (asn_data.desktop() != 0) + if (asn_data.desktop() != 0) { desktop = asn_data.desktop(); - if (!isOnAllDesktops()) + } + if (!isOnAllDesktops()) { workspace()->sendClientToDesktop(this, desktop, true); + } if (asn_data.xinerama() != -1) { AbstractOutput *output = kwinApp()->platform()->findOutput(asn_data.xinerama()); if (output) { @@ -840,19 +883,22 @@ void X11Client::startupIdChanged() const xcb_timestamp_t timestamp = asn_id.timestamp(); if (timestamp != 0) { bool activate = workspace()->allowClientActivation(this, timestamp); - if (asn_data.desktop() != 0 && !isOnCurrentDesktop()) + if (asn_data.desktop() != 0 && !isOnCurrentDesktop()) { activate = false; // it was started on different desktop than current one - if (activate) + } + if (activate) { workspace()->activateClient(this); - else + } else { demandAttention(); + } } } void X11Client::updateUrgency() { - if (info->urgency()) + if (info->urgency()) { demandAttention(); + } } //**************************************** @@ -864,8 +910,9 @@ void Group::startupIdChanged() KStartupInfoId asn_id; KStartupInfoData asn_data; bool asn_valid = workspace()->checkStartupNotification(leader_wid, asn_id, asn_data); - if (!asn_valid) + if (!asn_valid) { return; + } if (asn_id.timestamp() != 0 && user_time != -1U && NET::timestampCompare(asn_id.timestamp(), user_time) > 0) { user_time = asn_id.timestamp(); @@ -881,8 +928,9 @@ void Group::updateUserTime(xcb_timestamp_t time) } if (time != -1U && (user_time == XCB_CURRENT_TIME - || NET::timestampCompare(time, user_time) > 0)) // time > user_time + || NET::timestampCompare(time, user_time) > 0)) { // time > user_time user_time = time; + } } } // namespace diff --git a/src/activities.cpp b/src/activities.cpp index 0284721cf8..13d3398b26 100644 --- a/src/activities.cpp +++ b/src/activities.cpp @@ -62,8 +62,9 @@ void Activities::slotRemoved(const QString &activity) { const auto clients = Workspace::self()->allClientList(); for (auto *const client : clients) { - if (client->isDesktop()) + if (client->isDesktop()) { continue; + } client->setOnActivity(activity, false); } // toss out any session data for it @@ -79,19 +80,22 @@ void Activities::toggleClientOnActivity(AbstractClient *c, const QString &activi // note: all activities === no activities bool enable = was_on_all || !was_on_activity; c->setOnActivity(activity, enable); - if (c->isOnActivity(activity) == was_on_activity && c->isOnAllActivities() == was_on_all) // No change + if (c->isOnActivity(activity) == was_on_activity && c->isOnAllActivities() == was_on_all) { // No change return; + } Workspace *ws = Workspace::self(); if (c->isOnCurrentActivity()) { if (c->wantsTabFocus() && options->focusPolicyIsReasonable() && !was_on_activity && // for stickyness changes // FIXME not sure if the line above refers to the correct activity - !dont_activate) + !dont_activate) { ws->requestFocus(c); - else + } else { ws->restackClientUnderActive(c); - } else + } + } else { ws->raiseClient(c); + } // notifyWindowDesktopChanged( c, old_desktop ); @@ -144,8 +148,9 @@ bool Activities::stop(const QString &id) void Activities::reallyStop(const QString &id) { Workspace *ws = Workspace::self(); - if (ws->sessionManager()->state() == SessionState::Saving) + if (ws->sessionManager()->state() == SessionState::Saving) { return; // ksmserver doesn't queue requests (yet) + } qCDebug(KWIN_CORE) << id; @@ -153,8 +158,9 @@ void Activities::reallyStop(const QString &id) QSet dontCloseSessionIds; const auto clients = ws->allClientList(); for (auto *const c : clients) { - if (c->isDesktop()) + if (c->isDesktop()) { continue; + } const QByteArray sessionId = c->sessionId(); if (sessionId.isEmpty()) { continue; // TODO support old wm_command apps too? diff --git a/src/backends/virtual/egl_gbm_backend.cpp b/src/backends/virtual/egl_gbm_backend.cpp index 01919c4f64..cccd9fd318 100644 --- a/src/backends/virtual/egl_gbm_backend.cpp +++ b/src/backends/virtual/egl_gbm_backend.cpp @@ -64,8 +64,9 @@ bool EglGbmBackend::initializeEgl() } } - if (display == EGL_NO_DISPLAY) + if (display == EGL_NO_DISPLAY) { return false; + } setEglDisplay(display); return initEglAPI(); } diff --git a/src/backends/wayland/egl_wayland_backend.cpp b/src/backends/wayland/egl_wayland_backend.cpp index e51e1dbfb9..0a7d1ebd0c 100644 --- a/src/backends/wayland/egl_wayland_backend.cpp +++ b/src/backends/wayland/egl_wayland_backend.cpp @@ -174,8 +174,9 @@ bool EglWaylandBackend::initializeEgl() m_havePlatformBase = hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_base")); if (m_havePlatformBase) { // Make sure that the wayland platform is supported - if (!hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_wayland"))) + if (!hasClientExtension(QByteArrayLiteral("EGL_EXT_platform_wayland"))) { return false; + } display = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, m_backend->display(), nullptr); } else { @@ -183,8 +184,9 @@ bool EglWaylandBackend::initializeEgl() } } - if (display == EGL_NO_DISPLAY) + if (display == EGL_NO_DISPLAY) { return false; + } setEglDisplay(display); return initEglAPI(); } diff --git a/src/backends/x11/standalone/effects_x11.cpp b/src/backends/x11/standalone/effects_x11.cpp index 0df82606c4..be94db017a 100644 --- a/src/backends/x11/standalone/effects_x11.cpp +++ b/src/backends/x11/standalone/effects_x11.cpp @@ -45,8 +45,9 @@ EffectsHandlerImplX11::~EffectsHandlerImplX11() bool EffectsHandlerImplX11::doGrabKeyboard() { bool ret = grabXKeyboard(); - if (!ret) + if (!ret) { return false; + } // Workaround for Qt 5.9 regression introduced with 2b34aefcf02f09253473b096eb4faffd3e62b5f4 // we no longer get any events for the root window, one needs to call winId() on the desktop window // TODO: change effects event handling to create the appropriate QKeyEvent without relying on Qt diff --git a/src/backends/x11/standalone/glxbackend.cpp b/src/backends/x11/standalone/glxbackend.cpp index 881454c1a2..3ceb27c51e 100644 --- a/src/backends/x11/standalone/glxbackend.cpp +++ b/src/backends/x11/standalone/glxbackend.cpp @@ -139,14 +139,17 @@ GlxBackend::~GlxBackend() cleanupGL(); doneCurrent(); - if (ctx) + if (ctx) { glXDestroyContext(display(), ctx); + } - if (glxWindow) + if (glxWindow) { glXDestroyWindow(display(), glxWindow); + } - if (window) + if (window) { XDestroyWindow(display(), window); + } qDeleteAll(m_fbconfigHash); m_fbconfigHash.clear(); @@ -164,8 +167,9 @@ static glXFuncPtr getProcAddress(const char *name) ret = glXGetProcAddress((const GLubyte *)name); #endif #if HAVE_DL_LIBRARY - if (ret == nullptr) + if (ret == nullptr) { ret = (glXFuncPtr)dlsym(RTLD_DEFAULT, name); + } #endif return ret; } @@ -204,8 +208,9 @@ void GlxBackend::init() GLPlatform *glPlatform = GLPlatform::instance(); glPlatform->detect(GlxPlatformInterface); options->setGlPreferBufferSwap(options->glPreferBufferSwap()); // resolve autosetting - if (options->glPreferBufferSwap() == Options::AutoSwapStrategy) + if (options->glPreferBufferSwap() == Options::AutoSwapStrategy) { options->setGlPreferBufferSwap('e'); // for unknown drivers - should not happen + } glPlatform->printResults(); initGL(&getProcAddress); @@ -238,8 +243,9 @@ void GlxBackend::init() if (hasExtension(QByteArrayLiteral("GLX_EXT_buffer_age"))) { const QByteArray useBufferAge = qgetenv("KWIN_USE_BUFFER_AGE"); - if (useBufferAge != "0") + if (useBufferAge != "0") { setSupportsBufferAge(true); + } } // If the buffer age extension is unsupported, glXSwapBuffers() is not guaranteed to @@ -397,8 +403,9 @@ bool GlxBackend::initRenderingContext() } } - if (!ctx) + if (!ctx) { ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, globalShareContext, direct); + } if (!ctx) { qCDebug(KWIN_X11STANDALONE) << "Failed to create an OpenGL context."; @@ -417,8 +424,9 @@ bool GlxBackend::initRenderingContext() bool GlxBackend::initBuffer() { - if (!initFbConfig()) + if (!initFbConfig()) { return false; + } if (overlayWindow()->create()) { xcb_connection_t *const c = connection(); @@ -520,8 +528,9 @@ void GlxBackend::initVisualDepthHashTable() const int len = xcb_depth_visuals_length(depth.data); const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { m_visualDepthHash.insert(visuals[i].visual_id, depth.data->depth); + } } } } @@ -619,44 +628,51 @@ FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual) glXGetFBConfigAttrib(display(), configs[i], GLX_GREEN_SIZE, &green); glXGetFBConfigAttrib(display(), configs[i], GLX_BLUE_SIZE, &blue); - if (std::tie(red, green, blue) != rgb_sizes) + if (std::tie(red, green, blue) != rgb_sizes) { continue; + } xcb_visualid_t visual; glXGetFBConfigAttrib(display(), configs[i], GLX_VISUAL_ID, (int *)&visual); - if (visualDepth(visual) != depth) + if (visualDepth(visual) != depth) { continue; + } int bind_rgb, bind_rgba; glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &bind_rgba); glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &bind_rgb); - if (!bind_rgb && !bind_rgba) + if (!bind_rgb && !bind_rgba) { continue; + } int depth, stencil; glXGetFBConfigAttrib(display(), configs[i], GLX_DEPTH_SIZE, &depth); glXGetFBConfigAttrib(display(), configs[i], GLX_STENCIL_SIZE, &stencil); int texture_format; - if (alpha_bits) + if (alpha_bits) { texture_format = bind_rgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT; - else + } else { texture_format = bind_rgb ? GLX_TEXTURE_FORMAT_RGB_EXT : GLX_TEXTURE_FORMAT_RGBA_EXT; + } candidates.emplace_back(FBConfig{configs[i], depth, stencil, texture_format}); } - if (count > 0) + if (count > 0) { XFree(configs); + } std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) { - if (left.depth < right.depth) + if (left.depth < right.depth) { return true; + } - if (left.stencil < right.stencil) + if (left.stencil < right.stencil) { return true; + } return false; }); @@ -690,12 +706,13 @@ FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual) void GlxBackend::setSwapInterval(int interval) { - if (m_haveEXTSwapControl) + if (m_haveEXTSwapControl) { glXSwapIntervalEXT(display(), glxWindow, interval); - else if (m_haveMESASwapControl) + } else if (m_haveMESASwapControl) { glXSwapIntervalMESA(interval); - else if (m_haveSGISwapControl) + } else if (m_haveSGISwapControl) { glXSwapIntervalSGI(interval); + } } void GlxBackend::present(const QRegion &damage) @@ -787,8 +804,9 @@ void GlxBackend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, present(effectiveRenderedRegion); - if (overlayWindow()->window()) // show the window only after the first pass, + if (overlayWindow()->window()) { // show the window only after the first pass, overlayWindow()->show(); // since that pass may take long + } // Save the damaged region to history if (supportsBufferAge()) { @@ -883,12 +901,14 @@ void GlxPixmapTexturePrivate::onDamage() bool GlxPixmapTexturePrivate::create(SurfacePixmapX11 *texture) { - if (texture->pixmap() == XCB_NONE || texture->size().isEmpty() || texture->visual() == XCB_NONE) + if (texture->pixmap() == XCB_NONE || texture->size().isEmpty() || texture->visual() == XCB_NONE) { return false; + } const FBConfigInfo *info = m_backend->infoForVisual(texture->visual()); - if (!info || info->fbconfig == nullptr) + if (!info || info->fbconfig == nullptr) { return false; + } if (info->texture_targets & GLX_TEXTURE_2D_BIT_EXT) { m_target = GL_TEXTURE_2D; diff --git a/src/backends/x11/standalone/overlaywindow_x11.cpp b/src/backends/x11/standalone/overlaywindow_x11.cpp index c5563d8427..93ddc9b3bc 100644 --- a/src/backends/x11/standalone/overlaywindow_x11.cpp +++ b/src/backends/x11/standalone/overlaywindow_x11.cpp @@ -42,18 +42,21 @@ OverlayWindowX11::~OverlayWindowX11() bool OverlayWindowX11::create() { Q_ASSERT(m_window == XCB_WINDOW_NONE); - if (!Xcb::Extensions::self()->isCompositeOverlayAvailable()) + if (!Xcb::Extensions::self()->isCompositeOverlayAvailable()) { return false; - if (!Xcb::Extensions::self()->isShapeInputAvailable()) // needed in setupOverlay() + } + if (!Xcb::Extensions::self()->isShapeInputAvailable()) { // needed in setupOverlay() return false; + } #ifdef KWIN_HAVE_XCOMPOSITE_OVERLAY Xcb::OverlayWindow overlay(rootWindow()); if (overlay.isNull()) { return false; } m_window = overlay->overlay_win; - if (m_window == XCB_WINDOW_NONE) + if (m_window == XCB_WINDOW_NONE) { return false; + } resize(screens()->size()); return true; #else @@ -91,8 +94,9 @@ void OverlayWindowX11::setNoneBackgroundPixmap(xcb_window_t window) void OverlayWindowX11::show() { Q_ASSERT(m_window != XCB_WINDOW_NONE); - if (m_shown) + if (m_shown) { return; + } xcb_map_subwindows(connection(), m_window); xcb_map_window(connection(), m_window); m_shown = true; @@ -111,8 +115,9 @@ void OverlayWindowX11::setShape(const QRegion ®) { // Avoid setting the same shape again, it causes flicker (apparently it is not a no-op // and triggers something). - if (reg == m_shape) + if (reg == m_shape) { return; + } const QVector xrects = Xcb::regionToRects(reg); xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED, m_window, 0, 0, xrects.count(), xrects.data()); @@ -142,8 +147,9 @@ void OverlayWindowX11::setVisibility(bool visible) void OverlayWindowX11::destroy() { - if (m_window == XCB_WINDOW_NONE) + if (m_window == XCB_WINDOW_NONE) { return; + } // reset the overlay shape const QSize &s = screens()->size(); xcb_rectangle_t rec = {0, 0, static_cast(s.width()), static_cast(s.height())}; diff --git a/src/backends/x11/standalone/x11_platform.cpp b/src/backends/x11/standalone/x11_platform.cpp index 203f391973..3036dfb1f1 100644 --- a/src/backends/x11/standalone/x11_platform.cpp +++ b/src/backends/x11/standalone/x11_platform.cpp @@ -215,11 +215,12 @@ QString X11StandalonePlatform::compositingNotPossibleReason() const // first off, check whether we figured that we'll crash on detection because of a buggy driver KConfigGroup gl_workaround_group(kwinApp()->config(), "Compositing"); const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString())); - if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") && gl_workaround_group.readEntry(unsafeKey, false)) + if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") && gl_workaround_group.readEntry(unsafeKey, false)) { return i18n("OpenGL compositing (the default) has crashed KWin in the past.
" "This was most likely due to a driver bug." "

If you think that you have meanwhile upgraded to a stable driver,
" "you can reset this protection but be aware that this might result in an immediate crash!

"); + } if (!Xcb::Extensions::self()->isCompositeAvailable() || !Xcb::Extensions::self()->isDamageAvailable()) { return i18n("Required X extensions (XComposite and XDamage) are not available."); @@ -249,8 +250,9 @@ bool X11StandalonePlatform::compositingPossible() const qCWarning(KWIN_X11STANDALONE) << "Compositing disabled: no damage extension available"; return false; } - if (hasGlx()) + if (hasGlx()) { return true; + } if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { return true; } else if (qstrcmp(qgetenv("KWIN_COMPOSE"), "O2ES") == 0) { @@ -506,10 +508,12 @@ void X11StandalonePlatform::doUpdateOutputs() // refresh rate calculation - WTF was wikipedia 1998 when I needed it? int dotclock = modes[j].dot_clock, vtotal = modes[j].vtotal; - if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_INTERLACE) + if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_INTERLACE) { dotclock *= 2; - if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_DOUBLE_SCAN) + } + if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_DOUBLE_SCAN) { vtotal *= 2; + } refreshRate = dotclock / float(modes[j].htotal * vtotal); } break; // found mode diff --git a/src/composite.cpp b/src/composite.cpp index 1fdedd7c3e..25e3adf78e 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -983,12 +983,13 @@ void X11Compositor::updateClientCompositeBlocking(X11Client *c) if (c) { if (c->isBlockingCompositing()) { // Do NOT attempt to call suspend(true) from within the eventchain! - if (!(m_suspended & BlockRuleSuspend)) + if (!(m_suspended & BlockRuleSuspend)) { QMetaObject::invokeMethod( this, [this]() { suspend(BlockRuleSuspend); }, Qt::QueuedConnection); + } } } else if (m_suspended & BlockRuleSuspend) { // If !c we just check if we can resume in case a blocking client was lost. diff --git a/src/cursor.cpp b/src/cursor.cpp index 8c0d169bcb..713d0025d0 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -34,8 +34,9 @@ namespace KWin Cursors *Cursors::s_self = nullptr; Cursors *Cursors::self() { - if (!s_self) + if (!s_self) { s_self = new Cursors; + } return s_self; } @@ -54,10 +55,11 @@ void Cursors::removeCursor(Cursor *cursor) { m_cursors.removeOne(cursor); if (m_currentCursor == cursor) { - if (m_cursors.isEmpty()) + if (m_cursors.isEmpty()) { m_currentCursor = nullptr; - else + } else { setCurrentCursor(m_cursors.constFirst()); + } } if (m_mouse == cursor) { m_mouse = nullptr; @@ -87,8 +89,9 @@ bool Cursors::isCursorHidden() const void Cursors::setCurrentCursor(Cursor *cursor) { - if (m_currentCursor == cursor) + if (m_currentCursor == cursor) { return; + } Q_ASSERT(m_cursors.contains(cursor) || !cursor); @@ -686,8 +689,9 @@ QByteArray CursorShape::name() const InputConfig *InputConfig::s_self = nullptr; InputConfig *InputConfig::self() { - if (!s_self) + if (!s_self) { s_self = new InputConfig; + } return s_self; } diff --git a/src/deleted.cpp b/src/deleted.cpp index 66836ddb29..913b6dbf5e 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -41,8 +41,9 @@ Deleted::Deleted() Deleted::~Deleted() { - if (delete_refcount != 0) + if (delete_refcount != 0) { qCCritical(KWIN_CORE) << "Deleted client has non-zero reference count (" << delete_refcount << ")"; + } Q_ASSERT(delete_refcount == 0); if (workspace()) { workspace()->removeDeleted(this); @@ -80,8 +81,9 @@ void Deleted::copyToDeleted(Toplevel *c) m_type = c->windowType(); m_windowRole = c->windowRole(); m_shade = c->isShade(); - if (WinInfo *cinfo = dynamic_cast(info)) + if (WinInfo *cinfo = dynamic_cast(info)) { cinfo->disable(); + } if (AbstractClient *client = dynamic_cast(c)) { if (client->isDecorated()) { client->layoutDecorationRects(decoration_left, @@ -115,8 +117,9 @@ void Deleted::copyToDeleted(Toplevel *c) void Deleted::unrefWindow() { - if (--delete_refcount > 0) + if (--delete_refcount > 0) { return; + } // needs to be delayed // a) when calling from effects, otherwise it'd be rather complicated to handle the case of the // window going away during a painting pass @@ -171,8 +174,9 @@ NET::WindowType Deleted::windowType(bool direct, int supportedTypes) const void Deleted::mainClientClosed(Toplevel *client) { - if (AbstractClient *c = dynamic_cast(client)) + if (AbstractClient *c = dynamic_cast(client)) { m_mainClients.removeAll(c); + } } xcb_window_t Deleted::frameId() const diff --git a/src/effects.cpp b/src/effects.cpp index 8803e0eac9..1859b8d381 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -156,10 +156,11 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene) Q_EMIT desktopPresenceChanged(c->effectWindow(), old, c->desktop()); }); connect(ws, &Workspace::clientAdded, this, [this](AbstractClient *c) { - if (c->readyForPainting()) + if (c->readyForPainting()) { slotClientShown(c); - else + } else { connect(c, &Toplevel::windowShown, this, &EffectsHandlerImpl::slotClientShown); + } }); connect(ws, &Workspace::unmanagedAdded, this, [this](Unmanaged *u) { // it's never initially ready but has synthetic 50ms delay @@ -361,8 +362,9 @@ void EffectsHandlerImpl::paintScreen(int mask, const QRegion ®ion, ScreenPain if (m_currentPaintScreenIterator != m_activeEffects.constEnd()) { (*m_currentPaintScreenIterator++)->paintScreen(mask, region, data); --m_currentPaintScreenIterator; - } else + } else { m_scene->finalPaintScreen(mask, region, data); + } } void EffectsHandlerImpl::paintDesktop(int desktop, int mask, QRegion region, ScreenPaintData &data) @@ -404,8 +406,9 @@ void EffectsHandlerImpl::paintWindow(EffectWindow *w, int mask, const QRegion &r if (m_currentPaintWindowIterator != m_activeEffects.constEnd()) { (*m_currentPaintWindowIterator++)->paintWindow(w, mask, region, data); --m_currentPaintWindowIterator; - } else + } else { m_scene->finalPaintWindow(static_cast(w), mask, region, data); + } } void EffectsHandlerImpl::paintEffectFrame(EffectFrame *frame, const QRegion ®ion, double opacity, double frameOpacity) @@ -430,9 +433,11 @@ void EffectsHandlerImpl::postPaintWindow(EffectWindow *w) Effect *EffectsHandlerImpl::provides(Effect::Feature ef) { - for (int i = 0; i < loaded_effects.size(); ++i) - if (loaded_effects.at(i).second->provides(ef)) + for (int i = 0; i < loaded_effects.size(); ++i) { + if (loaded_effects.at(i).second->provides(ef)) { return loaded_effects.at(i).second; + } + } return nullptr; } @@ -441,8 +446,9 @@ void EffectsHandlerImpl::drawWindow(EffectWindow *w, int mask, const QRegion &re if (m_currentDrawWindowIterator != m_activeEffects.constEnd()) { (*m_currentDrawWindowIterator++)->drawWindow(w, mask, region, data); --m_currentDrawWindowIterator; - } else + } else { m_scene->finalDrawWindow(static_cast(w), mask, region, data); + } } bool EffectsHandlerImpl::hasDecorationShadows() const @@ -562,8 +568,9 @@ void EffectsHandlerImpl::slotGeometryShapeChanged(Toplevel *t, const QRect &old) { // during late cleanup effectWindow() may be already NULL // in some functions that may still call this - if (t == nullptr || t->effectWindow() == nullptr) + if (t == nullptr || t->effectWindow() == nullptr) { return; + } Q_EMIT windowGeometryShapeChanged(t->effectWindow(), old); } @@ -600,8 +607,9 @@ bool EffectsHandlerImpl::hasActiveFullScreenEffect() const bool EffectsHandlerImpl::grabKeyboard(Effect *effect) { - if (keyboard_grab_effect != nullptr) + if (keyboard_grab_effect != nullptr) { return false; + } if (!doGrabKeyboard()) { return false; } @@ -627,8 +635,9 @@ void EffectsHandlerImpl::doUngrabKeyboard() void EffectsHandlerImpl::grabbedKeyboardEvent(QKeyEvent *e) { - if (keyboard_grab_effect != nullptr) + if (keyboard_grab_effect != nullptr) { keyboard_grab_effect->grabbedKeyboardEvent(e); + } } void EffectsHandlerImpl::startMouseInterception(Effect *effect, Qt::CursorShape shape) @@ -799,23 +808,27 @@ void EffectsHandlerImpl::registerTouchscreenSwipeShortcut(SwipeDirection directi void *EffectsHandlerImpl::getProxy(QString name) { - for (QVector::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) - if ((*it).first == name) + for (QVector::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) { + if ((*it).first == name) { return (*it).second->proxy(); + } + } return nullptr; } void EffectsHandlerImpl::startMousePolling() { - if (Cursors::self()->mouse()) + if (Cursors::self()->mouse()) { Cursors::self()->mouse()->startMousePolling(); + } } void EffectsHandlerImpl::stopMousePolling() { - if (Cursors::self()->mouse()) + if (Cursors::self()->mouse()) { Cursors::self()->mouse()->stopMousePolling(); + } } bool EffectsHandlerImpl::hasKeyboardGrab() const @@ -825,11 +838,12 @@ bool EffectsHandlerImpl::hasKeyboardGrab() const void EffectsHandlerImpl::registerPropertyType(long atom, bool reg) { - if (reg) + if (reg) { ++registered_atoms[atom]; // initialized to 0 if not present yet - else { - if (--registered_atoms[atom] == 0) + } else { + if (--registered_atoms[atom] == 0) { registered_atoms.remove(atom); + } } } @@ -900,13 +914,15 @@ EffectWindow *EffectsHandlerImpl::activeWindow() const void EffectsHandlerImpl::moveWindow(EffectWindow *w, const QPoint &pos, bool snap, double snapAdjust) { auto cl = qobject_cast(static_cast(w)->window()); - if (!cl || !cl->isMovable()) + if (!cl || !cl->isMovable()) { return; + } - if (snap) + if (snap) { cl->move(Workspace::self()->adjustClientPosition(cl, pos, true, snapAdjust)); - else + } else { cl->move(pos); + } } void EffectsHandlerImpl::windowToDesktop(EffectWindow *w, int desktop) @@ -1026,8 +1042,9 @@ QPoint EffectsHandlerImpl::desktopGridCoords(int id) const QPoint EffectsHandlerImpl::desktopCoords(int id) const { QPoint coords = VirtualDesktopManager::self()->grid().gridCoords(id); - if (coords.x() == -1) + if (coords.x() == -1) { return QPoint(-1, -1); + } const QSize displaySize = Screens::self()->size(); return QPoint(coords.x() * displaySize.width(), coords.y() * displaySize.height()); } @@ -1070,10 +1087,12 @@ double EffectsHandlerImpl::animationTimeFactor() const EffectWindow *EffectsHandlerImpl::findWindow(WId id) const { - if (X11Client *w = Workspace::self()->findClient(Predicate::WindowMatch, id)) + if (X11Client *w = Workspace::self()->findClient(Predicate::WindowMatch, id)) { return w->effectWindow(); - if (Unmanaged *w = Workspace::self()->findUnmanaged(id)) + } + if (Unmanaged *w = Workspace::self()->findUnmanaged(id)) { return w->effectWindow(); + } return nullptr; } @@ -1115,8 +1134,9 @@ EffectWindowList EffectsHandlerImpl::stackingOrder() const QList list = Workspace::self()->xStackingOrder(); EffectWindowList ret; for (Toplevel *t : list) { - if (EffectWindow *w = effectWindow(t)) + if (EffectWindow *w = effectWindow(t)) { ret.append(w); + } } return ret; } @@ -1124,8 +1144,9 @@ EffectWindowList EffectsHandlerImpl::stackingOrder() const void EffectsHandlerImpl::setElevatedWindow(KWin::EffectWindow *w, bool set) { elevated_windows.removeAll(w); - if (set) + if (set) { elevated_windows.append(w); + } } void EffectsHandlerImpl::setTabBoxWindow(EffectWindow *w) @@ -1207,8 +1228,9 @@ int EffectsHandlerImpl::currentTabBoxDesktop() const EffectWindow *EffectsHandlerImpl::currentTabBoxWindow() const { #if KWIN_BUILD_TABBOX - if (auto c = TabBox::TabBox::self()->currentClient()) + if (auto c = TabBox::TabBox::self()->currentClient()) { return c->effectWindow(); + } #endif return nullptr; } @@ -1374,10 +1396,11 @@ QPainter *EffectsHandlerImpl::scenePainter() void EffectsHandlerImpl::toggleEffect(const QString &name) { - if (isEffectLoaded(name)) + if (isEffectLoaded(name)) { unloadEffect(name); - else + } else { loadEffect(name); + } } QStringList EffectsHandlerImpl::loadedEffects() const @@ -1448,13 +1471,14 @@ void EffectsHandlerImpl::destroyEffect(Effect *effect) void EffectsHandlerImpl::reconfigureEffect(const QString &name) { - for (QVector::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) + for (QVector::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) { if ((*it).first == name) { kwinApp()->config()->reparseConfiguration(); makeOpenGLContextCurrent(); (*it).second->reconfigure(Effect::ReconfigureAll); return; } + } } bool EffectsHandlerImpl::isEffectLoaded(const QString &name) const @@ -2202,10 +2226,11 @@ EffectWindowList EffectWindowImpl::mainWindows() const void EffectWindowImpl::setData(int role, const QVariant &data) { - if (!data.isNull()) + if (!data.isNull()) { dataMap[role] = data; - else + } else { dataMap.remove(role); + } Q_EMIT effects->windowDataChanged(this, role); } @@ -2445,18 +2470,20 @@ Qt::Alignment EffectFrameImpl::alignment() const void EffectFrameImpl::align(QRect &geometry) { - if (m_alignment & Qt::AlignLeft) + if (m_alignment & Qt::AlignLeft) { geometry.moveLeft(m_point.x()); - else if (m_alignment & Qt::AlignRight) + } else if (m_alignment & Qt::AlignRight) { geometry.moveLeft(m_point.x() - geometry.width()); - else + } else { geometry.moveLeft(m_point.x() - geometry.width() / 2); - if (m_alignment & Qt::AlignTop) + } + if (m_alignment & Qt::AlignTop) { geometry.moveTop(m_point.y()); - else if (m_alignment & Qt::AlignBottom) + } else if (m_alignment & Qt::AlignBottom) { geometry.moveTop(m_point.y() - geometry.height()); - else + } else { geometry.moveTop(m_point.y() - geometry.height() / 2); + } } void EffectFrameImpl::setAlignment(Qt::Alignment alignment) @@ -2511,8 +2538,9 @@ void EffectFrameImpl::setSelection(const QRect &selection) void EffectFrameImpl::autoResize() { - if (m_static) + if (m_static) { return; // Not automatically resizing + } QRect geometry; // Set size @@ -2522,8 +2550,9 @@ void EffectFrameImpl::autoResize() } if (!m_icon.isNull() && !m_iconSize.isEmpty()) { geometry.setLeft(-m_iconSize.width()); - if (m_iconSize.height() > geometry.height()) + if (m_iconSize.height() > geometry.height()) { geometry.setHeight(m_iconSize.height()); + } } align(geometry); diff --git a/src/effects.h b/src/effects.h index a110f0fe96..db27189698 100644 --- a/src/effects.h +++ b/src/effects.h @@ -644,8 +644,9 @@ private: inline QList EffectsHandlerImpl::elevatedWindows() const { - if (isScreenLocked()) + if (isScreenLocked()) { return QList(); + } return elevated_windows; } diff --git a/src/effects/backgroundcontrast/contrast.cpp b/src/effects/backgroundcontrast/contrast.cpp index 722b3642ef..204f4568a7 100644 --- a/src/effects/backgroundcontrast/contrast.cpp +++ b/src/effects/backgroundcontrast/contrast.cpp @@ -258,10 +258,12 @@ bool ContrastEffect::enabledByDefault() { GLPlatform *gl = GLPlatform::instance(); - if (gl->isIntel() && gl->chipClass() < SandyBridge) + if (gl->isIntel() && gl->chipClass() < SandyBridge) { return false; - if (gl->isPanfrost() && gl->chipClass() <= MaliT8XX) + } + if (gl->isPanfrost() && gl->chipClass() <= MaliT8XX) { return false; + } if (gl->isSoftwareEmulation()) { return false; } @@ -278,8 +280,9 @@ bool ContrastEffect::supported() glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); const QSize screenSize = effects->virtualScreenSize(); - if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) + if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) { supported = false; + } } return supported; } @@ -326,8 +329,9 @@ void ContrastEffect::uploadRegion(QVector2D *&map, const QRegion ®ion) void ContrastEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion ®ion) { const int vertexCount = region.rectCount() * 6; - if (!vertexCount) + if (!vertexCount) { return; + } QVector2D *map = (QVector2D *)vbo->map(vertexCount * sizeof(QVector2D)); uploadRegion(map, region); @@ -342,23 +346,28 @@ void ContrastEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion ®ion) bool ContrastEffect::shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const { - if (!shader || !shader->isValid()) + if (!shader || !shader->isValid()) { return false; + } - if (effects->activeFullScreenEffect() && !w->data(WindowForceBackgroundContrastRole).toBool()) + if (effects->activeFullScreenEffect() && !w->data(WindowForceBackgroundContrastRole).toBool()) { return false; + } - if (w->isDesktop()) + if (w->isDesktop()) { return false; + } bool scaled = !qFuzzyCompare(data.xScale(), 1.0) && !qFuzzyCompare(data.yScale(), 1.0); bool translated = data.xTranslation() || data.yTranslation(); - if ((scaled || (translated || (mask & PAINT_WINDOW_TRANSFORMED))) && !w->data(WindowForceBackgroundContrastRole).toBool()) + if ((scaled || (translated || (mask & PAINT_WINDOW_TRANSFORMED))) && !w->data(WindowForceBackgroundContrastRole).toBool()) { return false; + } - if (!w->hasAlpha()) + if (!w->hasAlpha()) { return false; + } return true; } diff --git a/src/effects/backgroundcontrast/contrastshader.cpp b/src/effects/backgroundcontrast/contrastshader.cpp index 7951f4271a..d94b635f70 100644 --- a/src/effects/backgroundcontrast/contrastshader.cpp +++ b/src/effects/backgroundcontrast/contrastshader.cpp @@ -61,8 +61,9 @@ float ContrastShader::opacity() const void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix) { - if (!isValid()) + if (!isValid()) { return; + } ShaderManager::instance()->pushShader(shader); shader->setUniform(colorMatrixLocation, matrix); @@ -71,24 +72,27 @@ void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix) void ContrastShader::setTextureMatrix(const QMatrix4x4 &matrix) { - if (!isValid()) + if (!isValid()) { return; + } shader->setUniform(textureMatrixLocation, matrix); } void ContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix) { - if (!isValid()) + if (!isValid()) { return; + } shader->setUniform(mvpMatrixLocation, matrix); } void ContrastShader::bind() { - if (!isValid()) + if (!isValid()) { return; + } ShaderManager::instance()->pushShader(shader); } @@ -158,8 +162,9 @@ void ContrastShader::init() stream2 << "uniform float opacity;\n"; stream2 << varying_in << " vec4 varyingTexCoords;\n"; - if (core) + if (core) { stream2 << "out vec4 fragColor;\n\n"; + } stream2 << "void main(void)\n"; stream2 << "{\n"; diff --git a/src/effects/blur/blur.cpp b/src/effects/blur/blur.cpp index 8af5b7a187..bd01058706 100644 --- a/src/effects/blur/blur.cpp +++ b/src/effects/blur/blur.cpp @@ -387,8 +387,9 @@ bool BlurEffect::enabledByDefault() { GLPlatform *gl = GLPlatform::instance(); - if (gl->isIntel() && gl->chipClass() < SandyBridge) + if (gl->isIntel() && gl->chipClass() < SandyBridge) { return false; + } if (gl->isPanfrost() && gl->chipClass() <= MaliT8XX) { return false; } @@ -408,8 +409,9 @@ bool BlurEffect::supported() glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); const QSize screenSize = effects->virtualScreenSize(); - if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) + if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize) { supported = false; + } } return supported; } @@ -500,8 +502,9 @@ void BlurEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion &blurRegion, { const int vertexCount = ((blurRegion.rectCount() * (m_downSampleIterations + 1)) + windowRegion.rectCount()) * 6; - if (!vertexCount) + if (!vertexCount) { return; + } QVector2D *map = (QVector2D *)vbo->map(vertexCount * sizeof(QVector2D)); @@ -581,25 +584,30 @@ void BlurEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std:: bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const { - if (!m_renderTargetsValid || !m_shader || !m_shader->isValid()) + if (!m_renderTargetsValid || !m_shader || !m_shader->isValid()) { return false; + } - if (effects->activeFullScreenEffect() && !w->data(WindowForceBlurRole).toBool()) + if (effects->activeFullScreenEffect() && !w->data(WindowForceBlurRole).toBool()) { return false; + } - if (w->isDesktop()) + if (w->isDesktop()) { return false; + } bool scaled = !qFuzzyCompare(data.xScale(), 1.0) && !qFuzzyCompare(data.yScale(), 1.0); bool translated = data.xTranslation() || data.yTranslation(); - if ((scaled || (translated || (mask & PAINT_WINDOW_TRANSFORMED))) && !w->data(WindowForceBlurRole).toBool()) + if ((scaled || (translated || (mask & PAINT_WINDOW_TRANSFORMED))) && !w->data(WindowForceBlurRole).toBool()) { return false; + } bool blurBehindDecos = effects->decorationsHaveAlpha() && decorationSupportsBlurBehind(w); - if (!w->hasAlpha() && w->opacity() >= 1.0 && !(blurBehindDecos && w->hasDecoration())) + if (!w->hasAlpha() && w->opacity() >= 1.0 && !(blurBehindDecos && w->hasDecoration())) { return false; + } return true; } diff --git a/src/effects/desktopgrid/desktopgrid.cpp b/src/effects/desktopgrid/desktopgrid.cpp index 4f7ab66cd7..ff3e20f4ef 100644 --- a/src/effects/desktopgrid/desktopgrid.cpp +++ b/src/effects/desktopgrid/desktopgrid.cpp @@ -194,8 +194,9 @@ void DesktopGridEffect::reconfigure(ReconfigureFlags) } effects->registerRealtimeTouchBorder(ElectricBorder(i), m_gestureAction, [this](ElectricBorder border, const QSizeF &deltaProgress, const EffectScreen *screen) { - if (activated) + if (activated) { return; + } if (timeline.currentValue() == 0) { activated = true; @@ -260,8 +261,9 @@ void DesktopGridEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mi } // PAINT_SCREEN_BACKGROUND_FIRST is needed because screen will be actually painted more than once, // so with normal screen painting second screen paint would erase parts of the first paint - if (timeline.currentValue() != 0 || (isUsingPresentWindows() && isMotionManagerMovingWindows())) + if (timeline.currentValue() != 0 || (isUsingPresentWindows() && isMotionManagerMovingWindows())) { data.mask |= PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_BACKGROUND_FIRST; + } } const EffectWindowList windows = effects->stackingOrder(); @@ -312,18 +314,20 @@ void DesktopGridEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaint textArea.adjust(textArea.width() / 10, textArea.height() / 10, -textArea.width() / 10, -textArea.height() / 10); int x, y; - if (desktopNameAlignment & Qt::AlignLeft) + if (desktopNameAlignment & Qt::AlignLeft) { x = textArea.x(); - else if (desktopNameAlignment & Qt::AlignRight) + } else if (desktopNameAlignment & Qt::AlignRight) { x = textArea.right(); - else + } else { x = textArea.center().x(); - if (desktopNameAlignment & Qt::AlignTop) + } + if (desktopNameAlignment & Qt::AlignTop) { y = textArea.y(); - else if (desktopNameAlignment & Qt::AlignBottom) + } else if (desktopNameAlignment & Qt::AlignBottom) { y = textArea.bottom(); - else + } else { y = textArea.center().y(); + } frame->setPosition(QPoint(x, y)); frame->render(region, timeline.currentValue(), 0.7); ++desktop; @@ -408,8 +412,9 @@ void DesktopGridEffect::paintWindow(EffectWindow *w, int mask, QRegion region, W WindowMotionManager &manager = m_managers[screen][paintingDesktop - 1]; if (manager.isManaging(w)) { transformedGeo = manager.transformedGeometry(w); - if (!manager.areWindowsMoving() && timeline.currentValue() == 1.0) + if (!manager.areWindowsMoving() && timeline.currentValue() == 1.0) { mask |= PAINT_WINDOW_LANCZOS; + } } else if (w->screen() != screen) { continue; // we don't want parts of overlapping windows on the other screen } @@ -442,8 +447,9 @@ void DesktopGridEffect::paintWindow(EffectWindow *w, int mask, QRegion region, W } effects->paintWindow(w, mask, effects->clientArea(ScreenArea, screen, 0), d); } - } else + } else { effects->paintWindow(w, mask, region, data); + } } //----------------------------------------------------------------------------- @@ -451,8 +457,9 @@ void DesktopGridEffect::paintWindow(EffectWindow *w, int mask, QRegion region, W void DesktopGridEffect::slotWindowAdded(EffectWindow *w) { - if (!activated) + if (!activated) { return; + } if (isUsingPresentWindows()) { if (!isRelevantWithPresentWindows(w)) { return; // don't add @@ -469,8 +476,9 @@ void DesktopGridEffect::slotWindowAdded(EffectWindow *w) void DesktopGridEffect::slotWindowClosed(EffectWindow *w) { - if (!activated && timeline.currentValue() == 0) + if (!activated && timeline.currentValue() == 0) { return; + } if (w == windowMove) { effects->setElevatedWindow(windowMove, false); windowMove = nullptr; @@ -488,8 +496,9 @@ void DesktopGridEffect::slotWindowClosed(EffectWindow *w) void DesktopGridEffect::slotWindowDeleted(EffectWindow *w) { - if (w == windowMove) + if (w == windowMove) { windowMove = nullptr; + } if (isUsingPresentWindows()) { for (auto it = m_managers.begin(); it != m_managers.end(); ++it) { for (WindowMotionManager &manager : *it) { @@ -502,10 +511,12 @@ void DesktopGridEffect::slotWindowDeleted(EffectWindow *w) void DesktopGridEffect::slotWindowFrameGeometryChanged(EffectWindow *w, const QRect &old) { Q_UNUSED(old) - if (!activated) + if (!activated) { return; - if (w == windowMove && wasWindowMove) + } + if (w == windowMove && wasWindowMove) { return; + } if (isUsingPresentWindows()) { const auto desktops = desktopList(w); for (const int i : desktops) { @@ -520,8 +531,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) if ((e->type() != QEvent::MouseMove && e->type() != QEvent::MouseButtonPress && e->type() != QEvent::MouseButtonRelease) - || timeline.currentValue() != 1) // Block user input during animations + || timeline.currentValue() != 1) { // Block user input during animations return; + } QMouseEvent *me = static_cast(e); if (!(wasWindowMove || wasDesktopMove)) { for (OffscreenQuickScene *view : qAsConst(m_desktopButtons)) { @@ -555,8 +567,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) } manager.unmanage(windowMove); if (EffectWindow *modal = windowMove->findModal()) { - if (manager.isManaging(modal)) + if (manager.isManaging(modal)) { manager.unmanage(modal); + } } m_proxy->calculateWindowTransformations(manager.managedWindows(), windowMove->screen(), manager); } @@ -586,8 +599,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) } effects->windowToDesktops(windowMove, desktops); EffectScreen *screen = effects->screenAt(me->pos()); - if (screen != windowMove->screen()) + if (screen != windowMove->screen()) { effects->windowToScreen(windowMove, screen); + } } effects->addRepaintFull(); } @@ -603,19 +617,24 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) end = windows.constEnd(); it != end; ++it) { EffectWindow *w = const_cast(*it); // we're not really touching it here but below - if (w->isOnAllDesktops()) + if (w->isOnAllDesktops()) { continue; - if (w->isOnDesktop(highlightedDesktop)) + } + if (w->isOnDesktop(highlightedDesktop)) { stack[0] << w; - if (w->isOnDesktop(d)) + } + if (w->isOnDesktop(d)) { stack[1] << w; - if (w->isOnDesktop(m_originalMovingDesktop)) + } + if (w->isOnDesktop(m_originalMovingDesktop)) { stack[2] << w; + } } const int desks[4] = {highlightedDesktop, d, m_originalMovingDesktop, highlightedDesktop}; for (int i = 0; i < 3; ++i) { - if (desks[i] == desks[i + 1]) + if (desks[i] == desks[i + 1]) { continue; + } for (EffectWindow *w : qAsConst(stack[i])) { auto desktops = w->desktops(); desktops.removeOne(desks[i]); @@ -649,12 +668,14 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) sourceDesktop = posToDesktop(me->pos()); bool isDesktop = (me->modifiers() & Qt::ShiftModifier); EffectWindow *w = isDesktop ? nullptr : windowAt(me->pos()); - if (w != nullptr) + if (w != nullptr) { isDesktop = w->isDesktop(); - if (isDesktop) + } + if (isDesktop) { m_originalMovingDesktop = posToDesktop(me->pos()); - else + } else { m_originalMovingDesktop = 0; + } if (w != nullptr && !w->isDesktop() && (w->isMovable() || w->isMovableAcrossScreens() || isUsingPresentWindows())) { // Prepare it for moving windowMoveDiff = w->pos() - unscalePos(me->pos(), nullptr); @@ -678,10 +699,11 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) for (int i = 0; i < effects->numberOfDesktops(); i++) { if (i != desktop - 1) { WindowMotionManager &manager = m_managers[w->screen()][i]; - if (isOnAllDesktops) + if (isOnAllDesktops) { manager.manage(w); - else + } else { manager.unmanage(w); + } m_proxy->calculateWindowTransformations(manager.managedWindows(), w->screen(), manager); } } @@ -706,8 +728,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) effects->defineCursor(Qt::ArrowCursor); } else { // click -> exit const int desk = posToDesktop(me->pos()); - if (desk > effects->numberOfDesktops()) + if (desk > effects->numberOfDesktops()) { return; // don't quit when missing desktop + } setCurrentDesktop(desk); deactivate(); } @@ -718,8 +741,9 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent *e) for (const int i : desktops) { WindowMotionManager &manager = m_managers[windowMove->screen()][i]; manager.manage(windowMove); - if (EffectWindow *modal = windowMove->findModal()) + if (EffectWindow *modal = windowMove->findModal()) { manager.manage(modal); + } if (i + 1 == targetDesktop) { // for the desktop the window is dropped on, we use the current geometry manager.setTransformedGeometry(windowMove, moveGeometryToDesktop(targetDesktop)); @@ -758,18 +782,21 @@ void DesktopGridEffect::deactivate() void DesktopGridEffect::toggle() { - if (activated) + if (activated) { deactivate(); - else + } else { activate(); + } } void DesktopGridEffect::grabbedKeyboardEvent(QKeyEvent *e) { - if (timeline.currentValue() != 1) // Block user input during animations + if (timeline.currentValue() != 1) { // Block user input during animations return; - if (windowMove != nullptr) + } + if (windowMove != nullptr) { return; + } if (e->type() == QEvent::KeyPress) { // check for global shortcuts // HACK: keyboard grab disables the global shortcuts so we have to check for global shortcut (bug 156155) @@ -780,10 +807,11 @@ void DesktopGridEffect::grabbedKeyboardEvent(QKeyEvent *e) int desktop = -1; // switch by F or just - if (e->key() >= Qt::Key_F1 && e->key() <= Qt::Key_F35) + if (e->key() >= Qt::Key_F1 && e->key() <= Qt::Key_F35) { desktop = e->key() - Qt::Key_F1 + 1; - else if (e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9) + } else if (e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9) { desktop = e->key() == Qt::Key_0 ? 10 : e->key() - Qt::Key_0; + } if (desktop != -1) { if (desktop <= effects->numberOfDesktops()) { setHighlightedDesktop(desktop); @@ -829,10 +857,12 @@ void DesktopGridEffect::grabbedKeyboardEvent(QKeyEvent *e) bool DesktopGridEffect::borderActivated(ElectricBorder border) { - if (!borderActivate.contains(border)) + if (!borderActivate.contains(border)) { return false; - if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) + } + if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) { return true; + } toggle(); return true; } @@ -902,10 +932,11 @@ QPoint DesktopGridEffect::unscalePos(const QPoint &pos, int *desktop) const scaledX -= gx; scaledY -= gy; if (desktop != nullptr) { - if (orientation == Qt::Horizontal) + if (orientation == Qt::Horizontal) { *desktop = gy * gridSize.width() + gx + 1; - else + } else { *desktop = gx * gridSize.height() + gy + 1; + } } return QPoint( @@ -934,8 +965,9 @@ int DesktopGridEffect::posToDesktop(const QPoint &pos) const double scaledY = (pos.y() - scaledOffset[screen].y() + double(border) / 2.0) / (scaledSize[screen].height() + border); int gx = qBound(0, int(scaledX), gridSize.width() - 1); // Zero-based int gy = qBound(0, int(scaledY), gridSize.height() - 1); - if (orientation == Qt::Horizontal) + if (orientation == Qt::Horizontal) { return gy * gridSize.width() + gx + 1; + } return gx * gridSize.height() + gy + 1; } @@ -946,18 +978,21 @@ EffectWindow *DesktopGridEffect::windowAt(QPoint pos) const EffectWindowList::Iterator begin = windows.begin(); EffectWindowList::Iterator end = windows.end(); --end; - while (begin < end) + while (begin < end) { qSwap(*begin++, *end--); + } int desktop; pos = unscalePos(pos, &desktop); - if (desktop > effects->numberOfDesktops()) + if (desktop > effects->numberOfDesktops()) { return nullptr; + } if (isUsingPresentWindows()) { EffectScreen *screen = effects->screenAt(pos); EffectWindow *w = m_managers[screen][desktop - 1].windowAtPoint(pos, false); - if (w) + if (w) { return w; + } for (EffectWindow *w : qAsConst(windows)) { if (w->isOnDesktop(desktop) && w->isDesktop() && w->frameGeometry().contains(pos)) { return w; @@ -982,20 +1017,24 @@ void DesktopGridEffect::setCurrentDesktop(int desktop) activeCell.setX((desktop - 1) / gridSize.height() + 1); activeCell.setY((desktop - 1) % gridSize.height() + 1); } - if (effects->currentDesktop() != desktop) + if (effects->currentDesktop() != desktop) { effects->setCurrentDesktop(desktop); + } } void DesktopGridEffect::setHighlightedDesktop(int d) { - if (d == highlightedDesktop || d <= 0 || d > effects->numberOfDesktops()) + if (d == highlightedDesktop || d <= 0 || d > effects->numberOfDesktops()) { return; - if (highlightedDesktop > 0 && highlightedDesktop <= hoverTimeline.count()) + } + if (highlightedDesktop > 0 && highlightedDesktop <= hoverTimeline.count()) { hoverTimeline[highlightedDesktop - 1]->setCurrentTime(qMin(hoverTimeline[highlightedDesktop - 1]->currentTime(), hoverTimeline[highlightedDesktop - 1]->duration())); + } highlightedDesktop = d; - if (highlightedDesktop <= hoverTimeline.count()) + if (highlightedDesktop <= hoverTimeline.count()) { hoverTimeline[highlightedDesktop - 1]->setCurrentTime(qMax(hoverTimeline[highlightedDesktop - 1]->currentTime(), 0)); + } effects->addRepaintFull(); } @@ -1006,18 +1045,20 @@ int DesktopGridEffect::desktopToRight(int desktop, bool wrap) const if (orientation == Qt::Vertical) { dt += gridSize.height(); if (dt >= effects->numberOfDesktops()) { - if (wrap) + if (wrap) { dt -= effects->numberOfDesktops(); - else + } else { return desktop; + } } } else { int d = (dt % gridSize.width()) + 1; if (d >= gridSize.width()) { - if (wrap) + if (wrap) { d -= gridSize.width(); - else + } else { return desktop; + } } dt = dt - (dt % gridSize.width()) + d; } @@ -1031,18 +1072,20 @@ int DesktopGridEffect::desktopToLeft(int desktop, bool wrap) const if (orientation == Qt::Vertical) { dt -= gridSize.height(); if (dt < 0) { - if (wrap) + if (wrap) { dt += effects->numberOfDesktops(); - else + } else { return desktop; + } } } else { int d = (dt % gridSize.width()) - 1; if (d < 0) { - if (wrap) + if (wrap) { d += gridSize.width(); - else + } else { return desktop; + } } dt = dt - (dt % gridSize.width()) + d; } @@ -1056,18 +1099,20 @@ int DesktopGridEffect::desktopUp(int desktop, bool wrap) const if (orientation == Qt::Horizontal) { dt -= gridSize.width(); if (dt < 0) { - if (wrap) + if (wrap) { dt += effects->numberOfDesktops(); - else + } else { return desktop; + } } } else { int d = (dt % gridSize.height()) - 1; if (d < 0) { - if (wrap) + if (wrap) { d += gridSize.height(); - else + } else { return desktop; + } } dt = dt - (dt % gridSize.height()) + d; } @@ -1081,18 +1126,20 @@ int DesktopGridEffect::desktopDown(int desktop, bool wrap) const if (orientation == Qt::Horizontal) { dt += gridSize.width(); if (dt >= effects->numberOfDesktops()) { - if (wrap) + if (wrap) { dt -= effects->numberOfDesktops(); - else + } else { return desktop; + } } } else { int d = (dt % gridSize.height()) + 1; if (d >= gridSize.height()) { - if (wrap) + if (wrap) { d -= gridSize.height(); - else + } else { return desktop; + } } dt = dt - (dt % gridSize.height()) + d; } @@ -1104,8 +1151,9 @@ int DesktopGridEffect::desktopDown(int desktop, bool wrap) const void DesktopGridEffect::setup() { - if (!isActive()) + if (!isActive()) { return; + } if (!keyboardGrab) { keyboardGrab = effects->grabKeyboard(this); effects->startMouseInterception(this, Qt::ArrowCursor); @@ -1140,8 +1188,9 @@ void DesktopGridEffect::setup() setCurrentDesktop(effects->currentDesktop()); // setup the motion managers - if (clickBehavior == SwitchDesktopAndActivateWindow) + if (clickBehavior == SwitchDesktopAndActivateWindow) { m_proxy = static_cast(effects->getProxy(QStringLiteral("presentwindows"))); + } if (isUsingPresentWindows()) { m_proxy->reCreateGrids(); // revalidation on multiscreen, bug #351724 const QList screens = effects->screens(); @@ -1222,8 +1271,9 @@ void DesktopGridEffect::setupGrid() case LayoutAutomatic: y = sqrt(float(numDesktops)) + 0.5; x = float(numDesktops) / float(y) + 0.5; - if (x * y < numDesktops) + if (x * y < numDesktops) { x++; + } orientation = Qt::Horizontal; gridSize.setWidth(x); gridSize.setHeight(y); @@ -1243,10 +1293,11 @@ void DesktopGridEffect::setupGrid() for (EffectScreen *screen : screens) { QRect geom = effects->clientArea(ScreenArea, screen, effects->currentDesktop()); double sScale; - if (gridSize.width() > gridSize.height()) + if (gridSize.width() > gridSize.height()) { sScale = (geom.width() - border * (gridSize.width() + 1)) / double(geom.width() * gridSize.width()); - else + } else { sScale = (geom.height() - border * (gridSize.height() + 1)) / double(geom.height() * gridSize.height()); + } double sBorder = border / sScale; QSizeF size( double(geom.width()) * sScale, @@ -1280,8 +1331,9 @@ void DesktopGridEffect::finish() } QTimer::singleShot(zoomDuration + 1, this, [this] { - if (activated) + if (activated) { return; + } for (OffscreenQuickScene *view : qAsConst(m_desktopButtons)) { view->hide(); } @@ -1290,8 +1342,9 @@ void DesktopGridEffect::finish() windowMoveElevateTimer->stop(); - if (keyboardGrab) + if (keyboardGrab) { effects->ungrabKeyboard(); + } keyboardGrab = false; lastPresentTime = std::chrono::milliseconds::zero(); effects->stopMouseInterception(this); @@ -1323,8 +1376,9 @@ bool DesktopGridEffect::isMotionManagerMovingWindows() const if (isUsingPresentWindows()) { for (auto it = m_managers.constBegin(); it != m_managers.constEnd(); ++it) { for (const WindowMotionManager &manager : *it) { - if (manager.areWindowsMoving()) + if (manager.areWindowsMoving()) { return true; + } } } } @@ -1368,13 +1422,15 @@ void DesktopGridEffect::slotRemoveDesktop() void DesktopGridEffect::slotNumberDesktopsChanged(uint old) { - if (!activated) + if (!activated) { return; + } const uint desktop = effects->numberOfDesktops(); - if (old < desktop) + if (old < desktop) { desktopsAdded(old); - else + } else { desktopsRemoved(old); + } } void DesktopGridEffect::desktopsAdded(int old) @@ -1449,8 +1505,9 @@ void DesktopGridEffect::desktopsRemoved(int old) WindowMotionManager &manager = m_managers[screen][desktop - 1]; const auto stackingOrder = effects->stackingOrder(); for (EffectWindow *w : stackingOrder) { - if (manager.isManaging(w)) + if (manager.isManaging(w)) { continue; + } if (w->isOnDesktop(desktop) && w->screen() == screen && isRelevantWithPresentWindows(w)) { manager.manage(w); } @@ -1471,8 +1528,9 @@ QVector DesktopGridEffect::desktopList(const EffectWindow *w) const static QVector allDesktops; if (allDesktops.count() != effects->numberOfDesktops()) { allDesktops.resize(effects->numberOfDesktops()); - for (int i = 0; i < effects->numberOfDesktops(); ++i) + for (int i = 0; i < effects->numberOfDesktops(); ++i) { allDesktops[i] = i; + } } return allDesktops; } diff --git a/src/effects/fallapart/fallapart.cpp b/src/effects/fallapart/fallapart.cpp index b7e4cbef03..58ab9d19b6 100644 --- a/src/effects/fallapart/fallapart.cpp +++ b/src/effects/fallapart/fallapart.cpp @@ -40,8 +40,9 @@ void FallApartEffect::reconfigure(ReconfigureFlags) void FallApartEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) { - if (!windows.isEmpty()) + if (!windows.isEmpty()) { data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + } effects->prePaintScreen(data, presentTime); } @@ -83,15 +84,19 @@ void FallApartEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W // they are (left pieces generally move to the left, etc.) QPointF p1(quad[0].x(), quad[0].y()); double xdiff = 0; - if (p1.x() < w->width() / 2) + if (p1.x() < w->width() / 2) { xdiff = -(w->width() / 2 - p1.x()) / w->width() * 100; - if (p1.x() > w->width() / 2) + } + if (p1.x() > w->width() / 2) { xdiff = (p1.x() - w->width() / 2) / w->width() * 100; + } double ydiff = 0; - if (p1.y() < w->height() / 2) + if (p1.y() < w->height() / 2) { ydiff = -(w->height() / 2 - p1.y()) / w->height() * 100; - if (p1.y() > w->height() / 2) + } + if (p1.y() > w->height() / 2) { ydiff = (p1.y() - w->height() / 2) / w->height() * 100; + } double modif = t * t * 64; srandom(cnt); // change direction randomly but consistently xdiff += (rand() % 21 - 10); @@ -125,8 +130,9 @@ void FallApartEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W void FallApartEffect::postPaintScreen() { - if (!windows.isEmpty()) + if (!windows.isEmpty()) { effects->addRepaintFull(); + } effects->postPaintScreen(); } @@ -150,22 +156,27 @@ bool FallApartEffect::isRealWindow(EffectWindow *w) if (w->isX11Client() && !w->isManaged()) { return false; } - if (!w->isNormalWindow()) + if (!w->isNormalWindow()) { return false; + } return true; } void FallApartEffect::slotWindowClosed(EffectWindow *c) { - if (effects->activeFullScreenEffect()) + if (effects->activeFullScreenEffect()) { return; - if (!isRealWindow(c)) + } + if (!isRealWindow(c)) { return; - if (!c->isVisible()) + } + if (!c->isVisible()) { return; + } const void *e = c->data(WindowClosedGrabRole).value(); - if (e && e != this) + if (e && e != this) { return; + } c->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast(this))); windows[c].progress = 0; c->refWindow(); diff --git a/src/effects/highlightwindow/highlightwindow.cpp b/src/effects/highlightwindow/highlightwindow.cpp index 5d260faa4c..fc0d61e265 100644 --- a/src/effects/highlightwindow/highlightwindow.cpp +++ b/src/effects/highlightwindow/highlightwindow.cpp @@ -97,8 +97,9 @@ void HighlightWindowEffect::slotWindowAdded(EffectWindow *w) void HighlightWindowEffect::slotWindowClosed(EffectWindow *w) { - if (m_monitorWindow == w) // The monitoring window was destroyed + if (m_monitorWindow == w) { // The monitoring window was destroyed finishHighlighting(); + } } void HighlightWindowEffect::slotWindowDeleted(EffectWindow *w) @@ -108,15 +109,17 @@ void HighlightWindowEffect::slotWindowDeleted(EffectWindow *w) void HighlightWindowEffect::slotPropertyNotify(EffectWindow *w, long a, EffectWindow *addedWindow) { - if (a != m_atom || m_atom == XCB_ATOM_NONE) + if (a != m_atom || m_atom == XCB_ATOM_NONE) { return; // Not our atom + } // if the window is null, the property was set on the root window - see events.cpp QByteArray byteData = w ? w->readProperty(m_atom, m_atom, 32) : effects->readRootProperty(m_atom, m_atom, 32); if (byteData.length() < 1) { // Property was removed, clearing highlight - if (!addedWindow || w != addedWindow) + if (!addedWindow || w != addedWindow) { finishHighlighting(); + } return; } auto *data = reinterpret_cast(byteData.data()); diff --git a/src/effects/invert/invert.cpp b/src/effects/invert/invert.cpp index 5b5ef7b20a..ef2049d664 100644 --- a/src/effects/invert/invert.cpp +++ b/src/effects/invert/invert.cpp @@ -83,8 +83,9 @@ bool InvertEffect::loadData() void InvertEffect::drawWindow(EffectWindow *w, int mask, const QRegion ®ion, WindowPaintData &data) { // Load if we haven't already - if (m_valid && !m_inited) + if (m_valid && !m_inited) { m_valid = loadData(); + } bool useShader = m_valid && (m_allWindows != m_windows.contains(w)); if (useShader) { @@ -128,10 +129,11 @@ void InvertEffect::toggleWindow() if (!effects->activeWindow()) { return; } - if (!m_windows.contains(effects->activeWindow())) + if (!m_windows.contains(effects->activeWindow())) { m_windows.append(effects->activeWindow()); - else + } else { m_windows.removeOne(effects->activeWindow()); + } effects->activeWindow()->addRepaintFull(); } diff --git a/src/effects/lookingglass/lookingglass.cpp b/src/effects/lookingglass/lookingglass.cpp index 14823eed6c..4bfa163a4b 100644 --- a/src/effects/lookingglass/lookingglass.cpp +++ b/src/effects/lookingglass/lookingglass.cpp @@ -201,10 +201,11 @@ void LookingGlassEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::m const int time = m_lastPresentTime.count() ? (presentTime - m_lastPresentTime).count() : 0; if (zoom != target_zoom) { double diff = time / animationTime(500.0); - if (target_zoom > zoom) + if (target_zoom > zoom) { zoom = qMin(zoom * qMax(1.0 + diff, 1.2), target_zoom); - else + } else { zoom = qMax(zoom * qMin(1.0 - diff, 0.8), target_zoom); + } qCDebug(KWIN_LOOKINGGLASS) << "zoom is now " << zoom; radius = qBound((double)initialradius, initialradius * zoom, 3.5 * initialradius); diff --git a/src/effects/magiclamp/magiclamp.cpp b/src/effects/magiclamp/magiclamp.cpp index d7a4e6cb0b..3394dd6c41 100644 --- a/src/effects/magiclamp/magiclamp.cpp +++ b/src/effects/magiclamp/magiclamp.cpp @@ -106,8 +106,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W di = d[1][1]; position = Bottom; } - if (d[0][1] < di) + if (d[0][1] < di) { position = Right; + } switch (position) { case Top: pt.setY(extG.y()); @@ -123,14 +124,15 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W break; } } else { - if (pt.y() < geo.y()) + if (pt.y() < geo.y()) { position = Top; - else if (pt.x() < geo.x()) + } else if (pt.x() < geo.x()) { position = Left; - else if (pt.y() > geo.bottom()) + } else if (pt.y() > geo.bottom()) { position = Bottom; - else if (pt.x() > geo.right()) + } else if (pt.x() > geo.right()) { position = Right; + } } icon = QRect(pt, QSize(0, 0)); } else { @@ -138,8 +140,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W EffectWindow *panel = nullptr; const auto stackingOrder = effects->stackingOrder(); for (EffectWindow *window : stackingOrder) { - if (!window->isDock()) + if (!window->isDock()) { continue; + } // we have to use intersects as there seems to be a Plasma bug // the published icon geometry might be bigger than the panel if (window->frameGeometry().intersects(icon)) { @@ -153,16 +156,18 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W QRect panelScreen = effects->clientArea(ScreenArea, panel); if (panel->width() >= panel->height()) { // horizontal panel - if (panel->y() <= panelScreen.height() / 2) + if (panel->y() <= panelScreen.height() / 2) { position = Top; - else + } else { position = Bottom; + } } else { // vertical panel - if (panel->x() <= panelScreen.width() / 2) + if (panel->x() <= panelScreen.width() / 2) { position = Left; - else + } else { position = Right; + } } } else { // we did not find a panel, so it might be autohidden @@ -228,8 +233,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W offset[1] = (icon.y() + quad[2].y() - geo.y()) * progress * ((quadFactor * quadFactor * quadFactor) / height_cube); p_progress[1] = qMin(offset[1] / (icon.y() + icon.height() - geo.y() - float(quad[2].y())), 1.0f); p_progress[0] = qMin(offset[0] / (icon.y() + icon.height() - geo.y() - float(quad[0].y())), 1.0f); - } else + } else { lastQuad = quad; + } SANITIZE_PROGRESS; // x values are moved towards the center of the icon @@ -246,8 +252,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W offset[1] = (geo.y() - icon.height() + geo.height() + quad[2].y() - icon.y()) * progress * ((quadFactor * quadFactor * quadFactor) / height_cube); p_progress[0] = qMin(offset[0] / (geo.y() - icon.height() + geo.height() - icon.y() - float(geo.height() - quad[0].y())), 1.0f); p_progress[1] = qMin(offset[1] / (geo.y() - icon.height() + geo.height() - icon.y() - float(geo.height() - quad[2].y())), 1.0f); - } else + } else { lastQuad = quad; + } offset[0] = -offset[0]; offset[1] = -offset[1]; @@ -267,8 +274,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W offset[1] = (geo.x() - icon.width() + geo.width() + quad[1].x() - icon.x()) * progress * ((quadFactor * quadFactor * quadFactor) / width_cube); p_progress[0] = qMin(offset[0] / (geo.x() - icon.width() + geo.width() - icon.x() - float(geo.width() - quad[0].x())), 1.0f); p_progress[1] = qMin(offset[1] / (geo.x() - icon.width() + geo.width() - icon.x() - float(geo.width() - quad[1].x())), 1.0f); - } else + } else { lastQuad = quad; + } offset[0] = -offset[0]; offset[1] = -offset[1]; @@ -288,8 +296,9 @@ void MagicLampEffect::deform(EffectWindow *w, int mask, WindowPaintData &data, W offset[1] = (icon.x() + quad[1].x() - geo.x()) * progress * ((quadFactor * quadFactor * quadFactor) / width_cube); p_progress[0] = qMin(offset[0] / (icon.x() + icon.width() - geo.x() - float(quad[0].x())), 1.0f); p_progress[1] = qMin(offset[1] / (icon.x() + icon.width() - geo.x() - float(quad[1].x())), 1.0f); - } else + } else { lastQuad = quad; + } SANITIZE_PROGRESS; // y values are moved towards the center of the icon @@ -324,8 +333,9 @@ void MagicLampEffect::slotWindowDeleted(EffectWindow *w) void MagicLampEffect::slotWindowMinimized(EffectWindow *w) { - if (effects->activeFullScreenEffect()) + if (effects->activeFullScreenEffect()) { return; + } MagicLampAnimation &animation = m_animations[w]; @@ -343,8 +353,9 @@ void MagicLampEffect::slotWindowMinimized(EffectWindow *w) void MagicLampEffect::slotWindowUnminimized(EffectWindow *w) { - if (effects->activeFullScreenEffect()) + if (effects->activeFullScreenEffect()) { return; + } MagicLampAnimation &animation = m_animations[w]; diff --git a/src/effects/magnifier/magnifier.cpp b/src/effects/magnifier/magnifier.cpp index c6b084c6d6..76c3c1303f 100644 --- a/src/effects/magnifier/magnifier.cpp +++ b/src/effects/magnifier/magnifier.cpp @@ -79,8 +79,9 @@ void MagnifierEffect::reconfigure(ReconfigureFlags) magnifier_size = QSize(width, height); // Load the saved zoom value. target_zoom = MagnifierConfig::initialZoom(); - if (target_zoom != zoom) + if (target_zoom != zoom) { toggle(); + } } void MagnifierEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) @@ -89,9 +90,9 @@ void MagnifierEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill if (zoom != target_zoom) { double diff = time / animationTime(500.0); - if (target_zoom > zoom) + if (target_zoom > zoom) { zoom = qMin(zoom * qMax(1 + diff, 1.2), target_zoom); - else { + } else { zoom = qMax(zoom * qMin(1 - diff, 0.8), target_zoom); if (zoom == 1.0) { // zoom ended - delete FBO and texture @@ -110,8 +111,9 @@ void MagnifierEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill } effects->prePaintScreen(data, presentTime); - if (zoom != 1.0) + if (zoom != 1.0) { data.paint |= magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH); + } } void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data) @@ -260,10 +262,11 @@ void MagnifierEffect::toggle() void MagnifierEffect::slotMouseChanged(const QPoint &pos, const QPoint &old, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { - if (pos != old && zoom != 1) + if (pos != old && zoom != 1) { // need full repaint as we might lose some change events on fast mouse movements // see Bug 187658 effects->addRepaintFull(); + } } void MagnifierEffect::slotWindowDamaged() diff --git a/src/effects/mouseclick/mouseclick.cpp b/src/effects/mouseclick/mouseclick.cpp index 891229804b..93746dd8f9 100644 --- a/src/effects/mouseclick/mouseclick.cpp +++ b/src/effects/mouseclick/mouseclick.cpp @@ -46,8 +46,9 @@ MouseClickEffect::MouseClickEffect() MouseClickEffect::~MouseClickEffect() { - if (m_enabled) + if (m_enabled) { effects->stopMousePolling(); + } qDeleteAll(m_clicks); m_clicks.clear(); @@ -158,8 +159,9 @@ void MouseClickEffect::slotMouseChanged(const QPoint &pos, const QPoint &, Qt::MouseButtons buttons, Qt::MouseButtons oldButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { - if (buttons == oldButtons) + if (buttons == oldButtons) { return; + } MouseEvent *m = nullptr; int i = BUTTON_COUNT; @@ -257,22 +259,25 @@ bool MouseClickEffect::isActive() const void MouseClickEffect::drawCircle(const QColor &color, float cx, float cy, float r) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { drawCircleGl(color, cx, cy, r); - else if (effects->compositingType() == QPainterCompositing) + } else if (effects->compositingType() == QPainterCompositing) { drawCircleQPainter(color, cx, cy, r); + } } void MouseClickEffect::paintScreenSetup(int mask, QRegion region, ScreenPaintData &data) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { paintScreenSetupGl(mask, region, data); + } } void MouseClickEffect::paintScreenFinish(int mask, QRegion region, ScreenPaintData &data) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { paintScreenFinishGl(mask, region, data); + } } void MouseClickEffect::drawCircleGl(const QColor &color, float cx, float cy, float r) diff --git a/src/effects/mouseclick/mouseclick.h b/src/effects/mouseclick/mouseclick.h index 296c8fbde4..66a18bc72b 100644 --- a/src/effects/mouseclick/mouseclick.h +++ b/src/effects/mouseclick/mouseclick.h @@ -78,8 +78,9 @@ public: { if (m_isPressed != pressed) { m_isPressed = pressed; - if (pressed) + if (pressed) { m_time = 0; + } } } }; diff --git a/src/effects/mousemark/mousemark.cpp b/src/effects/mousemark/mousemark.cpp index 52eecc54b1..3af8bb51e0 100644 --- a/src/effects/mousemark/mousemark.cpp +++ b/src/effects/mousemark/mousemark.cpp @@ -71,8 +71,9 @@ void MouseMarkEffect::reconfigure(ReconfigureFlags) void MouseMarkEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data) { effects->paintScreen(mask, region, data); // paint normal screen - if (marks.isEmpty() && drawing.isEmpty()) + if (marks.isEmpty() && drawing.isEmpty()) { return; + } if (effects->isOpenGLCompositing()) { if (!GLPlatform::instance()->isGLES()) { glEnable(GL_BLEND); @@ -146,17 +147,21 @@ void MouseMarkEffect::slotMouseChanged(const QPoint &pos, const QPoint &, arrow_start = NULL_POINT; effects->addRepaintFull(); return; - } else + } else { arrow_start = pos; + } } - if (arrow_start != NULL_POINT) + if (arrow_start != NULL_POINT) { return; + } // TODO the shortcuts now trigger this right before they're activated if (modifiers == (Qt::META | Qt::SHIFT)) { // activated - if (drawing.isEmpty()) + if (drawing.isEmpty()) { drawing.append(pos); - if (drawing.last() == pos) + } + if (drawing.last() == pos) { return; + } QPoint pos2 = drawing.last(); drawing.append(pos); QRect repaint = QRect(qMin(pos.x(), pos2.x()), qMin(pos.y(), pos2.y()), diff --git a/src/effects/overview/expolayout.cpp b/src/effects/overview/expolayout.cpp index 713424f16f..20c0bc84d0 100644 --- a/src/effects/overview/expolayout.cpp +++ b/src/effects/overview/expolayout.cpp @@ -354,11 +354,12 @@ void ExpoLayout::calculateWindowTransformationsClosest() // precalculate all slot centers QVector slotCenters; slotCenters.resize(rows * columns); - for (int x = 0; x < columns; ++x) + for (int x = 0; x < columns; ++x) { for (int y = 0; y < rows; ++y) { slotCenters[x + y * columns] = QPoint(area.x() + slotWidth * x + slotWidth / 2, area.y() + slotHeight * y + slotHeight / 2); } + } // Assign each window to the closest available slot QList tmpList = m_cells; // use a QLinkedList copy instead? @@ -618,9 +619,9 @@ void ExpoLayout::calculateWindowTransformationsNatural() target->y() - yDiff - heightDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) + if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(cell, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; @@ -632,9 +633,9 @@ void ExpoLayout::calculateWindowTransformationsNatural() target->y() + yDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) + if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(cell, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; @@ -646,9 +647,9 @@ void ExpoLayout::calculateWindowTransformationsNatural() target->y() + yDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) + if (isOverlappingAny(cell, targets, borderRegion, m_spacing)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(cell, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; diff --git a/src/effects/presentwindows/presentwindows.cpp b/src/effects/presentwindows/presentwindows.cpp index b2e2559c15..e7ff5e5dd5 100644 --- a/src/effects/presentwindows/presentwindows.cpp +++ b/src/effects/presentwindows/presentwindows.cpp @@ -199,8 +199,9 @@ void *PresentWindowsEffect::proxy() void PresentWindowsEffect::toggleActiveClass() { if (!m_activated) { - if (!effects->activeWindow()) + if (!effects->activeWindow()) { return; + } m_mode = ModeWindowClass; m_class = effects->activeWindow()->windowClass(); } @@ -224,13 +225,15 @@ void PresentWindowsEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono: m_motionManager.calculate(time); // We need to mark the screen as having been transformed otherwise there will be no repainting - if (m_activated || m_motionManager.managingWindows()) + if (m_activated || m_motionManager.managingWindows()) { data.mask |= Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + } - if (m_activated) + if (m_activated) { m_decalOpacity = qMin(1.0, m_decalOpacity + time / m_fadeDuration); - else + } else { m_decalOpacity = qMax(0.0, m_decalOpacity - time / m_fadeDuration); + } effects->prePaintScreen(data, presentTime); } @@ -240,11 +243,13 @@ void PresentWindowsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPa effects->paintScreen(mask, region, data); // Display the filter box - if (!m_windowFilter.isEmpty()) + if (!m_windowFilter.isEmpty()) { m_filterFrame->render(region); + } - if (m_closeView) + if (m_closeView) { effects->renderOffscreenQuickView(m_closeView); + } } void PresentWindowsEffect::postPaintScreen() @@ -334,29 +339,34 @@ void PresentWindowsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &d // Calculate window's opacity // TODO: Minimized windows or windows not on the current desktop are only 75% visible? if (winData->visible) { - if (winData->deleted) + if (winData->deleted) { winData->opacity = qMax(0.0, winData->opacity - time / m_fadeDuration); - else + } else { winData->opacity = qMin(/*(w->isMinimized() || !w->isOnCurrentDesktop()) ? 0.75 :*/ 1.0, winData->opacity + time / m_fadeDuration); - } else + } + } else { winData->opacity = qMax(0.0, winData->opacity - time / m_fadeDuration); + } if (winData->opacity <= 0.0) { // don't disable painting for panels if show panel is set - if (!(m_showPanel && w->isDock())) + if (!(m_showPanel && w->isDock())) { w->disablePainting(EffectWindow::PAINT_DISABLED); - } else if (winData->opacity != 1.0) + } + } else if (winData->opacity != 1.0) { data.setTranslucent(); + } const bool isInMotion = m_motionManager.isManaging(w); // Calculate window's brightness - if (w == m_highlightedWindow || !m_activated) + if (w == m_highlightedWindow || !m_activated) { winData->highlight = qMin(1.0, winData->highlight + time / m_fadeDuration); - else if (!isInMotion && w->isDesktop()) + } else if (!isInMotion && w->isDesktop()) { winData->highlight = 0.3; - else + } else { winData->highlight = qMax(0.0, winData->highlight - time / m_fadeDuration); + } // Closed windows if (winData->deleted) { @@ -366,16 +376,19 @@ void PresentWindowsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &d // we have to keep the window in the list to prevent flickering winData->referenced = false; w->unrefWindow(); - } else + } else { w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE); + } } // desktop windows on other desktops (Plasma activity per desktop) should not be painted - if (w->isDesktop() && !w->isOnCurrentDesktop()) + if (w->isDesktop() && !w->isOnCurrentDesktop()) { w->disablePainting(EffectWindow::PAINT_DISABLED_BY_DESKTOP); + } - if (isInMotion) + if (isInMotion) { data.setTransformed(); // We will be moving this window + } } effects->prePaintWindow(w, data, presentTime); } @@ -419,15 +432,18 @@ void PresentWindowsEffect::paintWindow(EffectWindow *w, int mask, QRegion region if (tScale < 1.05) { tScale = 1.05; } - if (effSize.width() * tScale > area.width()) + if (effSize.width() * tScale > area.width()) { tScale = area.width() / effSize.width(); - if (effSize.height() * tScale > area.height()) + } + if (effSize.height() * tScale > area.height()) { tScale = area.height() / effSize.height(); + } const qreal scale = interpolate(1.0, tScale, winData->highlight); if (scale > 1.0) { - if (scale < tScale) // don't use lanczos during transition + if (scale < tScale) { // don't use lanczos during transition mask &= ~PAINT_WINDOW_LANCZOS; + } const float df = (tScale - 1.0f) * 0.5f; int tx = qRound(rect.width() * df); @@ -477,8 +493,9 @@ void PresentWindowsEffect::paintWindow(EffectWindow *w, int mask, QRegion region } else { effects->paintWindow(w, mask, region, data); } - } else + } else { effects->paintWindow(w, mask, region, data); + } } //----------------------------------------------------------------------------- @@ -486,8 +503,9 @@ void PresentWindowsEffect::paintWindow(EffectWindow *w, int mask, QRegion region void PresentWindowsEffect::slotWindowAdded(EffectWindow *w) { - if (!m_activated) + if (!m_activated) { return; + } WindowData *winData = &m_windowData[w]; winData->visible = isVisibleWindow(w); @@ -513,12 +531,14 @@ void PresentWindowsEffect::slotWindowAdded(EffectWindow *w) void PresentWindowsEffect::slotWindowClosed(EffectWindow *w) { - if (m_managerWindow == w) + if (m_managerWindow == w) { m_managerWindow = nullptr; + } DataHash::iterator winData = m_windowData.find(w); - if (winData == m_windowData.end()) + if (winData == m_windowData.end()) { return; + } winData->deleted = true; if (!winData->referenced) { @@ -526,16 +546,18 @@ void PresentWindowsEffect::slotWindowClosed(EffectWindow *w) w->refWindow(); } - if (m_highlightedWindow == w) + if (m_highlightedWindow == w) { setHighlightedWindow(findFirstWindow()); + } rearrangeWindows(); const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *w : managedWindows) { winData = m_windowData.find(w); - if (winData != m_windowData.end() && !winData->deleted) + if (winData != m_windowData.end() && !winData->deleted) { return; // found one that is not deleted? then we go on + } } setActive(false); // else no need to keep this open } @@ -543,8 +565,9 @@ void PresentWindowsEffect::slotWindowClosed(EffectWindow *w) void PresentWindowsEffect::slotWindowDeleted(EffectWindow *w) { DataHash::iterator winData = m_windowData.find(w); - if (winData == m_windowData.end()) + if (winData == m_windowData.end()) { return; + } delete winData->textFrame; delete winData->iconFrame; @@ -556,10 +579,12 @@ void PresentWindowsEffect::slotWindowFrameGeometryChanged(EffectWindow *w, const { Q_UNUSED(old) - if (!m_activated) + if (!m_activated) { return; - if (!m_windowData.contains(w)) + } + if (!m_windowData.contains(w)) { return; + } rearrangeWindows(); } @@ -567,25 +592,29 @@ void PresentWindowsEffect::slotWindowFrameGeometryChanged(EffectWindow *w, const bool PresentWindowsEffect::borderActivated(ElectricBorder border) { int mode = 0; - if (m_borderActivate.contains(border)) + if (m_borderActivate.contains(border)) { mode |= 1; - else if (m_borderActivateAll.contains(border)) + } else if (m_borderActivateAll.contains(border)) { mode |= 2; - else if (m_borderActivateClass.contains(border)) + } else if (m_borderActivateClass.contains(border)) { mode |= 4; + } - if (!mode) + if (!mode) { return false; + } - if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) + if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) { return true; + } - if (mode & 1) + if (mode & 1) { toggleActive(); - else if (mode & 2) + } else if (mode & 2) { toggleActiveAllDesktops(); - else if (mode & 4) + } else if (mode & 4) { toggleActiveClass(); + } return true; } @@ -733,31 +762,35 @@ void PresentWindowsEffect::mouseActionWindow(WindowMouseAction &action) { switch (action) { case WindowActivateAction: - if (m_highlightedWindow) + if (m_highlightedWindow) { effects->activateWindow(m_highlightedWindow); + } setActive(false); break; case WindowExitAction: setActive(false); break; case WindowToCurrentDesktopAction: - if (m_highlightedWindow) + if (m_highlightedWindow) { effects->windowToDesktop(m_highlightedWindow, effects->currentDesktop()); + } break; case WindowToAllDesktopsAction: if (m_highlightedWindow) { - if (m_highlightedWindow->isOnAllDesktops()) + if (m_highlightedWindow->isOnAllDesktops()) { effects->windowToDesktop(m_highlightedWindow, effects->currentDesktop()); - else + } else { effects->windowToDesktop(m_highlightedWindow, NET::OnAllDesktops); + } } break; case WindowMinimizeAction: if (m_highlightedWindow) { - if (m_highlightedWindow->isMinimized()) + if (m_highlightedWindow->isMinimized()) { m_highlightedWindow->unminimize(); - else + } else { m_highlightedWindow->minimize(); + } } break; case WindowCloseAction: @@ -774,8 +807,9 @@ void PresentWindowsEffect::mouseActionDesktop(DesktopMouseAction &action) { switch (action) { case DesktopActivateAction: - if (m_highlightedWindow) + if (m_highlightedWindow) { effects->activateWindow(m_highlightedWindow); + } setActive(false); break; case DesktopExitAction: @@ -845,8 +879,9 @@ void PresentWindowsEffect::grabbedKeyboardEvent(QKeyEvent *e) return; case Qt::Key_Return: case Qt::Key_Enter: - if (m_highlightedWindow) + if (m_highlightedWindow) { effects->activateWindow(m_highlightedWindow); + } setActive(false); return; case Qt::Key_Tab: @@ -880,8 +915,9 @@ void PresentWindowsEffect::slotPropertyNotify(EffectWindow *w, long a) if (m_atomDesktop == XCB_ATOM_NONE && m_atomWindows == XCB_ATOM_NONE) { return; } - if (!w || (a != m_atomDesktop && a != m_atomWindows)) + if (!w || (a != m_atomDesktop && a != m_atomWindows)) { return; // Not our atom + } if (a == m_atomDesktop) { QByteArray byteData = w->readProperty(m_atomDesktop, m_atomDesktop, 32); @@ -898,15 +934,17 @@ void PresentWindowsEffect::slotPropertyNotify(EffectWindow *w, long a) return; } // present windows is active so don't do anything - if (m_activated) + if (m_activated) { return; + } int desktop = data[0]; - if (desktop > effects->numberOfDesktops()) + if (desktop > effects->numberOfDesktops()) { return; - if (desktop == -1) + } + if (desktop == -1) { toggleActiveAllDesktops(); - else { + } else { m_mode = ModeSelectedDesktop; m_desktop = desktop; m_managerWindow = w; @@ -927,8 +965,9 @@ void PresentWindowsEffect::slotPropertyNotify(EffectWindow *w, long a) return; } // present windows is active so don't do anything - if (m_activated) + if (m_activated) { return; + } // for security clear selected windows m_selectedWindows.clear(); @@ -966,12 +1005,14 @@ void PresentWindowsEffect::presentWindows(const QStringList &windows) void PresentWindowsEffect::rearrangeWindows() { - if (!m_activated) + if (!m_activated) { return; + } effects->addRepaintFull(); // Trigger the first repaint - if (m_closeView) + if (m_closeView) { m_closeView->hide(); + } // Work out which windows are on which screens EffectWindowList windowlist; @@ -981,8 +1022,9 @@ void PresentWindowsEffect::rearrangeWindows() windowlist = m_motionManager.managedWindows(); for (EffectWindow *w : qAsConst(windowlist)) { DataHash::iterator winData = m_windowData.find(w); - if (winData == m_windowData.end() || winData->deleted) + if (winData == m_windowData.end() || winData->deleted) { continue; // don't include closed windows + } windowlists[w->screen()].append(w); winData->visible = true; } @@ -991,15 +1033,17 @@ void PresentWindowsEffect::rearrangeWindows() const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *w : managedWindows) { DataHash::iterator winData = m_windowData.find(w); - if (winData == m_windowData.end() || winData->deleted) + if (winData == m_windowData.end() || winData->deleted) { continue; // don't include closed windows + } if (w->caption().contains(m_windowFilter, Qt::CaseInsensitive) || w->windowClass().contains(m_windowFilter, Qt::CaseInsensitive) || w->windowRole().contains(m_windowFilter, Qt::CaseInsensitive)) { windowlist.append(w); windowlists[w->screen()].append(w); winData->visible = true; - } else + } else { winData->visible = false; + } } } if (windowlist.isEmpty()) { @@ -1010,10 +1054,12 @@ void PresentWindowsEffect::rearrangeWindows() // We filtered out the highlighted window if (m_highlightedWindow) { DataHash::iterator winData = m_windowData.find(m_highlightedWindow); - if (winData != m_windowData.end() && !winData->visible) + if (winData != m_windowData.end() && !winData->visible) { setHighlightedWindow(findFirstWindow()); - } else + } + } else { setHighlightedWindow(findFirstWindow()); + } const QList screens = effects->screens(); for (EffectScreen *screen : screens) { @@ -1022,12 +1068,14 @@ void PresentWindowsEffect::rearrangeWindows() // Don't rearrange if the grid is the same size as what it was before to prevent // windows moving to a better spot if one was filtered out. - if (m_layoutMode == LayoutRegularGrid && m_gridSizes[screen].columns && m_gridSizes[screen].rows && windows.size() < m_gridSizes[screen].columns * m_gridSizes[screen].rows && windows.size() > (m_gridSizes[screen].columns - 1) * m_gridSizes[screen].rows && windows.size() > m_gridSizes[screen].columns * (m_gridSizes[screen].rows - 1)) + if (m_layoutMode == LayoutRegularGrid && m_gridSizes[screen].columns && m_gridSizes[screen].rows && windows.size() < m_gridSizes[screen].columns * m_gridSizes[screen].rows && windows.size() > (m_gridSizes[screen].columns - 1) * m_gridSizes[screen].rows && windows.size() > m_gridSizes[screen].columns * (m_gridSizes[screen].rows - 1)) { continue; + } // No point continuing if there is no windows to process - if (!windows.count()) + if (!windows.count()) { continue; + } calculateWindowTransformations(windows, screen, m_motionManager); } @@ -1037,16 +1085,19 @@ void PresentWindowsEffect::rearrangeWindows() const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *w : managedWindows) { DataHash::iterator winData = m_windowData.find(w); - if (winData == m_windowData.end()) + if (winData == m_windowData.end()) { continue; + } - if (!metrics) + if (!metrics) { metrics = new QFontMetrics(winData->textFrame->font()); + } QRect geom = m_motionManager.targetGeometry(w).toRect(); QString string = metrics->elidedText(w->caption(), Qt::ElideRight, geom.width() * 0.9); - if (string != winData->textFrame->text()) + if (string != winData->textFrame->text()) { winData->textFrame->setText(string); + } } delete metrics; } @@ -1054,16 +1105,18 @@ void PresentWindowsEffect::rearrangeWindows() void PresentWindowsEffect::calculateWindowTransformations(EffectWindowList windowlist, EffectScreen *screen, WindowMotionManager &motionManager, bool external) { - if (m_layoutMode == LayoutRegularGrid) + if (m_layoutMode == LayoutRegularGrid) { calculateWindowTransformationsClosest(windowlist, screen, motionManager); - else if (m_layoutMode == LayoutFlexibleGrid) + } else if (m_layoutMode == LayoutFlexibleGrid) { calculateWindowTransformationsKompose(windowlist, screen, motionManager); - else + } else { calculateWindowTransformationsNatural(windowlist, screen, motionManager); + } // If called externally we don't need to remember this data - if (external) + if (external) { m_windowData.clear(); + } } static inline int distance(QPoint &pos1, QPoint &pos2) @@ -1077,12 +1130,14 @@ void PresentWindowsEffect::calculateWindowTransformationsClosest(EffectWindowLis WindowMotionManager &motionManager) { // This layout mode requires at least one window visible - if (windowlist.count() == 0) + if (windowlist.count() == 0) { return; + } QRect area = effects->clientArea(ScreenArea, screen, effects->currentDesktop()); - if (m_showPanel) // reserve space for the panel + if (m_showPanel) { // reserve space for the panel area = effects->clientArea(MaximizeArea, screen, effects->currentDesktop()); + } int columns = int(ceil(sqrt(double(windowlist.count())))); int rows = int(ceil(windowlist.count() / double(columns))); @@ -1103,11 +1158,12 @@ void PresentWindowsEffect::calculateWindowTransformationsClosest(EffectWindowLis // precalculate all slot centers QVector slotCenters; slotCenters.resize(rows * columns); - for (int x = 0; x < columns; ++x) + for (int x = 0; x < columns; ++x) { for (int y = 0; y < rows; ++y) { slotCenters[x + y * columns] = QPoint(area.x() + slotWidth * x + slotWidth / 2, area.y() + slotHeight * y + slotHeight / 2); } + } // Assign each window to the closest available slot EffectWindowList tmpList = windowlist; // use a QLinkedList copy instead? @@ -1130,16 +1186,18 @@ void PresentWindowsEffect::calculateWindowTransformationsClosest(EffectWindowLis } } Q_ASSERT(slotCandidate != -1); - if (takenSlots[slotCandidate]) + if (takenSlots[slotCandidate]) { tmpList << takenSlots[slotCandidate]; // occupier needs a new home now :p + } tmpList.removeAll(w); takenSlots[slotCandidate] = w; // ...and we rumble in =) } for (int slot = 0; slot < columns * rows; ++slot) { EffectWindow *w = takenSlots[slot]; - if (!w) // some slots might be empty + if (!w) { // some slots might be empty continue; + } // Work out where the slot is QRect target( @@ -1176,12 +1234,14 @@ void PresentWindowsEffect::calculateWindowTransformationsKompose(EffectWindowLis WindowMotionManager &motionManager) { // This layout mode requires at least one window visible - if (windowlist.count() == 0) + if (windowlist.count() == 0) { return; + } QRect availRect = effects->clientArea(ScreenArea, screen, effects->currentDesktop()); - if (m_showPanel) // reserve space for the panel + if (m_showPanel) { // reserve space for the panel availRect = effects->clientArea(MaximizeArea, screen, effects->currentDesktop()); + } std::sort(windowlist.begin(), windowlist.end()); // The location of the windows should not depend on the stacking order // Following code is taken from Kompose 0.5.4, src/komposelayout.cpp @@ -1214,8 +1274,9 @@ void PresentWindowsEffect::calculateWindowTransformationsKompose(EffectWindowLis EffectWindow *window; // Check for end of List - if (it == windowlist.end()) + if (it == windowlist.end()) { break; + } window = *it; // Calculate width and height of widget @@ -1263,20 +1324,24 @@ void PresentWindowsEffect::calculateWindowTransformationsKompose(EffectWindowLis int alignmentXoffset = 0; int alignmentYoffset = 0; - if (i == 0 && h > widgeth) + if (i == 0 && h > widgeth) { alignmentYoffset = h - widgeth; - if (j == 0 && w > widgetw) + } + if (j == 0 && w > widgetw) { alignmentXoffset = w - widgetw; + } QRect geom(availRect.x() + j * (w + spacing) + spacing + alignmentXoffset + xOffsetFromLastCol, availRect.y() + i * (h + spacing) + spacing + alignmentYoffset, widgetw, widgeth); geometryRects.append(geom); // Set the x offset for the next column - if (alignmentXoffset == 0) + if (alignmentXoffset == 0) { xOffsetFromLastCol += widgetw - w; - if (maxHeightInRow < widgeth) + } + if (maxHeightInRow < widgeth) { maxHeightInRow = widgeth; + } } maxRowHeights.append(maxHeightInRow); } @@ -1285,8 +1350,9 @@ void PresentWindowsEffect::calculateWindowTransformationsKompose(EffectWindowLis for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { int pos = i * columns + j; - if (pos >= windowlist.count()) + if (pos >= windowlist.count()) { break; + } EffectWindow *window = windowlist[pos]; QRect target = geometryRects[pos]; @@ -1301,8 +1367,9 @@ void PresentWindowsEffect::calculateWindowTransformationsKompose(EffectWindowLis // mWindowData[window].area.left() << "; " << mWindowData[window].area.right() << // "), scale: " << mWindowData[window].scale << endl; } - if (maxRowHeights[i] - h > 0) + if (maxRowHeights[i] - h > 0) { topOffset += maxRowHeights[i] - h; + } } } @@ -1331,8 +1398,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis std::sort(windowlist.begin(), windowlist.end()); QRect area = effects->clientArea(ScreenArea, screen, effects->currentDesktop()); - if (m_showPanel) // reserve space for the panel + if (m_showPanel) { // reserve space for the panel area = effects->clientArea(MaximizeArea, screen, effects->currentDesktop()); + } QRect bounds = area; int direction = 0; QHash targets; @@ -1344,8 +1412,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis // is on the edge of the screen to try to use as much screen real estate as possible. directions[w] = direction; direction++; - if (direction == 4) + if (direction == 4) { direction = 0; + } } // Iterate over all windows, if two overlap push them apart _slightly_ as we try to @@ -1356,8 +1425,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis for (EffectWindow *w : qAsConst(windowlist)) { QRect *target_w = &targets[w]; for (EffectWindow *e : qAsConst(windowlist)) { - if (w == e) + if (w == e) { continue; + } QRect *target_e = &targets[e]; if (target_w->adjusted(-5, -5, 5, 5).intersects(target_e->adjusted(-5, -5, 5, 5))) { @@ -1366,8 +1436,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis // Determine pushing direction QPoint diff(target_e->center() - target_w->center()); // Prevent dividing by zero and non-movement - if (diff.x() == 0 && diff.y() == 0) + if (diff.x() == 0 && diff.y() == 0) { diff.setX(1); + } // Try to keep screen aspect ratio // if (bounds.height() / bounds.width() > area.height() / area.width()) // diff.setY(diff.y() / 2); @@ -1393,19 +1464,25 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis int ySection = (target_w->y() - bounds.y()) / (bounds.height() / 3); diff = QPoint(0, 0); if (xSection != 1 || ySection != 1) { // Remove this if you want the center to pull as well - if (xSection == 1) + if (xSection == 1) { xSection = (directions[w] / 2 ? 2 : 0); - if (ySection == 1) + } + if (ySection == 1) { ySection = (directions[w] % 2 ? 2 : 0); + } } - if (xSection == 0 && ySection == 0) + if (xSection == 0 && ySection == 0) { diff = QPoint(bounds.topLeft() - target_w->center()); - if (xSection == 2 && ySection == 0) + } + if (xSection == 2 && ySection == 0) { diff = QPoint(bounds.topRight() - target_w->center()); - if (xSection == 2 && ySection == 2) + } + if (xSection == 2 && ySection == 2) { diff = QPoint(bounds.bottomRight() - target_w->center()); - if (xSection == 0 && ySection == 2) + } + if (xSection == 0 && ySection == 2) { diff = QPoint(bounds.bottomLeft() - target_w->center()); + } if (diff.x() != 0 || diff.y() != 0) { diff *= m_accuracy / double(diff.manhattanLength()); target_w->translate(diff); @@ -1422,12 +1499,13 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis // Work out scaling by getting the most top-left and most bottom-right window coords. // The 20's and 10's are so that the windows don't touch the edge of the screen. double scale; - if (bounds == area) + if (bounds == area) { scale = 1.0; // Don't add borders to the screen - else if (area.width() / double(bounds.width()) < area.height() / double(bounds.height())) + } else if (area.width() / double(bounds.width()) < area.height() / double(bounds.height())) { scale = (area.width() - 20) / double(bounds.width()); - else + } else { scale = (area.height() - 20) / double(bounds.height()); + } // Make bounding rect fill the screen size for later steps bounds = QRect( (bounds.x() * scale - (area.width() - 20 - bounds.width() * scale) / 2 - 10) / scale, @@ -1472,9 +1550,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis target->y() - yDiff - heightDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(w, targets, borderRegion)) + if (isOverlappingAny(w, targets, borderRegion)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; @@ -1487,9 +1565,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis target->y() + yDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(w, targets, borderRegion)) + if (isOverlappingAny(w, targets, borderRegion)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; @@ -1502,9 +1580,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis target->y() + yDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(w, targets, borderRegion)) + if (isOverlappingAny(w, targets, borderRegion)) { *target = oldRect; - else { + } else { moved = true; heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); yDiff = heightDiff / 2; @@ -1517,10 +1595,11 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis target->y() - yDiff - heightDiff, target->width() + widthDiff, target->height() + heightDiff); - if (isOverlappingAny(w, targets, borderRegion)) + if (isOverlappingAny(w, targets, borderRegion)) { *target = oldRect; - else + } else { moved = true; + } } } while (moved); @@ -1550,18 +1629,22 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis bool PresentWindowsEffect::isOverlappingAny(EffectWindow *w, const QHash &targets, const QRegion &border) { QHash::const_iterator winTarget = targets.find(w); - if (winTarget == targets.constEnd()) + if (winTarget == targets.constEnd()) { return false; - if (border.intersects(*winTarget)) + } + if (border.intersects(*winTarget)) { return true; + } // Is there a better way to do this? QHash::const_iterator target; for (target = targets.constBegin(); target != targets.constEnd(); ++target) { - if (target == winTarget) + if (target == winTarget) { continue; - if (winTarget->adjusted(-5, -5, 5, 5).intersects(target->adjusted(-5, -5, 5, 5))) + } + if (winTarget->adjusted(-5, -5, 5, 5).intersects(target->adjusted(-5, -5, 5, 5))) { return true; + } } return false; } @@ -1571,10 +1654,12 @@ bool PresentWindowsEffect::isOverlappingAny(EffectWindow *w, const QHashactiveFullScreenEffect() && effects->activeFullScreenEffect() != this) + if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this) { return; - if (m_activated == active) + } + if (m_activated == active) { return; + } if (effects->isScreenLocked() && active) { return; } @@ -1610,8 +1695,9 @@ void PresentWindowsEffect::setActive(bool active) winData->deleted = false; winData->referenced = false; winData->opacity = 0.0; - if (w->isOnCurrentDesktop() && !w->isMinimized()) + if (w->isOnCurrentDesktop() && !w->isMinimized()) { winData->opacity = 1.0; + } winData->highlight = 1.0; winData->textFrame = effects->effectFrame(EffectFrameUnstyled, false); @@ -1665,8 +1751,9 @@ void PresentWindowsEffect::setActive(bool active) } } else { m_needInitialSelection = false; - if (m_highlightedWindow) + if (m_highlightedWindow) { effects->setElevatedWindow(m_highlightedWindow, false); + } // Fade in/out all windows EffectWindow *activeWindow = effects->activeWindow(); @@ -1697,16 +1784,18 @@ void PresentWindowsEffect::setActive(bool active) m_selectedWindows.clear(); effects->stopMouseInterception(this); - if (m_hasKeyboardGrab) + if (m_hasKeyboardGrab) { effects->ungrabKeyboard(); + } m_hasKeyboardGrab = false; // destroy atom on manager window if (m_managerWindow) { - if (m_mode == ModeSelectedDesktop && m_atomDesktop != XCB_ATOM_NONE) + if (m_mode == ModeSelectedDesktop && m_atomDesktop != XCB_ATOM_NONE) { m_managerWindow->deleteProperty(m_atomDesktop); - else if (m_mode == ModeWindowGroup && m_atomWindows != XCB_ATOM_NONE) + } else if (m_mode == ModeWindowGroup && m_atomWindows != XCB_ATOM_NONE) { m_managerWindow->deleteProperty(m_atomWindows); + } m_managerWindow = nullptr; } } @@ -1736,18 +1825,24 @@ void PresentWindowsEffect::updateFilterFrame() bool PresentWindowsEffect::isSelectableWindow(EffectWindow *w) { - if (!w->isOnCurrentActivity()) + if (!w->isOnCurrentActivity()) { return false; - if (w->isSpecialWindow() || w->isUtility()) + } + if (w->isSpecialWindow() || w->isUtility()) { return false; - if (w->isDeleted()) + } + if (w->isDeleted()) { return false; - if (!w->acceptsFocus()) + } + if (!w->acceptsFocus()) { return false; - if (w->isSkipSwitcher()) + } + if (w->isSkipSwitcher()) { return false; - if (m_ignoreMinimized && w->isMinimized()) + } + if (m_ignoreMinimized && w->isMinimized()) { return false; + } switch (m_mode) { default: @@ -1766,18 +1861,21 @@ bool PresentWindowsEffect::isSelectableWindow(EffectWindow *w) bool PresentWindowsEffect::isVisibleWindow(EffectWindow *w) { - if (w->isDesktop()) + if (w->isDesktop()) { return true; + } return isSelectableWindow(w); } void PresentWindowsEffect::setHighlightedWindow(EffectWindow *w) { - if (w == m_highlightedWindow || (w != nullptr && !m_motionManager.isManaging(w))) + if (w == m_highlightedWindow || (w != nullptr && !m_motionManager.isManaging(w))) { return; + } - if (m_closeView) + if (m_closeView) { m_closeView->hide(); + } if (m_highlightedWindow) { effects->setElevatedWindow(m_highlightedWindow, false); m_highlightedWindow->addRepaintFull(); // Trigger the first repaint @@ -1793,15 +1891,17 @@ void PresentWindowsEffect::setHighlightedWindow(EffectWindow *w) void PresentWindowsEffect::updateCloseWindow() { - if (!m_closeView || m_doNotCloseWindows) + if (!m_closeView || m_doNotCloseWindows) { return; + } if (!m_activated || !m_highlightedWindow || m_highlightedWindow->isDesktop()) { m_closeView->hide(); return; } - if (m_closeView->isVisible()) + if (m_closeView->isVisible()) { return; + } const QRectF rect(m_motionManager.targetGeometry(m_highlightedWindow)); if (2 * m_closeView->geometry().width() > rect.width() && 2 * m_closeView->geometry().height() > rect.height()) { @@ -1832,20 +1932,23 @@ void PresentWindowsEffect::updateCloseWindow() if (rect.contains(effects->cursorPos())) { m_closeView->show(); m_closeView->disarm(); - } else + } else { m_closeView->hide(); + } } void PresentWindowsEffect::closeWindow() { - if (m_highlightedWindow) + if (m_highlightedWindow) { m_highlightedWindow->closeWindow(); + } } EffectWindow *PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, int ydiff, bool wrap) const { - if (!w) + if (!w) { return m_motionManager.managedWindows().constFirst(); + } // TODO: Is it possible to select hidden windows? EffectWindow *next; @@ -1864,23 +1967,26 @@ EffectWindow *PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, i const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *e : managedWindows) { DataHash::const_iterator winData = m_windowData.find(e); - if (winData == m_windowData.end() || !winData->visible) + if (winData == m_windowData.end() || !winData->visible) { continue; + } QRectF eArea = m_motionManager.transformedGeometry(e); if (eArea.intersects(detectRect) && eArea.x() > wArea.x()) { - if (next == nullptr) + if (next == nullptr) { next = e; - else { + } else { QRectF nArea = m_motionManager.transformedGeometry(next); - if (eArea.x() < nArea.x()) + if (eArea.x() < nArea.x()) { next = e; + } } } } if (next == nullptr) { - if (wrap) // We are at the right-most window, now get the left-most one to wrap + if (wrap) { // We are at the right-most window, now get the left-most one to wrap return relativeWindow(w, -1000, 0, false); + } break; // No more windows to the right } w = next; @@ -1896,23 +2002,26 @@ EffectWindow *PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, i const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *e : managedWindows) { DataHash::const_iterator winData = m_windowData.find(e); - if (winData == m_windowData.end() || !winData->visible) + if (winData == m_windowData.end() || !winData->visible) { continue; + } QRectF eArea = m_motionManager.transformedGeometry(e); if (eArea.intersects(detectRect) && eArea.x() + eArea.width() < wArea.x() + wArea.width()) { - if (next == nullptr) + if (next == nullptr) { next = e; - else { + } else { QRectF nArea = m_motionManager.transformedGeometry(next); - if (eArea.x() + eArea.width() > nArea.x() + nArea.width()) + if (eArea.x() + eArea.width() > nArea.x() + nArea.width()) { next = e; + } } } } if (next == nullptr) { - if (wrap) // We are at the left-most window, now get the right-most one to wrap + if (wrap) { // We are at the left-most window, now get the right-most one to wrap return relativeWindow(w, 1000, 0, false); + } break; // No more windows to the left } w = next; @@ -1933,23 +2042,26 @@ EffectWindow *PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, i const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *e : managedWindows) { DataHash::const_iterator winData = m_windowData.find(e); - if (winData == m_windowData.end() || !winData->visible) + if (winData == m_windowData.end() || !winData->visible) { continue; + } QRectF eArea = m_motionManager.transformedGeometry(e); if (eArea.intersects(detectRect) && eArea.y() > wArea.y()) { - if (next == nullptr) + if (next == nullptr) { next = e; - else { + } else { QRectF nArea = m_motionManager.transformedGeometry(next); - if (eArea.y() < nArea.y()) + if (eArea.y() < nArea.y()) { next = e; + } } } } if (next == nullptr) { - if (wrap) // We are at the bottom-most window, now get the top-most one to wrap + if (wrap) { // We are at the bottom-most window, now get the top-most one to wrap return relativeWindow(w, 0, -1000, false); + } break; // No more windows to the bottom } w = next; @@ -1965,23 +2077,26 @@ EffectWindow *PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, i const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *e : managedWindows) { DataHash::const_iterator winData = m_windowData.find(e); - if (winData == m_windowData.end() || !winData->visible) + if (winData == m_windowData.end() || !winData->visible) { continue; + } QRectF eArea = m_motionManager.transformedGeometry(e); if (eArea.intersects(detectRect) && eArea.y() + eArea.height() < wArea.y() + wArea.height()) { - if (next == nullptr) + if (next == nullptr) { next = e; - else { + } else { QRectF nArea = m_motionManager.transformedGeometry(next); - if (eArea.y() + eArea.height() > nArea.y() + nArea.height()) + if (eArea.y() + eArea.height() > nArea.y() + nArea.height()) { next = e; + } } } } if (next == nullptr) { - if (wrap) // We are at the top-most window, now get the bottom-most one to wrap + if (wrap) { // We are at the top-most window, now get the bottom-most one to wrap return relativeWindow(w, 0, 1000, false); + } break; // No more windows to the top } w = next; @@ -2001,13 +2116,16 @@ EffectWindow *PresentWindowsEffect::findFirstWindow() const const auto managedWindows = m_motionManager.managedWindows(); for (EffectWindow *w : managedWindows) { DataHash::const_iterator winData = m_windowData.find(w); - if (winData == m_windowData.end()) + if (winData == m_windowData.end()) { continue; + } QRectF geometry = m_motionManager.transformedGeometry(w); - if (winData->visible == false) + if (winData->visible == false) { continue; // Not visible - if (winData->deleted) + } + if (winData->deleted) { continue; // Window has been closed + } if (topLeft == nullptr) { topLeft = w; topLeftGeometry = geometry; diff --git a/src/effects/showfps/showfps.cpp b/src/effects/showfps/showfps.cpp index 1ee992f9f6..806e89957b 100644 --- a/src/effects/showfps/showfps.cpp +++ b/src/effects/showfps/showfps.cpp @@ -44,8 +44,9 @@ ShowFpsEffect::ShowFpsEffect() } for (int i = 0; i < MAX_FPS; - ++i) + ++i) { frames[i] = 0; + } m_noBenchmark->setAlignment(Qt::AlignTop | Qt::AlignRight); m_noBenchmark->setText(i18n("This effect is not a benchmark")); reconfigure(ReconfigureAll); @@ -62,14 +63,16 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags) x = ShowFpsConfig::x(); y = ShowFpsConfig::y(); const QSize screenSize = effects->virtualScreenSize(); - if (x == -10000) // there's no -0 :( + if (x == -10000) { // there's no -0 :( x = screenSize.width() - 2 * NUM_PAINTS - FPS_WIDTH; - else if (x < 0) + } else if (x < 0) { x = screenSize.width() - 2 * NUM_PAINTS - FPS_WIDTH - x; - if (y == -10000) + } + if (y == -10000) { y = screenSize.height() - MAX_TIME; - else if (y < 0) + } else if (y < 0) { y = screenSize.height() - MAX_TIME - y; + } fps_rect = QRect(x, y, FPS_WIDTH + 2 * NUM_PAINTS, MAX_TIME); m_noBenchmark->setPosition(fps_rect.bottomRight() + QPoint(-6, 6)); @@ -78,8 +81,9 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags) textColor = ShowFpsConfig::textColor(); double textAlpha = ShowFpsConfig::textAlpha(); - if (!textColor.isValid()) + if (!textColor.isValid()) { textColor = QPalette().color(QPalette::Active, QPalette::WindowText); + } textColor.setAlphaF(textAlpha); switch (textPosition) { @@ -113,8 +117,9 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags) void ShowFpsEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) { frames[frames_pos] = QDateTime::currentMSecsSinceEpoch(); - if (++frames_pos == MAX_FPS) + if (++frames_pos == MAX_FPS) { frames_pos = 0; + } effects->prePaintScreen(data, presentTime); data.paint += fps_rect; @@ -141,17 +146,21 @@ void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData { effects->paintScreen(mask, region, data); int lastFrame = frames_pos - 1; - if (lastFrame < 0) + if (lastFrame < 0) { lastFrame = MAX_FPS - 1; + } const qint64 lastTimestamp = frames[lastFrame]; int fps = 0; for (int i = 0; i < MAX_FPS; - ++i) - if (abs(lastTimestamp - frames[i]) < 1000) + ++i) { + if (abs(lastTimestamp - frames[i]) < 1000) { ++fps; // count all frames in the last second - if (fps > MAX_TIME) + } + } + if (fps > MAX_TIME) { fps = MAX_TIME; // keep it the same height + } if (effects->isOpenGLCompositing()) { paintGL(fps, data.projectionMatrix()); glFinish(); // make sure all rendering is done @@ -287,8 +296,9 @@ void ShowFpsEffect::paintFPSGraph(int x, int y) void ShowFpsEffect::paintDrawSizeGraph(int x, int y) { int max_drawsize = 0; - for (int i = 0; i < NUM_PAINTS; i++) + for (int i = 0; i < NUM_PAINTS; i++) { max_drawsize = qMax(max_drawsize, paint_size[i]); + } // Log of min/max values shown on graph const float max_pixels_log = 7.2f; @@ -298,8 +308,9 @@ void ShowFpsEffect::paintDrawSizeGraph(int x, int y) float drawscale = (MAX_TIME - minh) / (max_pixels_log - min_pixels_log); QList drawlines; - for (int logh = (int)min_pixels_log; logh <= max_pixels_log; logh++) + for (int logh = (int)min_pixels_log; logh <= max_pixels_log; logh++) { drawlines.append((int)((logh - min_pixels_log) * drawscale) + minh); + } QList drawvalues; for (int i = 0; @@ -394,8 +405,9 @@ void ShowFpsEffect::postPaintScreen() { effects->postPaintScreen(); paints[paints_pos] = t.elapsed(); - if (++paints_pos == NUM_PAINTS) + if (++paints_pos == NUM_PAINTS) { paints_pos = 0; + } effects->addRepaint(fps_rect); } diff --git a/src/effects/slideback/slideback.cpp b/src/effects/slideback/slideback.cpp index 79ce2cec9f..2d2d247996 100644 --- a/src/effects/slideback/slideback.cpp +++ b/src/effects/slideback/slideback.cpp @@ -42,10 +42,11 @@ void SlideBackEffect::slotStackingOrderChanged() m_upmostWindow = usableNewStackingOrder.last(); - if (m_upmostWindow == m_justMapped) // a window was added, got on top, stacking changed. Nothing impressive + if (m_upmostWindow == m_justMapped) { // a window was added, got on top, stacking changed. Nothing impressive m_justMapped = nullptr; - else if (!usableOldStackingOrder.isEmpty() && m_upmostWindow != usableOldStackingOrder.last()) + } else if (!usableOldStackingOrder.isEmpty() && m_upmostWindow != usableOldStackingOrder.last()) { windowRaised(m_upmostWindow); + } oldStackingOrder = newStackingOrder; usableOldStackingOrder = usableNewStackingOrder; @@ -253,10 +254,12 @@ void SlideBackEffect::postPaintWindow(EffectWindow *w) void SlideBackEffect::slotWindowDeleted(EffectWindow *w) { - if (w == m_upmostWindow) + if (w == m_upmostWindow) { m_upmostWindow = nullptr; - if (w == m_justMapped) + } + if (w == m_justMapped) { m_justMapped = nullptr; + } usableOldStackingOrder.removeAll(w); oldStackingOrder.removeAll(w); coveringWindows.removeAll(w); diff --git a/src/effects/startupfeedback/startupfeedback.cpp b/src/effects/startupfeedback/startupfeedback.cpp index 387a3a68be..3a088a40e0 100644 --- a/src/effects/startupfeedback/startupfeedback.cpp +++ b/src/effects/startupfeedback/startupfeedback.cpp @@ -141,11 +141,11 @@ void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags) m_startupInfo->setTimeout(m_timeout.count()); const bool busyBlinking = c.readEntry("Blinking", false); const bool busyBouncing = c.readEntry("Bouncing", true); - if (!busyCursor) + if (!busyCursor) { m_type = NoFeedback; - else if (busyBouncing) + } else if (busyBouncing) { m_type = BouncingFeedback; - else if (busyBlinking) { + } else if (busyBlinking) { m_type = BlinkingFeedback; if (effects->compositingType() == OpenGLCompositing) { ensureResources(); @@ -156,8 +156,9 @@ void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags) qCDebug(KWIN_STARTUPFEEDBACK) << "Blinking Shader is not valid"; } } - } else + } else { m_type = PassiveFeedback; + } if (m_active) { stop(); start(m_startups[m_currentStartup]); @@ -235,8 +236,9 @@ void StartupFeedbackEffect::postPaintScreen() { if (m_active) { m_dirtyRect = m_currentGeometry; // ensure the now dirty region is cleaned on the next pass - if (m_type == BlinkingFeedback || m_type == BouncingFeedback) + if (m_type == BlinkingFeedback || m_type == BouncingFeedback) { effects->addRepaint(m_dirtyRect); // we also have to trigger a repaint + } } effects->postPaintScreen(); } @@ -300,10 +302,12 @@ void StartupFeedbackEffect::gotStartupChange(const QString &id, const QIcon &ico void StartupFeedbackEffect::start(const Startup &startup) { - if (m_type == NoFeedback || m_splashVisible || effects->isCursorHidden()) + if (m_type == NoFeedback || m_splashVisible || effects->isCursorHidden()) { return; - if (!m_active) + } + if (!m_active) { effects->startMousePolling(); + } m_active = true; // read details about the mouse-cursor theme define per default @@ -315,8 +319,9 @@ void StartupFeedbackEffect::start(const Startup &startup) iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); } // get ratio for bouncing cursor so we don't need to manually calculate the sizes for each icon size - if (m_type == BouncingFeedback) + if (m_type == BouncingFeedback) { m_bounceSizesRatio = iconSize / 16.0; + } const QPixmap iconPixmap = startup.icon.pixmap(iconSize); prepareTextures(iconPixmap); m_dirtyRect = m_currentGeometry = feedbackRect(); @@ -325,8 +330,9 @@ void StartupFeedbackEffect::start(const Startup &startup) void StartupFeedbackEffect::stop() { - if (m_active) + if (m_active) { effects->stopMousePolling(); + } m_active = false; m_lastPresentTime = std::chrono::milliseconds::zero(); effects->makeOpenGLContextCurrent(); @@ -377,8 +383,9 @@ QImage StartupFeedbackEffect::scalePixmap(const QPixmap &pm, const QSize &size) { const QSize &adjustedSize = size * m_bounceSizesRatio; QImage scaled = pm.toImage().scaled(adjustedSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - if (scaled.format() != QImage::Format_ARGB32_Premultiplied && scaled.format() != QImage::Format_ARGB32) + if (scaled.format() != QImage::Format_ARGB32_Premultiplied && scaled.format() != QImage::Format_ARGB32) { scaled = scaled.convertToFormat(QImage::Format_ARGB32); + } QImage result(20 * m_bounceSizesRatio, 20 * m_bounceSizesRatio, QImage::Format_ARGB32); QPainter p(&result); @@ -391,14 +398,15 @@ QImage StartupFeedbackEffect::scalePixmap(const QPixmap &pm, const QSize &size) QRect StartupFeedbackEffect::feedbackRect() const { int xDiff; - if (m_cursorSize <= 16) + if (m_cursorSize <= 16) { xDiff = 8 + 7; - else if (m_cursorSize <= 32) + } else if (m_cursorSize <= 32) { xDiff = 16 + 7; - else if (m_cursorSize <= 48) + } else if (m_cursorSize <= 48) { xDiff = 24 + 7; - else + } else { xDiff = 32 + 7; + } int yDiff = xDiff; GLTexture *texture = nullptr; int yOffset = 0; @@ -417,8 +425,9 @@ QRect StartupFeedbackEffect::feedbackRect() const } const QPoint cursorPos = effects->cursorPos() + QPoint(xDiff, yDiff + yOffset); QRect rect; - if (texture) + if (texture) { rect = QRect(cursorPos, texture->size()); + } return rect; } diff --git a/src/effects/thumbnailaside/thumbnailaside.cpp b/src/effects/thumbnailaside/thumbnailaside.cpp index 24803a6c3c..1b41303489 100644 --- a/src/effects/thumbnailaside/thumbnailaside.cpp +++ b/src/effects/thumbnailaside/thumbnailaside.cpp @@ -76,8 +76,9 @@ void ThumbnailAsideEffect::paintWindow(EffectWindow *w, int mask, QRegion region void ThumbnailAsideEffect::slotWindowDamaged(EffectWindow *w, const QRegion &) { for (const Data &d : qAsConst(windows)) { - if (d.window == w) + if (d.window == w) { effects->addRepaint(d.rect); + } } } @@ -85,10 +86,11 @@ void ThumbnailAsideEffect::slotWindowFrameGeometryChanged(EffectWindow *w, const { for (const Data &d : qAsConst(windows)) { if (d.window == w) { - if (w->size() == old.size()) + if (w->size() == old.size()) { effects->addRepaint(d.rect); - else + } else { arrange(); + } return; } } @@ -102,12 +104,14 @@ void ThumbnailAsideEffect::slotWindowClosed(EffectWindow *w) void ThumbnailAsideEffect::toggleCurrentThumbnail() { EffectWindow *active = effects->activeWindow(); - if (active == nullptr) + if (active == nullptr) { return; - if (windows.contains(active)) + } + if (windows.contains(active)) { removeThumbnail(active); - else + } else { addThumbnail(active); + } } void ThumbnailAsideEffect::addThumbnail(EffectWindow *w) @@ -122,8 +126,9 @@ void ThumbnailAsideEffect::addThumbnail(EffectWindow *w) void ThumbnailAsideEffect::removeThumbnail(EffectWindow *w) { - if (!windows.contains(w)) + if (!windows.contains(w)) { return; + } repaintAll(); // repaint old areas int index = windows[w].index; windows.remove(w); @@ -131,16 +136,18 @@ void ThumbnailAsideEffect::removeThumbnail(EffectWindow *w) it != windows.end(); ++it) { Data &d = *it; - if (d.index > index) + if (d.index > index) { --d.index; + } } arrange(); } void ThumbnailAsideEffect::arrange() { - if (windows.size() == 0) + if (windows.size() == 0) { return; + } int height = 0; QVector pos(windows.size()); int mwidth = 0; diff --git a/src/effects/touchpoints/touchpoints.cpp b/src/effects/touchpoints/touchpoints.cpp index 94023072f0..f94b5ec034 100644 --- a/src/effects/touchpoints/touchpoints.cpp +++ b/src/effects/touchpoints/touchpoints.cpp @@ -179,22 +179,25 @@ bool TouchPointsEffect::isActive() const void TouchPointsEffect::drawCircle(const QColor &color, float cx, float cy, float r) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { drawCircleGl(color, cx, cy, r); - else if (effects->compositingType() == QPainterCompositing) + } else if (effects->compositingType() == QPainterCompositing) { drawCircleQPainter(color, cx, cy, r); + } } void TouchPointsEffect::paintScreenSetup(int mask, QRegion region, ScreenPaintData &data) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { paintScreenSetupGl(mask, region, data); + } } void TouchPointsEffect::paintScreenFinish(int mask, QRegion region, ScreenPaintData &data) { - if (effects->isOpenGLCompositing()) + if (effects->isOpenGLCompositing()) { paintScreenFinishGl(mask, region, data); + } } void TouchPointsEffect::drawCircleGl(const QColor &color, float cx, float cy, float r) diff --git a/src/effects/trackmouse/trackmouse.cpp b/src/effects/trackmouse/trackmouse.cpp index 237c95c67d..b68c8a361a 100644 --- a/src/effects/trackmouse/trackmouse.cpp +++ b/src/effects/trackmouse/trackmouse.cpp @@ -35,8 +35,9 @@ TrackMouseEffect::TrackMouseEffect() { initConfig(); m_texture[0] = m_texture[1] = nullptr; - if (effects->isOpenGLCompositing() || effects->compositingType() == QPainterCompositing) + if (effects->isOpenGLCompositing() || effects->compositingType() == QPainterCompositing) { m_angleBase = 90.0; + } m_mousePolling = false; m_action = new QAction(this); @@ -54,8 +55,9 @@ TrackMouseEffect::TrackMouseEffect() TrackMouseEffect::~TrackMouseEffect() { - if (m_mousePolling) + if (m_mousePolling) { effects->stopMousePolling(); + } for (int i = 0; i < 2; ++i) { delete m_texture[i]; m_texture[i] = nullptr; @@ -66,18 +68,23 @@ void TrackMouseEffect::reconfigure(ReconfigureFlags) { m_modifiers = Qt::KeyboardModifiers(); TrackMouseConfig::self()->read(); - if (TrackMouseConfig::shift()) + if (TrackMouseConfig::shift()) { m_modifiers |= Qt::ShiftModifier; - if (TrackMouseConfig::alt()) + } + if (TrackMouseConfig::alt()) { m_modifiers |= Qt::AltModifier; - if (TrackMouseConfig::control()) + } + if (TrackMouseConfig::control()) { m_modifiers |= Qt::ControlModifier; - if (TrackMouseConfig::meta()) + } + if (TrackMouseConfig::meta()) { m_modifiers |= Qt::MetaModifier; + } if (m_modifiers) { - if (!m_mousePolling) + if (!m_mousePolling) { effects->startMousePolling(); + } m_mousePolling = true; } else if (m_mousePolling) { effects->stopMousePolling(); @@ -149,8 +156,9 @@ bool TrackMouseEffect::init() effects->makeOpenGLContextCurrent(); if (!m_texture[0] && m_image[0].isNull()) { loadTexture(); - if (!m_texture[0] && m_image[0].isNull()) + if (!m_texture[0] && m_image[0].isNull()) { return false; + } } m_lastRect[0].moveCenter(cursorPos()); m_lastRect[1].moveCenter(cursorPos()); @@ -225,8 +233,9 @@ void TrackMouseEffect::loadTexture() { QString f[2] = {QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("tm_outer.png")), QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("tm_inner.png"))}; - if (f[0].isEmpty() || f[1].isEmpty()) + if (f[0].isEmpty() || f[1].isEmpty()) { return; + } for (int i = 0; i < 2; ++i) { if (effects->isOpenGLCompositing()) { diff --git a/src/effects/wobblywindows/wobblywindows.cpp b/src/effects/wobblywindows/wobblywindows.cpp index 029594454c..511f56a8bd 100644 --- a/src/effects/wobblywindows/wobblywindows.cpp +++ b/src/effects/wobblywindows/wobblywindows.cpp @@ -331,14 +331,18 @@ void WobblyWindowsEffect::slotWindowStepUserMovedResized(EffectWindow *w, const if (windows.contains(w)) { WindowWobblyInfos &wwi = windows[w]; const QRect rect = w->frameGeometry(); - if (rect.y() != wwi.resize_original_rect.y()) + if (rect.y() != wwi.resize_original_rect.y()) { wwi.can_wobble_top = true; - if (rect.x() != wwi.resize_original_rect.x()) + } + if (rect.x() != wwi.resize_original_rect.x()) { wwi.can_wobble_left = true; - if (rect.right() != wwi.resize_original_rect.right()) + } + if (rect.right() != wwi.resize_original_rect.right()) { wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) + } + if (rect.bottom() != wwi.resize_original_rect.bottom()) { wwi.can_wobble_bottom = true; + } } } @@ -348,14 +352,18 @@ void WobblyWindowsEffect::slotWindowFinishUserMovedResized(EffectWindow *w) WindowWobblyInfos &wwi = windows[w]; wwi.status = Free; const QRect rect = w->frameGeometry(); - if (rect.y() != wwi.resize_original_rect.y()) + if (rect.y() != wwi.resize_original_rect.y()) { wwi.can_wobble_top = true; - if (rect.x() != wwi.resize_original_rect.x()) + } + if (rect.x() != wwi.resize_original_rect.x()) { wwi.can_wobble_left = true; - if (rect.right() != wwi.resize_original_rect.right()) + } + if (rect.right() != wwi.resize_original_rect.right()) { wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) + } + if (rect.bottom() != wwi.resize_original_rect.bottom()) { wwi.can_wobble_bottom = true; + } } } @@ -374,14 +382,18 @@ void WobblyWindowsEffect::slotWindowMaximizeStateChanged(EffectWindow *w, bool h if (windows.contains(w)) { WindowWobblyInfos &wwi = windows[w]; const QRect rect = w->frameGeometry(); - if (rect.y() != wwi.resize_original_rect.y()) + if (rect.y() != wwi.resize_original_rect.y()) { wwi.can_wobble_top = true; - if (rect.x() != wwi.resize_original_rect.x()) + } + if (rect.x() != wwi.resize_original_rect.x()) { wwi.can_wobble_left = true; - if (rect.right() != wwi.resize_original_rect.right()) + } + if (rect.right() != wwi.resize_original_rect.right()) { wwi.can_wobble_right = true; - if (rect.bottom() != wwi.resize_original_rect.bottom()) + } + if (rect.bottom() != wwi.resize_original_rect.bottom()) { wwi.can_wobble_bottom = true; + } } } @@ -907,24 +919,32 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time) } if (!wwi.can_wobble_top) { - for (unsigned int i = 0; i < wwi.width; ++i) - for (unsigned j = 0; j < wwi.width - 1; ++j) + for (unsigned int i = 0; i < wwi.width; ++i) { + for (unsigned j = 0; j < wwi.width - 1; ++j) { wwi.position[i + wwi.width * j].y = wwi.origin[i + wwi.width * j].y; + } + } } if (!wwi.can_wobble_bottom) { - for (unsigned int i = wwi.width * (wwi.height - 1); i < wwi.count; ++i) - for (unsigned j = 0; j < wwi.width - 1; ++j) + for (unsigned int i = wwi.width * (wwi.height - 1); i < wwi.count; ++i) { + for (unsigned j = 0; j < wwi.width - 1; ++j) { wwi.position[i - wwi.width * j].y = wwi.origin[i - wwi.width * j].y; + } + } } if (!wwi.can_wobble_left) { - for (unsigned int i = 0; i < wwi.count; i += wwi.width) - for (unsigned j = 0; j < wwi.width - 1; ++j) + for (unsigned int i = 0; i < wwi.count; i += wwi.width) { + for (unsigned j = 0; j < wwi.width - 1; ++j) { wwi.position[i + j].x = wwi.origin[i + j].x; + } + } } if (!wwi.can_wobble_right) { - for (unsigned int i = wwi.width - 1; i < wwi.count; i += wwi.width) - for (unsigned j = 0; j < wwi.width - 1; ++j) + for (unsigned int i = wwi.width - 1; i < wwi.count; i += wwi.width) { + for (unsigned j = 0; j < wwi.width - 1; ++j) { wwi.position[i - j].x = wwi.origin[i - j].x; + } + } } #if defined VERBOSE_MODE @@ -939,8 +959,9 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time) freeWobblyInfo(wwi); windows.remove(w); unredirect(w); - if (windows.isEmpty()) + if (windows.isEmpty()) { effects->addRepaintFull(); + } return false; } diff --git a/src/effects/zoom/zoom.cpp b/src/effects/zoom/zoom.cpp index fe3ad9ffb7..63885899e0 100644 --- a/src/effects/zoom/zoom.cpp +++ b/src/effects/zoom/zoom.cpp @@ -186,8 +186,9 @@ void ZoomEffect::showCursor() void ZoomEffect::hideCursor() { - if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep) + if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep) { return; // don't replace the actual cursor by a static image for no reason. + } if (!isMouseHidden) { // try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer GLTexture *texture = nullptr; @@ -225,8 +226,9 @@ void ZoomEffect::reconfigure(ReconfigureFlags) // Load the saved zoom value. source_zoom = 1.0; target_zoom = ZoomConfig::initialZoom(); - if (target_zoom > 1.0) + if (target_zoom > 1.0) { zoomIn(target_zoom); + } } else { source_zoom = 1.0; } @@ -236,15 +238,17 @@ void ZoomEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseco { if (zoom != target_zoom) { int time = 0; - if (lastPresentTime.count()) + if (lastPresentTime.count()) { time = (presentTime - lastPresentTime).count(); + } lastPresentTime = presentTime; const float zoomDist = qAbs(target_zoom - source_zoom); - if (target_zoom > zoom) + if (target_zoom > zoom) { zoom = qMin(zoom + ((zoomDist * time) / animationTime(150 * zoomFactor)), target_zoom); - else + } else { zoom = qMax(zoom - ((zoomDist * time) / animationTime(150 * zoomFactor)), target_zoom); + } } if (zoom == 1.0) { @@ -283,18 +287,22 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d int y = cursorPoint.y() * zoom - prevPoint.y() * (zoom - 1.0); int threshold = 4; xMove = yMove = 0; - if (x < threshold) + if (x < threshold) { xMove = (x - threshold) / zoom; - else if (x + threshold > screenSize.width()) + } else if (x + threshold > screenSize.width()) { xMove = (x + threshold - screenSize.width()) / zoom; - if (y < threshold) + } + if (y < threshold) { yMove = (y - threshold) / zoom; - else if (y + threshold > screenSize.height()) + } else if (y + threshold > screenSize.height()) { yMove = (y + threshold - screenSize.height()) / zoom; - if (xMove) + } + if (xMove) { prevPoint.setX(qMax(0, qMin(screenSize.width(), prevPoint.x() + xMove))); - if (yMove) + } + if (yMove) { prevPoint.setY(qMax(0, qMin(screenSize.height(), prevPoint.y() + yMove))); + } data.setXTranslation(-int(prevPoint.x() * (zoom - 1.0))); data.setYTranslation(-int(prevPoint.y() * (zoom - 1.0))); break; @@ -353,27 +361,30 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d void ZoomEffect::postPaintScreen() { - if (zoom != target_zoom) + if (zoom != target_zoom) { effects->addRepaintFull(); - else + } else { lastPresentTime = std::chrono::milliseconds::zero(); + } effects->postPaintScreen(); } void ZoomEffect::zoomIn(double to) { source_zoom = zoom; - if (to < 0.0) + if (to < 0.0) { target_zoom *= zoomFactor; - else + } else { target_zoom = to; + } if (!polling) { polling = true; effects->startMousePolling(); } cursorPoint = effects->cursorPos(); - if (mouseTracking == MouseTrackingDisabled) + if (mouseTracking == MouseTrackingDisabled) { prevPoint = cursorPoint; + } effects->addRepaintFull(); } @@ -388,8 +399,9 @@ void ZoomEffect::zoomOut() effects->stopMousePolling(); } } - if (mouseTracking == MouseTrackingDisabled) + if (mouseTracking == MouseTrackingDisabled) { prevPoint = effects->cursorPos(); + } effects->addRepaintFull(); } @@ -415,23 +427,26 @@ void ZoomEffect::timelineFrameChanged(int /* frame */) void ZoomEffect::moveZoom(int x, int y) { - if (timeline.state() == QTimeLine::Running) + if (timeline.state() == QTimeLine::Running) { timeline.stop(); + } const QSize screenSize = effects->virtualScreenSize(); - if (x < 0) + if (x < 0) { xMove = -qMax(1.0, screenSize.width() / zoom / moveFactor); - else if (x > 0) + } else if (x > 0) { xMove = qMax(1.0, screenSize.width() / zoom / moveFactor); - else + } else { xMove = 0; + } - if (y < 0) + if (y < 0) { yMove = -qMax(1.0, screenSize.height() / zoom / moveFactor); - else if (y > 0) + } else if (y > 0) { yMove = qMax(1.0, screenSize.height() / zoom / moveFactor); - else + } else { yMove = 0; + } timeline.start(); } @@ -470,8 +485,9 @@ void ZoomEffect::moveMouseToCenter() void ZoomEffect::slotMouseChanged(const QPoint &pos, const QPoint &old, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { - if (zoom == 1.0) + if (zoom == 1.0) { return; + } cursorPoint = pos; if (pos != old) { lastMouseEvent = QTime::currentTime(); @@ -488,8 +504,9 @@ void ZoomEffect::slotWindowDamaged() void ZoomEffect::moveFocus(const QPoint &point) { - if (zoom == 1.0) + if (zoom == 1.0) { return; + } focusPoint = point; lastFocusEvent = QTime::currentTime(); effects->addRepaintFull(); diff --git a/src/events.cpp b/src/events.cpp index 1d4d1c1663..f8e4c34a47 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -151,34 +151,41 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) { const uint8_t eventType = e->response_type & ~0x80; if (effects && static_cast(effects)->hasKeyboardGrab() - && (eventType == XCB_KEY_PRESS || eventType == XCB_KEY_RELEASE)) + && (eventType == XCB_KEY_PRESS || eventType == XCB_KEY_RELEASE)) { return false; // let Qt process it, it'll be intercepted again in eventFilter() + } // events that should be handled before Clients can get them switch (eventType) { case XCB_CONFIGURE_NOTIFY: - if (reinterpret_cast(e)->event == kwinApp()->x11RootWindow()) + if (reinterpret_cast(e)->event == kwinApp()->x11RootWindow()) { markXStackingOrderAsDirty(); + } break; }; const xcb_window_t eventWindow = findEventWindow(e); if (eventWindow != XCB_WINDOW_NONE) { if (X11Client *c = findClient(Predicate::WindowMatch, eventWindow)) { - if (c->windowEvent(e)) + if (c->windowEvent(e)) { return true; + } } else if (X11Client *c = findClient(Predicate::WrapperIdMatch, eventWindow)) { - if (c->windowEvent(e)) + if (c->windowEvent(e)) { return true; + } } else if (X11Client *c = findClient(Predicate::FrameIdMatch, eventWindow)) { - if (c->windowEvent(e)) + if (c->windowEvent(e)) { return true; + } } else if (X11Client *c = findClient(Predicate::InputIdMatch, eventWindow)) { - if (c->windowEvent(e)) + if (c->windowEvent(e)) { return true; + } } else if (Unmanaged *c = findUnmanaged(eventWindow)) { - if (c->windowEvent(e)) + if (c->windowEvent(e)) { return true; + } } } @@ -231,8 +238,9 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) const auto *event = reinterpret_cast(e); if (event->override_redirect) { Unmanaged *c = findUnmanaged(event->window); - if (c == nullptr) + if (c == nullptr) { c = createUnmanaged(event->window); + } if (c) { // if hasScheduledRelease is true, it means a unamp and map sequence has occurred. // since release is scheduled after map notify, this old Unmanaged will get released @@ -241,8 +249,9 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) c->release(); c = createUnmanaged(event->window); } - if (c) + if (c) { return c->windowEvent(e); + } } } return (event->event != event->window); // hide wm typical event from Qt @@ -287,12 +296,13 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) if (!currentInput.isNull() && (currentInput->focus == XCB_WINDOW_NONE || currentInput->focus == XCB_INPUT_FOCUS_POINTER_ROOT || lostFocusPointerToRoot)) { // kWarning( 1212 ) << "X focus set to None/PointerRoot, reseting focus" ; AbstractClient *c = mostRecentlyActivatedClient(); - if (c != nullptr) + if (c != nullptr) { requestFocus(c, true); - else if (activateNextClient(nullptr)) + } else if (activateNextClient(nullptr)) { ; // ok, activated - else + } else { focusToNull(); + } } } } @@ -332,16 +342,19 @@ bool X11Client::windowEvent(xcb_generic_event_t *e) NET::Properties2 dirtyProperties2; info->event(e, &dirtyProperties, &dirtyProperties2); // pass through the NET stuff - if ((dirtyProperties & NET::WMName) != 0) + if ((dirtyProperties & NET::WMName) != 0) { fetchName(); - if ((dirtyProperties & NET::WMIconName) != 0) + } + if ((dirtyProperties & NET::WMIconName) != 0) { fetchIconicName(); + } if ((dirtyProperties & NET::WMStrut) != 0 || (dirtyProperties2 & NET::WM2ExtendedStrut) != 0) { workspace()->updateClientArea(); } - if ((dirtyProperties & NET::WMIcon) != 0) + if ((dirtyProperties & NET::WMIcon) != 0) { getIcons(); + } // Note there's a difference between userTime() and info->userTime() // info->userTime() is the value of the property, userTime() also includes // updates of the time done by KWin (ButtonPress on windowrapper etc.). @@ -349,8 +362,9 @@ bool X11Client::windowEvent(xcb_generic_event_t *e) workspace()->setWasUserInteraction(); updateUserTime(info->userTime()); } - if ((dirtyProperties2 & NET::WM2StartupId) != 0) + if ((dirtyProperties2 & NET::WM2StartupId) != 0) { startupIdChanged(); + } if (dirtyProperties2 & NET::WM2Opacity) { if (Compositor::compositing()) { setOpacity(info->opacityF()); @@ -481,8 +495,9 @@ bool X11Client::windowEvent(xcb_generic_event_t *e) detectShape(window()); // workaround for #19644 updateShape(); } - if (eventType == Xcb::Extensions::self()->damageNotifyEvent() && reinterpret_cast(e)->drawable == frameId()) + if (eventType == Xcb::Extensions::self()->damageNotifyEvent() && reinterpret_cast(e)->drawable == frameId()) { damageNotifyEvent(); + } break; } return true; // eat all events @@ -506,20 +521,24 @@ bool X11Client::mapRequestEvent(xcb_map_request_event_t *e) // always maps. Returning true here means that Workspace::workspaceEvent() // will handle this MapRequest and manage this window (i.e. act as if // it was reparented to root window). - if (e->parent == wrapperId()) + if (e->parent == wrapperId()) { return false; + } return true; // no messing with frame etc. } // also copied in clientMessage() - if (isMinimized()) + if (isMinimized()) { unminimize(); - if (isShade()) + } + if (isShade()) { setShade(ShadeNone); + } if (!isOnCurrentDesktop()) { - if (workspace()->allowClientActivation(this)) + if (workspace()->allowClientActivation(this)) { workspace()->activateClient(this); - else + } else { demandAttention(); + } } return true; } @@ -529,15 +548,18 @@ bool X11Client::mapRequestEvent(xcb_map_request_event_t *e) */ void X11Client::unmapNotifyEvent(xcb_unmap_notify_event_t *e) { - if (e->window != window()) + if (e->window != window()) { return; + } if (e->event != wrapperId()) { // most probably event from root window when initially reparenting bool ignore = true; - if (e->event == kwinApp()->x11RootWindow() && (e->response_type & 0x80)) + if (e->event == kwinApp()->x11RootWindow() && (e->response_type & 0x80)) { ignore = false; // XWithdrawWindow() - if (ignore) + } + if (ignore) { return; + } } // check whether this is result of an XReparentWindow - client then won't be parented by wrapper @@ -554,8 +576,9 @@ void X11Client::unmapNotifyEvent(xcb_unmap_notify_event_t *e) void X11Client::destroyNotifyEvent(xcb_destroy_notify_event_t *e) { - if (e->window != window()) + if (e->window != window()) { return; + } destroyClient(); } @@ -565,12 +588,14 @@ void X11Client::destroyNotifyEvent(xcb_destroy_notify_event_t *e) void X11Client::clientMessageEvent(xcb_client_message_event_t *e) { Toplevel::clientMessageEvent(e); - if (e->window != window()) + if (e->window != window()) { return; // ignore frame/wrapper + } // WM_STATE if (e->type == atoms->wm_change_state) { - if (e->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) + if (e->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) { minimize(); + } return; } } @@ -580,10 +605,12 @@ void X11Client::clientMessageEvent(xcb_client_message_event_t *e) */ void X11Client::configureRequestEvent(xcb_configure_request_event_t *e) { - if (e->window != window()) + if (e->window != window()) { return; // ignore frame/wrapper - if (isInteractiveResize() || isInteractiveMove()) + } + if (isInteractiveResize() || isInteractiveMove()) { return; // we have better things to do right now + } if (m_fullscreenMode == FullScreenNormal) { // refuse resizing of fullscreen windows // but allow resizing fullscreen hacks in order to let them cancel fullscreen mode @@ -600,11 +627,13 @@ void X11Client::configureRequestEvent(xcb_configure_request_event_t *e) m_client.setBorderWidth(0); } - if (e->value_mask & (XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH)) + if (e->value_mask & (XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH)) { configureRequest(e->value_mask, e->x, e->y, e->width, e->height, 0, false); + } - if (e->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) + if (e->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) { restackWindow(e->sibling, e->stack_mode, NET::FromApplication, userTime(), false); + } // Sending a synthetic configure notify always is fine, even in cases where // the ICCCM doesn't require this - it can be though of as 'the WM decided to move @@ -623,8 +652,9 @@ void X11Client::configureRequestEvent(xcb_configure_request_event_t *e) void X11Client::propertyNotifyEvent(xcb_property_notify_event_t *e) { Toplevel::propertyNotifyEvent(e); - if (e->window != window()) + if (e->window != window()) { return; // ignore frame/wrapper + } switch (e->atom) { case XCB_ATOM_WM_NORMAL_HINTS: getWmNormalHints(); @@ -644,20 +674,21 @@ void X11Client::propertyNotifyEvent(xcb_property_notify_event_t *e) default: if (e->atom == atoms->motif_wm_hints) { getMotifHints(); - } else if (e->atom == atoms->net_wm_sync_request_counter) + } else if (e->atom == atoms->net_wm_sync_request_counter) { getSyncCounter(); - else if (e->atom == atoms->activities) + } else if (e->atom == atoms->activities) { checkActivities(); - else if (e->atom == atoms->kde_first_in_window_list) + } else if (e->atom == atoms->kde_first_in_window_list) { updateFirstInTabBox(); - else if (e->atom == atoms->kde_color_sheme) + } else if (e->atom == atoms->kde_color_sheme) { updateColorScheme(); - else if (e->atom == atoms->kde_screen_edge_show) + } else if (e->atom == atoms->kde_screen_edge_show) { updateShowOnScreenEdge(); - else if (e->atom == atoms->kde_net_wm_appmenu_service_name) + } else if (e->atom == atoms->kde_net_wm_appmenu_service_name) { checkApplicationMenuServiceName(); - else if (e->atom == atoms->kde_net_wm_appmenu_object_path) + } else if (e->atom == atoms->kde_net_wm_appmenu_object_path) { checkApplicationMenuObjectPath(); + } break; } } @@ -667,8 +698,9 @@ void X11Client::enterNotifyEvent(xcb_enter_notify_event_t *e) if (waylandServer()) { return; } - if (e->event != frameId()) + if (e->event != frameId()) { return; // care only about entering the whole frame + } #define MOUSE_DRIVEN_FOCUS (!options->focusPolicyIsReasonable() || (options->focusPolicy() == Options::FocusFollowsMouse && options->isNextFocusPrefersMouse())) if (e->mode == XCB_NOTIFY_MODE_NORMAL || (e->mode == XCB_NOTIFY_MODE_UNGRAB && MOUSE_DRIVEN_FOCUS)) { @@ -684,8 +716,9 @@ void X11Client::leaveNotifyEvent(xcb_leave_notify_event_t *e) if (waylandServer()) { return; } - if (e->event != frameId()) + if (e->event != frameId()) { return; // care only about leaving the whole frame + } if (e->mode == XCB_NOTIFY_MODE_NORMAL) { if (!isInteractiveMoveResizePointerButtonDown()) { setInteractiveMoveResizeGravity(Gravity::None); @@ -750,8 +783,9 @@ void X11Client::establishCommandWindowGrab(uint8_t button) 0, XCapL, XNumL, XNumL | XCapL, XScrL, XScrL | XCapL, XScrL | XNumL, XScrL | XNumL | XCapL}; - for (int i = 0; i < 8; ++i) + for (int i = 0; i < 8; ++i) { m_wrapper.ungrabButton(x11Modifier | mods[i], button); + } } void X11Client::establishCommandAllGrab(uint8_t button) @@ -762,8 +796,9 @@ void X11Client::establishCommandAllGrab(uint8_t button) 0, XCapL, XNumL, XNumL | XCapL, XScrL, XScrL | XCapL, XScrL | XNumL, XScrL | XNumL | XCapL}; - for (int i = 0; i < 8; ++i) + for (int i = 0; i < 8; ++i) { m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, x11Modifier | mods[i], button); + } } #undef XCapL #undef XNumL @@ -841,8 +876,9 @@ bool X11Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, i return true; } if (isInteractiveMoveResizePointerButtonDown()) { - if (w == wrapperId()) + if (w == wrapperId()) { xcb_allow_events(kwinApp()->x11Connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); // xTime()); + } return true; } @@ -855,8 +891,9 @@ bool X11Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, i && button == XCB_BUTTON_INDEX_1 && !bModKeyHeld) { // hide splashwindow if the user clicks on it hideClient(); - if (w == wrapperId()) + if (w == wrapperId()) { xcb_allow_events(kwinApp()->x11Connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); // xTime()); + } return true; } @@ -891,11 +928,13 @@ bool X11Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, i if (was_action) { bool replay = performMouseCommand(com, QPoint(x_root, y_root)); - if (isSpecialWindow()) + if (isSpecialWindow()) { replay = true; + } - if (w == wrapperId()) // these can come only from a grab + if (w == wrapperId()) { // these can come only from a grab xcb_allow_events(kwinApp()->x11Connection(), replay ? XCB_ALLOW_REPLAY_POINTER : XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); // xTime()); + } return true; } } @@ -977,8 +1016,9 @@ bool X11Client::buttonReleaseEvent(xcb_window_t w, int button, int state, int x, xcb_allow_events(kwinApp()->x11Connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); // xTime()); return true; } - if (w != frameId() && w != inputId() && w != moveResizeGrabWindow()) + if (w != frameId() && w != inputId() && w != moveResizeGrabWindow()) { return true; + } if (w == frameId() && workspace()->userActionsMenu() && workspace()->userActionsMenu()->isShown()) { const_cast(workspace()->userActionsMenu())->grabInput(); } @@ -987,12 +1027,13 @@ bool X11Client::buttonReleaseEvent(xcb_window_t w, int button, int state, int x, // Check whether other buttons are still left pressed int buttonMask = XCB_BUTTON_MASK_1 | XCB_BUTTON_MASK_2 | XCB_BUTTON_MASK_3; - if (button == XCB_BUTTON_INDEX_1) + if (button == XCB_BUTTON_INDEX_1) { buttonMask &= ~XCB_BUTTON_MASK_1; - else if (button == XCB_BUTTON_INDEX_2) + } else if (button == XCB_BUTTON_INDEX_2) { buttonMask &= ~XCB_BUTTON_MASK_2; - else if (button == XCB_BUTTON_INDEX_3) + } else if (button == XCB_BUTTON_INDEX_3) { buttonMask &= ~XCB_BUTTON_MASK_3; + } if ((state & buttonMask) == 0) { endInteractiveMoveResize(); @@ -1011,8 +1052,9 @@ bool X11Client::motionNotifyEvent(xcb_window_t w, int state, int x, int y, int x QHoverEvent event(QEvent::HoverMove, QPointF(x, y), QPointF(x, y)); QCoreApplication::instance()->sendEvent(decoration(), &event); } - if (w != frameId() && w != inputId() && w != moveResizeGrabWindow()) + if (w != frameId() && w != inputId() && w != moveResizeGrabWindow()) { return true; // care only about the whole frame + } if (!isInteractiveMoveResizePointerButtonDown()) { if (w == inputId()) { int x = x_root - frameGeometry().x(); // + padding_left; @@ -1045,14 +1087,18 @@ bool X11Client::motionNotifyEvent(xcb_window_t w, int state, int x, int y, int x void X11Client::focusInEvent(xcb_focus_in_event_t *e) { - if (e->event != window()) + if (e->event != window()) { return; // only window gets focus - if (e->mode == XCB_NOTIFY_MODE_UNGRAB) + } + if (e->mode == XCB_NOTIFY_MODE_UNGRAB) { return; // we don't care - if (e->detail == XCB_NOTIFY_DETAIL_POINTER) + } + if (e->detail == XCB_NOTIFY_DETAIL_POINTER) { return; // we don't care - if (isShade() || !isShown() || !isOnCurrentDesktop()) // we unmapped it, but it got focus meanwhile -> + } + if (isShade() || !isShown() || !isOnCurrentDesktop()) { // we unmapped it, but it got focus meanwhile -> return; // activateNextClient() already transferred focus elsewhere + } workspace()->forEachClient([](X11Client *client) { client->cancelFocusOutTimer(); }); @@ -1073,18 +1119,23 @@ void X11Client::focusInEvent(xcb_focus_in_event_t *e) void X11Client::focusOutEvent(xcb_focus_out_event_t *e) { - if (e->event != window()) + if (e->event != window()) { return; // only window gets focus - if (e->mode == XCB_NOTIFY_MODE_GRAB) + } + if (e->mode == XCB_NOTIFY_MODE_GRAB) { return; // we don't care - if (isShade()) + } + if (isShade()) { return; // here neither + } if (e->detail != XCB_NOTIFY_DETAIL_NONLINEAR - && e->detail != XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL) + && e->detail != XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL) { // SELI check all this return; // hack for motif apps like netscape - if (QApplication::activePopupWidget()) + } + if (QApplication::activePopupWidget()) { return; + } // When a client loses focus, FocusOut events are usually immediatelly // followed by FocusIn events for another client that gains the focus @@ -1135,17 +1186,20 @@ void X11Client::NETMoveResize(int x_root, int y_root, NET::Direction direction) Gravity::Bottom, Gravity::BottomLeft, Gravity::Left}; - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { return; - if (isInteractiveMoveResize()) + } + if (isInteractiveMoveResize()) { finishInteractiveMoveResize(false); + } setInteractiveMoveResizePointerButtonDown(true); setInteractiveMoveOffset(QPoint(x_root - x(), y_root - y())); // map from global setInvertedInteractiveMoveOffset(rect().bottomRight() - interactiveMoveOffset()); setUnrestrictedInteractiveMoveResize(false); setInteractiveMoveResizeGravity(convert[direction]); - if (!startInteractiveMoveResize()) + if (!startInteractiveMoveResize()) { setInteractiveMoveResizePointerButtonDown(false); + } updateCursor(); } else if (direction == NET::KeyboardMove) { // ignore mouse coordinates given in the message, mouse position is used by the moving algorithm @@ -1232,8 +1286,9 @@ bool Unmanaged::windowEvent(xcb_generic_event_t *e) addWorkspaceRepaint(frameGeometry()); // in case shape change removes part of this window Q_EMIT geometryShapeChanged(this, frameGeometry()); } - if (eventType == Xcb::Extensions::self()->damageNotifyEvent()) + if (eventType == Xcb::Extensions::self()->damageNotifyEvent()) { damageNotifyEvent(); + } break; } } @@ -1242,8 +1297,9 @@ bool Unmanaged::windowEvent(xcb_generic_event_t *e) void Unmanaged::configureNotifyEvent(xcb_configure_notify_event_t *e) { - if (effects) + if (effects) { static_cast(effects)->checkInputWindowStacking(); // keep them on top + } QRect newgeom(e->x, e->y, e->width, e->height); if (newgeom != m_frameGeometry) { QRect old = m_frameGeometry; @@ -1263,16 +1319,18 @@ void Unmanaged::configureNotifyEvent(xcb_configure_notify_event_t *e) void Toplevel::propertyNotifyEvent(xcb_property_notify_event_t *e) { - if (e->window != window()) + if (e->window != window()) { return; // ignore frame/wrapper + } switch (e->atom) { default: - if (e->atom == atoms->wm_client_leader) + if (e->atom == atoms->wm_client_leader) { getWmClientLeader(); - else if (e->atom == atoms->kde_net_wm_shadow) + } else if (e->atom == atoms->kde_net_wm_shadow) { updateShadow(); - else if (e->atom == atoms->kde_skip_close_animation) + } else if (e->atom == atoms->kde_skip_close_animation) { getSkipCloseAnimation(); + } break; } } diff --git a/src/group.cpp b/src/group.cpp index 740d2bd854..f575e67309 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -49,9 +49,9 @@ Group::~Group() QIcon Group::icon() const { - if (leader_client != nullptr) + if (leader_client != nullptr) { return leader_client->icon(); - else if (leader_wid != XCB_WINDOW_NONE) { + } else if (leader_wid != XCB_WINDOW_NONE) { QIcon ic; NETWinInfo info(kwinApp()->x11Connection(), leader_wid, kwinApp()->x11RootWindow(), NET::WMIcon, NET::WM2IconPixmap); auto readIcon = [&ic, &info, this](int size, bool scale = true) { diff --git a/src/kcmkwin/kwinscreenedges/monitor.cpp b/src/kcmkwin/kwinscreenedges/monitor.cpp index 4ae6872f93..baf13c883c 100644 --- a/src/kcmkwin/kwinscreenedges/monitor.cpp +++ b/src/kcmkwin/kwinscreenedges/monitor.cpp @@ -57,8 +57,9 @@ Monitor::Monitor(QWidget *parent) setRatio((qreal)avail.width() / (qreal)avail.height()); for (int i = 0; i < 8; - ++i) + ++i) { popups[i] = new QMenu(this); + } scene = new QGraphicsScene(this); view = new QGraphicsView(scene, this); view->setBackgroundBrush(Qt::black); @@ -137,10 +138,11 @@ void Monitor::setEdgeEnabled(int edge, bool enabled) void Monitor::setEdgeHidden(int edge, bool set) { hidden[edge] = set; - if (set) + if (set) { items[edge]->hide(); - else + } else { items[edge]->show(); + } } bool Monitor::edgeHidden(int edge) const @@ -198,8 +200,9 @@ void Monitor::popup(Corner *c, QPoint pos) i < 8; ++i) { if (items[i] == c) { - if (popup_actions[i].count() == 0) + if (popup_actions[i].count() == 0) { return; + } if (QAction *a = popups[i]->exec(pos)) { selectEdgeItem(i, popup_actions[i].indexOf(a)); Q_EMIT changed(); @@ -218,10 +221,11 @@ void Monitor::flip(Corner *c, QPoint pos) i < 8; ++i) { if (items[i] == c) { - if (popup_actions[i].count() == 0) + if (popup_actions[i].count() == 0) { setEdge(i, !edge(i)); - else + } else { popup(c, pos); + } return; } } diff --git a/src/kcmkwin/kwinscreenedges/screenpreviewwidget.cpp b/src/kcmkwin/kwinscreenedges/screenpreviewwidget.cpp index 675b0624e4..b792664899 100644 --- a/src/kcmkwin/kwinscreenedges/screenpreviewwidget.cpp +++ b/src/kcmkwin/kwinscreenedges/screenpreviewwidget.cpp @@ -136,14 +136,16 @@ void ScreenPreviewWidget::paintEvent(QPaintEvent *event) void ScreenPreviewWidget::dropEvent(QDropEvent *e) { - if (!e->mimeData()->hasUrls()) + if (!e->mimeData()->hasUrls()) { return; + } QList uris(KUrlMimeData::urlsFromMimeData(e->mimeData())); if (!uris.isEmpty()) { // TODO: Download remote file - if (uris.first().isLocalFile()) + if (uris.first().isLocalFile()) { Q_EMIT imageDropped(uris.first().path()); + } } } diff --git a/src/kcmkwin/kwintabbox/thumbnailitem.cpp b/src/kcmkwin/kwintabbox/thumbnailitem.cpp index aaac922ca4..a29b9fb559 100644 --- a/src/kcmkwin/kwintabbox/thumbnailitem.cpp +++ b/src/kcmkwin/kwintabbox/thumbnailitem.cpp @@ -63,20 +63,23 @@ const char *const *BrightnessSaturationShader::attributeNames() const void BrightnessSaturationShader::updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) { Q_ASSERT(program()->isLinked()); - if (state.isMatrixDirty()) + if (state.isMatrixDirty()) { program()->setUniformValue(m_id_matrix, state.combinedMatrix()); - if (state.isOpacityDirty()) + } + if (state.isOpacityDirty()) { program()->setUniformValue(m_id_opacity, state.opacity()); + } auto *tx = static_cast(newMaterial); auto *oldTx = static_cast(oldMaterial); QSGTexture *t = tx->texture(); t->setFiltering(QSGTexture::Linear); - if (!oldTx || oldTx->texture()->textureId() != t->textureId()) + if (!oldTx || oldTx->texture()->textureId() != t->textureId()) { t->bind(); - else + } else { t->updateBindOptions(); + } program()->setUniformValue(m_id_saturation, static_cast(tx->saturation)); program()->setUniformValue(m_id_brightness, static_cast(tx->brightness)); diff --git a/src/layers.cpp b/src/layers.cpp index d5c15a2107..c513edb7d8 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -97,8 +97,9 @@ namespace KWin void Workspace::updateStackingOrder(bool propagate_new_clients) { if (block_stacking_updates > 0) { - if (propagate_new_clients) + if (propagate_new_clients) { blocked_propagating_new_clients = true; + } return; } QList new_stacking_order = constrainedStackingOrder(); @@ -115,8 +116,9 @@ void Workspace::updateStackingOrder(bool propagate_new_clients) Q_EMIT stackingOrderChanged(); - if (active_client) + if (active_client) { active_client->updateMouseGrab(); + } } } @@ -167,9 +169,10 @@ void Workspace::propagateClients(bool propagate_new_clients) continue; } - if (client->inputId()) + if (client->inputId()) { // Stack the input window above the frame newWindowStack << client->inputId(); + } newWindowStack << client->frameId(); } @@ -179,8 +182,9 @@ void Workspace::propagateClients(bool propagate_new_clients) // these windows that should be unmapped to interfere with other windows for (int i = stacking_order.size() - 1; i >= 0; --i) { X11Client *client = qobject_cast(stacking_order.at(i)); - if (!client || !client->hiddenPreview()) + if (!client || !client->hiddenPreview()) { continue; + } newWindowStack << client->frameId(); } // TODO isn't it too inefficient to restack always all clients? @@ -195,8 +199,9 @@ void Workspace::propagateClients(bool propagate_new_clients) for (const auto win : qAsConst(manual_overlays)) { cl[pos++] = win; } - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) + for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { cl[pos++] = (*it)->window(); + } rootInfo()->setClientList(cl, pos); delete[] cl; } @@ -226,22 +231,26 @@ AbstractClient *Workspace::topClientOnDesktop(VirtualDesktop *desktop, AbstractO { // TODO Q_ASSERT( block_stacking_updates == 0 ); QList list; - if (!unconstrained) + if (!unconstrained) { list = stacking_order; - else + } else { list = unconstrained_stacking_order; + } for (int i = list.size() - 1; i >= 0; --i) { AbstractClient *c = qobject_cast(list.at(i)); if (!c) { continue; } if (c->isOnDesktop(desktop) && c->isShown() && c->isOnCurrentActivity() && !c->isShade()) { - if (output && c->output() != output) + if (output && c->output() != output) { continue; - if (!only_normal) + } + if (!only_normal) { return c; - if (c->wantsTabFocus() && !c->isSpecialWindow()) + } + if (c->wantsTabFocus() && !c->isSpecialWindow()) { return c; + } } } return nullptr; @@ -278,16 +287,18 @@ void Workspace::raiseOrLowerClient(AbstractClient *c) topClientOnDesktop(VirtualDesktopManager::self()->currentDesktop(), options->isSeparateScreenFocus() ? c->output() : nullptr); - if (c == topmost) + if (c == topmost) { lowerClient(c); - else + } else { raiseClient(c); + } } void Workspace::lowerClient(AbstractClient *c, bool nogroup) { - if (!c) + if (!c) { return; + } c->cancelAutoRaise(); @@ -302,16 +313,18 @@ void Workspace::lowerClient(AbstractClient *c, bool nogroup) wins = ensureStackingOrder(group->members()); } for (int i = wins.size() - 1; i >= 0; --i) { - if (wins[i] != c) + if (wins[i] != c) { lowerClient(wins[i], true); + } } } } void Workspace::lowerClientWithinApplication(AbstractClient *c) { - if (!c) + if (!c) { return; + } c->cancelAutoRaise(); @@ -331,15 +344,17 @@ void Workspace::lowerClientWithinApplication(AbstractClient *c) break; } } - if (!lowered) + if (!lowered) { unconstrained_stacking_order.prepend(c); + } // ignore mainwindows } void Workspace::raiseClient(AbstractClient *c, bool nogroup) { - if (!c) + if (!c) { return; + } c->cancelAutoRaise(); @@ -348,8 +363,9 @@ void Workspace::raiseClient(AbstractClient *c, bool nogroup) if (!nogroup && c->isTransient()) { QList transients; AbstractClient *transient_parent = c; - while ((transient_parent = transient_parent->transientFor())) + while ((transient_parent = transient_parent->transientFor())) { transients << transient_parent; + } for (const auto &transient_parent : qAsConst(transients)) { raiseClient(transient_parent, true); } @@ -361,8 +377,9 @@ void Workspace::raiseClient(AbstractClient *c, bool nogroup) void Workspace::raiseClientWithinApplication(AbstractClient *c) { - if (!c) + if (!c) { return; + } c->cancelAutoRaise(); @@ -375,8 +392,9 @@ void Workspace::raiseClientWithinApplication(AbstractClient *c) if (!other) { continue; } - if (other == c) // don't lower it just because it asked to be raised + if (other == c) { // don't lower it just because it asked to be raised return; + } if (AbstractClient::belongToSameApplication(other, c)) { unconstrained_stacking_order.removeAll(c); unconstrained_stacking_order.insert(unconstrained_stacking_order.indexOf(other) + 1, c); // insert after the found one @@ -387,9 +405,9 @@ void Workspace::raiseClientWithinApplication(AbstractClient *c) void Workspace::raiseClientRequest(KWin::AbstractClient *c, NET::RequestSource src, xcb_timestamp_t timestamp) { - if (src == NET::FromTool || allowFullClientRaising(c, timestamp)) + if (src == NET::FromTool || allowFullClientRaising(c, timestamp)) { raiseClient(c); - else { + } else { raiseClientWithinApplication(c); c->demandAttention(); } @@ -401,10 +419,11 @@ void Workspace::lowerClientRequest(KWin::X11Client *c, NET::RequestSource src, x // do only lowering within the application, as that's the more logical // variant of lowering when application requests it. // No demanding of attention here of course. - if (src == NET::FromTool || !c->hasUserTimeSupport()) + if (src == NET::FromTool || !c->hasUserTimeSupport()) { lowerClient(c); - else + } else { lowerClientWithinApplication(c); + } } void Workspace::lowerClientRequest(KWin::AbstractClient *c) @@ -446,8 +465,9 @@ void Workspace::restackClientUnderActive(AbstractClient *c) void Workspace::restoreSessionStackingOrder(X11Client *c) { - if (c->sessionStackingOrder() < 0) + if (c->sessionStackingOrder() < 0) { return; + } StackingUpdatesBlocker blocker(this); unconstrained_stacking_order.removeAll(c); for (auto it = unconstrained_stacking_order.begin(); it != unconstrained_stacking_order.end(); ++it) { @@ -559,14 +579,16 @@ QList Workspace::constrainedStackingOrder() void Workspace::blockStackingUpdates(bool block) { if (block) { - if (block_stacking_updates == 0) + if (block_stacking_updates == 0) { blocked_propagating_new_clients = false; + } ++block_stacking_updates; } else // !block if (--block_stacking_updates == 0) { updateStackingOrder(blocked_propagating_new_clients); - if (effects) + if (effects) { static_cast(effects)->checkInputWindowStacking(); + } } } @@ -578,8 +600,9 @@ QList ensureStackingOrderInList(const QList &stackingOrder, con static_assert(std::is_base_of::value, "U must be derived from T"); // TODO Q_ASSERT( block_stacking_updates == 0 ); - if (list.count() < 2) + if (list.count() < 2) { return list; + } // TODO is this worth optimizing? QList result = list; for (auto it = stackingOrder.begin(); it != stackingOrder.end(); ++it) { @@ -587,8 +610,9 @@ QList ensureStackingOrderInList(const QList &stackingOrder, con if (!c) { continue; } - if (result.removeAll(c) != 0) + if (result.removeAll(c) != 0) { result.append(c); + } } return result; } @@ -669,18 +693,21 @@ void X11Client::restackWindow(xcb_window_t above, int detail, NET::RequestSource } } else if (detail == XCB_STACK_MODE_TOP_IF) { other = workspace()->findClient(Predicate::WindowMatch, above); - if (other && other->frameGeometry().intersects(frameGeometry())) + if (other && other->frameGeometry().intersects(frameGeometry())) { workspace()->raiseClientRequest(this, src, timestamp); + } return; } else if (detail == XCB_STACK_MODE_BOTTOM_IF) { other = workspace()->findClient(Predicate::WindowMatch, above); - if (other && other->frameGeometry().intersects(frameGeometry())) + if (other && other->frameGeometry().intersects(frameGeometry())) { workspace()->lowerClientRequest(this, src, timestamp); + } return; } - if (!other) + if (!other) { other = workspace()->findClient(Predicate::WindowMatch, above); + } if (other && detail == XCB_STACK_MODE_ABOVE) { auto it = workspace()->stackingOrder().constEnd(), @@ -694,36 +721,42 @@ void X11Client::restackWindow(xcb_window_t above, int detail, NET::RequestSource } X11Client *c = qobject_cast(*it); - if (!c || !((*it)->isNormalWindow() && c->isShown() && (*it)->isOnCurrentDesktop() && (*it)->isOnCurrentActivity() && (*it)->isOnOutput(output()))) + if (!c || !((*it)->isNormalWindow() && c->isShown() && (*it)->isOnCurrentDesktop() && (*it)->isOnCurrentActivity() && (*it)->isOnOutput(output()))) { continue; // irrelevant clients + } - if (*(it - 1) == other) + if (*(it - 1) == other) { break; // "it" is the one above the target one, stack below "it" + } } - if (it != begin && (*(it - 1) == other)) + if (it != begin && (*(it - 1) == other)) { other = qobject_cast(*it); - else + } else { other = nullptr; + } } - if (other) + if (other) { workspace()->restack(this, other); - else if (detail == XCB_STACK_MODE_BELOW) + } else if (detail == XCB_STACK_MODE_BELOW) { workspace()->lowerClientRequest(this, src, timestamp); - else if (detail == XCB_STACK_MODE_ABOVE) + } else if (detail == XCB_STACK_MODE_ABOVE) { workspace()->raiseClientRequest(this, src, timestamp); + } - if (send_event) + if (send_event) { sendSyntheticConfigureNotify(); + } } bool X11Client::belongsToDesktop() const { const auto members = group()->members(); for (const X11Client *c : members) { - if (c->isDesktop()) + if (c->isDesktop()) { return true; + } } return false; } diff --git a/src/libkwineffects/kwinanimationeffect.cpp b/src/libkwineffects/kwinanimationeffect.cpp index fc63df5137..4f46bae86d 100644 --- a/src/libkwineffects/kwinanimationeffect.cpp +++ b/src/libkwineffects/kwinanimationeffect.cpp @@ -48,8 +48,9 @@ AnimationEffect::AnimationEffect() : d_ptr(new AnimationEffectPrivate()) { Q_D(AnimationEffect); - if (!s_clock.isValid()) + if (!s_clock.isValid()) { s_clock.start(); + } /* this is the same as the QTimer::singleShot(0, SLOT(init())) kludge * defering the init and esp. the connection to the windowClosed slot */ QMetaObject::invokeMethod(this, &AnimationEffect::init, Qt::QueuedConnection); @@ -63,8 +64,9 @@ AnimationEffect::~AnimationEffect() void AnimationEffect::init() { Q_D(AnimationEffect); - if (d->m_isInitialized) + if (d->m_isInitialized) { return; // not more than once, please + } d->m_isInitialized = true; /* by connecting the signal from a slot AFTER the inheriting class constructor had the chance to * connect it we can provide auto-referencing of animated and closed windows, since at the time @@ -108,10 +110,12 @@ void AnimationEffect::validate(Attribute a, uint &meta, FPx2 *from, FPx2 *to, co to->set(0.0, 0.0); } } - if (from && !from->isValid()) + if (from && !from->isValid()) { from->set(1.0, 1.0); - if (to && !to->isValid()) + } + if (to && !to->isValid()) { to->set(1.0, 1.0); + } } else if (a == Position) { QRect area = effects->clientArea(ScreenArea, w); @@ -208,15 +212,17 @@ quint64 AnimationEffect::p_animate(EffectWindow *w, Attribute a, uint meta, int validate(a, meta, &from, &to, w); Q_D(AnimationEffect); - if (!d->m_isInitialized) + if (!d->m_isInitialized) { init(); // needs to ensure the window gets removed if deleted in the same event cycle + } if (d->m_animations.isEmpty()) { connect(effects, &EffectsHandler::windowExpandedGeometryChanged, this, &AnimationEffect::_windowExpandedGeometryChanged); } AniMap::iterator it = d->m_animations.find(w); - if (it == d->m_animations.end()) + if (it == d->m_animations.end()) { it = d->m_animations.insert(w, QPair, QRect>(QList(), QRect())); + } FullScreenEffectLockPtr fullscreen; if (fullScreenEffect) { @@ -267,8 +273,9 @@ quint64 AnimationEffect::p_animate(EffectWindow *w, Attribute a, uint meta, int if (delay > 0) { QTimer::singleShot(delay, this, &AnimationEffect::triggerRepaint); const QSize &s = effects->virtualScreenSize(); - if (waitAtSource) + if (waitAtSource) { w->addLayerRepaint(0, 0, s.width(), s.height()); + } } else { triggerRepaint(); } @@ -278,8 +285,9 @@ quint64 AnimationEffect::p_animate(EffectWindow *w, Attribute a, uint meta, int bool AnimationEffect::retarget(quint64 animationId, FPx2 newTarget, int newRemainingTime) { Q_D(AnimationEffect); - if (animationId == d->m_justEndedAnimation) + if (animationId == d->m_justEndedAnimation) { return false; // this is just ending, do not try to retarget it + } for (AniMap::iterator entry = d->m_animations.begin(), mapEnd = d->m_animations.end(); entry != mapEnd; ++entry) { @@ -365,8 +373,9 @@ bool AnimationEffect::complete(quint64 animationId) bool AnimationEffect::cancel(quint64 animationId) { Q_D(AnimationEffect); - if (animationId == d->m_justEndedAnimation) + if (animationId == d->m_justEndedAnimation) { return true; // this is just ending, do not try to cancel it but fake success + } for (AniMap::iterator entry = d->m_animations.begin(), mapEnd = d->m_animations.end(); entry != mapEnd; ++entry) { for (QList::iterator anim = entry->first.begin(), animEnd = entry->first.end(); anim != animEnd; ++anim) { if (anim->id == animationId) { @@ -374,8 +383,9 @@ bool AnimationEffect::cancel(quint64 animationId) if (entry->first.isEmpty()) { // no other animations on the window, release it. d->m_animations.erase(entry); } - if (d->m_animations.isEmpty()) + if (d->m_animations.isEmpty()) { disconnectGeometryChanges(); + } d->m_animationsTouched = true; // could be called from animationEnded return true; } @@ -408,22 +418,24 @@ void AnimationEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill static int xCoord(const QRect &r, int flag) { - if (flag & AnimationEffect::Left) + if (flag & AnimationEffect::Left) { return r.x(); - else if (flag & AnimationEffect::Right) + } else if (flag & AnimationEffect::Right) { return r.right(); - else + } else { return r.x() + r.width() / 2; + } } static int yCoord(const QRect &r, int flag) { - if (flag & AnimationEffect::Top) + if (flag & AnimationEffect::Top) { return r.y(); - else if (flag & AnimationEffect::Bottom) + } else if (flag & AnimationEffect::Bottom) { return r.bottom(); - else + } else { return r.y() + r.height() / 2; + } } QRect AnimationEffect::clipRect(const QRect &geo, const AniData &anim) const @@ -461,25 +473,27 @@ void AnimationEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, bool isUsed = false; bool paintDeleted = false; for (QList::const_iterator anim = entry->first.constBegin(); anim != entry->first.constEnd(); ++anim) { - if (anim->startTime > clock() && !anim->waitAtSource) + if (anim->startTime > clock() && !anim->waitAtSource) { continue; + } isUsed = true; - if (anim->attribute == Opacity || anim->attribute == CrossFadePrevious) + if (anim->attribute == Opacity || anim->attribute == CrossFadePrevious) { data.setTranslucent(); - else if (!(anim->attribute == Brightness || anim->attribute == Saturation)) { + } else if (!(anim->attribute == Brightness || anim->attribute == Saturation)) { data.setTransformed(); } paintDeleted |= anim->keepAlive; } if (isUsed) { - if (w->isMinimized()) + if (w->isMinimized()) { w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE); - else if (w->isDeleted() && paintDeleted) + } else if (w->isDeleted() && paintDeleted) { w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE); - else if (!w->isOnCurrentDesktop()) + } else if (!w->isOnCurrentDesktop()) { w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DESKTOP); + } // if( !w->isPaintingEnabled() && !effects->activeFullScreenEffect() ) // effects->addLayerRepaint(w->expandedGeometry()); } @@ -489,10 +503,12 @@ void AnimationEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, static inline float geometryCompensation(int flags, float v) { - if (flags & (AnimationEffect::Left | AnimationEffect::Top)) + if (flags & (AnimationEffect::Left | AnimationEffect::Top)) { return 0.0; // no compensation required - if (flags & (AnimationEffect::Right | AnimationEffect::Bottom)) + } + if (flags & (AnimationEffect::Right | AnimationEffect::Bottom)) { return 1.0 - v; // full compensation + } return 0.5 * (1.0 - v); // half compensation } @@ -503,8 +519,9 @@ void AnimationEffect::paintWindow(EffectWindow *w, int mask, QRegion region, Win if (entry != d->m_animations.constEnd()) { for (QList::const_iterator anim = entry->first.constBegin(); anim != entry->first.constEnd(); ++anim) { - if (anim->startTime > clock() && !anim->waitAtSource) + if (anim->startTime > clock() && !anim->waitAtSource) { continue; + } switch (anim->attribute) { case Opacity: @@ -529,8 +546,9 @@ void AnimationEffect::paintWindow(EffectWindow *w, int mask, QRegion region, Win if (!anim->isOneDimensional()) { f1 = interpolated(*anim, 1); f2 = geometryCompensation(anim->meta & AnimationEffect::Vertical, f1); - } else if (((anim->meta & AnimationEffect::Vertical) >> 1) != (anim->meta & AnimationEffect::Horizontal)) + } else if (((anim->meta & AnimationEffect::Vertical) >> 1) != (anim->meta & AnimationEffect::Horizontal)) { f2 = geometryCompensation(anim->meta & AnimationEffect::Vertical, f1); + } data.translate(0.0, f2 * sz.height()); data.setYScale(data.yScale() * f1); } @@ -663,8 +681,9 @@ void AnimationEffect::postPaintScreen() } else { for (auto entry = d->m_animations.constBegin(); entry != d->m_animations.constEnd(); ++entry) { for (auto anim = entry->first.constBegin(); anim != entry->first.constEnd(); ++anim) { - if (anim->startTime > clock()) + if (anim->startTime > clock()) { continue; + } if (!anim->timeLine.done()) { entry.key()->addLayerRepaint(entry->second); break; @@ -736,10 +755,11 @@ void AnimationEffect::setMetaData(MetaType type, uint value, uint &meta) case RelativeTargetX: case RelativeTargetY: { const int shift = 10 + type - RelativeSourceX; - if (value) + if (value) { meta |= (1 << shift); - else + } else { meta &= ~(1 << shift); + } break; } case Axis: @@ -754,8 +774,9 @@ void AnimationEffect::setMetaData(MetaType type, uint value, uint &meta) void AnimationEffect::triggerRepaint() { Q_D(AnimationEffect); - for (AniMap::const_iterator entry = d->m_animations.constBegin(), mapEnd = d->m_animations.constEnd(); entry != mapEnd; ++entry) + for (AniMap::const_iterator entry = d->m_animations.constBegin(), mapEnd = d->m_animations.constEnd(); entry != mapEnd; ++entry) { *const_cast(&(entry->second)) = QRect(); + } updateLayerRepaints(); if (d->m_needSceneRepaint) { effects->addRepaintFull(); @@ -790,16 +811,18 @@ void AnimationEffect::updateLayerRepaints() Q_D(AnimationEffect); d->m_needSceneRepaint = false; for (AniMap::const_iterator entry = d->m_animations.constBegin(), mapEnd = d->m_animations.constEnd(); entry != mapEnd; ++entry) { - if (!entry->second.isNull()) + if (!entry->second.isNull()) { continue; + } float f[2] = {1.0, 1.0}; float t[2] = {0.0, 0.0}; bool createRegion = false; QList rects; QRect *layerRect = const_cast(&(entry->second)); for (QList::const_iterator anim = entry->first.constBegin(), animEnd = entry->first.constEnd(); anim != animEnd; ++anim) { - if (anim->startTime > clock()) + if (anim->startTime > clock()) { continue; + } switch (anim->attribute) { case Opacity: case Brightness: @@ -849,16 +872,18 @@ void AnimationEffect::updateLayerRepaints() float fx = qMax(fixOvershoot(anim->from[0], *anim, 1), fixOvershoot(anim->to[0], *anim, 2)); // float fx = qMax(interpolated(*anim,0), anim->to[0]); if (fx >= 0.0) { - if (anim->attribute == Size) + if (anim->attribute == Size) { fx /= sz.width(); + } f[0] *= fx; t[0] += geometryCompensation(anim->meta & AnimationEffect::Horizontal, fx) * sz.width(); } // float fy = qMax(interpolated(*anim,1), anim->to[1]); float fy = qMax(fixOvershoot(anim->from[1], *anim, 1), fixOvershoot(anim->to[1], *anim, 2)); if (fy >= 0.0) { - if (anim->attribute == Size) + if (anim->attribute == Size) { fy /= sz.height(); + } if (!anim->isOneDimensional()) { f[1] *= fy; t[1] += geometryCompensation(anim->meta & AnimationEffect::Vertical, fy) * sz.height(); @@ -874,8 +899,9 @@ void AnimationEffect::updateLayerRepaints() region_creation: if (createRegion) { const QRect geo = entry.key()->expandedGeometry(); - if (rects.isEmpty()) + if (rects.isEmpty()) { rects << geo; + } QList::const_iterator r, rEnd = rects.constEnd(); for (r = rects.constBegin(); r != rEnd; ++r) { // transform const_cast(&(*r))->setSize(QSize(qRound(r->width() * f[0]), qRound(r->height() * f[1]))); @@ -883,8 +909,9 @@ void AnimationEffect::updateLayerRepaints() } QRect rect = rects.at(0); if (rects.count() > 1) { - for (r = rects.constBegin() + 1; r != rEnd; ++r) // unite + for (r = rects.constBegin() + 1; r != rEnd; ++r) { // unite rect |= *r; + } const int dx = 110 * (rect.width() - geo.width()) / 100 + 1 - rect.width() + geo.width(); const int dy = 110 * (rect.height() - geo.height()) / 100 + 1 - rect.height() + geo.height(); rect.adjust(-dx, -dy, dx, dy); // fix pot. overshoot @@ -901,8 +928,9 @@ void AnimationEffect::_windowExpandedGeometryChanged(KWin::EffectWindow *w) if (entry != d->m_animations.constEnd()) { *const_cast(&(entry->second)) = QRect(); updateLayerRepaints(); - if (!entry->second.isNull()) // actually got updated, ie. is in use - ensure it get's a repaint + if (!entry->second.isNull()) { // actually got updated, ie. is in use - ensure it get's a repaint w->addLayerRepaint(entry->second); + } } } @@ -943,18 +971,20 @@ QString AnimationEffect::debug(const QString & /*parameter*/) const { Q_D(const AnimationEffect); QString dbg; - if (d->m_animations.isEmpty()) + if (d->m_animations.isEmpty()) { dbg = QStringLiteral("No window is animated"); - else { + } else { AniMap::const_iterator entry = d->m_animations.constBegin(), mapEnd = d->m_animations.constEnd(); for (; entry != mapEnd; ++entry) { QString caption = entry.key()->isDeleted() ? QStringLiteral("[Deleted]") : entry.key()->caption(); - if (caption.isEmpty()) + if (caption.isEmpty()) { caption = QStringLiteral("[Untitled]"); + } dbg += QLatin1String("Animating window: ") + caption + QLatin1Char('\n'); QList::const_iterator anim = entry->first.constBegin(), animEnd = entry->first.constEnd(); - for (; anim != animEnd; ++anim) + for (; anim != animEnd; ++anim) { dbg += anim->debugInfo(); + } } } return dbg; diff --git a/src/libkwineffects/kwinanimationeffect.h b/src/libkwineffects/kwinanimationeffect.h index b5ac38cec6..34c4331081 100644 --- a/src/libkwineffects/kwinanimationeffect.h +++ b/src/libkwineffects/kwinanimationeffect.h @@ -84,10 +84,11 @@ public: inline QString toString() const { QString ret; - if (valid) + if (valid) { ret = QString::number(f[0]) + QLatin1Char(',') + QString::number(f[1]); - else + } else { ret = QString(); + } return ret; } diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index f549edd936..2681caf2fe 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -760,8 +760,9 @@ bool EffectPluginFactory::isSupported() const EffectsHandler::EffectsHandler(CompositingType type) : compositing_type(type) { - if (compositing_type == NoCompositing) + if (compositing_type == NoCompositing) { return; + } KWin::effects = this; connect(this, QOverload::of(&EffectsHandler::desktopChanged), this, &EffectsHandler::desktopChangedLegacy); } @@ -946,10 +947,12 @@ WindowQuadList WindowQuadList::splitAtX(double x) const bool wholeleft = true; bool wholeright = true; for (int i = 0; i < 4; ++i) { - if (quad[i].x() < x) + if (quad[i].x() < x) { wholeright = false; - if (quad[i].x() > x) + } + if (quad[i].x() > x) { wholeleft = false; + } } if (wholeleft || wholeright) { // is whole in one split part ret.append(quad); @@ -973,10 +976,12 @@ WindowQuadList WindowQuadList::splitAtY(double y) const bool wholetop = true; bool wholebottom = true; for (int i = 0; i < 4; ++i) { - if (quad[i].y() < y) + if (quad[i].y() < y) { wholebottom = false; - if (quad[i].y() > y) + } + if (quad[i].y() > y) { wholetop = false; + } } if (wholetop || wholebottom) { // is whole in one split part ret.append(quad); @@ -994,8 +999,9 @@ WindowQuadList WindowQuadList::splitAtY(double y) const WindowQuadList WindowQuadList::makeGrid(int maxQuadSize) const { - if (empty()) + if (empty()) { return *this; + } // Find the bounding rectangle double left = first().left(); @@ -1047,8 +1053,9 @@ WindowQuadList WindowQuadList::makeGrid(int maxQuadSize) const WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisions) const { - if (empty()) + if (empty()) { return *this; + } // Find the bounding rectangle double left = first().left(); @@ -1303,8 +1310,9 @@ WindowMotionManager::~WindowMotionManager() void WindowMotionManager::manage(EffectWindow *w) { - if (m_managedWindows.contains(w)) + if (m_managedWindows.contains(w)) { return; + } double strength = 0.08; double smoothness = 4.0; @@ -1358,9 +1366,9 @@ void WindowMotionManager::calculate(int time) // TODO: Motion needs to be calculated from the window's center Motion2D *trans = &motion->translation; - if (trans->distance().isNull()) + if (trans->distance().isNull()) { ++stopped; - else { + } else { // Still moving trans->calculate(time); const short fx = trans->target().x() <= trans->startValue().x() ? -1 : 1; @@ -1374,9 +1382,9 @@ void WindowMotionManager::calculate(int time) } Motion2D *scale = &motion->scale; - if (scale->distance().isNull()) + if (scale->distance().isNull()) { ++stopped; - else { + } else { // Still scaling scale->calculate(time); const short fx = scale->target().x() < 1.0 ? -1 : 1; @@ -1390,8 +1398,9 @@ void WindowMotionManager::calculate(int time) } // We just finished this window's motion - if (stopped == 2) + if (stopped == 2) { m_movingWindowsSet.remove(it.key()); + } } } @@ -1411,8 +1420,9 @@ void WindowMotionManager::reset() void WindowMotionManager::reset(EffectWindow *w) { QHash::iterator it = m_managedWindows.find(w); - if (it == m_managedWindows.end()) + if (it == m_managedWindows.end()) { return; + } WindowMotion *motion = &it.value(); motion->translation.setTarget(w->pos()); @@ -1424,8 +1434,9 @@ void WindowMotionManager::reset(EffectWindow *w) void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data) { QHash::iterator it = m_managedWindows.find(w); - if (it == m_managedWindows.end()) + if (it == m_managedWindows.end()) { return; + } // TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid) WindowMotion *motion = &it.value(); @@ -1440,12 +1451,14 @@ void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scal WindowMotion *motion = &it.value(); - if (yScale == 0.0) + if (yScale == 0.0) { yScale = scale; + } QPointF scalePoint(scale, yScale); - if (motion->translation.value() == target && motion->scale.value() == scalePoint) + if (motion->translation.value() == target && motion->scale.value() == scalePoint) { return; // Window already at that position + } motion->translation.setTarget(target); motion->scale.setTarget(scalePoint); @@ -1456,8 +1469,9 @@ void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scal QRectF WindowMotionManager::transformedGeometry(EffectWindow *w) const { QHash::const_iterator it = m_managedWindows.constFind(w); - if (it == m_managedWindows.end()) + if (it == m_managedWindows.end()) { return w->frameGeometry(); + } const WindowMotion *motion = &it.value(); QRectF geometry(w->frameGeometry()); @@ -1473,8 +1487,9 @@ QRectF WindowMotionManager::transformedGeometry(EffectWindow *w) const void WindowMotionManager::setTransformedGeometry(EffectWindow *w, const QRectF &geometry) { QHash::iterator it = m_managedWindows.find(w); - if (it == m_managedWindows.end()) + if (it == m_managedWindows.end()) { return; + } WindowMotion *motion = &it.value(); motion->translation.setValue(geometry.topLeft()); motion->scale.setValue(QPointF(geometry.width() / qreal(w->width()), geometry.height() / qreal(w->height()))); @@ -1483,8 +1498,9 @@ void WindowMotionManager::setTransformedGeometry(EffectWindow *w, const QRectF & QRectF WindowMotionManager::targetGeometry(EffectWindow *w) const { QHash::const_iterator it = m_managedWindows.constFind(w); - if (it == m_managedWindows.end()) + if (it == m_managedWindows.end()) { return w->frameGeometry(); + } const WindowMotion *motion = &it.value(); QRectF geometry(w->frameGeometry()); @@ -1503,8 +1519,9 @@ EffectWindow *WindowMotionManager::windowAtPoint(QPoint point, bool useStackingO // TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows QHash::ConstIterator it = m_managedWindows.constBegin(); while (it != m_managedWindows.constEnd()) { - if (transformedGeometry(it.key()).contains(point)) + if (transformedGeometry(it.key()).contains(point)) { return it.key(); + } ++it; } diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index 4448b64bba..875b0a1450 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -3402,8 +3402,9 @@ public: */ inline void manage(const EffectWindowList &list) { - for (int i = 0; i < list.size(); i++) + for (int i = 0; i < list.size(); i++) { manage(list.at(i)); + } } /** * Deregister a window. All transformations applied to the @@ -4045,8 +4046,9 @@ Motion::~Motion() template void Motion::calculate(const int msec) { - if (m_value == m_target && m_velocity == T()) // At target and not moving + if (m_value == m_target && m_velocity == T()) { // At target and not moving return; + } // Poor man's time independent calculation int steps = qMax(1, msec / 5); diff --git a/src/libkwineffects/kwinglplatform.cpp b/src/libkwineffects/kwinglplatform.cpp index b5c27e4273..77095f80fd 100644 --- a/src/libkwineffects/kwinglplatform.cpp +++ b/src/libkwineffects/kwinglplatform.cpp @@ -33,13 +33,15 @@ static qint64 parseVersionString(const QByteArray &version) { // Skip any leading non digit int start = 0; - while (start < version.length() && !QChar::fromLatin1(version[start]).isDigit()) + while (start < version.length() && !QChar::fromLatin1(version[start]).isDigit()) { start++; + } // Strip any non digit, non '.' characters from the end int end = start; - while (end < version.length() && (version[end] == '.' || QChar::fromLatin1(version[end]).isDigit())) + while (end < version.length() && (version[end] == '.' || QChar::fromLatin1(version[end]).isDigit())) { end++; + } const QByteArray result = version.mid(start, end - start); const QList tokens = result.split('.'); @@ -76,8 +78,9 @@ static qint64 getKernelVersion() struct utsname name; uname(&name); - if (qstrcmp(name.sysname, "Linux") == 0) + if (qstrcmp(name.sysname, "Linux") == 0) { return parseVersionString(name.release); + } return 0; } @@ -87,36 +90,41 @@ static QString extract(const QString &text, const QString &pattern) { const QRegularExpression regexp(pattern); const QRegularExpressionMatch match = regexp.match(text); - if (!match.hasMatch()) + if (!match.hasMatch()) { return QString(); + } return match.captured(); } static ChipClass detectRadeonClass(const QByteArray &chipset) { - if (chipset.isEmpty()) + if (chipset.isEmpty()) { return UnknownRadeon; + } if (chipset.contains("R100") || chipset.contains("RV100") - || chipset.contains("RS100")) + || chipset.contains("RS100")) { return R100; + } if (chipset.contains("RV200") || chipset.contains("RS200") || chipset.contains("R200") || chipset.contains("RV250") || chipset.contains("RS300") - || chipset.contains("RV280")) + || chipset.contains("RV280")) { return R200; + } if (chipset.contains("R300") || chipset.contains("R350") || chipset.contains("R360") || chipset.contains("RV350") || chipset.contains("RV370") - || chipset.contains("RV380")) + || chipset.contains("RV380")) { return R300; + } if (chipset.contains("R420") || chipset.contains("R423") @@ -130,16 +138,18 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) || chipset.contains("RS482") || chipset.contains("RS600") || chipset.contains("RS690") - || chipset.contains("RS740")) + || chipset.contains("RS740")) { return R400; + } if (chipset.contains("RV515") || chipset.contains("R520") || chipset.contains("RV530") || chipset.contains("R580") || chipset.contains("RV560") - || chipset.contains("RV570")) + || chipset.contains("RV570")) { return R500; + } if (chipset.contains("R600") || chipset.contains("RV610") @@ -148,15 +158,17 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) || chipset.contains("RV620") || chipset.contains("RV635") || chipset.contains("RS780") - || chipset.contains("RS880")) + || chipset.contains("RS880")) { return R600; + } if (chipset.contains("R700") || chipset.contains("RV770") || chipset.contains("RV730") || chipset.contains("RV710") - || chipset.contains("RV740")) + || chipset.contains("RV740")) { return R700; + } if (chipset.contains("EVERGREEN") // Not an actual chipset, but returned by R600G in 7.9 || chipset.contains("CEDAR") @@ -164,16 +176,18 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) || chipset.contains("JUNIPER") || chipset.contains("CYPRESS") || chipset.contains("HEMLOCK") - || chipset.contains("PALM")) + || chipset.contains("PALM")) { return Evergreen; + } if (chipset.contains("SUMO") || chipset.contains("SUMO2") || chipset.contains("BARTS") || chipset.contains("TURKS") || chipset.contains("CAICOS") - || chipset.contains("CAYMAN")) + || chipset.contains("CAYMAN")) { return NorthernIslands; + } if (chipset.contains("TAHITI") || chipset.contains("PITCAIRN") @@ -226,20 +240,25 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) QString name = extract(chipset16, QStringLiteral("HD [0-9]{4}")); // HD followed by a space and 4 digits if (!name.isEmpty()) { const int id = QStringView(name).right(4).toInt(); - if (id == 6250 || id == 6310) // Palm + if (id == 6250 || id == 6310) { // Palm return Evergreen; + } - if (id >= 6000 && id < 7000) + if (id >= 6000 && id < 7000) { return NorthernIslands; // HD 6xxx + } - if (id >= 5000 && id < 6000) + if (id >= 5000 && id < 6000) { return Evergreen; // HD 5xxx + } - if (id >= 4000 && id < 5000) + if (id >= 4000 && id < 5000) { return R700; // HD 4xxx + } - if (id >= 2000 && id < 4000) // HD 2xxx/3xxx + if (id >= 2000 && id < 4000) { // HD 2xxx/3xxx return R600; + } return UnknownRadeon; } @@ -249,16 +268,19 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) const int id = QStringView(name).mid(1, -1).toInt(); // X1xxx - if (id >= 1300) + if (id >= 1300) { return R500; + } // X7xx, X8xx, X12xx, 2100 - if ((id >= 700 && id < 1000) || id >= 1200) + if ((id >= 700 && id < 1000) || id >= 1200) { return R400; + } // X200, X3xx, X5xx, X6xx, X10xx, X11xx - if ((id >= 300 && id < 700) || (id >= 1000 && id < 1200)) + if ((id >= 300 && id < 700) || (id >= 1000 && id < 1200)) { return R300; + } return UnknownRadeon; } @@ -268,19 +290,23 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) const int id = name.toInt(); // 7xxx - if (id >= 7000 && id < 8000) + if (id >= 7000 && id < 8000) { return R100; + } // 8xxx, 9xxx - if (id >= 8000 && id < 9500) + if (id >= 8000 && id < 9500) { return R200; + } // 9xxx - if (id >= 9500) + if (id >= 9500) { return R300; + } - if (id == 2100) + if (id == 2100) { return R400; + } } return UnknownRadeon; @@ -318,19 +344,22 @@ static ChipClass detectNVidiaClass(const QString &chipset) } } - if (chipset.contains(QLatin1String("GeForce2")) || chipset.contains(QLatin1String("GeForce 256"))) + if (chipset.contains(QLatin1String("GeForce2")) || chipset.contains(QLatin1String("GeForce 256"))) { return NV10; + } - if (chipset.contains(QLatin1String("GeForce3"))) + if (chipset.contains(QLatin1String("GeForce3"))) { return NV20; + } if (chipset.contains(QLatin1String("GeForce4"))) { if (chipset.contains(QLatin1String("MX 420")) || chipset.contains(QLatin1String("MX 440")) // including MX 440SE || chipset.contains(QLatin1String("MX 460")) || chipset.contains(QLatin1String("MX 4000")) - || chipset.contains(QLatin1String("PCX 4300"))) + || chipset.contains(QLatin1String("PCX 4300"))) { return NV10; + } return NV20; } @@ -338,18 +367,22 @@ static ChipClass detectNVidiaClass(const QString &chipset) // GeForce 5,6,7,8,9 name = extract(chipset, QStringLiteral("GeForce (FX |PCX |Go )?\\d{4}(M|\\b)")).trimmed(); if (!name.isEmpty()) { - if (!name[name.length() - 1].isDigit()) + if (!name[name.length() - 1].isDigit()) { name.chop(1); + } const int id = QStringView(name).right(4).toInt(); - if (id < 6000) + if (id < 6000) { return NV30; + } - if (id >= 6000 && id < 8000) + if (id >= 6000 && id < 8000) { return NV40; + } - if (id >= 8000) + if (id >= 8000) { return G80; + } return UnknownNVidia; } @@ -357,13 +390,15 @@ static ChipClass detectNVidiaClass(const QString &chipset) // GeForce 100/200/300/400/500 name = extract(chipset, QStringLiteral("GeForce (G |GT |GTX |GTS )?\\d{3}(M|\\b)")).trimmed(); if (!name.isEmpty()) { - if (!name[name.length() - 1].isDigit()) + if (!name[name.length() - 1].isDigit()) { name.chop(1); + } const int id = QStringView(name).right(3).toInt(); if (id >= 100 && id < 600) { - if (id >= 400) + if (id >= 400) { return GF100; + } return G80; } @@ -384,8 +419,9 @@ static ChipClass detectIntelClass(const QByteArray &chipset) if (chipset.contains("845G") || chipset.contains("830M") || chipset.contains("852GM/855GM") - || chipset.contains("865G")) + || chipset.contains("865G")) { return I8XX; + } // GL 1.4, DX 9.0, SM 2.0 if (chipset.contains("915G") @@ -399,8 +435,9 @@ static ChipClass detectIntelClass(const QByteArray &chipset) || chipset.contains("G33") || chipset.contains("965Q") // GMA 3000, but apparently considered gen 4 by the driver || chipset.contains("946GZ") // GMA 3000, but apparently considered gen 4 by the driver - || chipset.contains("IGD")) + || chipset.contains("IGD")) { return I915; + } // GL 2.0, DX 9.0c, SM 3.0 if (chipset.contains("965G") @@ -411,8 +448,9 @@ static ChipClass detectIntelClass(const QByteArray &chipset) || chipset.contains("Q45/Q43") || chipset.contains("G41") || chipset.contains("B43") - || chipset.contains("Ironlake")) + || chipset.contains("Ironlake")) { return I965; + } // GL 3.1, CL 1.1, DX 10.1 if (chipset.contains("Sandybridge") || chipset.contains("SNB GT")) { @@ -502,14 +540,17 @@ static ChipClass detectQualcommClass(const QByteArray &chipClass) static ChipClass detectPanfrostClass(const QByteArray &chipClass) { - if (chipClass.contains("T720") || chipClass.contains("T760")) + if (chipClass.contains("T720") || chipClass.contains("T760")) { return MaliT7XX; + } - if (chipClass.contains("T820") || chipClass.contains("T860")) + if (chipClass.contains("T820") || chipClass.contains("T860")) { return MaliT8XX; + } - if (chipClass.contains("G31") || chipClass.contains("G52") || chipClass.contains("G72")) + if (chipClass.contains("G31") || chipClass.contains("G52") || chipClass.contains("G72")) { return MaliGXX; + } return UnknownPanfrost; } @@ -525,8 +566,9 @@ QByteArray GLPlatform::versionToString8(qint64 version) int patch = version & 0xffff; QByteArray string = QByteArray::number(major) + '.' + QByteArray::number(minor); - if (patch != 0) + if (patch != 0) { string += '.' + QByteArray::number(patch); + } return string; } @@ -806,21 +848,22 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) const QByteArray &chipClass = tokens.at(2); m_chipset = tokens.at(3).mid(1, -1); // Strip the leading '(' - if (chipClass == "R100") + if (chipClass == "R100") { // Vendor: Tungsten Graphics, Inc. m_driver = Driver_R100; - else if (chipClass == "R200") + } else if (chipClass == "R200") { // Vendor: Tungsten Graphics, Inc. m_driver = Driver_R200; - else if (chipClass == "R300") + } else if (chipClass == "R300") { // Vendor: DRI R300 Project m_driver = Driver_R300C; - else if (chipClass == "R600") + } else if (chipClass == "R600") { // Vendor: Advanced Micro Devices, Inc. m_driver = Driver_R600C; + } m_chipClass = detectRadeonClass(m_chipset); } @@ -831,10 +874,11 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) // Sample renderer string: Mesa DRI Mobile Intel® GM45 Express Chipset GEM 20100328 2010Q1 QByteArray chipset; - if (m_renderer.startsWith("Intel(R) Integrated Graphics Device")) + if (m_renderer.startsWith("Intel(R) Integrated Graphics Device")) { chipset = "IGD"; - else + } else { chipset = m_renderer; + } m_driver = Driver_Intel; m_chipClass = detectIntelClass(chipset); @@ -846,12 +890,13 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) m_chipClass = detectRadeonClass(m_renderer); m_driver = Driver_Catalyst; - if (versionTokens.count() > 1 && versionTokens.at(2)[0] == '(') + if (versionTokens.count() > 1 && versionTokens.at(2)[0] == '(') { m_driverVersion = parseVersionString(versionTokens.at(1)); - else if (versionTokens.count() > 0) + } else if (versionTokens.count() > 0) { m_driverVersion = parseVersionString(versionTokens.at(0)); - else + } else { m_driverVersion = 0; + } } else if (m_vendor == "NVIDIA Corporation") { @@ -859,10 +904,11 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) m_driver = Driver_NVidia; int index = versionTokens.indexOf("NVIDIA"); - if (versionTokens.count() > index) + if (versionTokens.count() > index) { m_driverVersion = parseVersionString(versionTokens.at(index + 1)); - else + } else { m_driverVersion = 0; + } } else if (m_vendor == "Qualcomm") { @@ -886,10 +932,11 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) m_driver = Driver_VirtualBox; const int index = versionTokens.indexOf("Chromium"); - if (versionTokens.count() > index) + if (versionTokens.count() > index) { m_driverVersion = parseVersionString(versionTokens.at(index + 1)); - else + } else { m_driverVersion = 0; + } } // Gallium drivers @@ -957,17 +1004,19 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) if (isRadeon()) { // R200 technically has a programmable pipeline, but since it's SM 1.4, // it's too limited to to be of any practical value to us. - if (m_chipClass < R300) + if (m_chipClass < R300) { m_supportsGLSL = false; + } m_limitedGLSL = false; m_limitedNPOT = false; if (m_chipClass < R600) { - if (driver() == Driver_Catalyst) + if (driver() == Driver_Catalyst) { m_textureNPOT = m_limitedNPOT = false; // Software fallback - else if (driver() == Driver_R300G) + } else if (driver() == Driver_R300G) { m_limitedNPOT = m_textureNPOT; + } m_limitedGLSL = m_supportsGLSL; } @@ -988,8 +1037,9 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) } if (isNvidia()) { - if (m_driver == Driver_NVidia && m_chipClass < NV40) + if (m_driver == Driver_NVidia && m_chipClass < NV40) { m_supportsGLSL = false; // High likelihood of software emulation + } if (m_driver == Driver_NVidia) { m_looseBinding = true; @@ -1007,8 +1057,9 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) } if (isIntel()) { - if (m_chipClass < I915) + if (m_chipClass < I915) { m_supportsGLSL = false; + } m_limitedGLSL = m_supportsGLSL && m_chipClass < I965; // see https://bugs.freedesktop.org/show_bug.cgi?id=80349#c1 @@ -1095,28 +1146,34 @@ void GLPlatform::printResults() const print(QByteArrayLiteral("OpenGL renderer string:"), m_renderer); print(QByteArrayLiteral("OpenGL version string:"), m_version); - if (m_supportsGLSL) + if (m_supportsGLSL) { print(QByteArrayLiteral("OpenGL shading language version string:"), m_glsl_version); + } print(QByteArrayLiteral("Driver:"), driverToString8(m_driver)); - if (!isMesaDriver()) + if (!isMesaDriver()) { print(QByteArrayLiteral("Driver version:"), versionToString8(m_driverVersion)); + } print(QByteArrayLiteral("GPU class:"), chipClassToString8(m_chipClass)); print(QByteArrayLiteral("OpenGL version:"), versionToString8(m_glVersion)); - if (m_supportsGLSL) + if (m_supportsGLSL) { print(QByteArrayLiteral("GLSL version:"), versionToString8(m_glslVersion)); + } - if (isMesaDriver()) + if (isMesaDriver()) { print(QByteArrayLiteral("Mesa version:"), versionToString8(mesaVersion())); + } // if (galliumVersion() > 0) // print("Gallium version:", versionToString(m_galliumVersion)); - if (serverVersion() > 0) + if (serverVersion() > 0) { print(QByteArrayLiteral("X server version:"), versionToString8(m_serverVersion)); - if (kernelVersion() > 0) + } + if (kernelVersion() > 0) { print(QByteArrayLiteral("Linux kernel version:"), versionToString8(m_kernelVersion)); + } print(QByteArrayLiteral("Requires strict binding:"), !m_looseBinding ? QByteArrayLiteral("yes") : QByteArrayLiteral("no")); print(QByteArrayLiteral("GLSL shaders:"), m_supportsGLSL ? (m_limitedGLSL ? QByteArrayLiteral("limited") : QByteArrayLiteral("yes")) : QByteArrayLiteral("no")); @@ -1182,8 +1239,9 @@ qint64 GLPlatform::kernelVersion() const qint64 GLPlatform::driverVersion() const { - if (isMesaDriver()) + if (isMesaDriver()) { return mesaVersion(); + } return m_driverVersion; } diff --git a/src/libkwineffects/kwinglplatform.h b/src/libkwineffects/kwinglplatform.h index 34aed63cbf..927f47d53a 100644 --- a/src/libkwineffects/kwinglplatform.h +++ b/src/libkwineffects/kwinglplatform.h @@ -458,8 +458,9 @@ private: inline GLPlatform *GLPlatform::instance() { - if (!s_platform) + if (!s_platform) { s_platform = new GLPlatform; + } return s_platform; } diff --git a/src/libkwineffects/kwingltexture.cpp b/src/libkwineffects/kwingltexture.cpp index ac874f5b42..bca8e426fa 100644 --- a/src/libkwineffects/kwingltexture.cpp +++ b/src/libkwineffects/kwingltexture.cpp @@ -104,8 +104,9 @@ GLTexture::GLTexture(const QImage &image, GLenum target) { Q_D(GLTexture); - if (image.isNull()) + if (image.isNull()) { return; + } d->m_target = target; @@ -365,8 +366,9 @@ void GLTexture::setSize(const QSize &size) void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &src) { - if (image.isNull() || isNull()) + if (image.isNull() || isNull()) { return; + } Q_D(GLTexture); Q_ASSERT(!d->m_foreign); @@ -495,8 +497,9 @@ void GLTexture::generateMipmaps() { Q_D(GLTexture); - if (d->m_canUseMipmaps && d->s_supportsFramebufferObjects) + if (d->m_canUseMipmaps && d->s_supportsFramebufferObjects) { glGenerateMipmap(d->m_target); + } } void GLTexture::unbind() @@ -513,8 +516,9 @@ void GLTexture::render(const QRect &rect) void GLTexture::render(const QRegion ®ion, const QRect &rect, bool hardwareClipping) { Q_D(GLTexture); - if (rect.isEmpty()) + if (rect.isEmpty()) { return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090 + } if (rect.size() != d->m_cachedSize) { d->m_cachedSize = rect.size(); QRect r(rect); @@ -572,20 +576,23 @@ void GLTexture::clear() { Q_D(GLTexture); Q_ASSERT(!d->m_foreign); - if (!GLTexturePrivate::s_fbo && GLRenderTarget::supported() && GLPlatform::instance()->driver() != Driver_Catalyst) // fail. -> bug #323065 + if (!GLTexturePrivate::s_fbo && GLRenderTarget::supported() && GLPlatform::instance()->driver() != Driver_Catalyst) { // fail. -> bug #323065 glGenFramebuffers(1, &GLTexturePrivate::s_fbo); + } if (GLTexturePrivate::s_fbo) { // Clear the texture GLuint previousFramebuffer = 0; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, reinterpret_cast(&previousFramebuffer)); - if (GLTexturePrivate::s_fbo != previousFramebuffer) + if (GLTexturePrivate::s_fbo != previousFramebuffer) { glBindFramebuffer(GL_FRAMEBUFFER, GLTexturePrivate::s_fbo); + } glClearColor(0, 0, 0, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, d->m_texture, 0); glClear(GL_COLOR_BUFFER_BIT); - if (GLTexturePrivate::s_fbo != previousFramebuffer) + if (GLTexturePrivate::s_fbo != previousFramebuffer) { glBindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); + } } else { if (const int size = width() * height()) { uint32_t *buffer = new uint32_t[size]; @@ -645,10 +652,11 @@ void GLTexturePrivate::updateMatrix() m_matrix[NormalizedCoordinates].setToIdentity(); m_matrix[UnnormalizedCoordinates].setToIdentity(); - if (m_target == GL_TEXTURE_RECTANGLE_ARB) + if (m_target == GL_TEXTURE_RECTANGLE_ARB) { m_matrix[NormalizedCoordinates].scale(m_size.width(), m_size.height()); - else + } else { m_matrix[UnnormalizedCoordinates].scale(1.0 / m_size.width(), 1.0 / m_size.height()); + } if (!m_yInverted) { m_matrix[NormalizedCoordinates].translate(0.0, 1.0); @@ -668,8 +676,9 @@ bool GLTexture::isYInverted() const void GLTexture::setYInverted(bool inverted) { Q_D(GLTexture); - if (d->m_yInverted == inverted) + if (d->m_yInverted == inverted) { return; + } d->m_yInverted = inverted; d->updateMatrix(); diff --git a/src/libkwineffects/kwinglutils.cpp b/src/libkwineffects/kwinglutils.cpp index 62095dc2b3..2a6432a5c4 100644 --- a/src/libkwineffects/kwinglutils.cpp +++ b/src/libkwineffects/kwinglutils.cpp @@ -58,8 +58,9 @@ static void initDebugOutput() const bool have_KHR_debug = hasGLExtension(QByteArrayLiteral("GL_KHR_debug")); const bool have_ARB_debug = hasGLExtension(QByteArrayLiteral("GL_ARB_debug_output")); - if (!have_KHR_debug && !have_ARB_debug) + if (!have_KHR_debug && !have_ARB_debug) { return; + } if (!have_ARB_debug) { // if we don't have ARB debug, but only KHR debug we need to verify whether the context is a debug context @@ -111,8 +112,9 @@ static void initDebugOutput() glDebugMessageCallback(callback, nullptr); // This state exists only in GL_KHR_debug - if (have_KHR_debug) + if (have_KHR_debug) { glEnable(GL_DEBUG_OUTPUT); + } #if !defined(QT_NO_DEBUG) // Enable all debug messages @@ -140,8 +142,9 @@ void initGL(const std::function &resolveFunction) const QByteArray name = (const char *)glGetStringi(GL_EXTENSIONS, i); glExtensions << name; } - } else + } else { glExtensions = QByteArray((const char *)glGetString(GL_EXTENSIONS)).split(' '); + } // handle OpenGL extensions functions glResolveFunctions(resolveFunction); @@ -341,11 +344,13 @@ bool GLShader::compile(GLuint program, GLenum shaderType, const QByteArray &sour qCCritical(LIBKWINGLUTILS) << "Failed to compile" << typeName << "shader:" << "\n" << log; - } else if (length > 0) + } else if (length > 0) { qCDebug(LIBKWINGLUTILS) << "Shader compile log:" << log; + } - if (status != 0) + if (status != 0) { glAttachShader(program, shader); + } glDeleteShader(shader); return status != 0; @@ -367,20 +372,23 @@ bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSo if (!vertexSource.isEmpty()) { bool success = compile(mProgram, GL_VERTEX_SHADER, vertexSource); - if (!success) + if (!success) { return false; + } } // Compile the fragment shader if (!fragmentSource.isEmpty()) { bool success = compile(mProgram, GL_FRAGMENT_SHADER, fragmentSource); - if (!success) + if (!success) { return false; + } } - if (mExplicitLinking) + if (mExplicitLinking) { return true; + } // link() sets mValid return link(); @@ -393,8 +401,9 @@ void GLShader::bindAttributeLocation(const char *name, int index) void GLShader::bindFragDataLocation(const char *name, int index) { - if (!GLPlatform::instance()->isGLES() && (hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_EXT_gpu_shader4")))) + if (!GLPlatform::instance()->isGLES() && (hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_EXT_gpu_shader4")))) { glBindFragDataLocation(mProgram, index, name); + } } void GLShader::bind() @@ -409,8 +418,9 @@ void GLShader::unbind() void GLShader::resolveLocations() { - if (mLocationsResolved) + if (mLocationsResolved) { return; + } mMatrixLocation[TextureMatrix] = uniformLocation("textureMatrix"); mMatrixLocation[ProjectionMatrix] = uniformLocation("projection"); @@ -655,30 +665,34 @@ QByteArray ShaderManager::generateVertexSource(ShaderTraits traits) const attribute = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute"); varying = glsl_140 ? QByteArrayLiteral("out") : QByteArrayLiteral("varying"); - if (glsl_140) + if (glsl_140) { stream << "#version 140\n\n"; + } } else { const bool glsl_es_300 = gl->glslVersion() >= kVersionNumber(3, 0); attribute = glsl_es_300 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute"); varying = glsl_es_300 ? QByteArrayLiteral("out") : QByteArrayLiteral("varying"); - if (glsl_es_300) + if (glsl_es_300) { stream << "#version 300 es\n\n"; + } } stream << attribute << " vec4 position;\n"; if (traits & ShaderTrait::MapTexture) { stream << attribute << " vec4 texcoord;\n\n"; stream << varying << " vec2 texcoord0;\n\n"; - } else + } else { stream << "\n"; + } stream << "uniform mat4 modelViewProjectionMatrix;\n\n"; stream << "void main()\n{\n"; - if (traits & ShaderTrait::MapTexture) + if (traits & ShaderTrait::MapTexture) { stream << " texcoord0 = texcoord.st;\n"; + } stream << " gl_Position = modelViewProjectionMatrix * position;\n"; stream << "}\n"; @@ -698,8 +712,9 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const if (!gl->isGLES()) { const bool glsl_140 = gl->glslVersion() >= kVersionNumber(1, 40); - if (glsl_140) + if (glsl_140) { stream << "#version 140\n\n"; + } varying = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("varying"); textureLookup = glsl_140 ? QByteArrayLiteral("texture") : QByteArrayLiteral("texture2D"); @@ -707,8 +722,9 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const } else { const bool glsl_es_300 = GLPlatform::instance()->glslVersion() >= kVersionNumber(3, 0); - if (glsl_es_300) + if (glsl_es_300) { stream << "#version 300 es\n\n"; + } // From the GLSL ES specification: // @@ -723,19 +739,23 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const if (traits & ShaderTrait::MapTexture) { stream << "uniform sampler2D sampler;\n"; - if (traits & ShaderTrait::Modulate) + if (traits & ShaderTrait::Modulate) { stream << "uniform vec4 modulation;\n"; - if (traits & ShaderTrait::AdjustSaturation) + } + if (traits & ShaderTrait::AdjustSaturation) { stream << "uniform float saturation;\n"; + } stream << "\n" << varying << " vec2 texcoord0;\n"; - } else if (traits & ShaderTrait::UniformColor) + } else if (traits & ShaderTrait::UniformColor) { stream << "uniform vec4 geometryColor;\n"; + } - if (output != QByteArrayLiteral("gl_FragColor")) + if (output != QByteArrayLiteral("gl_FragColor")) { stream << "\nout vec4 " << output << ";\n"; + } stream << "\nvoid main(void)\n{\n"; if (traits & ShaderTrait::MapTexture) { @@ -743,17 +763,20 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const if (traits & (ShaderTrait::Modulate | ShaderTrait::AdjustSaturation)) { stream << " vec4 texel = " << textureLookup << "(sampler, texcoordC);\n"; - if (traits & ShaderTrait::Modulate) + if (traits & ShaderTrait::Modulate) { stream << " texel *= modulation;\n"; - if (traits & ShaderTrait::AdjustSaturation) + } + if (traits & ShaderTrait::AdjustSaturation) { stream << " texel.rgb = mix(vec3(dot(texel.rgb, vec3(0.2126, 0.7152, 0.0722))), texel.rgb, saturation);\n"; + } stream << " " << output << " = texel;\n"; } else { stream << " " << output << " = " << textureLookup << "(sampler, texcoordC);\n"; } - } else if (traits & ShaderTrait::UniformColor) + } else if (traits & ShaderTrait::UniformColor) { stream << " " << output << " = geometryColor;\n"; + } stream << "}"; stream.flush(); @@ -1098,10 +1121,11 @@ void GLRenderTarget::initFBO(GLTexture *colorAttachment) if (status != GL_FRAMEBUFFER_COMPLETE) { // We have an incomplete framebuffer, consider it invalid - if (status == 0) + if (status == 0) { qCCritical(LIBKWINGLUTILS) << "glCheckFramebufferStatus failed: " << formatGLError(glGetError()); - else + } else { qCCritical(LIBKWINGLUTILS) << "Invalid framebuffer status: " << formatFramebufferStatus(status); + } glDeleteFramebuffers(1, &mFramebuffer); return; } @@ -1355,8 +1379,9 @@ IndexBuffer::~IndexBuffer() void IndexBuffer::accommodate(int count) { // Check if we need to grow the buffer. - if (count <= m_count) + if (count <= m_count) { return; + } count = align(count, 128); size_t size = 6 * sizeof(uint16_t) * count; @@ -1379,8 +1404,9 @@ void IndexBuffer::accommodate(int count) const uint16_t index[] = {1, 0, 3, 3, 2, 1}; for (int i = m_count; i < count; i++) { - for (int j = 0; j < 6; j++) + for (int j = 0; j < 6; j++) { *(map++) = i * 4 + index[j]; + } } glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); @@ -1407,10 +1433,11 @@ public: void operator=(bool val) { - if (val) + if (val) { m_bitfield |= m_mask; - else + } else { m_bitfield &= ~m_mask; + } } operator bool() const @@ -1511,8 +1538,9 @@ struct BufferFence static void deleteAll(std::deque &fences) { - for (const BufferFence &fence : fences) + for (const BufferFence &fence : fences) { glDeleteSync(fence.sync); + } fences.clear(); } @@ -1537,8 +1565,9 @@ public: size_t average() const { size_t sum = 0; - for (size_t size : m_array) + for (size_t size : m_array) { sum += size; + } return sum / Count; } @@ -1665,8 +1694,9 @@ void GLVertexBufferPrivate::interleaveArrays(float *dst, int dim, default: for (int i = 0; i < count; i++) { - for (int j = 0; j < dim; j++) + for (int j = 0; j < dim; j++) { *(dst++) = *(vertices++); + } *(dst++) = *(texcoords++); *(dst++) = *(texcoords++); @@ -1695,8 +1725,9 @@ void GLVertexBufferPrivate::bindArrays() void GLVertexBufferPrivate::unbindArrays() { BitfieldIterator it(enabledArrays); - while (it.hasNext()) + while (it.hasNext()) { glDisableVertexAttribArray(it.next()); + } } void GLVertexBufferPrivate::reallocatePersistentBuffer(size_t size) @@ -1709,8 +1740,9 @@ void GLVertexBufferPrivate::reallocatePersistentBuffer(size_t size) deleteAll(fences); } - if (buffer == 0) + if (buffer == 0) { glGenBuffers(1, &buffer); + } // Round the size up to 64 kb size_t minSize = qMax(frameSizes.average() * 3, 128 * 1024); @@ -1762,16 +1794,18 @@ bool GLVertexBufferPrivate::awaitFence(intptr_t end) GLvoid *GLVertexBufferPrivate::getIdleRange(size_t size) { - if (unlikely(size > bufferSize)) + if (unlikely(size > bufferSize)) { reallocatePersistentBuffer(size * 2); + } // Handle wrap-around if (unlikely(nextOffset + size > bufferSize)) { nextOffset = 0; bufferEnd -= bufferSize; - for (BufferFence &fence : fences) + for (BufferFence &fence : fences) { fence.nextEnd -= bufferSize; + } // Emit a fence now BufferFence fence; @@ -1782,8 +1816,9 @@ GLvoid *GLVertexBufferPrivate::getIdleRange(size_t size) } if (unlikely(nextOffset + intptr_t(size) > bufferEnd)) { - if (!awaitFence(nextOffset + size)) + if (!awaitFence(nextOffset + size)) { return nullptr; + } } return map + nextOffset; @@ -1862,21 +1897,24 @@ GLvoid *GLVertexBuffer::map(size_t size) d->mappedSize = size; d->frameSize += size; - if (d->persistent) + if (d->persistent) { return d->getIdleRange(size); + } glBindBuffer(GL_ARRAY_BUFFER, d->buffer); bool preferBufferSubData = GLPlatform::instance()->preferBufferSubData(); - if (GLVertexBufferPrivate::hasMapBufferRange && !preferBufferSubData) + if (GLVertexBufferPrivate::hasMapBufferRange && !preferBufferSubData) { return (GLvoid *)d->mapNextFreeRange(size); + } // If we can't map the buffer we allocate local memory to hold the // buffer data and return a pointer to it. The data will be submitted // to the actual buffer object when the user calls unmap(). - if (size_t(d->dataStore.size()) < size) + if (size_t(d->dataStore.size()) < size) { d->dataStore.resize(size); + } return (GLvoid *)d->dataStore.data(); } @@ -1915,8 +1953,9 @@ void GLVertexBuffer::unmap() } // Free the local memory buffer if it's unlikely to be used again - if (d->usage == GL_STATIC_DRAW) + if (d->usage == GL_STATIC_DRAW) { d->dataStore = QByteArray(); + } } d->mappedSize = 0; @@ -1980,8 +2019,9 @@ void GLVertexBuffer::draw(const QRegion ®ion, GLenum primitiveMode, int first if (primitiveMode == GL_QUADS) { IndexBuffer *&indexBuffer = GLVertexBufferPrivate::s_indexBuffer; - if (!indexBuffer) + if (!indexBuffer) { indexBuffer = new IndexBuffer; + } indexBuffer->bind(); indexBuffer->accommodate(count / 4); @@ -2043,8 +2083,9 @@ void GLVertexBuffer::reset() void GLVertexBuffer::endOfFrame() { - if (!d->persistent) + if (!d->persistent) { return; + } // Emit a fence if we have uploaded data if (d->frameSize > 0) { @@ -2074,8 +2115,9 @@ void GLVertexBuffer::endOfFrame() void GLVertexBuffer::beginFrame() { - if (!d->persistent) + if (!d->persistent) { return; + } // Remove finished fences from the list and update the bufferEnd offset while (d->fences.size() > 1 && d->fences.front().signaled()) { diff --git a/src/libkwineffects/kwinxrenderutils.cpp b/src/libkwineffects/kwinxrenderutils.cpp index a930605e86..375c7a686e 100644 --- a/src/libkwineffects/kwinxrenderutils.cpp +++ b/src/libkwineffects/kwinxrenderutils.cpp @@ -89,8 +89,9 @@ XRenderPicture xRenderBlendPicture(double opacity) static xcb_render_picture_t createPicture(xcb_pixmap_t pix, int depth) { - if (pix == XCB_PIXMAP_NONE) + if (pix == XCB_PIXMAP_NONE) { return XCB_RENDER_PICTURE_NONE; + } xcb_connection_t *c = XRenderUtils::s_connection; static QHash s_renderFormats; if (!s_renderFormats.contains(depth)) { @@ -240,8 +241,9 @@ struct PictFormatData const xcb_render_pictvisual_t *visuals = xcb_render_pictdepth_visuals(depths.data); const int len = xcb_render_pictdepth_visuals_length(depths.data); - for (int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { visualHash.insert(visuals[i].visual, visuals[i].format); + } } } @@ -250,8 +252,9 @@ struct PictFormatData const int len = xcb_render_query_pict_formats_formats_length(reply); for (int i = 0; i < len; i++) { - if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT) + if (formats[i].type == XCB_RENDER_PICT_TYPE_DIRECT) { formatInfoHash.insert(formats[i].id, &formats[i].direct); + } } } diff --git a/src/main_wayland.cpp b/src/main_wayland.cpp index 51e14584c4..b04a4fba7b 100644 --- a/src/main_wayland.cpp +++ b/src/main_wayland.cpp @@ -313,12 +313,15 @@ int main(int argc, char *argv[]) KWin::gainRealTime(); KWin::dropNiceCapability(); - if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) + if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) { signal(SIGTERM, SIG_IGN); - if (signal(SIGINT, KWin::sighandler) == SIG_IGN) + } + if (signal(SIGINT, KWin::sighandler) == SIG_IGN) { signal(SIGINT, SIG_IGN); - if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) + } + if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) { signal(SIGHUP, SIG_IGN); + } signal(SIGPIPE, SIG_IGN); QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); diff --git a/src/main_x11.cpp b/src/main_x11.cpp index 449c479884..01ca4a1762 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -90,8 +90,9 @@ public: void addWM(const QString &wm) { // TODO: Check if WM is installed - if (!QStandardPaths::findExecutable(wm).isEmpty()) + if (!QStandardPaths::findExecutable(wm).isEmpty()) { wmList->addItem(wm); + } } QString selectedWM() const { @@ -118,8 +119,9 @@ private: int32_t version[] = {2, 0}; xcb_change_property(kwinApp()->x11Connection(), XCB_PROP_MODE_REPLACE, requestor_P, property_P, XCB_ATOM_INTEGER, 32, 2, version); - } else + } else { return KSelectionOwner::genericReply(target_P, property_P, requestor_P); + } return true; } @@ -149,8 +151,9 @@ private: xcb_atom_t make_selection_atom(int screen_P) { - if (screen_P < 0) + if (screen_P < 0) { screen_P = QX11Info::appScreen(); + } QByteArray screen(QByteArrayLiteral("WM_S")); screen.append(QByteArray::number(screen_P)); ScopedCPointer atom(xcb_intern_atom_reply( @@ -184,8 +187,9 @@ ApplicationX11::~ApplicationX11() setTerminating(); destroyCompositor(); destroyWorkspace(); - if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM) + if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) { // If there was no --replace (no new WM) Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT); + } } void ApplicationX11::setReplace(bool replace) @@ -251,8 +255,9 @@ void ApplicationX11::performStartup() maskValues))); if (!redirectCheck.isNull()) { fputs(i18n("kwin: another window manager is running (try using --replace)\n").toLocal8Bit().constData(), stderr); - if (!wasCrash()) // if this is a crash-restart, DrKonqi may have stopped the process w/o killing the connection + if (!wasCrash()) { // if this is a crash-restart, DrKonqi may have stopped the process w/o killing the connection ::exit(1); + } } createInput(); @@ -273,8 +278,9 @@ void ApplicationX11::performStartup() bool ApplicationX11::notify(QObject *o, QEvent *e) { - if (e->spontaneous() && Workspace::self()->workspaceEvent(e)) + if (e->spontaneous() && Workspace::self()->workspaceEvent(e)) { return true; + } return QApplication::notify(o, e); } @@ -290,10 +296,11 @@ void ApplicationX11::crashChecking() // Something has gone seriously wrong AlternativeWMDialog dialog; QString cmd = QStringLiteral(KWIN_INTERNAL_NAME_X11); - if (dialog.exec() == QDialog::Accepted) + if (dialog.exec() == QDialog::Accepted) { cmd = dialog.selectedWM(); - else + } else { ::exit(1); + } if (cmd.length() > 500) { qCDebug(KWIN_CORE) << "Command is too long, truncating"; cmd = cmd.left(500); @@ -371,8 +378,9 @@ int main(int argc, char *argv[]) int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head QByteArray display_name = qgetenv("DISPLAY"); - if ((pos = display_name.lastIndexOf('.')) != -1) + if ((pos = display_name.lastIndexOf('.')) != -1) { display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s" + } for (int i = 0; i < number_of_screens; i++) { // If execution doesn't pass by here, then kwin @@ -402,12 +410,15 @@ int main(int argc, char *argv[]) } } - if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) + if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) { signal(SIGTERM, SIG_IGN); - if (signal(SIGINT, KWin::sighandler) == SIG_IGN) + } + if (signal(SIGINT, KWin::sighandler) == SIG_IGN) { signal(SIGINT, SIG_IGN); - if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) + } + if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) { signal(SIGHUP, SIG_IGN); + } signal(SIGPIPE, SIG_IGN); // Disable the glib event loop integration, since it seems to be responsible diff --git a/src/netinfo.cpp b/src/netinfo.cpp index e8655e3b9a..c74c637fce 100644 --- a/src/netinfo.cpp +++ b/src/netinfo.cpp @@ -152,26 +152,29 @@ void RootInfo::changeActiveWindow(xcb_window_t w, NET::RequestSource src, xcb_ti { Workspace *workspace = Workspace::self(); if (X11Client *c = workspace->findClient(Predicate::WindowMatch, w)) { - if (timestamp == XCB_CURRENT_TIME) + if (timestamp == XCB_CURRENT_TIME) { timestamp = c->userTime(); - if (src != NET::FromApplication && src != FromTool) + } + if (src != NET::FromApplication && src != FromTool) { src = NET::FromTool; - if (src == NET::FromTool) + } + if (src == NET::FromTool) { workspace->activateClient(c, true); // force - else if (c == workspace->mostRecentlyActivatedClient()) { + } else if (c == workspace->mostRecentlyActivatedClient()) { return; // WORKAROUND? With > 1 plasma activities, we cause this ourselves. bug #240673 } else { // NET::FromApplication X11Client *c2; - if (workspace->allowClientActivation(c, timestamp, false, true)) + if (workspace->allowClientActivation(c, timestamp, false, true)) { workspace->activateClient(c); // if activation of the requestor's window would be allowed, allow activation too - else if (active_window != XCB_WINDOW_NONE - && (c2 = workspace->findClient(Predicate::WindowMatch, active_window)) != nullptr - && workspace->allowClientActivation(c2, - timestampCompare(timestamp, c2->userTime() > 0 ? timestamp : c2->userTime()), false, true)) { + } else if (active_window != XCB_WINDOW_NONE + && (c2 = workspace->findClient(Predicate::WindowMatch, active_window)) != nullptr + && workspace->allowClientActivation(c2, + timestampCompare(timestamp, c2->userTime() > 0 ? timestamp : c2->userTime()), false, true)) { workspace->activateClient(c); - } else + } else { c->demandAttention(); + } } } } @@ -179,10 +182,12 @@ void RootInfo::changeActiveWindow(xcb_window_t w, NET::RequestSource src, xcb_ti void RootInfo::restackWindow(xcb_window_t w, RequestSource src, xcb_window_t above, int detail, xcb_timestamp_t timestamp) { if (X11Client *c = Workspace::self()->findClient(Predicate::WindowMatch, w)) { - if (timestamp == XCB_CURRENT_TIME) + if (timestamp == XCB_CURRENT_TIME) { timestamp = c->userTime(); - if (src != NET::FromApplication && src != FromTool) + } + if (src != NET::FromApplication && src != FromTool) { src = NET::FromTool; + } c->restackWindow(above, detail, src, timestamp, true); } } @@ -190,8 +195,9 @@ void RootInfo::restackWindow(xcb_window_t w, RequestSource src, xcb_window_t abo void RootInfo::closeWindow(xcb_window_t w) { X11Client *c = Workspace::self()->findClient(Predicate::WindowMatch, w); - if (c) + if (c) { c->closeWindow(); + } } void RootInfo::moveResize(xcb_window_t w, int x_root, int y_root, unsigned long direction) @@ -206,14 +212,16 @@ void RootInfo::moveResize(xcb_window_t w, int x_root, int y_root, unsigned long void RootInfo::moveResizeWindow(xcb_window_t w, int flags, int x, int y, int width, int height) { X11Client *c = Workspace::self()->findClient(Predicate::WindowMatch, w); - if (c) + if (c) { c->NETMoveResizeWindow(flags, x, y, width, height); + } } void RootInfo::gotPing(xcb_window_t w, xcb_timestamp_t timestamp) { - if (X11Client *c = Workspace::self()->findClient(Predicate::WindowMatch, w)) + if (X11Client *c = Workspace::self()->findClient(Predicate::WindowMatch, w)) { c->gotPing(timestamp); + } } void RootInfo::changeShowingDesktop(bool showing) @@ -258,34 +266,45 @@ void WinInfo::changeState(NET::States state, NET::States mask) mask &= ~NET::Hidden; // clients are not allowed to change this directly state &= mask; // for safety, clear all other bits - if ((mask & NET::FullScreen) != 0 && (state & NET::FullScreen) == 0) + if ((mask & NET::FullScreen) != 0 && (state & NET::FullScreen) == 0) { m_client->setFullScreen(false, false); - if ((mask & NET::Max) == NET::Max) + } + if ((mask & NET::Max) == NET::Max) { m_client->setMaximize(state & NET::MaxVert, state & NET::MaxHoriz); - else if (mask & NET::MaxVert) + } else if (mask & NET::MaxVert) { m_client->setMaximize(state & NET::MaxVert, m_client->maximizeMode() & MaximizeHorizontal); - else if (mask & NET::MaxHoriz) + } else if (mask & NET::MaxHoriz) { m_client->setMaximize(m_client->maximizeMode() & MaximizeVertical, state & NET::MaxHoriz); + } - if (mask & NET::Shaded) + if (mask & NET::Shaded) { m_client->setShade(state & NET::Shaded ? ShadeNormal : ShadeNone); - if (mask & NET::KeepAbove) + } + if (mask & NET::KeepAbove) { m_client->setKeepAbove((state & NET::KeepAbove) != 0); - if (mask & NET::KeepBelow) + } + if (mask & NET::KeepBelow) { m_client->setKeepBelow((state & NET::KeepBelow) != 0); - if (mask & NET::SkipTaskbar) + } + if (mask & NET::SkipTaskbar) { m_client->setOriginalSkipTaskbar((state & NET::SkipTaskbar) != 0); - if (mask & NET::SkipPager) + } + if (mask & NET::SkipPager) { m_client->setSkipPager((state & NET::SkipPager) != 0); - if (mask & NET::SkipSwitcher) + } + if (mask & NET::SkipSwitcher) { m_client->setSkipSwitcher((state & NET::SkipSwitcher) != 0); - if (mask & NET::DemandsAttention) + } + if (mask & NET::DemandsAttention) { m_client->demandAttention((state & NET::DemandsAttention) != 0); - if (mask & NET::Modal) + } + if (mask & NET::Modal) { m_client->setModal((state & NET::Modal) != 0); + } // unsetting fullscreen first, setting it last (because e.g. maximize works only for !isFullScreen() ) - if ((mask & NET::FullScreen) != 0 && (state & NET::FullScreen) != 0) + if ((mask & NET::FullScreen) != 0 && (state & NET::FullScreen) != 0) { m_client->setFullScreen(true, false); + } } void WinInfo::disable() diff --git a/src/options.cpp b/src/options.cpp index dfbf3ce8e6..296b1825d8 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -603,10 +603,11 @@ void Options::setGlPreferBufferSwap(char glPreferBufferSwap) // buffer copying is very fast with the nvidia blob // but due to restrictions in DRI2 *incredibly* slow for all MESA drivers // see https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt, item 2.5 - if (GLPlatform::instance()->driver() == Driver_NVidia) + if (GLPlatform::instance()->driver() == Driver_NVidia) { glPreferBufferSwap = CopyFrontBuffer; - else if (GLPlatform::instance()->driver() != Driver_Unknown) // undetected, finally resolved when context is initialized + } else if (GLPlatform::instance()->driver() != Driver_Unknown) { // undetected, finally resolved when context is initialized glPreferBufferSwap = ExtendDamage; + } } if (m_glPreferBufferSwap == (GlSwapStrategy)glPreferBufferSwap) { return; @@ -797,10 +798,11 @@ bool Options::loadCompositingConfig(bool force) bool useCompositing = false; CompositingType compositingMode = NoCompositing; QString compositingBackend = config.readEntry("Backend", "OpenGL"); - if (compositingBackend == "QPainter") + if (compositingBackend == "QPainter") { compositingMode = QPainterCompositing; - else + } else { compositingMode = OpenGLCompositing; + } if (const char *c = getenv("KWIN_COMPOSE")) { switch (c[0]) { @@ -815,10 +817,11 @@ bool Options::loadCompositingConfig(bool force) useCompositing = true; break; case 'N': - if (getenv("KDE_FAILSAFE")) + if (getenv("KDE_FAILSAFE")) { qCDebug(KWIN_CORE) << "Compositing disabled forcefully by KDE failsafe mode"; - else + } else { qCDebug(KWIN_CORE) << "Compositing disabled forcefully by environment variable"; + } compositingMode = NoCompositing; break; default: @@ -837,8 +840,9 @@ bool Options::loadCompositingConfig(bool force) // it's either enforced by env or by initial resume from "suspend" or we check the settings setUseCompositing(useCompositing || force || config.readEntry("Enabled", Options::defaultUseCompositing() || !platformSupportsNoCompositing)); - if (!m_useCompositing) + if (!m_useCompositing) { return false; // not enforced or necessary and not "enabled" by settings + } return true; } @@ -861,21 +865,24 @@ void Options::reloadCompositingSettings(bool force) char c = 0; const QString s = config.readEntry("GLPreferBufferSwap", QString(QLatin1Char(Options::defaultGlPreferBufferSwap()))); - if (!s.isEmpty()) + if (!s.isEmpty()) { c = s.at(0).toLatin1(); - if (c != 'a' && c != 'c' && c != 'p' && c != 'e') + } + if (c != 'a' && c != 'c' && c != 'p' && c != 'e') { c = Options::defaultGlPreferBufferSwap(); + } setGlPreferBufferSwap(c); HiddenPreviews previews = Options::defaultHiddenPreviews(); // 4 - off, 5 - shown, 6 - always, other are old values int hps = config.readEntry("HiddenPreviews", 5); - if (hps == 4) + if (hps == 4) { previews = HiddenPreviewsNever; - else if (hps == 5) + } else if (hps == 5) { previews = HiddenPreviewsShown; - else if (hps == 6) + } else if (hps == 6) { previews = HiddenPreviewsAlways; + } setHiddenPreviews(previews); auto interfaceToKey = [](OpenGLPlatformInterface interface) { @@ -905,96 +912,125 @@ void Options::reloadCompositingSettings(bool force) // may not be able to move it back, unless they know about Meta+LMB) Options::WindowOperation Options::windowOperation(const QString &name, bool restricted) { - if (name == QStringLiteral("Move")) + if (name == QStringLiteral("Move")) { return restricted ? MoveOp : UnrestrictedMoveOp; - else if (name == QStringLiteral("Resize")) + } else if (name == QStringLiteral("Resize")) { return restricted ? ResizeOp : UnrestrictedResizeOp; - else if (name == QStringLiteral("Maximize")) + } else if (name == QStringLiteral("Maximize")) { return MaximizeOp; - else if (name == QStringLiteral("Minimize")) + } else if (name == QStringLiteral("Minimize")) { return MinimizeOp; - else if (name == QStringLiteral("Close")) + } else if (name == QStringLiteral("Close")) { return CloseOp; - else if (name == QStringLiteral("OnAllDesktops")) + } else if (name == QStringLiteral("OnAllDesktops")) { return OnAllDesktopsOp; - else if (name == QStringLiteral("Shade")) + } else if (name == QStringLiteral("Shade")) { return ShadeOp; - else if (name == QStringLiteral("Operations")) + } else if (name == QStringLiteral("Operations")) { return OperationsOp; - else if (name == QStringLiteral("Maximize (vertical only)")) + } else if (name == QStringLiteral("Maximize (vertical only)")) { return VMaximizeOp; - else if (name == QStringLiteral("Maximize (horizontal only)")) + } else if (name == QStringLiteral("Maximize (horizontal only)")) { return HMaximizeOp; - else if (name == QStringLiteral("Lower")) + } else if (name == QStringLiteral("Lower")) { return LowerOp; + } return NoOp; } Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted) { QString lowerName = name.toLower(); - if (lowerName == QStringLiteral("raise")) + if (lowerName == QStringLiteral("raise")) { return MouseRaise; - if (lowerName == QStringLiteral("lower")) + } + if (lowerName == QStringLiteral("lower")) { return MouseLower; - if (lowerName == QStringLiteral("operations menu")) + } + if (lowerName == QStringLiteral("operations menu")) { return MouseOperationsMenu; - if (lowerName == QStringLiteral("toggle raise and lower")) + } + if (lowerName == QStringLiteral("toggle raise and lower")) { return MouseToggleRaiseAndLower; - if (lowerName == QStringLiteral("activate and raise")) + } + if (lowerName == QStringLiteral("activate and raise")) { return MouseActivateAndRaise; - if (lowerName == QStringLiteral("activate and lower")) + } + if (lowerName == QStringLiteral("activate and lower")) { return MouseActivateAndLower; - if (lowerName == QStringLiteral("activate")) + } + if (lowerName == QStringLiteral("activate")) { return MouseActivate; - if (lowerName == QStringLiteral("activate, raise and pass click")) + } + if (lowerName == QStringLiteral("activate, raise and pass click")) { return MouseActivateRaiseAndPassClick; - if (lowerName == QStringLiteral("activate and pass click")) + } + if (lowerName == QStringLiteral("activate and pass click")) { return MouseActivateAndPassClick; - if (lowerName == QStringLiteral("scroll")) + } + if (lowerName == QStringLiteral("scroll")) { return MouseNothing; - if (lowerName == QStringLiteral("activate and scroll")) + } + if (lowerName == QStringLiteral("activate and scroll")) { return MouseActivateAndPassClick; - if (lowerName == QStringLiteral("activate, raise and scroll")) + } + if (lowerName == QStringLiteral("activate, raise and scroll")) { return MouseActivateRaiseAndPassClick; - if (lowerName == QStringLiteral("activate, raise and move")) + } + if (lowerName == QStringLiteral("activate, raise and move")) { return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove; - if (lowerName == QStringLiteral("move")) + } + if (lowerName == QStringLiteral("move")) { return restricted ? MouseMove : MouseUnrestrictedMove; - if (lowerName == QStringLiteral("resize")) + } + if (lowerName == QStringLiteral("resize")) { return restricted ? MouseResize : MouseUnrestrictedResize; - if (lowerName == QStringLiteral("shade")) + } + if (lowerName == QStringLiteral("shade")) { return MouseShade; - if (lowerName == QStringLiteral("minimize")) + } + if (lowerName == QStringLiteral("minimize")) { return MouseMinimize; - if (lowerName == QStringLiteral("close")) + } + if (lowerName == QStringLiteral("close")) { return MouseClose; - if (lowerName == QStringLiteral("increase opacity")) + } + if (lowerName == QStringLiteral("increase opacity")) { return MouseOpacityMore; - if (lowerName == QStringLiteral("decrease opacity")) + } + if (lowerName == QStringLiteral("decrease opacity")) { return MouseOpacityLess; - if (lowerName == QStringLiteral("nothing")) + } + if (lowerName == QStringLiteral("nothing")) { return MouseNothing; + } return MouseNothing; } Options::MouseWheelCommand Options::mouseWheelCommand(const QString &name) { QString lowerName = name.toLower(); - if (lowerName == QStringLiteral("raise/lower")) + if (lowerName == QStringLiteral("raise/lower")) { return MouseWheelRaiseLower; - if (lowerName == QStringLiteral("shade/unshade")) + } + if (lowerName == QStringLiteral("shade/unshade")) { return MouseWheelShadeUnshade; - if (lowerName == QStringLiteral("maximize/restore")) + } + if (lowerName == QStringLiteral("maximize/restore")) { return MouseWheelMaximizeRestore; - if (lowerName == QStringLiteral("above/below")) + } + if (lowerName == QStringLiteral("above/below")) { return MouseWheelAboveBelow; - if (lowerName == QStringLiteral("previous/next desktop")) + } + if (lowerName == QStringLiteral("previous/next desktop")) { return MouseWheelPreviousNextDesktop; - if (lowerName == QStringLiteral("change opacity")) + } + if (lowerName == QStringLiteral("change opacity")) { return MouseWheelChangeOpacity; - if (lowerName == QStringLiteral("nothing")) + } + if (lowerName == QStringLiteral("nothing")) { return MouseWheelNothing; + } return MouseWheelNothing; } diff --git a/src/placement.cpp b/src/placement.cpp index 4cb29a6434..df1fa958a0 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -52,26 +52,28 @@ void Placement::place(AbstractClient *c, const QRect &area) return; } - if (c->isUtility()) + if (c->isUtility()) { placeUtility(c, area, options->placement()); - else if (c->isDialog()) + } else if (c->isDialog()) { placeDialog(c, area, options->placement()); - else if (c->isSplash()) + } else if (c->isSplash()) { placeOnMainWindow(c, area); // on mainwindow, if any, otherwise centered - else if (c->isOnScreenDisplay() || c->isNotification() || c->isCriticalNotification()) + } else if (c->isOnScreenDisplay() || c->isNotification() || c->isCriticalNotification()) { placeOnScreenDisplay(c, area); - else if (c->isTransient() && c->hasTransientPlacementHint()) + } else if (c->isTransient() && c->hasTransientPlacementHint()) { placeTransient(c); - else if (c->isTransient() && c->surface()) + } else if (c->isTransient() && c->surface()) { placeDialog(c, area, options->placement()); - else + } else { place(c, area, options->placement()); + } } void Placement::place(AbstractClient *c, const QRect &area, Policy policy, Policy nextPlacement) { - if (policy == Unknown || policy == Default) + if (policy == Unknown || policy == Default) { policy = options->placement(); + } switch (policy) { case NoPlacement: @@ -134,14 +136,16 @@ void Placement::placeAtRandom(AbstractClient *c, const QRect &area, Policy /*nex ty = py; if (tx + c->width() > area.right()) { tx = area.right() - c->width(); - if (tx < 0) + if (tx < 0) { tx = 0; + } px = area.x(); } if (ty + c->height() > area.bottom()) { ty = area.bottom() - c->height(); - if (ty < 0) + if (ty < 0) { ty = 0; + } py = area.y(); } c->move(QPoint(tx, ty)); @@ -150,18 +154,24 @@ void Placement::placeAtRandom(AbstractClient *c, const QRect &area, Policy /*nex // TODO: one day, there'll be C++11 ... static inline bool isIrrelevant(const AbstractClient *client, const AbstractClient *regarding, int desktop) { - if (!client) + if (!client) { return true; - if (client == regarding) + } + if (client == regarding) { return true; - if (!client->isShown() || client->isShade()) + } + if (!client->isShown() || client->isShade()) { return true; - if (!client->isOnDesktop(desktop)) + } + if (!client->isOnDesktop(desktop)) { return true; - if (!client->isOnCurrentActivity()) + } + if (!client->isOnCurrentActivity()) { return true; - if (client->isDesktop()) + } + if (client->isDesktop()) { return true; + } return false; } @@ -237,12 +247,13 @@ void Placement::placeSmart(AbstractClient *c, const QRect &area, Policy /*next*/ xr = qMin(cxr, xr); yt = qMax(cyt, yt); yb = qMin(cyb, yb); - if (client->keepAbove()) + if (client->keepAbove()) { overlap += 16 * (xr - xl) * (yb - yt); - else if (client->keepBelow() && !client->isDock()) // ignore KeepBelow windows + } else if (client->keepBelow() && !client->isDock()) { // ignore KeepBelow windows overlap += 0; // for placement (see X11Client::belongsToLayer() for Dock) - else + } else { overlap += (xr - xl) * (yb - yt); + } } } } @@ -269,8 +280,9 @@ void Placement::placeSmart(AbstractClient *c, const QRect &area, Policy /*next*/ if (overlap > none) { possible = area.right(); - if (possible - cw > x) + if (possible - cw > x) { possible -= cw; + } // compare to the position of each client on the same desk for (auto l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd(); ++l) { @@ -288,12 +300,14 @@ void Placement::placeSmart(AbstractClient *c, const QRect &area, Policy /*next*/ // determine the first non-overlapped x position if ((y < yb) && (yt < ch + y)) { - if ((xr > x) && (possible > xr)) + if ((xr > x) && (possible > xr)) { possible = xr; + } basket = xl - cw; - if ((basket > x) && (possible > basket)) + if ((basket > x) && (possible > basket)) { possible = basket; + } } } x = possible; @@ -304,8 +318,9 @@ void Placement::placeSmart(AbstractClient *c, const QRect &area, Policy /*next*/ x = area.left(); possible = area.bottom(); - if (possible - ch > y) + if (possible - ch > y) { possible -= ch; + } // test the position of each window on the desk for (auto l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd(); ++l) { @@ -321,12 +336,14 @@ void Placement::placeSmart(AbstractClient *c, const QRect &area, Policy /*next*/ // if not enough room to the left or right of the current tested client // determine the first non-overlapped y position - if ((yb > y) && (possible > yb)) + if ((yb > y) && (possible > yb)) { possible = yb; + } basket = yt - ch; - if ((basket > y) && (possible > basket)) + if ((basket > y) && (possible > basket)) { possible = basket; + } } y = possible; } @@ -393,8 +410,9 @@ void Placement::placeCascaded(AbstractClient *c, const QRect &area, Policy nextP const int H = area.height(); const int W = area.width(); - if (nextPlacement == Unknown) + if (nextPlacement == Unknown) { nextPlacement = Smart; + } // initialize if needed if (cci[dn].pos.x() < 0 || cci[dn].pos.x() < X || cci[dn].pos.y() < Y) { @@ -406,15 +424,17 @@ void Placement::placeCascaded(AbstractClient *c, const QRect &area, Policy nextP yp = cci[dn].pos.y(); // here to touch in case people vote for resize on placement - if ((yp + ch) > H) + if ((yp + ch) > H) { yp = Y; + } if ((xp + cw) > W) { if (!yp) { place(c, area, nextPlacement); return; - } else + } else { xp = X; + } } // if this isn't the first window @@ -535,23 +555,26 @@ void Placement::placeOnMainWindow(AbstractClient *c, const QRect &area, Policy n { Q_ASSERT(area.isValid()); - if (nextPlacement == Unknown) + if (nextPlacement == Unknown) { nextPlacement = Centered; - if (nextPlacement == Maximizing) // maximize if needed + } + if (nextPlacement == Maximizing) { // maximize if needed placeMaximizing(c, area, NoPlacement); + } auto mainwindows = c->mainClients(); AbstractClient *place_on = nullptr; AbstractClient *place_on2 = nullptr; int mains_count = 0; for (auto it = mainwindows.constBegin(); it != mainwindows.constEnd(); ++it) { - if (mainwindows.count() > 1 && (*it)->isSpecialWindow()) + if (mainwindows.count() > 1 && (*it)->isSpecialWindow()) { continue; // don't consider toolbars etc when placing + } ++mains_count; place_on2 = *it; if ((*it)->isOnCurrentDesktop()) { - if (place_on == nullptr) + if (place_on == nullptr) { place_on = *it; - else { + } else { // two or more on current desktop -> center // That's the default at least. However, with maximizing placement // policy as the default, the dialog should be either maximized or @@ -587,12 +610,13 @@ void Placement::placeMaximizing(AbstractClient *c, const QRect &area, Policy nex { Q_ASSERT(area.isValid()); - if (nextPlacement == Unknown) + if (nextPlacement == Unknown) { nextPlacement = Smart; + } if (c->isMaximizable() && c->maxSize().width() >= area.width() && c->maxSize().height() >= area.height()) { - if (workspace()->clientArea(MaximizeArea, c) == area) + if (workspace()->clientArea(MaximizeArea, c) == area) { c->maximize(MaximizeFull); - else { // if the geometry doesn't match default maximize area (xinerama case?), + } else { // if the geometry doesn't match default maximize area (xinerama case?), // it's probably better to use the given area c->moveResize(area); } @@ -610,8 +634,9 @@ void Placement::cascadeDesktop() const auto stackingOrder = ws->stackingOrder(); for (Toplevel *toplevel : stackingOrder) { auto client = qobject_cast(toplevel); - if (!client || (!client->isOnCurrentDesktop()) || (client->isMinimized()) || (client->isOnAllDesktops()) || (!client->isMovable())) + if (!client || (!client->isOnCurrentDesktop()) || (client->isMinimized()) || (client->isOnAllDesktops()) || (!client->isMovable())) { continue; + } const QRect placementArea = workspace()->clientArea(PlacementArea, client); placeCascaded(client, placementArea); } @@ -622,8 +647,9 @@ void Placement::unclutterDesktop() const auto &clients = Workspace::self()->allClientList(); for (int i = clients.size() - 1; i >= 0; i--) { auto client = clients.at(i); - if ((!client->isOnCurrentDesktop()) || (client->isMinimized()) || (client->isOnAllDesktops()) || (!client->isMovable())) + if ((!client->isOnCurrentDesktop()) || (client->isMinimized()) || (client->isOnAllDesktops()) || (!client->isMovable())) { continue; + } const QRect placementArea = workspace()->clientArea(PlacementArea, client); placeSmart(client, placementArea); } @@ -654,8 +680,9 @@ void AbstractClient::packTo(int left, int top) move(QPoint(left, top)); if (output() != oldOutput) { workspace()->sendClientToOutput(this, output()); // checks rule validity - if (maximizeMode() != MaximizeRestore) + if (maximizeMode() != MaximizeRestore) { checkWorkspacePosition(); + } } } @@ -711,14 +738,16 @@ void Workspace::slotWindowCenter() void Workspace::slotWindowExpandHorizontal() { - if (active_client) + if (active_client) { active_client->growHorizontal(); + } } void AbstractClient::growHorizontal() { - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { return; + } QRect geom = moveResizeGeometry(); geom.setRight(workspace()->packPositionRight(this, geom.right(), true)); QSize adjsize = constrainFrameSize(geom.size(), SizeModeFixedW); @@ -730,8 +759,9 @@ void AbstractClient::growHorizontal() this, QPoint((x() + newright) / 2, moveResizeGeometry().center().y())) .right() - >= newright) + >= newright) { geom.setRight(newright); + } } geom.setSize(constrainFrameSize(geom.size(), SizeModeFixedW)); geom.setSize(constrainFrameSize(geom.size(), SizeModeFixedH)); @@ -741,18 +771,21 @@ void AbstractClient::growHorizontal() void Workspace::slotWindowShrinkHorizontal() { - if (active_client) + if (active_client) { active_client->shrinkHorizontal(); + } } void AbstractClient::shrinkHorizontal() { - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { return; + } QRect geom = moveResizeGeometry(); geom.setRight(workspace()->packPositionLeft(this, geom.right(), false)); - if (geom.width() <= 1) + if (geom.width() <= 1) { return; + } geom.setSize(constrainFrameSize(geom.size(), SizeModeFixedW)); if (geom.width() > 20) { workspace()->updateFocusMousePosition(Cursors::self()->mouse()->pos()); // may cause leave event; @@ -762,14 +795,16 @@ void AbstractClient::shrinkHorizontal() void Workspace::slotWindowExpandVertical() { - if (active_client) + if (active_client) { active_client->growVertical(); + } } void AbstractClient::growVertical() { - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { return; + } QRect geom = moveResizeGeometry(); geom.setBottom(workspace()->packPositionDown(this, geom.bottom(), true)); QSize adjsize = constrainFrameSize(geom.size(), SizeModeFixedH); @@ -780,8 +815,9 @@ void AbstractClient::growVertical() this, QPoint(moveResizeGeometry().center().x(), (y() + newbottom) / 2)) .bottom() - >= newbottom) + >= newbottom) { geom.setBottom(newbottom); + } } geom.setSize(constrainFrameSize(geom.size(), SizeModeFixedH)); workspace()->updateFocusMousePosition(Cursors::self()->mouse()->pos()); // may cause leave event; @@ -790,18 +826,21 @@ void AbstractClient::growVertical() void Workspace::slotWindowShrinkVertical() { - if (active_client) + if (active_client) { active_client->shrinkVertical(); + } } void AbstractClient::shrinkVertical() { - if (!isResizable() || isShade()) + if (!isResizable() || isShade()) { return; + } QRect geom = moveResizeGeometry(); geom.setBottom(workspace()->packPositionUp(this, geom.bottom(), false)); - if (geom.height() <= 1) + if (geom.height() <= 1) { return; + } geom.setSize(constrainFrameSize(geom.size(), SizeModeFixedH)); if (geom.height() > 20) { workspace()->updateFocusMousePosition(Cursors::self()->mouse()->pos()); // may cause leave event; diff --git a/src/platform.cpp b/src/platform.cpp index 782b1d1c66..f1baf8d35e 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -526,8 +526,9 @@ static quint32 monotonicTime() timespec ts; const int result = clock_gettime(CLOCK_MONOTONIC, &ts); - if (result) + if (result) { qCWarning(KWIN_CORE, "Failed to query monotonic time: %s", strerror(errno)); + } return ts.tv_sec * 1000 + ts.tv_nsec / 1000000L; } diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp index b98f2dc8d8..29ea22ea00 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp @@ -145,8 +145,9 @@ void AbstractEglBackend::initKWinGL() GLPlatform *glPlatform = GLPlatform::instance(); glPlatform->detect(EglPlatformInterface); options->setGlPreferBufferSwap(options->glPreferBufferSwap()); // resolve autosetting - if (options->glPreferBufferSwap() == Options::AutoSwapStrategy) + if (options->glPreferBufferSwap() == Options::AutoSwapStrategy) { options->setGlPreferBufferSwap('e'); // for unknown drivers - should not happen + } glPlatform->printResults(); initGL(&getProcAddress); } diff --git a/src/plugins/kdecorations/aurorae/themes/plastik/code/plastikbutton.cpp b/src/plugins/kdecorations/aurorae/themes/plastik/code/plastikbutton.cpp index 121bc08d4d..39e3a655e5 100644 --- a/src/plugins/kdecorations/aurorae/themes/plastik/code/plastikbutton.cpp +++ b/src/plugins/kdecorations/aurorae/themes/plastik/code/plastikbutton.cpp @@ -103,8 +103,9 @@ QPixmap PlastikButtonProvider::requestPixmap(const QString &id, QSize *size, con QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool shadow) { Q_UNUSED(active); - if (size % 2 == 0) + if (size % 2 == 0) { --size; + } QPixmap image(size, size); image.fill(Qt::transparent); @@ -175,8 +176,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool int margin1, margin2; margin1 = margin2 = lineWidth2 * 2; - if (r.width() < 8) + if (r.width() < 8) { margin1 = 1; + } // background window drawObject(p, HorizontalLine, r.x() + margin1, r.top(), r.width() - margin1, lineWidth2); @@ -258,8 +260,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool case NotOnAllDesktopsIcon: { int lwMark = r.width() - lwTitleBar * 2 - 2; - if (lwMark < 1) + if (lwMark < 1) { lwMark = 3; + } drawObject(p, HorizontalLine, r.x() + (r.width() - lwMark) / 2, r.y() + (r.height() - lwMark) / 2, lwMark, lwMark); @@ -283,8 +286,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool // arrow drawObject(p, CrossDiagonalLine, r.x(), center + 2 * lwArrow, center - r.x(), lwArrow); drawObject(p, DiagonalLine, r.x() + center, r.y() + 1 + 2 * lwArrow, center - r.x(), lwArrow); - if (lwArrow > 1) + if (lwArrow > 1) { drawObject(p, HorizontalLine, center - (lwArrow - 2), r.y() + 2 * lwArrow, (lwArrow - 2) * 2, lwArrow); + } // Fall through to KeepAboveIcon intended! Q_FALLTHROUGH(); @@ -295,8 +299,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool // arrow drawObject(p, CrossDiagonalLine, r.x(), center, center - r.x(), lwArrow); drawObject(p, DiagonalLine, r.x() + center, r.y() + 1, center - r.x(), lwArrow); - if (lwArrow > 1) + if (lwArrow > 1) { drawObject(p, HorizontalLine, center - (lwArrow - 2), r.y(), (lwArrow - 2) * 2, lwArrow); + } break; } @@ -307,8 +312,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool // arrow drawObject(p, DiagonalLine, r.x(), center - 2 * lwArrow, center - r.x(), lwArrow); drawObject(p, CrossDiagonalLine, r.x() + center, r.bottom() - 1 - 2 * lwArrow, center - r.x(), lwArrow); - if (lwArrow > 1) + if (lwArrow > 1) { drawObject(p, HorizontalLine, center - (lwArrow - 2), r.bottom() - (lwArrow - 1) - 2 * lwArrow, (lwArrow - 2) * 2, lwArrow); + } // Fall through to KeepBelowIcon intended! Q_FALLTHROUGH(); @@ -319,8 +325,9 @@ QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool // arrow drawObject(p, DiagonalLine, r.x(), center, center - r.x(), lwArrow); drawObject(p, CrossDiagonalLine, r.x() + center, r.bottom() - 1, center - r.x(), lwArrow); - if (lwArrow > 1) + if (lwArrow > 1) { drawObject(p, HorizontalLine, center - (lwArrow - 2), r.bottom() - (lwArrow - 1), (lwArrow - 2) * 2, lwArrow); + } break; } diff --git a/src/plugins/screencast/pipewirecore.cpp b/src/plugins/screencast/pipewirecore.cpp index 90e95cab29..33dabdbcbd 100644 --- a/src/plugins/screencast/pipewirecore.cpp +++ b/src/plugins/screencast/pipewirecore.cpp @@ -67,8 +67,9 @@ bool PipeWireCore::init() QSocketNotifier *notifier = new QSocketNotifier(pw_loop_get_fd(pwMainLoop), QSocketNotifier::Read, this); connect(notifier, &QSocketNotifier::activated, this, [this] { int result = pw_loop_iterate(pwMainLoop, 0); - if (result < 0) + if (result < 0) { qCWarning(KWIN_SCREENCAST) << "pipewire_loop_iterate failed: " << result; + } }); pwContext = pw_context_new(pwMainLoop, nullptr, 0); diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index 07d2d2d1f3..da482bea26 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -141,8 +141,9 @@ void ScreenCastStream::onStreamAddBuffer(void *data, pw_buffer *buffer) spa_data->mapoffset = 0; spa_data->flags = SPA_DATA_FLAG_READWRITE; - if (spa_data[0].type != SPA_ID_INVALID && spa_data[0].type & (1 << SPA_DATA_DmaBuf)) + if (spa_data[0].type != SPA_ID_INVALID && spa_data[0].type & (1 << SPA_DATA_DmaBuf)) { dmabuf.reset(kwinApp()->platform()->createDmaBufTexture(stream->m_resolution)); + } if (dmabuf) { spa_data->type = SPA_DATA_DmaBuf; @@ -175,8 +176,9 @@ void ScreenCastStream::onStreamAddBuffer(void *data, pw_buffer *buffer) } unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; - if (fcntl(spa_data->fd, F_ADD_SEALS, seals) == -1) + if (fcntl(spa_data->fd, F_ADD_SEALS, seals) == -1) { qCWarning(KWIN_SCREENCAST) << "memfd: Failed to add seals"; + } spa_data->data = mmap(nullptr, spa_data->maxsize, @@ -184,10 +186,11 @@ void ScreenCastStream::onStreamAddBuffer(void *data, pw_buffer *buffer) MAP_SHARED, spa_data->fd, spa_data->mapoffset); - if (spa_data->data == MAP_FAILED) + if (spa_data->data == MAP_FAILED) { qCCritical(KWIN_SCREENCAST) << "memfd: Failed to mmap memory"; - else + } else { qCDebug(KWIN_SCREENCAST) << "memfd: created successfully" << spa_data->data << spa_data->maxsize; + } #endif } } @@ -412,8 +415,9 @@ void ScreenCastStream::recordFrame(const QRegion &damagedRegion) mvp.ortho(r); shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - if (!m_cursor.texture || m_cursor.lastKey != cursor->image().cacheKey()) + if (!m_cursor.texture || m_cursor.lastKey != cursor->image().cacheKey()) { m_cursor.texture.reset(new GLTexture(cursor->image())); + } m_cursor.texture->setYInverted(false); m_cursor.texture->bind(); diff --git a/src/rootinfo_filter.cpp b/src/rootinfo_filter.cpp index 195cfe4090..e556f937f4 100644 --- a/src/rootinfo_filter.cpp +++ b/src/rootinfo_filter.cpp @@ -24,10 +24,12 @@ bool RootInfoFilter::event(xcb_generic_event_t *event) NET::Properties dirtyProtocols; NET::Properties2 dirtyProtocols2; m_rootInfo->event(event, &dirtyProtocols, &dirtyProtocols2); - if (dirtyProtocols & NET::DesktopNames) + if (dirtyProtocols & NET::DesktopNames) { VirtualDesktopManager::self()->save(); - if (dirtyProtocols2 & NET::WM2DesktopLayout) + } + if (dirtyProtocols2 & NET::WM2DesktopLayout) { VirtualDesktopManager::self()->updateLayout(); + } return false; } diff --git a/src/rules.cpp b/src/rules.cpp index fd593b776b..751d30f3d1 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -93,8 +93,9 @@ Rules::Rules(const QString &str, bool temporary) auto cfg = KSharedConfig::openConfig(file.fileName(), KConfig::SimpleConfig); RuleSettings settings(cfg, QString()); readFromSettings(&settings); - if (description.isEmpty()) + if (description.isEmpty()) { description = QStringLiteral("temporary"); + } } #define READ_MATCH_STRING(var, func) \ @@ -130,14 +131,17 @@ void Rules::readFromSettings(const RuleSettings *settings) READ_FORCE_RULE(placement, ); READ_SET_RULE(position); READ_SET_RULE(size); - if (size.isEmpty() && sizerule != static_cast(Remember)) + if (size.isEmpty() && sizerule != static_cast(Remember)) { sizerule = UnusedSetRule; + } READ_FORCE_RULE(minsize, ); - if (!minsize.isValid()) + if (!minsize.isValid()) { minsize = QSize(1, 1); + } READ_FORCE_RULE(maxsize, ); - if (maxsize.isEmpty()) + if (maxsize.isEmpty()) { maxsize = QSize(32767, 32767); + } READ_FORCE_RULE(opacityactive, ); READ_FORCE_RULE(opacityinactive, ); READ_SET_RULE(ignoregeometry); @@ -145,8 +149,9 @@ void Rules::readFromSettings(const RuleSettings *settings) READ_SET_RULE(screen); READ_SET_RULE(activity); READ_FORCE_RULE(type, static_cast); - if (type == NET::Unknown) + if (type == NET::Unknown) { typerule = UnusedForceRule; + } READ_SET_RULE(maximizevert); READ_SET_RULE(maximizehoriz); READ_SET_RULE(minimize); @@ -160,8 +165,9 @@ void Rules::readFromSettings(const RuleSettings *settings) READ_SET_RULE(noborder); READ_FORCE_RULE(decocolor, getDecoColor); - if (decocolor.isEmpty()) + if (decocolor.isEmpty()) { decocolorrule = UnusedForceRule; + } READ_FORCE_RULE(blockcompositing, ); READ_FORCE_RULE(fsplevel, ); @@ -302,8 +308,9 @@ bool Rules::isEmpty() const Rules::ForceRule Rules::convertForceRule(int v) { - if (v == DontAffect || v == Force || v == ForceTemporarily) + if (v == DontAffect || v == Force || v == ForceTemporarily) { return static_cast(v); + } return UnusedForceRule; } @@ -320,10 +327,12 @@ QString Rules::getDecoColor(const QString &themeName) bool Rules::matchType(NET::WindowType match_type) const { if (types != NET::AllTypesMask) { - if (match_type == NET::Unknown) + if (match_type == NET::Unknown) { match_type = NET::Normal; // NET::Unknown->NET::Normal is only here for matching - if (!NET::typeMatchesMask(match_type, types)) + } + if (!NET::typeMatchesMask(match_type, types)) { return false; + } } return true; } @@ -335,12 +344,15 @@ bool Rules::matchWMClass(const QByteArray &match_class, const QByteArray &match_ QByteArray cwmclass = wmclasscomplete ? match_name + ' ' + match_class : match_class; - if (wmclassmatch == RegExpMatch && !QRegularExpression(QString::fromUtf8(wmclass)).match(QString::fromUtf8(cwmclass)).hasMatch()) + if (wmclassmatch == RegExpMatch && !QRegularExpression(QString::fromUtf8(wmclass)).match(QString::fromUtf8(cwmclass)).hasMatch()) { return false; - if (wmclassmatch == ExactMatch && wmclass != cwmclass) + } + if (wmclassmatch == ExactMatch && wmclass != cwmclass) { return false; - if (wmclassmatch == SubstringMatch && !cwmclass.contains(wmclass)) + } + if (wmclassmatch == SubstringMatch && !cwmclass.contains(wmclass)) { return false; + } } return true; } @@ -348,12 +360,15 @@ bool Rules::matchWMClass(const QByteArray &match_class, const QByteArray &match_ bool Rules::matchRole(const QByteArray &match_role) const { if (windowrolematch != UnimportantMatch) { - if (windowrolematch == RegExpMatch && !QRegularExpression(QString::fromUtf8(windowrole)).match(QString::fromUtf8(match_role)).hasMatch()) + if (windowrolematch == RegExpMatch && !QRegularExpression(QString::fromUtf8(windowrole)).match(QString::fromUtf8(match_role)).hasMatch()) { return false; - if (windowrolematch == ExactMatch && windowrole != match_role) + } + if (windowrolematch == ExactMatch && windowrole != match_role) { return false; - if (windowrolematch == SubstringMatch && !match_role.contains(windowrole)) + } + if (windowrolematch == SubstringMatch && !match_role.contains(windowrole)) { return false; + } } return true; } @@ -361,12 +376,15 @@ bool Rules::matchRole(const QByteArray &match_role) const bool Rules::matchTitle(const QString &match_title) const { if (titlematch != UnimportantMatch) { - if (titlematch == RegExpMatch && !QRegularExpression(title).match(match_title).hasMatch()) + if (titlematch == RegExpMatch && !QRegularExpression(title).match(match_title).hasMatch()) { return false; - if (titlematch == ExactMatch && title != match_title) + } + if (titlematch == ExactMatch && title != match_title) { return false; - if (titlematch == SubstringMatch && !match_title.contains(title)) + } + if (titlematch == SubstringMatch && !match_title.contains(title)) { return false; + } } return true; } @@ -376,17 +394,21 @@ bool Rules::matchClientMachine(const QByteArray &match_machine, bool local) cons if (clientmachinematch != UnimportantMatch) { // if it's localhost, check also "localhost" before checking hostname if (match_machine != "localhost" && local - && matchClientMachine("localhost", true)) + && matchClientMachine("localhost", true)) { return true; + } if (clientmachinematch == RegExpMatch - && !QRegularExpression(QString::fromUtf8(clientmachine)).match(QString::fromUtf8(match_machine)).hasMatch()) + && !QRegularExpression(QString::fromUtf8(clientmachine)).match(QString::fromUtf8(match_machine)).hasMatch()) { return false; + } if (clientmachinematch == ExactMatch - && clientmachine != match_machine) + && clientmachine != match_machine) { return false; + } if (clientmachinematch == SubstringMatch - && !match_machine.contains(clientmachine)) + && !match_machine.contains(clientmachine)) { return false; + } } return true; } @@ -394,21 +416,27 @@ bool Rules::matchClientMachine(const QByteArray &match_machine, bool local) cons #ifndef KCMRULES bool Rules::match(const AbstractClient *c) const { - if (!matchType(c->windowType(true))) + if (!matchType(c->windowType(true))) { return false; - if (!matchWMClass(c->resourceClass(), c->resourceName())) + } + if (!matchWMClass(c->resourceClass(), c->resourceName())) { return false; - if (!matchRole(c->windowRole().toLower())) + } + if (!matchRole(c->windowRole().toLower())) { return false; - if (!matchClientMachine(c->clientMachine()->hostName(), c->clientMachine()->isLocal())) + } + if (!matchClientMachine(c->clientMachine()->hostName(), c->clientMachine()->isLocal())) { return false; - if (titlematch != UnimportantMatch) // track title changes to rematch rules + } + if (titlematch != UnimportantMatch) { // track title changes to rematch rules QObject::connect(c, &AbstractClient::captionChanged, c, &AbstractClient::evaluateWindowRules, // QueuedConnection, because title may change before // the client is ready (could segfault!) static_cast(Qt::QueuedConnection | Qt::UniqueConnection)); - if (!matchTitle(c->captionNormal())) + } + if (!matchTitle(c->captionNormal())) { return false; + } return true; } @@ -422,10 +450,12 @@ bool Rules::update(AbstractClient *c, int selection) if (!c->isFullScreen()) { QPoint new_pos = position; // don't use the position in the direction which is maximized - if ((c->maximizeMode() & MaximizeHorizontal) == 0) + if ((c->maximizeMode() & MaximizeHorizontal) == 0) { new_pos.setX(c->pos().x()); - if ((c->maximizeMode() & MaximizeVertical) == 0) + } + if ((c->maximizeMode() & MaximizeVertical) == 0) { new_pos.setY(c->pos().y()); + } updated = updated || position != new_pos; position = new_pos; } @@ -434,10 +464,12 @@ bool Rules::update(AbstractClient *c, int selection) if (!c->isFullScreen()) { QSize new_size = size; // don't use the position in the direction which is maximized - if ((c->maximizeMode() & MaximizeHorizontal) == 0) + if ((c->maximizeMode() & MaximizeHorizontal) == 0) { new_size.setWidth(c->size().width()); - if ((c->maximizeMode() & MaximizeVertical) == 0) + } + if ((c->maximizeMode() & MaximizeVertical) == 0) { new_size.setHeight(c->size().height()); + } updated = updated || size != new_size; size = new_size; } @@ -543,15 +575,17 @@ bool Rules::applyGeometry(QRect &rect, bool init) const bool Rules::applyPosition(QPoint &pos, bool init) const { - if (this->position != invalidPoint && checkSetRule(positionrule, init)) + if (this->position != invalidPoint && checkSetRule(positionrule, init)) { pos = this->position; + } return checkSetStop(positionrule); } bool Rules::applySize(QSize &s, bool init) const { - if (this->size.isValid() && checkSetRule(sizerule, init)) + if (this->size.isValid() && checkSetRule(sizerule, init)) { s = this->size; + } return checkSetStop(sizerule); } @@ -580,15 +614,17 @@ bool Rules::applyDesktops(QVector &vds, bool init) const bool Rules::applyMaximizeHoriz(MaximizeMode &mode, bool init) const { - if (checkSetRule(maximizehorizrule, init)) + if (checkSetRule(maximizehorizrule, init)) { mode = static_cast((maximizehoriz ? MaximizeHorizontal : 0) | (mode & MaximizeVertical)); + } return checkSetStop(maximizehorizrule); } bool Rules::applyMaximizeVert(MaximizeMode &mode, bool init) const { - if (checkSetRule(maximizevertrule, init)) + if (checkSetRule(maximizevertrule, init)) { mode = static_cast((maximizevert ? MaximizeVertical : 0) | (mode & MaximizeHorizontal)); + } return checkSetStop(maximizevertrule); } @@ -597,10 +633,12 @@ APPLY_RULE(minimize, Minimize, bool) bool Rules::applyShade(ShadeMode &sh, bool init) const { if (checkSetRule(shaderule, init)) { - if (!this->shade) + if (!this->shade) { sh = ShadeNone; - if (this->shade && sh == ShadeNone) + } + if (this->shade && sh == ShadeNone) { sh = ShadeNormal; + } } return checkSetStop(shaderule); } @@ -636,8 +674,9 @@ bool Rules::isTemporary() const bool Rules::discardTemporary(bool force) { - if (temporary_state == 0) // not temporary + if (temporary_state == 0) { // not temporary return false; + } if (force || --temporary_state == 0) { // too old delete this; return true; @@ -718,9 +757,9 @@ void WindowRules::discardTemporary() QVector::Iterator it2 = rules.begin(); for (QVector::Iterator it = rules.begin(); it != rules.end();) { - if ((*it)->discardTemporary(true)) + if ((*it)->discardTemporary(true)) { ++it; - else { + } else { *it2++ = *it++; } } @@ -732,11 +771,14 @@ void WindowRules::update(AbstractClient *c, int selection) bool updated = false; for (QVector::ConstIterator it = rules.constBegin(); it != rules.constEnd(); - ++it) - if ((*it)->update(c, selection)) // no short-circuiting here + ++it) { + if ((*it)->update(c, selection)) { // no short-circuiting here updated = true; - if (updated) + } + } + if (updated) { RuleBook::self()->requestDiskStorage(); + } } #define CHECK_RULE(rule, type) \ @@ -868,10 +910,11 @@ void AbstractClient::applyWindowRules() // Type maximize(maximizeMode()); // Minimize : functions don't check, and there are two functions - if (client_rules->checkMinimize(isMinimized())) + if (client_rules->checkMinimize(isMinimized())) { minimize(); - else + } else { unminimize(); + } setShade(shadeMode()); setOriginalSkipTaskbar(skipTaskbar()); setSkipPager(skipPager()); @@ -884,8 +927,9 @@ void AbstractClient::applyWindowRules() // FSP // AcceptFocus : if (workspace()->mostRecentlyActivatedClient() == this - && !client_rules->checkAcceptFocus(true)) + && !client_rules->checkAcceptFocus(true)) { workspace()->activateNextClient(this); + } // Autogrouping : Only checked on window manage // AutogroupInForeground : Only checked on window manage // AutogroupById : Only checked on window manage @@ -895,22 +939,25 @@ void AbstractClient::applyWindowRules() if (isActive()) { setOpacity(rules()->checkOpacityActive(qRound(opacity() * 100.0)) / 100.0); workspace()->disableGlobalShortcutsForClient(rules()->checkDisableGlobalShortcuts(false)); - } else + } else { setOpacity(rules()->checkOpacityInactive(qRound(opacity() * 100.0)) / 100.0); + } setDesktopFileName(rules()->checkDesktopFile(desktopFileName()).toUtf8()); } void X11Client::updateWindowRules(Rules::Types selection) { - if (!isManaged()) // not fully setup yet + if (!isManaged()) { // not fully setup yet return; + } AbstractClient::updateWindowRules(selection); } void AbstractClient::updateWindowRules(Rules::Types selection) { - if (RuleBook::self()->areUpdatesDisabled()) + if (RuleBook::self()->areUpdatesDisabled()) { return; + } m_rules.update(this, selection); } @@ -976,10 +1023,11 @@ WindowRules RuleBook::find(const AbstractClient *c, bool ignore_temporary) if ((*it)->match(c)) { Rules *rule = *it; qCDebug(KWIN_CORE) << "Rule found:" << rule << ":" << c; - if (rule->isTemporary()) + if (rule->isTemporary()) { it = m_rules.erase(it); - else + } else { ++it; + } ret.append(rule); continue; } @@ -993,8 +1041,9 @@ void RuleBook::edit(AbstractClient *c, bool whole_app) save(); QStringList args; args << QStringLiteral("--uuid") << c->internalId().toString(); - if (whole_app) + if (whole_app) { args << QStringLiteral("--whole-app"); + } QProcess *p = new QProcess(this); p->setArguments(args); p->setProcessEnvironment(kwinApp()->processStartupEnvironment()); @@ -1046,13 +1095,16 @@ void RuleBook::temporaryRulesMessage(const QString &message) bool was_temporary = false; for (QList::ConstIterator it = m_rules.constBegin(); it != m_rules.constEnd(); - ++it) - if ((*it)->isTemporary()) + ++it) { + if ((*it)->isTemporary()) { was_temporary = true; + } + } Rules *rule = new Rules(message, true); m_rules.prepend(rule); // highest priority first - if (!was_temporary) + if (!was_temporary) { QTimer::singleShot(60000, this, &RuleBook::cleanupTemporaryRules); + } } void RuleBook::cleanupTemporaryRules() @@ -1063,13 +1115,15 @@ void RuleBook::cleanupTemporaryRules() if ((*it)->discardTemporary(false)) { // deletes (*it) it = m_rules.erase(it); } else { - if ((*it)->isTemporary()) + if ((*it)->isTemporary()) { has_temporary = true; + } ++it; } } - if (has_temporary) + if (has_temporary) { QTimer::singleShot(60000, this, &RuleBook::cleanupTemporaryRules); + } } void RuleBook::discardUsed(AbstractClient *c, bool withdrawn) @@ -1091,8 +1145,9 @@ void RuleBook::discardUsed(AbstractClient *c, bool withdrawn) } ++it; } - if (updated) + if (updated) { requestDiskStorage(); + } } void RuleBook::requestDiskStorage() diff --git a/src/rules.h b/src/rules.h index dbea8e4c1f..75dd712d5f 100644 --- a/src/rules.h +++ b/src/rules.h @@ -342,8 +342,9 @@ inline bool Rules::checkSetRule(SetRule rule, bool init) { if (rule > (SetRule)DontAffect) { // Unused or DontAffect if (rule == (SetRule)Force || rule == (SetRule)ApplyNow - || rule == (SetRule)ForceTemporarily || init) + || rule == (SetRule)ForceTemporarily || init) { return true; + } } return false; } diff --git a/src/scene.cpp b/src/scene.cpp index d5ed0d566d..7c1803940c 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -641,8 +641,9 @@ void Scene::clearStackingOrder() void Scene::paintWindow(Window *w, int mask, const QRegion ®ion) { - if (region.isEmpty()) // completely clipped + if (region.isEmpty()) { // completely clipped return; + } WindowPaintData data(w->window()->effectWindow(), screenProjectionMatrix()); effects->paintWindow(effectWindow(w), mask, region, data); @@ -795,14 +796,18 @@ QRegion Scene::Window::decorationShape() const bool Scene::Window::isVisible() const { - if (toplevel->isDeleted()) + if (toplevel->isDeleted()) { return false; - if (!toplevel->isOnCurrentDesktop()) + } + if (!toplevel->isOnCurrentDesktop()) { return false; - if (!toplevel->isOnCurrentActivity()) + } + if (!toplevel->isOnCurrentActivity()) { return false; - if (AbstractClient *c = dynamic_cast(toplevel)) + } + if (AbstractClient *c = dynamic_cast(toplevel)) { return c->isShown(); + } return true; // Unmanaged is always visible } @@ -819,21 +824,25 @@ bool Scene::Window::isPaintingEnabled() const void Scene::Window::resetPaintingEnabled() { disable_painting = 0; - if (toplevel->isDeleted()) + if (toplevel->isDeleted()) { disable_painting |= PAINT_DISABLED_BY_DELETE; + } if (static_cast(effects)->isDesktopRendering()) { if (!toplevel->isOnDesktop(static_cast(effects)->currentRenderedDesktop())) { disable_painting |= PAINT_DISABLED_BY_DESKTOP; } } else { - if (!toplevel->isOnCurrentDesktop()) + if (!toplevel->isOnCurrentDesktop()) { disable_painting |= PAINT_DISABLED_BY_DESKTOP; + } } - if (!toplevel->isOnCurrentActivity()) + if (!toplevel->isOnCurrentActivity()) { disable_painting |= PAINT_DISABLED_BY_ACTIVITY; + } if (AbstractClient *c = dynamic_cast(toplevel)) { - if (c->isMinimized()) + if (c->isMinimized()) { disable_painting |= PAINT_DISABLED_BY_MINIMIZE; + } if (c->isHiddenInternal()) { disable_painting |= PAINT_DISABLED; } diff --git a/src/scenes/opengl/lanczosfilter.cpp b/src/scenes/opengl/lanczosfilter.cpp index 2f909f35b2..edb75b4fce 100644 --- a/src/scenes/opengl/lanczosfilter.cpp +++ b/src/scenes/opengl/lanczosfilter.cpp @@ -46,27 +46,32 @@ LanczosFilter::~LanczosFilter() void LanczosFilter::init() { - if (m_inited) + if (m_inited) { return; + } m_inited = true; const bool force = (qstrcmp(qgetenv("KWIN_FORCE_LANCZOS"), "1") == 0); if (force) { qCWarning(KWIN_OPENGL) << "Lanczos Filter forced on by environment variable"; } - if (!force && options->glSmoothScale() != 2) + if (!force && options->glSmoothScale() != 2) { return; // disabled by config - if (!GLRenderTarget::supported()) + } + if (!GLRenderTarget::supported()) { return; + } GLPlatform *gl = GLPlatform::instance(); if (!force) { // The lanczos filter is reported to be broken with the Intel driver prior SandyBridge - if (gl->driver() == Driver_Intel && gl->chipClass() < SandyBridge) + if (gl->driver() == Driver_Intel && gl->chipClass() < SandyBridge) { return; + } // also radeon before R600 has trouble - if (gl->isRadeon() && gl->chipClass() < R600) + if (gl->isRadeon() && gl->chipClass() < R600) { return; + } // and also for software emulation (e.g. llvmpipe) if (gl->isSoftwareEmulation()) { return; @@ -109,11 +114,13 @@ static float sinc(float x) static float lanczos(float x, float a) { - if (qFuzzyCompare(x + 1.0, 1.0)) + if (qFuzzyCompare(x + 1.0, 1.0)) { return 1.0; + } - if (qAbs(x) >= a) + if (qAbs(x) >= a) { return 0.0; + } return sinc(x) * sinc(x / a); } @@ -160,8 +167,9 @@ void LanczosFilter::createOffsets(int count, float width, Qt::Orientation direct void LanczosFilter::performPaint(EffectWindowImpl *w, int mask, QRegion region, WindowPaintData &data) { if (data.xScale() < 0.9 || data.yScale() < 0.9) { - if (!m_inited) + if (!m_inited) { init(); + } const QRect screenRect = Workspace::self()->clientArea(ScreenArea, w->window()); // window geometry may not be bigger than screen geometry to fit into the FBO QRect winGeo(w->expandedGeometry()); diff --git a/src/scenes/opengl/scene_opengl.cpp b/src/scenes/opengl/scene_opengl.cpp index 3f4cb4b51f..39fbc97242 100644 --- a/src/scenes/opengl/scene_opengl.cpp +++ b/src/scenes/opengl/scene_opengl.cpp @@ -108,15 +108,17 @@ QMatrix4x4 SceneOpenGL::transformation(int mask, const ScreenPaintData &data) co { QMatrix4x4 matrix; - if (!(mask & PAINT_SCREEN_TRANSFORMED)) + if (!(mask & PAINT_SCREEN_TRANSFORMED)) { return matrix; + } matrix.translate(data.translation()); const QVector3D scale = data.scale(); matrix.scale(scale.x(), scale.y(), scale.z()); - if (data.rotationAngle() == 0.0) + if (data.rotationAngle() == 0.0) { return matrix; + } // Apply the rotation // cannot use data.rotation->applyTo(&matrix) as QGraphicsRotation uses projectedRotate to map back to 2D @@ -323,8 +325,9 @@ void SceneOpenGL::performPaintWindow(EffectWindowImpl *w, int mask, const QRegio m_lanczosFilter = new LanczosFilter(this); } m_lanczosFilter->performPaint(w, mask, region, data); - } else + } else { w->sceneWindow()->performPaint(mask, region, data); + } } //**************************************** @@ -351,10 +354,11 @@ QVector4D OpenGLWindow::modulate(float opacity, float brightness) const void OpenGLWindow::setBlendEnabled(bool enabled) { - if (enabled && !m_blendingEnabled) + if (enabled && !m_blendingEnabled) { glEnable(GL_BLEND); - else if (!enabled && m_blendingEnabled) + } else if (!enabled && m_blendingEnabled) { glDisable(GL_BLEND); + } m_blendingEnabled = enabled; } @@ -505,14 +509,16 @@ QMatrix4x4 OpenGLWindow::modelViewProjectionMatrix(int mask, const WindowPaintDa // the same dimensions as the default framebuffer. // // Note that the screen transformation is not applied here. - if (!pMatrix.isIdentity()) + if (!pMatrix.isIdentity()) { return pMatrix * mvMatrix; + } // If an effect has specified a model-view matrix, we multiply that matrix // with the default projection matrix. If the effect hasn't specified a // model-view matrix, mvMatrix will be the identity matrix. - if (mask & Scene::PAINT_SCREEN_TRANSFORMED) + if (mask & Scene::PAINT_SCREEN_TRANSFORMED) { return m_scene->screenProjectionMatrix() * mvMatrix; + } return m_scene->renderTargetProjectionMatrix() * mvMatrix; } @@ -574,11 +580,13 @@ void OpenGLWindow::performPaint(int mask, const QRegion ®ion, const WindowPai if (!shader) { ShaderTraits traits = ShaderTrait::MapTexture; - if (data.opacity() != 1.0 || data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) + if (data.opacity() != 1.0 || data.brightness() != 1.0 || data.crossFadeProgress() != 1.0) { traits |= ShaderTrait::Modulate; + } - if (data.saturation() != 1.0) + if (data.saturation() != 1.0) { traits |= ShaderTrait::AdjustSaturation; + } shader = ShaderManager::instance()->pushShader(traits); } @@ -606,8 +614,9 @@ void OpenGLWindow::performPaint(int mask, const QRegion ®ion, const WindowPai for (int i = 0, v = 0; i < renderContext.renderNodes.count(); i++) { RenderNode &renderNode = renderContext.renderNodes[i]; - if (renderNode.quads.isEmpty() || !renderNode.texture) + if (renderNode.quads.isEmpty() || !renderNode.texture) { continue; + } renderNode.firstVertex = v; renderNode.vertexCount = renderNode.quads.count() * verticesPerQuad; @@ -635,8 +644,9 @@ void OpenGLWindow::performPaint(int mask, const QRegion ®ion, const WindowPai const QMatrix4x4 modelViewProjection = modelViewProjectionMatrix(mask, data); for (int i = 0; i < renderContext.renderNodes.count(); i++) { const RenderNode &renderNode = renderContext.renderNodes[i]; - if (renderNode.vertexCount == 0) + if (renderNode.vertexCount == 0) { continue; + } setBlendEnabled(renderNode.hasAlpha || renderNode.opacity < 1.0); @@ -660,8 +670,9 @@ void OpenGLWindow::performPaint(int mask, const QRegion ®ion, const WindowPai setBlendEnabled(false); - if (!data.shader) + if (!data.shader) { ShaderManager::instance()->popShader(); + } if (renderContext.hardwareClipping) { glDisable(GL_SCISSOR_TEST); @@ -758,8 +769,9 @@ void SceneOpenGL::EffectFrame::crossFadeText() void SceneOpenGL::EffectFrame::render(const QRegion &_region, double opacity, double frameOpacity) { - if (m_effectFrame->geometry().isEmpty()) + if (m_effectFrame->geometry().isEmpty()) { return; // Nothing to display + } Q_UNUSED(_region); // TODO: Old region doesn't seem to work with OpenGL @@ -906,8 +918,9 @@ void SceneOpenGL::EffectFrame::render(const QRegion &_region, double opacity, do m_unstyledVBO->render(GL_TRIANGLES); m_unstyledTexture->unbind(); } else if (m_effectFrame->style() == EffectFrameStyled) { - if (!m_texture) // Lazy creation + if (!m_texture) { // Lazy creation updateTexture(); + } if (shader) { const float a = opacity * frameOpacity; @@ -928,8 +941,9 @@ void SceneOpenGL::EffectFrame::render(const QRegion &_region, double opacity, do if (!m_effectFrame->selection().isNull()) { if (!m_selectionTexture) { // Lazy creation QPixmap pixmap = m_effectFrame->selectionFrame().framePixmap(); - if (!pixmap.isNull()) + if (!pixmap.isNull()) { m_selectionTexture = new GLTexture(pixmap); + } } if (m_selectionTexture) { if (shader) { @@ -1008,8 +1022,9 @@ void SceneOpenGL::EffectFrame::render(const QRegion &_region, double opacity, do shader->setUniform(GLShader::ModulationConstant, constant); } } - if (!m_textTexture) // Lazy creation + if (!m_textTexture) { // Lazy creation updateTextTexture(); + } if (m_textTexture) { m_textTexture->bind(); @@ -1041,13 +1056,15 @@ void SceneOpenGL::EffectFrame::updateTextTexture() delete m_textPixmap; m_textPixmap = nullptr; - if (m_effectFrame->text().isEmpty()) + if (m_effectFrame->text().isEmpty()) { return; + } // Determine position on texture to paint text QRect rect(QPoint(0, 0), m_effectFrame->geometry().size()); - if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) + if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) { rect.setLeft(m_effectFrame->iconSize().width()); + } // If static size elide text as required QString text = m_effectFrame->text(); @@ -1060,10 +1077,11 @@ void SceneOpenGL::EffectFrame::updateTextTexture() m_textPixmap->fill(Qt::transparent); QPainter p(m_textPixmap); p.setFont(m_effectFrame->font()); - if (m_effectFrame->style() == EffectFrameStyled) + if (m_effectFrame->style() == EffectFrameStyled) { p.setPen(m_effectFrame->styledTextColor()); - else // TODO: What about no frame? Custom color setting required + } else { // TODO: What about no frame? Custom color setting required p.setPen(Qt::white); + } p.drawText(rect, m_effectFrame->alignment(), text); p.end(); m_textTexture = new GLTexture(*m_textPixmap); @@ -1245,8 +1263,9 @@ bool SceneOpenGLShadow::prepareBackend() uint8_t *const dst = reinterpret_cast(alphaImage.scanLine(y)); for (ptrdiff_t x = 0; x < image.width(); x++) { - if (src[x] & 0x00ffffff) + if (src[x] & 0x00ffffff) { alphaOnly = false; + } dst[x] = qAlpha(src[x]); } @@ -1460,8 +1479,9 @@ void SceneOpenGLDecorationRenderer::resizeTexture() size.rwidth() += 2 * TexturePad; size.rwidth() = align(size.width(), 128); - if (m_texture && m_texture->size() == size) + if (m_texture && m_texture->size() == size) { return; + } if (!size.isEmpty()) { m_texture.reset(new GLTexture(GL_RGBA8, size.width(), size.height())); diff --git a/src/scenes/qpainter/scene_qpainter.cpp b/src/scenes/qpainter/scene_qpainter.cpp index 25bbeaf417..6bebc8448b 100644 --- a/src/scenes/qpainter/scene_qpainter.cpp +++ b/src/scenes/qpainter/scene_qpainter.cpp @@ -137,11 +137,13 @@ void SceneQPainter::Window::performPaint(int mask, const QRegion &_region, const QRegion region = _region; const QRect boundingRect = windowItem()->mapToGlobal(windowItem()->boundingRect()); - if (!(mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED))) + if (!(mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED))) { region &= boundingRect; + } - if (region.isEmpty()) + if (region.isEmpty()) { return; + } QPainter *scenePainter = m_scene->scenePainter(); QPainter *painter = scenePainter; diff --git a/src/screenedge.cpp b/src/screenedge.cpp index cb8a4dc5ec..a0f1dde0c8 100644 --- a/src/screenedge.cpp +++ b/src/screenedge.cpp @@ -502,8 +502,9 @@ void Edge::switchDesktop(const QPoint &cursorPos) void Edge::pushCursorBack(const QPoint &cursorPos) { - if (m_pushBackBlocked) + if (m_pushBackBlocked) { return; + } int x = cursorPos.x(); int y = cursorPos.y(); const QSize &distance = edges()->cursorPushBackDistance(); @@ -1261,8 +1262,9 @@ ElectricBorderAction ScreenEdges::actionForTouchEdge(Edge *edge) const void ScreenEdges::reserveDesktopSwitching(bool isToReserve, Qt::Orientations o) { - if (!o) + if (!o) { return; + } for (auto it = m_edges.begin(); it != m_edges.end(); ++it) { Edge *edge = *it; if (edge->isCorner()) { @@ -1313,8 +1315,9 @@ void ScreenEdges::reserve(AbstractClient *client, ElectricBorder border) if (border != ElectricNone) { createEdgeForClient(client, border); } else { - if (hadBorder) // show again + if (hadBorder) { // show again client->showOnScreenEdge(); + } } } diff --git a/src/scripting/scriptedeffect.cpp b/src/scripting/scriptedeffect.cpp index 2bbdbd25dd..eb3e0159f1 100644 --- a/src/scripting/scriptedeffect.cpp +++ b/src/scripting/scriptedeffect.cpp @@ -428,10 +428,11 @@ quint64 ScriptedEffect::animate(KWin::EffectWindow *window, KWin::AnimationEffec int delay, bool fullScreen, bool keepAlive) { QEasingCurve qec; - if (curve < QEasingCurve::Custom) + if (curve < QEasingCurve::Custom) { qec.setType(static_cast(curve)); - else if (curve == GaussianCurve) + } else if (curve == GaussianCurve) { qec.setCustomType(qecGaussian); + } return AnimationEffect::animate(window, attribute, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from), fullScreen, keepAlive); } @@ -446,10 +447,11 @@ quint64 ScriptedEffect::set(KWin::EffectWindow *window, KWin::AnimationEffect::A int delay, bool fullScreen, bool keepAlive) { QEasingCurve qec; - if (curve < QEasingCurve::Custom) + if (curve < QEasingCurve::Custom) { qec.setType(static_cast(curve)); - else if (curve == GaussianCurve) + } else if (curve == GaussianCurve) { qec.setCustomType(qecGaussian); + } return AnimationEffect::set(window, attribute, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from), fullScreen, keepAlive); } diff --git a/src/scripting/workspace_wrapper.cpp b/src/scripting/workspace_wrapper.cpp index 0c8efe1caa..d14ee93799 100644 --- a/src/scripting/workspace_wrapper.cpp +++ b/src/scripting/workspace_wrapper.cpp @@ -308,8 +308,9 @@ void WorkspaceWrapper::setupClientConnections(AbstractClient *client) this, &WorkspaceWrapper::clientMaximizeSet); X11Client *x11Client = qobject_cast(client); // TODO: Drop X11-specific signals. - if (!x11Client) + if (!x11Client) { return; + } connect(x11Client, &X11Client::clientManaging, this, &WorkspaceWrapper::clientManaging); connect(x11Client, &X11Client::clientFullScreenSet, this, &WorkspaceWrapper::clientFullScreenSet); diff --git a/src/sm.cpp b/src/sm.cpp index 5032196ddf..db7ce84588 100644 --- a/src/sm.cpp +++ b/src/sm.cpp @@ -52,10 +52,12 @@ static const char *const window_type_names[] = { static const char *windowTypeToTxt(NET::WindowType type) { - if (type >= NET::Unknown && type <= NET::Splash) + if (type >= NET::Unknown && type <= NET::Splash) { return window_type_names[type + 1]; // +1 (unknown==-1) - if (type == -2) // undefined (not really part of NET::WindowType) + } + if (type == -2) { // undefined (not really part of NET::WindowType) return "Undefined"; + } qFatal("Unknown Window Type"); return nullptr; } @@ -64,9 +66,11 @@ static NET::WindowType txtToWindowType(const char *txt) { for (int i = NET::Unknown; i <= NET::Splash; - ++i) - if (qstrcmp(txt, window_type_names[i + 1]) == 0) // +1 + ++i) { + if (qstrcmp(txt, window_type_names[i + 1]) == 0) { // +1 return static_cast(i); + } + } return static_cast(-2); // undefined } @@ -93,16 +97,20 @@ void Workspace::storeSession(const QString &sessionName, SMSavePhase phase) } QByteArray sessionId = c->sessionId(); QByteArray wmCommand = c->wmCommand(); - if (sessionId.isEmpty()) + if (sessionId.isEmpty()) { // remember also applications that are not XSMP capable // and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF - if (wmCommand.isEmpty()) + if (wmCommand.isEmpty()) { continue; + } + } count++; - if (c->isActive()) + if (c->isActive()) { active_client = count; - if (phase == SMSavePhase2 || phase == SMSavePhase2Full) + } + if (phase == SMSavePhase2 || phase == SMSavePhase2Full) { storeClient(cg, count, c); + } } if (phase == SMSavePhase0) { // it would be much simpler to save these values to the config file, @@ -171,18 +179,22 @@ void Workspace::storeSubSession(const QString &name, QSet sessionIds } QByteArray sessionId = c->sessionId(); QByteArray wmCommand = c->wmCommand(); - if (sessionId.isEmpty()) + if (sessionId.isEmpty()) { // remember also applications that are not XSMP capable // and use the obsolete WM_COMMAND / WM_SAVE_YOURSELF - if (wmCommand.isEmpty()) + if (wmCommand.isEmpty()) { continue; - if (!sessionIds.contains(sessionId)) + } + } + if (!sessionIds.contains(sessionId)) { continue; + } qCDebug(KWIN_CORE) << "storing" << sessionId; count++; - if (c->isActive()) + if (c->isActive()) { active_client = count; + } storeClient(cg, count, c); } cg.writeEntry("count", count); @@ -277,8 +289,9 @@ SessionInfo *Workspace::takeSessionInfo(X11Client *c) if (!sessionId.isEmpty()) { // look for a real session managed client (algorithm suggested by ICCCM) for (SessionInfo *info : qAsConst(session)) { - if (realInfo) + if (realInfo) { break; + } if (info->sessionId == sessionId && sessionInfoWindowTypeMatch(c, info)) { if (!windowRole.isEmpty()) { if (info->windowRole == windowRole) { @@ -298,8 +311,9 @@ SessionInfo *Workspace::takeSessionInfo(X11Client *c) } else { // look for a sessioninfo with matching features. for (SessionInfo *info : qAsConst(session)) { - if (realInfo) + if (realInfo) { break; + } if (info->resourceName == resourceName && info->resourceClass == resourceClass && sessionInfoWindowTypeMatch(c, info)) { diff --git a/src/tabbox/clientmodel.cpp b/src/tabbox/clientmodel.cpp index 0e8c92cd18..64d3f94e75 100644 --- a/src/tabbox/clientmodel.cpp +++ b/src/tabbox/clientmodel.cpp @@ -35,16 +35,18 @@ ClientModel::~ClientModel() QVariant ClientModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) + if (!index.isValid()) { return QVariant(); + } if (m_clientList.isEmpty()) { return QVariant(); } int clientIndex = index.row(); - if (clientIndex >= m_clientList.count()) + if (clientIndex >= m_clientList.count()) { return QVariant(); + } QSharedPointer client = m_clientList[clientIndex].toStrongRef(); if (!client) { return QVariant(); @@ -118,8 +120,9 @@ QModelIndex ClientModel::index(int row, int column, const QModelIndex &parent) c return QModelIndex(); } int index = row * columnCount(); - if (index >= m_clientList.count() && !m_clientList.isEmpty()) + if (index >= m_clientList.count() && !m_clientList.isEmpty()) { return QModelIndex(); + } return createIndex(row, 0); } @@ -137,8 +140,9 @@ QHash ClientModel::roleNames() const QModelIndex ClientModel::index(QWeakPointer client) const { - if (!m_clientList.contains(client)) + if (!m_clientList.contains(client)) { return QModelIndex(); + } int index = m_clientList.indexOf(client); int row = index / columnCount(); int column = index % columnCount(); @@ -199,8 +203,9 @@ void ClientModel::createClientList(int desktop, bool partialReset) if (start == add.data()) { m_clientList.removeAll(add); m_clientList.prepend(add); - } else + } else { m_clientList += add; + } if (add.data()->isFirstInTabBox()) { stickyClients << add; } @@ -211,8 +216,9 @@ void ClientModel::createClientList(int desktop, bool partialReset) c = stacking[++index]; } - if (c == stop) + if (c == stop) { break; + } } break; } @@ -224,8 +230,9 @@ void ClientModel::createClientList(int desktop, bool partialReset) if (tabBox->config().clientApplicationsMode() != TabBoxConfig::AllWindowsCurrentApplication && (tabBox->config().showDesktopMode() == TabBoxConfig::ShowDesktopClient || m_clientList.isEmpty())) { QWeakPointer desktopClient = tabBox->desktopClient(); - if (!desktopClient.isNull()) + if (!desktopClient.isNull()) { m_clientList.append(desktopClient); + } } endResetModel(); } diff --git a/src/tabbox/desktopmodel.cpp b/src/tabbox/desktopmodel.cpp index d441399ced..1e2d2d68a5 100644 --- a/src/tabbox/desktopmodel.cpp +++ b/src/tabbox/desktopmodel.cpp @@ -31,8 +31,9 @@ DesktopModel::~DesktopModel() QVariant DesktopModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.column() != 0) + if (!index.isValid() || index.column() != 0) { return QVariant(); + } if (index.parent().isValid()) { // parent is valid -> access to Client @@ -41,8 +42,9 @@ QVariant DesktopModel::data(const QModelIndex &index, int role) const } const int desktopIndex = index.row(); - if (desktopIndex >= m_desktopList.count()) + if (desktopIndex >= m_desktopList.count()) { return QVariant(); + } switch (role) { case Qt::DisplayRole: case DesktopNameRole: @@ -118,8 +120,9 @@ QModelIndex DesktopModel::index(int row, int column, const QModelIndex &parent) } return createIndex(row, column, parent.row() + 1); } - if (row > m_desktopList.count() || m_desktopList.isEmpty()) + if (row > m_desktopList.count() || m_desktopList.isEmpty()) { return QModelIndex(); + } return createIndex(row, column); } @@ -135,8 +138,9 @@ QHash DesktopModel::roleNames() const QModelIndex DesktopModel::desktopIndex(int desktop) const { - if (desktop > m_desktopList.count()) + if (desktop > m_desktopList.count()) { return QModelIndex(); + } return createIndex(m_desktopList.indexOf(desktop), 0); } diff --git a/src/tabbox/switcheritem.cpp b/src/tabbox/switcheritem.cpp index ad57ff52a2..79f97e4e1a 100644 --- a/src/tabbox/switcheritem.cpp +++ b/src/tabbox/switcheritem.cpp @@ -63,8 +63,9 @@ void SwitcherItem::setVisible(bool visible) if (m_visible == visible) { return; } - if (visible) + if (visible) { Q_EMIT screenGeometryChanged(); + } m_visible = visible; Q_EMIT visibleChanged(); } diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index 4ec43e4bb7..8f01f7ceee 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -94,8 +94,9 @@ int TabBoxHandlerImpl::currentDesktop() const QString TabBoxHandlerImpl::desktopName(TabBoxClient *client) const { if (TabBoxClientImpl *c = static_cast(client)) { - if (!c->client()->isOnAllDesktops()) + if (!c->client()->isOnAllDesktops()) { return desktopName(c->client()->desktop()); + } } return desktopName(VirtualDesktopManager::self()->current()); } @@ -110,8 +111,9 @@ QWeakPointer TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient { if (TabBoxClientImpl *c = static_cast(client)) { auto next = FocusChain::self()->nextMostRecentlyUsed(c->client()); - if (next) + if (next) { return qWeakPointerCast(next->tabBoxClient()); + } } return QWeakPointer(); } @@ -145,10 +147,11 @@ int TabBoxHandlerImpl::numberOfDesktops() const QWeakPointer TabBoxHandlerImpl::activeClient() const { - if (Workspace::self()->activeClient()) + if (Workspace::self()->activeClient()) { return qWeakPointerCast(Workspace::self()->activeClient()->tabBoxClient()); - else + } else { return QWeakPointer(); + } } bool TabBoxHandlerImpl::checkDesktop(TabBoxClient *client, int desktop) const @@ -260,18 +263,19 @@ QWeakPointer TabBoxHandlerImpl::clientToAddToList(TabBoxClient *cl if (addClient) { // don't add windows that have modal dialogs AbstractClient *modal = current->findModal(); - if (modal == nullptr || modal == current) + if (modal == nullptr || modal == current) { ret = current; - else if (!clientList().contains(qWeakPointerCast(modal->tabBoxClient()))) + } else if (!clientList().contains(qWeakPointerCast(modal->tabBoxClient()))) { ret = modal; - else { + } else { // nothing } } - if (ret) + if (ret) { return qWeakPointerCast(ret->tabBoxClient()); - else + } else { return QWeakPointer(); + } } TabBoxClientList TabBoxHandlerImpl::stackingOrder() const @@ -306,18 +310,20 @@ void TabBoxHandlerImpl::elevateClient(TabBoxClient *c, QWindow *tabbox, bool b) { auto cl = static_cast(c)->client(); cl->elevate(b); - if (Toplevel *w = Workspace::self()->findInternal(tabbox)) + if (Toplevel *w = Workspace::self()->findInternal(tabbox)) { w->elevate(b); + } } void TabBoxHandlerImpl::shadeClient(TabBoxClient *c, bool b) const { AbstractClient *client = static_cast(c)->client(); client->cancelShadeHoverTimer(); // stop core shading action - if (!b && client->shadeMode() == ShadeNormal) + if (!b && client->shadeMode() == ShadeNormal) { client->setShade(ShadeHover); - else if (b && client->shadeMode() == ShadeHover) + } else if (b && client->shadeMode() == ShadeHover) { client->setShade(ShadeNormal); + } } QWeakPointer TabBoxHandlerImpl::desktopClient() const @@ -373,9 +379,10 @@ TabBoxClientImpl::~TabBoxClientImpl() QString TabBoxClientImpl::caption() const { - if (m_client->isDesktop()) + if (m_client->isDesktop()) { return i18nc("Special entry in alt+tab list for minimizing all windows", "Show Desktop"); + } return m_client->caption(); } @@ -615,22 +622,26 @@ void TabBox::reset(bool partial_reset) case TabBoxConfig::ClientTabBox: m_tabBox->createModel(partial_reset); if (!partial_reset) { - if (Workspace::self()->activeClient()) + if (Workspace::self()->activeClient()) { setCurrentClient(Workspace::self()->activeClient()); + } // it's possible that the active client is not part of the model // in that case the index is invalid - if (!m_tabBox->currentIndex().isValid()) + if (!m_tabBox->currentIndex().isValid()) { setCurrentIndex(m_tabBox->first()); + } } else { - if (!m_tabBox->currentIndex().isValid() || !m_tabBox->client(m_tabBox->currentIndex())) + if (!m_tabBox->currentIndex().isValid() || !m_tabBox->client(m_tabBox->currentIndex())) { setCurrentIndex(m_tabBox->first()); + } } break; case TabBoxConfig::DesktopTabBox: m_tabBox->createModel(); - if (!partial_reset) + if (!partial_reset) { setCurrentDesktop(VirtualDesktopManager::self()->current()); + } break; } @@ -646,11 +657,13 @@ void TabBox::nextPrev(bool next) AbstractClient *TabBox::currentClient() { if (TabBoxClientImpl *client = static_cast(m_tabBox->client(m_tabBox->currentIndex()))) { - if (!Workspace::self()->hasClient(client->client())) + if (!Workspace::self()->hasClient(client->client())) { return nullptr; + } return client->client(); - } else + } else { return nullptr; + } } QList TabBox::currentClientList() @@ -659,10 +672,12 @@ QList TabBox::currentClientList() QList ret; for (const QWeakPointer &clientPointer : list) { QSharedPointer client = clientPointer.toStrongRef(); - if (!client) + if (!client) { continue; - if (const TabBoxClientImpl *c = static_cast(client.data())) + } + if (const TabBoxClientImpl *c = static_cast(client.data())) { ret.append(c->client()); + } } return ret; } @@ -689,8 +704,9 @@ void TabBox::setCurrentDesktop(int newDesktop) void TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects) { - if (!index.isValid()) + if (!index.isValid()) { return; + } m_tabBox->setCurrentIndex(index); if (notifyEffects) { Q_EMIT tabBoxUpdated(); @@ -718,8 +734,9 @@ void TabBox::hide(bool abort) unreference(); } Q_EMIT tabBoxClosed(); - if (isDisplayed()) + if (isDisplayed()) { qCDebug(KWIN_TABBOX) << "Tab box was not properly closed by an effect"; + } m_tabBox->hide(abort); if (kwinApp()->x11Connection()) { Xcb::sync(); @@ -759,8 +776,9 @@ void TabBox::reconfigure() for (const QString &s : qAsConst(list)) { bool ok; const int i = s.toInt(&ok); - if (!ok) + if (!ok) { continue; + } borders->append(ElectricBorder(i)); ScreenEdges::self()->reserve(ElectricBorder(i), this, "toggle"); } @@ -819,9 +837,10 @@ void TabBox::loadConfig(const KConfigGroup &config, TabBoxConfig &tabBoxConfig) void TabBox::delayedShow() { - if (isDisplayed() || m_delayedShowTimer.isActive()) + if (isDisplayed() || m_delayedShowTimer.isActive()) { // already called show - no need to call it twice return; + } if (!m_delayShowTime) { show(); @@ -1003,8 +1022,9 @@ static bool areModKeysDepressedWayland(const QKeySequence &seq) static bool areModKeysDepressed(const QKeySequence &seq) { - if (seq.isEmpty()) + if (seq.isEmpty()) { return false; + } if (kwinApp()->shouldUseWaylandForCompositing()) { return areModKeysDepressedWayland(seq); } else { @@ -1023,16 +1043,19 @@ void TabBox::navigatingThroughWindows(bool forward, const QKeySequence &shortcut CDEWalkThroughWindows(forward); } else { workspace()->forEachAbstractClient([](Toplevel *toplevel) { - if (toplevel->isPopupWindow()) + if (toplevel->isPopupWindow()) { toplevel->popupDone(); + } }); if (areModKeysDepressed(shortcut)) { - if (startKDEWalkThroughWindows(mode)) + if (startKDEWalkThroughWindows(mode)) { KDEWalkThroughWindows(forward); - } else + } + } else { // if the shortcut has no modifiers, don't show the tabbox, // don't grab, but simply go to the next window KDEOneStepThroughWindows(forward, mode); + } } } @@ -1082,8 +1105,9 @@ void TabBox::slotWalkThroughDesktops() return; } if (areModKeysDepressed(m_cutWalkThroughDesktops)) { - if (startWalkThroughDesktops()) + if (startWalkThroughDesktops()) { walkThroughDesktops(true); + } } else { oneStepThroughDesktops(true); } @@ -1095,8 +1119,9 @@ void TabBox::slotWalkBackThroughDesktops() return; } if (areModKeysDepressed(m_cutWalkThroughDesktopsReverse)) { - if (startWalkThroughDesktops()) + if (startWalkThroughDesktops()) { walkThroughDesktops(false); + } } else { oneStepThroughDesktops(false); } @@ -1108,8 +1133,9 @@ void TabBox::slotWalkThroughDesktopList() return; } if (areModKeysDepressed(m_cutWalkThroughDesktopList)) { - if (startWalkThroughDesktopList()) + if (startWalkThroughDesktopList()) { walkThroughDesktops(true); + } } else { oneStepThroughDesktopList(true); } @@ -1121,8 +1147,9 @@ void TabBox::slotWalkBackThroughDesktopList() return; } if (areModKeysDepressed(m_cutWalkThroughDesktopListReverse)) { - if (startWalkThroughDesktopList()) + if (startWalkThroughDesktopList()) { walkThroughDesktops(false); + } } else { oneStepThroughDesktopList(false); } @@ -1130,8 +1157,9 @@ void TabBox::slotWalkBackThroughDesktopList() void TabBox::shadeActivate(AbstractClient *c) { - if ((c->shadeMode() == ShadeNormal || c->shadeMode() == ShadeHover) && options->isShadeHover()) + if ((c->shadeMode() == ShadeNormal || c->shadeMode() == ShadeHover) && options->isShadeHover()) { c->setShade(ShadeActivated); + } } bool TabBox::toggle(ElectricBorder eb) @@ -1145,14 +1173,16 @@ bool TabBox::toggle(ElectricBorder eb) bool TabBox::toggleMode(TabBoxMode mode) { - if (!options->focusPolicyIsReasonable()) + if (!options->focusPolicyIsReasonable()) { return false; // not supported. + } if (isDisplayed()) { accept(); return true; } - if (!establishTabBoxGrab()) + if (!establishTabBoxGrab()) { return false; + } m_noModifierGrab = m_tabGrab = true; setMode(mode); reset(); @@ -1162,8 +1192,9 @@ bool TabBox::toggleMode(TabBoxMode mode) bool TabBox::startKDEWalkThroughWindows(TabBoxMode mode) { - if (!establishTabBoxGrab()) + if (!establishTabBoxGrab()) { return false; + } m_tabGrab = true; m_noModifierGrab = false; setMode(mode); @@ -1173,8 +1204,9 @@ bool TabBox::startKDEWalkThroughWindows(TabBoxMode mode) bool TabBox::startWalkThroughDesktops(TabBoxMode mode) { - if (!establishTabBoxGrab()) + if (!establishTabBoxGrab()) { return false; + } m_desktopGrab = true; m_noModifierGrab = false; setMode(mode); @@ -1243,14 +1275,16 @@ void TabBox::CDEWalkThroughWindows(bool forward) } } while (nc && nc != c && ((!options_traverse_all && !nc->isOnDesktop(currentDesktop())) || nc->isMinimized() || !nc->wantsTabFocus() || nc->keepAbove() || nc->keepBelow() || !nc->isOnCurrentActivity())); if (nc) { - if (c && c != nc) + if (c && c != nc) { Workspace::self()->lowerClient(c); + } if (options->focusPolicyIsReasonable()) { Workspace::self()->activateClient(nc); shadeActivate(nc); } else { - if (!nc->isOnDesktop(currentDesktop())) + if (!nc->isOnDesktop(currentDesktop())) { setCurrentDesktop(nc->desktop()); + } Workspace::self()->raiseClient(nc); } } @@ -1272,8 +1306,9 @@ void TabBox::oneStepThroughDesktops(bool forward, TabBoxMode mode) setMode(mode); reset(); nextPrev(forward); - if (currentDesktop() != -1) + if (currentDesktop() != -1) { setCurrentDesktop(currentDesktop()); + } } void TabBox::oneStepThroughDesktops(bool forward) @@ -1306,30 +1341,37 @@ void TabBox::keyPress(int keyQt) // tests whether a shortcut matches and handles pitfalls on ShiftKey invocation auto directionFor = [keyQt, contains](const QKeySequence &forward, const QKeySequence &backward) -> Direction { - if (contains(forward, keyQt)) + if (contains(forward, keyQt)) { return Forward; - if (contains(backward, keyQt)) + } + if (contains(backward, keyQt)) { return Backward; - if (!(keyQt & Qt::ShiftModifier)) + } + if (!(keyQt & Qt::ShiftModifier)) { return Steady; + } // Before testing the unshifted key (Ctrl+A vs. Ctrl+Shift+a etc.), see whether this is +Shift+Tab // and check that against +Shift+Backtab (as well) Qt::KeyboardModifiers mods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier | Qt::GroupSwitchModifier; mods &= keyQt; if ((keyQt & ~mods) == Qt::Key_Tab) { - if (contains(forward, mods | Qt::Key_Backtab)) + if (contains(forward, mods | Qt::Key_Backtab)) { return Forward; - if (contains(backward, mods | Qt::Key_Backtab)) + } + if (contains(backward, mods | Qt::Key_Backtab)) { return Backward; + } } // if the shortcuts do not match, try matching again after filtering the shift key from keyQt // it is needed to handle correctly the ALT+~ shorcut for example as it is coded as ALT+SHIFT+~ in keyQt - if (contains(forward, keyQt & ~Qt::ShiftModifier)) + if (contains(forward, keyQt & ~Qt::ShiftModifier)) { return Forward; - if (contains(backward, keyQt & ~Qt::ShiftModifier)) + } + if (contains(backward, keyQt & ~Qt::ShiftModifier)) { return Backward; + } return Steady; }; @@ -1382,10 +1424,12 @@ void TabBox::keyPress(int keyQt) } } else if (m_desktopGrab) { direction = directionFor(m_cutWalkThroughDesktops, m_cutWalkThroughDesktopsReverse); - if (direction == Steady) + if (direction == Steady) { direction = directionFor(m_cutWalkThroughDesktopList, m_cutWalkThroughDesktopListReverse); - if (direction != Steady) + } + if (direction != Steady) { walkThroughDesktops(direction == Forward); + } } if (m_desktopGrab || m_tabGrab) { @@ -1414,13 +1458,15 @@ void TabBox::close(bool abort) void TabBox::accept(bool closeTabBox) { AbstractClient *c = currentClient(); - if (closeTabBox) + if (closeTabBox) { close(); + } if (c) { Workspace::self()->activateClient(c); shadeActivate(c); - if (c->isDesktop()) + if (c->isDesktop()) { Workspace::self()->setShowingDesktop(!Workspace::self()->showingDesktop()); + } } } @@ -1465,14 +1511,17 @@ int TabBox::previousDesktopStatic(int iDesktop) const AbstractClient *TabBox::nextClientStatic(AbstractClient *c) const { const auto &list = Workspace::self()->allClientList(); - if (!c || list.isEmpty()) + if (!c || list.isEmpty()) { return nullptr; + } int pos = list.indexOf(c); - if (pos == -1) + if (pos == -1) { return list.first(); + } ++pos; - if (pos == list.count()) + if (pos == list.count()) { return list.first(); + } return list.at(pos); } @@ -1483,13 +1532,16 @@ AbstractClient *TabBox::nextClientStatic(AbstractClient *c) const AbstractClient *TabBox::previousClientStatic(AbstractClient *c) const { const auto &list = Workspace::self()->allClientList(); - if (!c || list.isEmpty()) + if (!c || list.isEmpty()) { return nullptr; + } int pos = list.indexOf(c); - if (pos == -1) + if (pos == -1) { return list.last(); - if (pos == 0) + } + if (pos == 0) { return list.last(); + } --pos; return list.at(pos); } @@ -1501,8 +1553,9 @@ bool TabBox::establishTabBoxGrab() return true; } updateXTime(); - if (!grabXKeyboard()) + if (!grabXKeyboard()) { return false; + } // Don't try to establish a global mouse grab using XGrabPointer, as that would prevent // using Alt+Tab while DND (#44972). However force passive grabs on all windows // in order to catch MouseRelease events and close the tabbox (#67416). @@ -1510,8 +1563,9 @@ bool TabBox::establishTabBoxGrab() // the active client, which may not have it. Q_ASSERT(!m_forcedGlobalMouseGrab); m_forcedGlobalMouseGrab = true; - if (Workspace::self()->activeClient() != nullptr) + if (Workspace::self()->activeClient() != nullptr) { Workspace::self()->activeClient()->updateMouseGrab(); + } m_x11EventFilter.reset(new X11Filter); return true; } @@ -1526,8 +1580,9 @@ void TabBox::removeTabBoxGrab() ungrabXKeyboard(); Q_ASSERT(m_forcedGlobalMouseGrab); m_forcedGlobalMouseGrab = false; - if (Workspace::self()->activeClient() != nullptr) + if (Workspace::self()->activeClient() != nullptr) { Workspace::self()->activeClient()->updateMouseGrab(); + } m_x11EventFilter.reset(); } } // namespace TabBox diff --git a/src/tabbox/tabboxhandler.cpp b/src/tabbox/tabboxhandler.cpp index 2cc2cec94f..417a842eec 100644 --- a/src/tabbox/tabboxhandler.cpp +++ b/src/tabbox/tabboxhandler.cpp @@ -146,23 +146,27 @@ DesktopModel *TabBoxHandlerPrivate::desktopModel() const void TabBoxHandlerPrivate::updateHighlightWindows() { - if (!isShown || config.tabBoxMode() != TabBoxConfig::ClientTabBox) + if (!isShown || config.tabBoxMode() != TabBoxConfig::ClientTabBox) { return; + } TabBoxClient *currentClient = q->client(index); QWindow *w = window(); if (q->isKWinCompositing()) { - if (lastRaisedClient) + if (lastRaisedClient) { q->elevateClient(lastRaisedClient, w, false); + } lastRaisedClient = currentClient; - if (currentClient) + if (currentClient) { q->elevateClient(currentClient, w, true); + } } else { if (lastRaisedClient) { q->shadeClient(lastRaisedClient, true); - if (lastRaisedClientSucc) + if (lastRaisedClientSucc) { q->restack(lastRaisedClient, lastRaisedClientSucc); + } // TODO lastRaisedClient->setMinimized( lastRaisedClientWasMinimized ); } @@ -205,10 +209,12 @@ void TabBoxHandlerPrivate::endHighlightWindows(bool abort) } } QWindow *w = window(); - if (currentClient) + if (currentClient) { q->elevateClient(currentClient, w, false); - if (abort && lastRaisedClient && lastRaisedClientSucc) + } + if (abort && lastRaisedClient && lastRaisedClientSucc) { q->restack(lastRaisedClient, lastRaisedClientSucc); + } lastRaisedClient = nullptr; lastRaisedClientSucc = nullptr; // highlight windows @@ -438,60 +444,69 @@ QModelIndex TabBoxHandler::nextPrev(bool forward) const if (column == model->columnCount()) { column = 0; row++; - if (row == model->rowCount()) + if (row == model->rowCount()) { row = 0; + } } ret = model->index(row, column); - if (!ret.isValid()) + if (!ret.isValid()) { ret = model->index(0, 0); + } } else { int column = d->index.column() - 1; int row = d->index.row(); if (column < 0) { column = model->columnCount() - 1; row--; - if (row < 0) + if (row < 0) { row = model->rowCount() - 1; + } } ret = model->index(row, column); if (!ret.isValid()) { row = model->rowCount() - 1; for (int i = model->columnCount() - 1; i >= 0; i--) { ret = model->index(row, i); - if (ret.isValid()) + if (ret.isValid()) { break; + } } } } - if (ret.isValid()) + if (ret.isValid()) { return ret; - else + } else { return d->index; + } } QModelIndex TabBoxHandler::desktopIndex(int desktop) const { - if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox) + if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox) { return QModelIndex(); + } return d->desktopModel()->desktopIndex(desktop); } QList TabBoxHandler::desktopList() const { - if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox) + if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox) { return QList(); + } return d->desktopModel()->desktopList(); } int TabBoxHandler::desktop(const QModelIndex &index) const { - if (!index.isValid() || (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox)) + if (!index.isValid() || (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox)) { return -1; + } QVariant ret = d->desktopModel()->data(index, DesktopModel::DesktopRole); - if (ret.isValid()) + if (ret.isValid()) { return ret.toInt(); - else + } else { return -1; + } } void TabBoxHandler::setCurrentIndex(const QModelIndex &index) @@ -543,15 +558,17 @@ QModelIndex TabBoxHandler::index(QWeakPointer client TabBoxClientList TabBoxHandler::clientList() const { - if (d->config.tabBoxMode() != TabBoxConfig::ClientTabBox) + if (d->config.tabBoxMode() != TabBoxConfig::ClientTabBox) { return TabBoxClientList(); + } return d->clientModel()->clientList(); } TabBoxClient *TabBoxHandler::client(const QModelIndex &index) const { - if ((!index.isValid()) || (d->config.tabBoxMode() != TabBoxConfig::ClientTabBox)) + if ((!index.isValid()) || (d->config.tabBoxMode() != TabBoxConfig::ClientTabBox)) { return nullptr; + } TabBoxClient *c = static_cast( d->clientModel()->data(index, ClientModel::ClientRole).value()); return c; @@ -578,10 +595,12 @@ void TabBoxHandler::createModel(bool partialReset) lastRaisedSucc = true; } } - if (d->lastRaisedClient && !lastRaised) + if (d->lastRaisedClient && !lastRaised) { d->lastRaisedClient = nullptr; - if (d->lastRaisedClientSucc && !lastRaisedSucc) + } + if (d->lastRaisedClientSucc && !lastRaisedSucc) { d->lastRaisedClientSucc = nullptr; + } break; } case TabBoxConfig::DesktopTabBox: diff --git a/src/tabbox/x11_filter.cpp b/src/tabbox/x11_filter.cpp index 62171589d3..1ec1ef9104 100644 --- a/src/tabbox/x11_filter.cpp +++ b/src/tabbox/x11_filter.cpp @@ -112,16 +112,18 @@ void X11Filter::keyRelease(xcb_generic_event_t *event) int mod_index = -1; for (int i = XCB_MAP_INDEX_SHIFT; i <= XCB_MAP_INDEX_5; - ++i) + ++i) { if ((mk & (1 << i)) != 0) { - if (mod_index >= 0) + if (mod_index >= 0) { return; + } mod_index = i; } + } bool release = false; - if (mod_index == -1) + if (mod_index == -1) { release = true; - else { + } else { Xcb::ModifierMapping xmk; if (xmk) { xcb_keycode_t *keycodes = xmk.keycodes(); diff --git a/src/toplevel.cpp b/src/toplevel.cpp index f2b812adb9..caf07774da 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -116,8 +116,9 @@ void Toplevel::copyToDeleted(Toplevel *c) ready_for_painting = c->ready_for_painting; is_shape = c->is_shape; effect_window = c->effect_window; - if (effect_window != nullptr) + if (effect_window != nullptr) { effect_window->setWindow(this); + } m_shadow = c->m_shadow; if (m_shadow) { m_shadow->setToplevel(this); @@ -271,8 +272,9 @@ void Toplevel::setOpacity(qreal opacity) bool Toplevel::setupCompositing() { - if (!Compositor::compositing()) + if (!Compositor::compositing()) { return false; + } effect_window = new EffectWindowImpl(this); updateShadow(); diff --git a/src/unmanaged.cpp b/src/unmanaged.cpp index 71de6a853e..32e2febb90 100644 --- a/src/unmanaged.cpp +++ b/src/unmanaged.cpp @@ -124,8 +124,9 @@ bool Unmanaged::track(xcb_window_t w) getResourceClass(); getWmClientLeader(); getWmClientMachine(); - if (Xcb::Extensions::self()->isShapeAvailable()) + if (Xcb::Extensions::self()->isShapeAvailable()) { xcb_shape_select_input(kwinApp()->x11Connection(), w, true); + } detectShape(w); getWmOpaqueRegion(); getSkipCloseAnimation(); @@ -133,8 +134,9 @@ bool Unmanaged::track(xcb_window_t w) if (QWindow *internalWindow = findInternalWindow()) { m_outline = internalWindow->property("__kwin_outline").toBool(); } - if (effects) + if (effects) { static_cast(effects)->checkInputWindowStacking(); + } return true; } @@ -147,8 +149,9 @@ void Unmanaged::release(ReleaseReason releaseReason) Q_EMIT windowClosed(this, del); finishCompositing(releaseReason); if (!QWidget::find(window()) && releaseReason != ReleaseReason::Destroyed) { // don't affect our own windows - if (Xcb::Extensions::self()->isShapeAvailable()) + if (Xcb::Extensions::self()->isShapeAvailable()) { xcb_shape_select_input(kwinApp()->x11Connection(), window(), false); + } Xcb::selectInput(window(), XCB_EVENT_MASK_NO_EVENT); } workspace()->removeUnmanaged(this); diff --git a/src/useractions.cpp b/src/useractions.cpp index e75e43b074..3b6c9e7e0c 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -185,12 +185,14 @@ void UserActionsMenu::helperDialog(const QString &message, AbstractClient *clien if (!type.isEmpty()) { KConfig cfg(QStringLiteral("kwin_dialogsrc")); KConfigGroup cg(&cfg, "Notification Messages"); // Depends on KMessageBox - if (!cg.readEntry(type, true)) + if (!cg.readEntry(type, true)) { return; + } args << QStringLiteral("--dontagain") << QLatin1String("kwin_dialogsrc:") + type; } - if (client) + if (client) { args << QStringLiteral("--embed") << QString::number(client->window()); + } QtConcurrent::run([args]() { KProcess::startDetached(QStringLiteral("kdialog"), args); }); @@ -200,9 +202,9 @@ QStringList configModules(bool controlCenter) { QStringList args; args << QStringLiteral("kwindecoration"); - if (controlCenter) + if (controlCenter) { args << QStringLiteral("kwinoptions"); - else if (KAuthorized::authorizeControlModule(QStringLiteral("kde-kwinoptions.desktop"))) + } else if (KAuthorized::authorizeControlModule(QStringLiteral("kde-kwinoptions.desktop"))) { args << QStringLiteral("kwinactions") << QStringLiteral("kwinfocus") << QStringLiteral("kwinmoving") << QStringLiteral("kwinadvanced") << QStringLiteral("kwinrules") << QStringLiteral("kwincompositing") << QStringLiteral("kwineffects") #if KWIN_BUILD_TABBOX @@ -210,6 +212,7 @@ QStringList configModules(bool controlCenter) #endif << QStringLiteral("kwinscreenedges") << QStringLiteral("kwinscripts"); + } return args; } @@ -355,8 +358,9 @@ void UserActionsMenu::discard() void UserActionsMenu::menuAboutToShow() { - if (m_client.isNull() || !m_menu) + if (m_client.isNull() || !m_menu) { return; + } if (VirtualDesktopManager::self()->count() == 1) { delete m_desktopMenu; @@ -446,8 +450,9 @@ void UserActionsMenu::initDesktopPopup() action->setIcon(QIcon::fromTheme(QStringLiteral("virtual-desktops"))); } else { - if (m_desktopMenu) + if (m_desktopMenu) { return; + } m_desktopMenu = new QMenu(m_menu); connect(m_desktopMenu, &QMenu::aboutToShow, this, &UserActionsMenu::desktopPopupAboutToShow); @@ -478,8 +483,9 @@ void UserActionsMenu::initScreenPopup() void UserActionsMenu::initActivityPopup() { - if (m_activityMenu) + if (m_activityMenu) { return; + } m_activityMenu = new QMenu(m_menu); connect(m_activityMenu, &QMenu::triggered, this, &UserActionsMenu::slotToggleOnActivity); @@ -494,8 +500,9 @@ void UserActionsMenu::initActivityPopup() void UserActionsMenu::desktopPopupAboutToShow() { - if (!m_desktopMenu) + if (!m_desktopMenu) { return; + } const VirtualDesktopManager *vds = VirtualDesktopManager::self(); m_desktopMenu->clear(); @@ -561,8 +568,9 @@ void UserActionsMenu::desktopPopupAboutToShow() void UserActionsMenu::multipleDesktopsPopupAboutToShow() { - if (!m_multipleDesktopsMenu) + if (!m_multipleDesktopsMenu) { return; + } VirtualDesktopManager *vds = VirtualDesktopManager::self(); m_multipleDesktopsMenu->clear(); @@ -684,8 +692,9 @@ void UserActionsMenu::screenPopupAboutToShow() void UserActionsMenu::activityPopupAboutToShow() { - if (!m_activityMenu) + if (!m_activityMenu) { return; + } #if KWIN_BUILD_ACTIVITIES if (!Activities::self()) { @@ -732,28 +741,33 @@ void UserActionsMenu::activityPopupAboutToShow() void UserActionsMenu::slotWindowOperation(QAction *action) { - if (!action->data().isValid()) + if (!action->data().isValid()) { return; + } Options::WindowOperation op = static_cast(action->data().toInt()); QPointer c = m_client ? m_client : QPointer(Workspace::self()->activeClient()); - if (c.isNull()) + if (c.isNull()) { return; + } QString type; switch (op) { case Options::FullScreenOp: - if (!c->isFullScreen() && c->userCanSetFullScreen()) + if (!c->isFullScreen() && c->userCanSetFullScreen()) { type = QStringLiteral("fullscreenaltf3"); + } break; case Options::NoBorderOp: - if (!c->noBorder() && c->userCanSetNoBorder()) + if (!c->noBorder() && c->userCanSetNoBorder()) { type = QStringLiteral("noborderaltf3"); + } break; default: break; } - if (!type.isEmpty()) + if (!type.isEmpty()) { helperDialog(type, c); + } // need to delay performing the window operation as we need to have the // user actions menu closed before we destroy the decoration. Otherwise Qt crashes qRegisterMetaType(); @@ -767,8 +781,9 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action) return; } QString activity = action->data().toString(); - if (m_client.isNull()) + if (m_client.isNull()) { return; + } if (activity.isEmpty()) { // the 'on_all_activities' menu entry m_client->setOnAllActivities(!m_client->isOnAllActivities()); @@ -843,8 +858,9 @@ void ShortcutDialog::keySequenceChanged() { activateWindow(); // where is the kbd focus lost? cause of popup state? QKeySequence seq = m_ui.keySequenceEdit->keySequence(); - if (_shortcut == seq) + if (_shortcut == seq) { return; // don't try to update the same + } if (seq.isEmpty()) { // clear _shortcut = seq; @@ -869,8 +885,9 @@ void ShortcutDialog::keySequenceChanged() m_ui.keySequenceEdit->setKeySequence(shortcut()); } else if (seq != _shortcut) { m_ui.warning->hide(); - if (QPushButton *ok = m_ui.buttonBox->button(QDialogButtonBox::Ok)) + if (QPushButton *ok = m_ui.buttonBox->button(QDialogButtonBox::Ok)) { ok->setFocus(); + } } _shortcut = seq; @@ -1106,10 +1123,12 @@ void Workspace::setupWindowShortcut(AbstractClient *c) QRect r = clientArea(ScreenArea, c); QSize size = client_keys_dialog->sizeHint(); QPoint pos = c->pos() + c->clientPos(); - if (pos.x() + size.width() >= r.right()) + if (pos.x() + size.width() >= r.right()) { pos.setX(r.right() - size.width()); - if (pos.y() + size.height() >= r.bottom()) + } + if (pos.y() + size.height() >= r.bottom()) { pos.setY(r.bottom() - size.height()); + } client_keys_dialog->move(pos); client_keys_dialog->show(); active_popup = client_keys_dialog; @@ -1121,14 +1140,16 @@ void Workspace::setupWindowShortcutDone(bool ok) // keys->setEnabled( true ); // disable_shortcuts_keys->setEnabled( true ); // client_keys->setEnabled( true ); - if (ok) + if (ok) { client_keys_client->setShortcut(client_keys_dialog->shortcut().toString()); + } closeActivePopup(); client_keys_dialog->deleteLater(); client_keys_dialog = nullptr; client_keys_client = nullptr; - if (active_client) + if (active_client) { active_client->takeFocus(); + } } void Workspace::clientShortcutUpdated(AbstractClient *c) @@ -1158,12 +1179,15 @@ void Workspace::clientShortcutUpdated(AbstractClient *c) void Workspace::performWindowOperation(AbstractClient *c, Options::WindowOperation op) { - if (!c) + if (!c) { return; - if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp) + } + if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp) { Cursors::self()->mouse()->setPos(c->frameGeometry().center()); - if (op == Options::ResizeOp || op == Options::UnrestrictedResizeOp) + } + if (op == Options::ResizeOp || op == Options::UnrestrictedResizeOp) { Cursors::self()->mouse()->setPos(c->frameGeometry().bottomRight()); + } switch (op) { case Options::MoveOp: c->performMouseCommand(Options::MouseMove, Cursors::self()->mouse()->pos()); @@ -1219,16 +1243,18 @@ void Workspace::performWindowOperation(AbstractClient *c, Options::WindowOperati StackingUpdatesBlocker blocker(this); bool was = c->keepAbove(); c->setKeepAbove(!c->keepAbove()); - if (was && !c->keepAbove()) + if (was && !c->keepAbove()) { raiseClient(c); + } break; } case Options::KeepBelowOp: { StackingUpdatesBlocker blocker(this); bool was = c->keepBelow(); c->setKeepBelow(!c->keepBelow()); - if (was && !c->keepBelow()) + if (was && !c->keepBelow()) { lowerClient(c); + } break; } case Options::OperationsOp: @@ -1253,8 +1279,9 @@ void Workspace::performWindowOperation(AbstractClient *c, Options::WindowOperati void Workspace::slotActivateAttentionWindow() { - if (attention_chain.count() > 0) + if (attention_chain.count() > 0) { activateClient(attention_chain.first()); + } } static uint senderValue(QObject *sender) @@ -1262,10 +1289,12 @@ static uint senderValue(QObject *sender) QAction *act = qobject_cast(sender); bool ok = false; uint i = -1; - if (act) + if (act) { i = act->data().toUInt(&ok); - if (ok) + } + if (ok) { return i; + } return -1; } @@ -1280,8 +1309,9 @@ void Workspace::slotWindowToDesktop(VirtualDesktop *desktop) static bool screenSwitchImpossible() { - if (!options->activeMouseScreen()) + if (!options->activeMouseScreen()) { return false; + } QStringList args; args << QStringLiteral("--passivepopup") << i18n("The window manager is configured to consider the screen with the mouse on it as active one.\n" "Therefore it is not possible to switch to a screen explicitly.") @@ -1308,8 +1338,9 @@ AbstractOutput *Workspace::previousOutput(AbstractOutput *reference) const void Workspace::slotSwitchToScreen() { - if (screenSwitchImpossible()) + if (screenSwitchImpossible()) { return; + } AbstractOutput *output = kwinApp()->platform()->findOutput(senderValue(sender())); if (output) { switchToOutput(output); @@ -1318,15 +1349,17 @@ void Workspace::slotSwitchToScreen() void Workspace::slotSwitchToNextScreen() { - if (screenSwitchImpossible()) + if (screenSwitchImpossible()) { return; + } switchToOutput(nextOutput(activeOutput())); } void Workspace::slotSwitchToPrevScreen() { - if (screenSwitchImpossible()) + if (screenSwitchImpossible()) { return; + } switchToOutput(previousOutput(activeOutput())); } @@ -1359,8 +1392,9 @@ void Workspace::slotWindowToPrevScreen() */ void Workspace::slotWindowMaximize() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::MaximizeOp); + } } /** @@ -1368,8 +1402,9 @@ void Workspace::slotWindowMaximize() */ void Workspace::slotWindowMaximizeVertical() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::VMaximizeOp); + } } /** @@ -1377,8 +1412,9 @@ void Workspace::slotWindowMaximizeVertical() */ void Workspace::slotWindowMaximizeHorizontal() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::HMaximizeOp); + } } /** @@ -1386,8 +1422,9 @@ void Workspace::slotWindowMaximizeHorizontal() */ void Workspace::slotWindowMinimize() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::MinimizeOp); + } } /** @@ -1395,8 +1432,9 @@ void Workspace::slotWindowMinimize() */ void Workspace::slotWindowShade() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::ShadeOp); + } } /** @@ -1404,8 +1442,9 @@ void Workspace::slotWindowShade() */ void Workspace::slotWindowRaise() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { raiseClient(active_client); + } } /** @@ -1421,8 +1460,9 @@ void Workspace::slotWindowLower() if (active_client->isActive() && options->focusPolicyIsReasonable()) { if (options->isNextFocusPrefersMouse()) { AbstractClient *next = clientUnderMouse(active_client->output()); - if (next && next != active_client) + if (next && next != active_client) { requestFocus(next, false); + } } else { activateClient(topClientOnDesktop(VirtualDesktopManager::self()->currentDesktop())); } @@ -1435,43 +1475,50 @@ void Workspace::slotWindowLower() */ void Workspace::slotWindowRaiseOrLower() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { raiseOrLowerClient(active_client); + } } void Workspace::slotWindowOnAllDesktops() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { active_client->setOnAllDesktops(!active_client->isOnAllDesktops()); + } } void Workspace::slotWindowFullScreen() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::FullScreenOp); + } } void Workspace::slotWindowNoBorder() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::NoBorderOp); + } } void Workspace::slotWindowAbove() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::KeepAboveOp); + } } void Workspace::slotWindowBelow() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::KeepBelowOp); + } } void Workspace::slotSetupWindowShortcut() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::SetupWindowShortcutOp); + } } /** @@ -1503,8 +1550,9 @@ void windowToDesktop(AbstractClient *c) */ void Workspace::slotWindowToNextDesktop() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { windowToNextDesktop(active_client); + } } void Workspace::windowToNextDesktop(AbstractClient *c) @@ -1517,8 +1565,9 @@ void Workspace::windowToNextDesktop(AbstractClient *c) */ void Workspace::slotWindowToPreviousDesktop() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { windowToPreviousDesktop(active_client); + } } void Workspace::windowToPreviousDesktop(AbstractClient *c) @@ -1586,8 +1635,9 @@ void Workspace::slotKillWindow() */ void Workspace::switchWindow(Direction direction) { - if (!active_client) + if (!active_client) { return; + } AbstractClient *c = active_client; VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); @@ -1675,8 +1725,9 @@ bool Workspace::switchWindow(AbstractClient *c, Direction direction, QPoint curP */ void Workspace::slotWindowOperations() { - if (!active_client) + if (!active_client) { return; + } QPoint pos = active_client->pos() + active_client->clientPos(); showWindowMenu(QRect(pos, pos), active_client); } @@ -1699,8 +1750,9 @@ void Workspace::slotWindowClose() // TODO: why? // if ( tab_box->isVisible()) // return; - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::CloseOp); + } } /** @@ -1708,8 +1760,9 @@ void Workspace::slotWindowClose() */ void Workspace::slotWindowMove() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::UnrestrictedMoveOp); + } } /** @@ -1717,8 +1770,9 @@ void Workspace::slotWindowMove() */ void Workspace::slotWindowResize() { - if (USABLE_ACTIVE_CLIENT) + if (USABLE_ACTIVE_CLIENT) { performWindowOperation(active_client, Options::UnrestrictedResizeOp); + } } #undef USABLE_ACTIVE_CLIENT @@ -1727,8 +1781,9 @@ void AbstractClient::setShortcut(const QString &_cut) { QString cut = rules()->checkShortcut(_cut); auto updateShortcut = [this](const QKeySequence &cut = QKeySequence()) { - if (_shortcut == cut) + if (_shortcut == cut) { return; + } _shortcut = cut; setShortcutInternal(); }; @@ -1743,10 +1798,11 @@ void AbstractClient::setShortcut(const QString &_cut) // base+(abcdef)base+(abcdef) // E.g. Alt+Ctrl+(ABCDEF);Meta+X,Meta+(ABCDEF) if (!cut.contains(QLatin1Char('(')) && !cut.contains(QLatin1Char(')')) && !cut.contains(QLatin1String(" - "))) { - if (workspace()->shortcutAvailable(cut, this)) + if (workspace()->shortcutAvailable(cut, this)) { updateShortcut(QKeySequence(cut)); - else + } else { updateShortcut(); + } return; } const QRegularExpression reg(QStringLiteral("(.*\\+)\\((.*)\\)")); @@ -1763,8 +1819,9 @@ void AbstractClient::setShortcut(const QString &_cut) i < list.length(); ++i) { QKeySequence c(base + list[i]); - if (!c.isEmpty()) + if (!c.isEmpty()) { keys.append(c); + } } } else { // regexp doesn't match, so it should be a normal shortcut @@ -1777,8 +1834,9 @@ void AbstractClient::setShortcut(const QString &_cut) for (auto it = keys.constBegin(); it != keys.constEnd(); ++it) { - if (_shortcut == *it) // current one is in the list + if (_shortcut == *it) { // current one is in the list return; + } } for (auto it = keys.constBegin(); it != keys.constEnd(); @@ -1812,8 +1870,9 @@ void X11Client::setShortcutInternal() bool Workspace::shortcutAvailable(const QKeySequence &cut, AbstractClient *ignore) const { - if (ignore && cut == ignore->shortcut()) + if (ignore && cut == ignore->shortcut()) { return true; + } // Check if the shortcut is already registered const QList registeredShortcuts = KGlobalAccel::globalShortcutsByKey(cut); diff --git a/src/utils/common.cpp b/src/utils/common.cpp index af124abae5..d8b3e80d6e 100644 --- a/src/utils/common.cpp +++ b/src/utils/common.cpp @@ -84,8 +84,9 @@ static int server_grab_count = 0; void grabXServer() { - if (++server_grab_count == 1) + if (++server_grab_count == 1) { xcb_grab_server(connection()); + } } void ungrabXServer() @@ -101,14 +102,18 @@ static bool keyboard_grabbed = false; bool grabXKeyboard(xcb_window_t w) { - if (QWidget::keyboardGrabber() != nullptr) + if (QWidget::keyboardGrabber() != nullptr) { return false; - if (keyboard_grabbed) + } + if (keyboard_grabbed) { return false; - if (qApp->activePopupWidget() != nullptr) + } + if (qApp->activePopupWidget() != nullptr) { return false; - if (w == XCB_WINDOW_NONE) + } + if (w == XCB_WINDOW_NONE) { w = rootWindow(); + } const xcb_grab_keyboard_cookie_t c = xcb_grab_keyboard_unchecked(connection(), false, w, xTime(), XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); ScopedCPointer grab(xcb_grab_keyboard_reply(connection(), c, nullptr)); @@ -138,46 +143,60 @@ void ungrabXKeyboard() Qt::MouseButton x11ToQtMouseButton(int button) { - if (button == XCB_BUTTON_INDEX_1) + if (button == XCB_BUTTON_INDEX_1) { return Qt::LeftButton; - if (button == XCB_BUTTON_INDEX_2) + } + if (button == XCB_BUTTON_INDEX_2) { return Qt::MiddleButton; - if (button == XCB_BUTTON_INDEX_3) + } + if (button == XCB_BUTTON_INDEX_3) { return Qt::RightButton; - if (button == XCB_BUTTON_INDEX_4) + } + if (button == XCB_BUTTON_INDEX_4) { return Qt::XButton1; - if (button == XCB_BUTTON_INDEX_5) + } + if (button == XCB_BUTTON_INDEX_5) { return Qt::XButton2; + } return Qt::NoButton; } Qt::MouseButtons x11ToQtMouseButtons(int state) { Qt::MouseButtons ret = {}; - if (state & XCB_KEY_BUT_MASK_BUTTON_1) + if (state & XCB_KEY_BUT_MASK_BUTTON_1) { ret |= Qt::LeftButton; - if (state & XCB_KEY_BUT_MASK_BUTTON_2) + } + if (state & XCB_KEY_BUT_MASK_BUTTON_2) { ret |= Qt::MiddleButton; - if (state & XCB_KEY_BUT_MASK_BUTTON_3) + } + if (state & XCB_KEY_BUT_MASK_BUTTON_3) { ret |= Qt::RightButton; - if (state & XCB_KEY_BUT_MASK_BUTTON_4) + } + if (state & XCB_KEY_BUT_MASK_BUTTON_4) { ret |= Qt::XButton1; - if (state & XCB_KEY_BUT_MASK_BUTTON_5) + } + if (state & XCB_KEY_BUT_MASK_BUTTON_5) { ret |= Qt::XButton2; + } return ret; } Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state) { Qt::KeyboardModifiers ret = {}; - if (state & XCB_KEY_BUT_MASK_SHIFT) + if (state & XCB_KEY_BUT_MASK_SHIFT) { ret |= Qt::ShiftModifier; - if (state & XCB_KEY_BUT_MASK_CONTROL) + } + if (state & XCB_KEY_BUT_MASK_CONTROL) { ret |= Qt::ControlModifier; - if (state & KKeyServer::modXAlt()) + } + if (state & KKeyServer::modXAlt()) { ret |= Qt::AltModifier; - if (state & KKeyServer::modXMeta()) + } + if (state & KKeyServer::modXMeta()) { ret |= Qt::MetaModifier; + } return ret; } diff --git a/src/utils/serviceutils.h b/src/utils/serviceutils.h index 21dac93996..96f181ab02 100644 --- a/src/utils/serviceutils.h +++ b/src/utils/serviceutils.h @@ -31,8 +31,9 @@ static QStringList fetchProcessServiceField(const QString &executablePath, const // needed to be able to use the logging category in a header static function static QLoggingCategory KWIN_UTILS("KWIN_UTILS", QtWarningMsg); const auto servicesFound = KApplicationTrader::query([&executablePath](const KService::Ptr &service) { - if (service->exec().isEmpty() || QFileInfo(service->exec()).canonicalFilePath() != executablePath) + if (service->exec().isEmpty() || QFileInfo(service->exec()).canonicalFilePath() != executablePath) { return false; + } return true; }); diff --git a/src/utils/subsurfacemonitor.cpp b/src/utils/subsurfacemonitor.cpp index a0166df38e..eb92d57ad4 100644 --- a/src/utils/subsurfacemonitor.cpp +++ b/src/utils/subsurfacemonitor.cpp @@ -50,8 +50,9 @@ void SubSurfaceMonitor::registerSubSurface(SubSurfaceInterface *subSurface) void SubSurfaceMonitor::unregisterSubSurface(SubSurfaceInterface *subSurface) { SurfaceInterface *surface = subSurface->surface(); - if (!surface) + if (!surface) { return; + } disconnect(subSurface, nullptr, this, nullptr); diff --git a/src/utils/xcbutils.h b/src/utils/xcbutils.h index e9405a5869..2b7cba78b7 100644 --- a/src/utils/xcbutils.h +++ b/src/utils/xcbutils.h @@ -615,8 +615,9 @@ public: } inline xcb_window_t parent() { - if (isNull()) + if (isNull()) { return XCB_WINDOW_NONE; + } return (*this)->parent; } }; @@ -639,8 +640,9 @@ public: inline xcb_window_t window() { - if (isNull()) + if (isNull()) { return XCB_WINDOW_NONE; + } return (*this)->focus; } }; diff --git a/src/wayland_server.cpp b/src/wayland_server.cpp index 5fcbbe527e..2ab63149dd 100644 --- a/src/wayland_server.cpp +++ b/src/wayland_server.cpp @@ -766,8 +766,9 @@ void WaylandServer::simulateUserActivity() void WaylandServer::updateKeyState(KWin::LEDs leds) { - if (!m_keyState) + if (!m_keyState) { return; + } m_keyState->setState(KeyStateInterface::Key::CapsLock, leds & KWin::LED::CapsLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked); m_keyState->setState(KeyStateInterface::Key::NumLock, leds & KWin::LED::NumLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked); diff --git a/src/workspace.cpp b/src/workspace.cpp index 22b87a260a..ed3e747bec 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -250,8 +250,9 @@ void Workspace::init() // load is needed to be called again when starting xwayalnd to sync to RootInfo, see BUG 385260 vds->save(); - if (!VirtualDesktopManager::self()->setCurrent(m_initialDesktop)) + if (!VirtualDesktopManager::self()->setCurrent(m_initialDesktop)) { VirtualDesktopManager::self()->setCurrent(1); + } reconfigureTimer.setSingleShot(true); updateToolWindowsTimer.setSingleShot(true); @@ -356,8 +357,9 @@ void Workspace::initializeX11() rootInfo->setActiveWindow(XCB_WINDOW_NONE); focusToNull(); - if (!sessionRestored) + if (!sessionRestored) { ++block_focus; // Because it will be set below + } { // Begin updates blocker block @@ -384,9 +386,10 @@ void Workspace::initializeX11() } if (attr->override_redirect) { - if (attr->map_state == XCB_MAP_STATE_VIEWABLE && attr->_class != XCB_WINDOW_CLASS_INPUT_ONLY) + if (attr->map_state == XCB_MAP_STATE_VIEWABLE && attr->_class != XCB_WINDOW_CLASS_INPUT_ONLY) { // ### This will request the attributes again createUnmanaged(wins[i]); + } } else if (attr->map_state != XCB_MAP_STATE_UNMAPPED) { if (Application::wasCrash()) { fixPositionAfterCrash(wins[i], windowGeometries.at(i).data()); @@ -425,13 +428,16 @@ void Workspace::initializeX11() if (new_active_client == nullptr && activeClient() == nullptr && should_get_focus.count() == 0) { // No client activated in manage() - if (new_active_client == nullptr) + if (new_active_client == nullptr) { new_active_client = topClientOnDesktop(VirtualDesktopManager::self()->currentDesktop()); - if (new_active_client == nullptr) + } + if (new_active_client == nullptr) { new_active_client = findDesktop(true, VirtualDesktopManager::self()->currentDesktop()); + } } - if (new_active_client != nullptr) + if (new_active_client != nullptr) { activateClient(new_active_client); + } } void Workspace::cleanupX11() @@ -692,12 +698,14 @@ void Workspace::addClient(X11Client *c) Q_EMIT clientAdded(c); - if (grp != nullptr) + if (grp != nullptr) { grp->gotLeader(c); + } if (c->isDesktop()) { - if (active_client == nullptr && should_get_focus.isEmpty() && c->isOnCurrentDesktop()) + if (active_client == nullptr && should_get_focus.isEmpty() && c->isOnCurrentDesktop()) { requestFocus(c); // TODO: Make sure desktop is active after startup if there's no other window active + } } else { FocusChain::self()->update(c, FocusChain::Update); } @@ -710,14 +718,16 @@ void Workspace::addClient(X11Client *c) if (c->isDesktop()) { raiseClient(c); // If there's no active client, make this desktop the active one - if (activeClient() == nullptr && should_get_focus.count() == 0) + if (activeClient() == nullptr && should_get_focus.count() == 0) { activateClient(findDesktop(true, VirtualDesktopManager::self()->currentDesktop())); + } } c->checkActiveModal(); checkTransients(c->window()); // SELI TODO: Does this really belong here? updateStackingOrder(true); // Propagate new client - if (c->isUtility() || c->isMenu() || c->isToolbar()) + if (c->isUtility() || c->isMenu() || c->isToolbar()) { updateToolWindows(true); + } updateTabbox(); } @@ -732,8 +742,9 @@ void Workspace::addUnmanaged(Unmanaged *c) */ void Workspace::removeX11Client(X11Client *c) { - if (c == active_popup_client) + if (c == active_popup_client) { closeActivePopup(); + } if (m_userActionsMenu->isMenuClient(c)) { m_userActionsMenu->close(); } @@ -742,8 +753,9 @@ void Workspace::removeX11Client(X11Client *c) // TODO: if marked client is removed, notify the marked list m_x11Clients.removeAll(c); Group *group = findGroup(c->window()); - if (group != nullptr) + if (group != nullptr) { group->lostLeader(); + } removeAbstractClient(c); } @@ -867,8 +879,9 @@ void Workspace::updateToolWindows(bool also_hide) { // TODO: What if Client's transiency/group changes? should this be called too? (I'm paranoid, am I not?) if (!options->isHideUtilityWindowsForInactive()) { - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) + for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { (*it)->showClient(); + } return; } const Group *group = nullptr; @@ -876,8 +889,9 @@ void Workspace::updateToolWindows(bool also_hide) // Go up in transiency hiearchy, if the top is found, only tool transients for the top mainwindow // will be shown; if a group transient is group, all tools in the group will be shown while (client != nullptr) { - if (!client->isTransient()) + if (!client->isTransient()) { break; + } if (client->groupTransient()) { group = client->group(); break; @@ -897,47 +911,56 @@ void Workspace::updateToolWindows(bool also_hide) if (c->isUtility() || c->isMenu() || c->isToolbar()) { bool show = true; if (!c->isTransient()) { - if (!c->group() || c->group()->members().count() == 1) // Has its own group, keep always visible + if (!c->group() || c->group()->members().count() == 1) { // Has its own group, keep always visible show = true; - else if (client != nullptr && c->group() == client->group()) + } else if (client != nullptr && c->group() == client->group()) { show = true; - else + } else { show = false; + } } else { - if (group != nullptr && c->group() == group) + if (group != nullptr && c->group() == group) { show = true; - else if (client != nullptr && client->hasTransient(c, true)) + } else if (client != nullptr && client->hasTransient(c, true)) { show = true; - else + } else { show = false; + } } if (!show && also_hide) { const auto mainclients = c->mainClients(); // Don't hide utility windows which are standalone(?) or // have e.g. kicker as mainwindow - if (mainclients.isEmpty()) + if (mainclients.isEmpty()) { show = true; - for (auto it2 = mainclients.constBegin(); it2 != mainclients.constEnd(); ++it2) { - if ((*it2)->isSpecialWindow()) - show = true; } - if (!show) + for (auto it2 = mainclients.constBegin(); it2 != mainclients.constEnd(); ++it2) { + if ((*it2)->isSpecialWindow()) { + show = true; + } + } + if (!show) { to_hide.append(c); + } } - if (show) + if (show) { to_show.append(c); + } } } // First show new ones, then hide - for (int i = to_show.size() - 1; i >= 0; --i) // From topmost + for (int i = to_show.size() - 1; i >= 0; --i) { // From topmost // TODO: Since this is in stacking order, the order of taskbar entries changes :( to_show.at(i)->showClient(); + } if (also_hide) { - for (auto it = to_hide.constBegin(); it != to_hide.constEnd(); ++it) // From bottommost + for (auto it = to_hide.constBegin(); it != to_hide.constEnd(); ++it) { // From bottommost (*it)->hideClient(); + } updateToolWindowsTimer.stop(); - } else // setActiveClient() is after called with NULL client, quickly followed + } else { // setActiveClient() is after called with NULL client, quickly followed // by setting a new client, which would result in flickering resetUpdateToolWindowsTimer(); + } } void Workspace::resetUpdateToolWindowsTimer() @@ -990,8 +1013,9 @@ void Workspace::slotReconfigure() // in case borderless maximized windows option changed and new option // is to have borders, we need to unset the borders for all maximized windows for (auto it = m_allClients.cbegin(); it != m_allClients.cend(); ++it) { - if ((*it)->maximizeMode() == MaximizeFull) + if ((*it)->maximizeMode() == MaximizeFull) { (*it)->checkNoBorder(); + } } } } @@ -1034,11 +1058,13 @@ void Workspace::updateClientVisibilityOnDesktopChange(VirtualDesktop *newDesktop if (!c) { continue; } - if (c->isOnDesktop(newDesktop) && c->isOnCurrentActivity()) + if (c->isOnDesktop(newDesktop) && c->isOnCurrentActivity()) { c->updateVisibility(); + } } - if (showingDesktop()) // Do this only after desktop change to avoid flicker + if (showingDesktop()) { // Do this only after desktop change to avoid flicker setShowingDesktop(false); + } } void Workspace::activateClientOnNewDesktop(VirtualDesktop *desktop) @@ -1050,19 +1076,23 @@ void Workspace::activateClientOnNewDesktop(VirtualDesktop *desktop) // If "unreasonable focus policy" and active_client is on_all_desktops and // under mouse (Hence == old_active_client), conserve focus. // (Thanks to Volker Schatz ) - else if (active_client && active_client->isShown() && active_client->isOnCurrentDesktop()) + else if (active_client && active_client->isShown() && active_client->isOnCurrentDesktop()) { c = active_client; + } - if (!c) + if (!c) { c = findDesktop(true, desktop); + } - if (c != active_client) + if (c != active_client) { setActiveClient(nullptr); + } - if (c) + if (c) { requestFocus(c); - else + } else { focusToNull(); + } } AbstractClient *Workspace::findClientToActivateOnDesktop(VirtualDesktop *desktop) @@ -1080,12 +1110,14 @@ AbstractClient *Workspace::findClientToActivateOnDesktop(VirtualDesktop *desktop continue; } - if (!(!client->isShade() && client->isShown() && client->isOnDesktop(desktop) && client->isOnCurrentActivity() && client->isOnActiveOutput())) + if (!(!client->isShade() && client->isShown() && client->isOnDesktop(desktop) && client->isOnCurrentActivity() && client->isOnActiveOutput())) { continue; + } if (client->frameGeometry().contains(Cursors::self()->mouse()->pos())) { - if (!client->isDesktop()) + if (!client->isDesktop()) { return client; + } break; // unconditional break - we do not pass the focus to some client below an unusable one } } @@ -1139,13 +1171,15 @@ void Workspace::updateCurrentActivity(const QString &new_activity) if (!c) { continue; } - if (c->isOnActivity(new_activity)) + if (c->isOnActivity(new_activity)) { c->updateVisibility(); + } } // FIXME not sure if I should do this either - if (showingDesktop()) // Do this only after desktop change to avoid flicker + if (showingDesktop()) { // Do this only after desktop change to avoid flicker setShowingDesktop(false); + } // Restore the focus on this desktop --block_focus; @@ -1160,16 +1194,19 @@ void Workspace::updateCurrentActivity(const QString &new_activity) c = FocusChain::self()->getForActivation(VirtualDesktopManager::self()->currentDesktop()); } - if (!c) + if (!c) { c = findDesktop(true, VirtualDesktopManager::self()->currentDesktop()); + } - if (c != active_client) + if (c != active_client) { setActiveClient(nullptr); + } - if (c) + if (c) { requestFocus(c); - else + } else { focusToNull(); + } Q_EMIT currentActivityChanged(); #else @@ -1255,29 +1292,34 @@ void Workspace::selectWmInputEventMask() */ void Workspace::sendClientToDesktop(AbstractClient *c, int desk, bool dont_activate) { - if ((desk < 1 && desk != NET::OnAllDesktops) || desk > static_cast(VirtualDesktopManager::self()->count())) + if ((desk < 1 && desk != NET::OnAllDesktops) || desk > static_cast(VirtualDesktopManager::self()->count())) { return; + } int old_desktop = c->desktop(); const bool wasOnCurrent = c->isOnCurrentDesktop(); c->setDesktop(desk); - if (c->desktop() != desk) // No change or desktop forced + if (c->desktop() != desk) { // No change or desktop forced return; + } desk = c->desktop(); // Client did range checking if (c->isOnCurrentDesktop()) { if (c->wantsTabFocus() && options->focusPolicyIsReasonable() && !wasOnCurrent && // for stickyness changes - !dont_activate) + !dont_activate) { requestFocus(c); - else + } else { restackClientUnderActive(c); - } else + } + } else { raiseClient(c); + } c->checkWorkspacePosition(QRect(), VirtualDesktopManager::self()->desktopForX11Id(old_desktop)); auto transients_stacking_order = ensureStackingOrder(c->transients()); - for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) + for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) { sendClientToDesktop(*it, desk, dont_activate); + } updateClientArea(); } @@ -1376,8 +1418,9 @@ void Workspace::setShowingDesktop(bool showing) } else if (c->isDesktop() && c->isShown()) { c->updateLayer(); lowerClient(c); - if (!topDesk) + if (!topDesk) { topDesk = c; + } if (auto group = c->group()) { const auto members = group->members(); for (X11Client *cm : members) { @@ -1397,14 +1440,16 @@ void Workspace::setShowingDesktop(bool showing) activateClient(client); } } - if (changed) + if (changed) { Q_EMIT showingDesktopChanged(showing); + } } void Workspace::disableGlobalShortcutsForClient(bool disable) { - if (global_shortcuts_disabled_for_client == disable) + if (global_shortcuts_disabled_for_client == disable) { return; + } QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kglobalaccel"), QStringLiteral("/kglobalaccel"), QStringLiteral("org.kde.KGlobalAccel"), @@ -1414,8 +1459,9 @@ void Workspace::disableGlobalShortcutsForClient(bool disable) global_shortcuts_disabled_for_client = disable; // Update also Meta+LMB actions etc. - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) + for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { (*it)->updateMouseGrab(); + } } QString Workspace::supportInformation() const @@ -1550,10 +1596,11 @@ QString Workspace::supportInformation() const support.append(QStringLiteral("no\n")); } support.append(QStringLiteral("Active screen follows mouse: ")); - if (options->activeMouseScreen()) + if (options->activeMouseScreen()) { support.append(QStringLiteral(" yes\n")); - else + } else { support.append(QStringLiteral(" no\n")); + } const QVector outputs = kwinApp()->platform()->enabledOutputs(); support.append(QStringLiteral("Number of Screens: %1\n\n").arg(outputs.count())); for (int i = 0; i < outputs.count(); ++i) { @@ -1616,26 +1663,32 @@ QString Workspace::supportInformation() const } support.append(QStringLiteral("\n")); - if (platform->supports(LimitedGLSL) || platform->supports(GLSL)) + if (platform->supports(LimitedGLSL) || platform->supports(GLSL)) { support.append(QStringLiteral("OpenGL shading language version string: ") + QString::fromUtf8(platform->glShadingLanguageVersionString()) + QStringLiteral("\n")); + } support.append(QStringLiteral("Driver: ") + GLPlatform::driverToString(platform->driver()) + QStringLiteral("\n")); - if (!platform->isMesaDriver()) + if (!platform->isMesaDriver()) { support.append(QStringLiteral("Driver version: ") + GLPlatform::versionToString(platform->driverVersion()) + QStringLiteral("\n")); + } support.append(QStringLiteral("GPU class: ") + GLPlatform::chipClassToString(platform->chipClass()) + QStringLiteral("\n")); support.append(QStringLiteral("OpenGL version: ") + GLPlatform::versionToString(platform->glVersion()) + QStringLiteral("\n")); - if (platform->supports(LimitedGLSL) || platform->supports(GLSL)) + if (platform->supports(LimitedGLSL) || platform->supports(GLSL)) { support.append(QStringLiteral("GLSL version: ") + GLPlatform::versionToString(platform->glslVersion()) + QStringLiteral("\n")); + } - if (platform->isMesaDriver()) + if (platform->isMesaDriver()) { support.append(QStringLiteral("Mesa version: ") + GLPlatform::versionToString(platform->mesaVersion()) + QStringLiteral("\n")); - if (platform->serverVersion() > 0) + } + if (platform->serverVersion() > 0) { support.append(QStringLiteral("X server version: ") + GLPlatform::versionToString(platform->serverVersion()) + QStringLiteral("\n")); - if (platform->kernelVersion() > 0) + } + if (platform->kernelVersion() > 0) { support.append(QStringLiteral("Linux kernel version: ") + GLPlatform::versionToString(platform->kernelVersion()) + QStringLiteral("\n")); + } support.append(QStringLiteral("Direct rendering: ")); support.append(QStringLiteral("Requires strict binding: ")); @@ -1902,9 +1955,11 @@ void Workspace::removeInternalClient(InternalClient *client) Group *Workspace::findGroup(xcb_window_t leader) const { Q_ASSERT(leader != XCB_WINDOW_NONE); - for (auto it = groups.constBegin(); it != groups.constEnd(); ++it) - if ((*it)->leader() == leader) + for (auto it = groups.constBegin(); it != groups.constEnd(); ++it) { + if ((*it)->leader() == leader) { return *it; + } + } return nullptr; } @@ -1914,12 +1969,13 @@ Group *Workspace::findClientLeaderGroup(const X11Client *c) const { Group *ret = nullptr; for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { - if (*it == c) + if (*it == c) { continue; + } if ((*it)->wmClientLeader() == c->wmClientLeader()) { - if (ret == nullptr || ret == (*it)->group()) + if (ret == nullptr || ret == (*it)->group()) { ret = (*it)->group(); - else { + } else { // There are already two groups with the same client leader. // This most probably means the app uses group transients without // setting group for its windows. Merging the two groups is a bad @@ -1928,8 +1984,9 @@ Group *Workspace::findClientLeaderGroup(const X11Client *c) const // old_group autodeletes when being empty for (int pos = 0; pos < old_group.count(); ++pos) { X11Client *tmp = old_group[pos]; - if (tmp != c) + if (tmp != c) { tmp->changeClientLeaderGroup(ret); + } } } } @@ -1942,8 +1999,9 @@ void Workspace::updateMinimizedOfTransients(AbstractClient *c) // if mainwindow is minimized or shaded, minimize transients too if (c->isMinimized()) { for (auto it = c->transients().constBegin(); it != c->transients().constEnd(); ++it) { - if ((*it)->isModal()) + if ((*it)->isModal()) { continue; // there's no reason to hide modal dialogs with the main client + } // but to keep them to eg. watch progress or whatever if (!(*it)->isMinimized()) { (*it)->minimize(); @@ -1979,16 +2037,18 @@ void Workspace::updateMinimizedOfTransients(AbstractClient *c) void Workspace::updateOnAllDesktopsOfTransients(AbstractClient *c) { for (auto it = c->transients().constBegin(); it != c->transients().constEnd(); ++it) { - if ((*it)->isOnAllDesktops() != c->isOnAllDesktops()) + if ((*it)->isOnAllDesktops() != c->isOnAllDesktops()) { (*it)->setOnAllDesktops(c->isOnAllDesktops()); + } } } // A new window has been mapped. Check if it's not a mainwindow for some already existing transient window. void Workspace::checkTransients(xcb_window_t w) { - for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) + for (auto it = m_x11Clients.constBegin(); it != m_x11Clients.constEnd(); ++it) { (*it)->checkTransient(w); + } } /** @@ -2254,10 +2314,11 @@ QRect Workspace::clientArea(clientAreaOption opt, const AbstractOutput *output, case ScreenArea: return effectiveOutput->geometry(); case WorkArea: - if (is_multihead) + if (is_multihead) { return screenArea; - else + } else { return workArea; + } case FullArea: return QRect(QPoint(0, 0), m_geometry.size()); @@ -2458,18 +2519,24 @@ QPoint Workspace::adjustClientPosition(AbstractClient *c, QPoint pos, bool unres int snap = options->windowSnapZone() * snapAdjust; if (snap) { for (auto l = m_allClients.constBegin(); l != m_allClients.constEnd(); ++l) { - if ((*l) == c) + if ((*l) == c) { continue; - if ((*l)->isMinimized() || (*l)->isShade()) + } + if ((*l)->isMinimized() || (*l)->isShade()) { continue; - if (!(*l)->isShown()) + } + if (!(*l)->isShown()) { continue; - if (!(*l)->isOnCurrentDesktop()) + } + if (!(*l)->isOnCurrentDesktop()) { continue; // wrong virtual desktop - if (!(*l)->isOnCurrentActivity()) + } + if (!(*l)->isOnCurrentActivity()) { continue; // wrong activity - if ((*l)->isDesktop() || (*l)->isSplash() || (*l)->isNotification() || (*l)->isCriticalNotification() || (*l)->isOnScreenDisplay()) + } + if ((*l)->isDesktop() || (*l)->isSplash() || (*l)->isNotification() || (*l)->isCriticalNotification() || (*l)->isOnScreenDisplay()) { continue; + } lx = (*l)->x(); ly = (*l)->y(); @@ -2791,10 +2858,11 @@ void Workspace::setMoveResizeClient(AbstractClient *c) Q_ASSERT(!c || !movingClient); // Catch attempts to move a second // window while still moving the first one. movingClient = c; - if (movingClient) + if (movingClient) { ++block_focus; - else + } else { --block_focus; + } } // When kwin crashes, windows will not be gravitated back to their original position diff --git a/src/x11client.cpp b/src/x11client.cpp index 580633f399..fc148a426c 100644 --- a/src/x11client.cpp +++ b/src/x11client.cpp @@ -228,8 +228,9 @@ X11Client::X11Client() connect(this, &X11Client::moveResizeCursorChanged, this, [this](CursorShape cursor) { xcb_cursor_t nativeCursor = Cursors::self()->mouse()->x11Cursor(cursor); m_frame.defineCursor(nativeCursor); - if (m_decoInputExtent.isValid()) + if (m_decoInputExtent.isValid()) { m_decoInputExtent.defineCursor(nativeCursor); + } if (isInteractiveMoveResize()) { // changing window attributes doesn't change cursor if there's pointer grab active xcb_change_active_pointer_grab(kwinApp()->x11Connection(), nativeCursor, xTime(), @@ -277,14 +278,16 @@ void X11Client::releaseWindow(bool on_shutdown) if (!on_shutdown) { del = Deleted::create(this); } - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { Q_EMIT clientFinishUserMovedResized(this); + } Q_EMIT windowClosed(this, del); finishCompositing(); RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules StackingUpdatesBlocker blocker(workspace()); - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { leaveInteractiveMoveResize(); + } finishWindowRules(); blockGeometryUpdates(); // Grab X during the release to make removing of properties, setting to withdrawn state @@ -293,8 +296,9 @@ void X11Client::releaseWindow(bool on_shutdown) exportMappingState(XCB_ICCCM_WM_STATE_WITHDRAWN); setModal(false); // Otherwise its mainwindow wouldn't get focus hidden = true; // So that it's not considered visible anymore (can't use hideClient(), it would set flags) - if (!on_shutdown) + if (!on_shutdown) { workspace()->clientHidden(this); + } m_frame.unmap(); // Destroying decoration would cause ugly visual effect destroyDecoration(); cleanGrouping(); @@ -311,13 +315,14 @@ void X11Client::releaseWindow(bool on_shutdown) m_client.reparent(kwinApp()->x11RootWindow(), m_bufferGeometry.x(), m_bufferGeometry.y()); xcb_change_save_set(c, XCB_SET_MODE_DELETE, m_client); m_client.selectInput(XCB_EVENT_MASK_NO_EVENT); - if (on_shutdown) + if (on_shutdown) { // Map the window, so it can be found after another WM is started m_client.map(); // TODO: Preserve minimized, shaded etc. state? - else // Make sure it's not mapped if the app unmapped it (#65279). The app + } else { // Make sure it's not mapped if the app unmapped it (#65279). The app // may do map+unmap before we initially map the window by calling rawShow() from manage(). m_client.unmap(); + } m_client.reset(); m_wrapper.reset(); m_frame.reset(); @@ -339,14 +344,16 @@ void X11Client::destroyClient() markAsZombie(); cleanTabBox(); Deleted *del = Deleted::create(this); - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { Q_EMIT clientFinishUserMovedResized(this); + } Q_EMIT windowClosed(this, del); finishCompositing(ReleaseReason::Destroyed); RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules StackingUpdatesBlocker blocker(workspace()); - if (isInteractiveMoveResize()) + if (isInteractiveMoveResize()) { leaveInteractiveMoveResize(); + } finishWindowRules(); blockGeometryUpdates(); setModal(false); @@ -431,8 +438,9 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) connect(this, &X11Client::windowClassChanged, this, &X11Client::evaluateWindowRules); - if (Xcb::Extensions::self()->isShapeAvailable()) + if (Xcb::Extensions::self()->isShapeAvailable()) { xcb_shape_select_input(kwinApp()->x11Connection(), window(), true); + } detectShape(window()); detectNoBorder(); fetchIconicName(); @@ -513,13 +521,16 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) { if (mainclients.count() > 1 && // A group-transient (*it)->isSpecialWindow() && // Don't consider toolbars etc when placing - !(info->state() & NET::Modal)) // except when it's modal (blocks specials as well) + !(info->state() & NET::Modal)) { // except when it's modal (blocks specials as well) continue; + } maincl = *it; - if ((*it)->isOnCurrentDesktop()) + if ((*it)->isOnCurrentDesktop()) { on_current = true; - if ((*it)->isOnAllDesktops()) + } + if ((*it)->isOnAllDesktops()) { on_all = true; + } } if (on_all) { initialDesktops = QVector{}; @@ -529,8 +540,9 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) initialDesktops = maincl->desktops(); } - if (maincl) + if (maincl) { setOnActivities(maincl->activities()); + } } else { // a transient shall appear on its leader and not drag that around int desktopId = 0; if (info->desktop()) { @@ -580,14 +592,16 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) QStringList activitiesList; activitiesList = rules()->checkActivity(activitiesList, !isMapped); - if (!activitiesList.isEmpty()) + if (!activitiesList.isEmpty()) { setOnActivities(activitiesList); + } QRect geom(windowGeometry.rect()); bool placementDone = false; - if (session) + if (session) { geom = session->geometry; + } QRect area; bool partial_keep_in_area = isMapped || session; @@ -606,18 +620,19 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) area = workspace()->clientArea(PlacementArea, this, output->geometry().center()); } - if (isDesktop()) + if (isDesktop()) { // KWin doesn't manage desktop windows placementDone = true; + } bool usePosition = false; - if (isMapped || session || placementDone) + if (isMapped || session || placementDone) { placementDone = true; // Use geometry - else if (isTransient() && !isUtility() && !isDialog() && !isSplash()) + } else if (isTransient() && !isUtility() && !isDialog() && !isSplash()) { usePosition = true; - else if (isTransient() && !hasNETSupport()) + } else if (isTransient() && !hasNETSupport()) { usePosition = true; - else if (isDialog() && hasNETSupport()) { + } else if (isDialog() && hasNETSupport()) { // If the dialog is actually non-NETWM transient window, don't try to apply placement to it, // it breaks with too many things (xmms, display) if (mainClients().count() >= 1) { @@ -632,12 +647,14 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) #else ; // Force using placement policy #endif - } else + } else { usePosition = true; - } else if (isSplash()) + } + } else if (isSplash()) { ; // Force using placement policy - else + } else { usePosition = true; + } if (!rules()->checkIgnoreGeometry(!usePosition, true)) { if (m_geometryHints.hasPosition()) { placementDone = true; @@ -646,8 +663,9 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) } } - if (isMovable() && (geom.x() > area.right() || geom.y() > area.bottom())) + if (isMovable() && (geom.x() > area.right() || geom.y() > area.bottom())) { placementDone = false; // Weird, do not trust. + } if (placementDone) { QPoint position = geom.topLeft(); @@ -705,10 +723,12 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) const QRect fsa = workspace()->clientArea(FullArea, this, geom.center()); const QSize cs = clientSize(); int pseudo_max = ((info->state() & NET::MaxVert) ? MaximizeVertical : 0) | ((info->state() & NET::MaxHoriz) ? MaximizeHorizontal : 0); - if (width() >= area.width()) + if (width() >= area.width()) { pseudo_max |= MaximizeHorizontal; - if (height() >= area.height()) + } + if (height() >= area.height()) { pseudo_max |= MaximizeVertical; + } // heuristics: // if decorated client is smaller than the entire screen, the user might want to move it around (multiscreen) @@ -743,13 +763,15 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) } setGeometryRestore(savedGeometry); } - if (keepInFsArea) + if (keepInFsArea) { keepInArea(fsa, partial_keep_in_area); + } } } - if ((!isSpecialWindow() || isToolbar()) && isMovable() && !dontKeepInArea) + if ((!isSpecialWindow() || isToolbar()) && isMovable() && !dontKeepInArea) { keepInArea(area, partial_keep_in_area); + } updateShape(); @@ -758,9 +780,11 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) // window that is not Iconic, set init_state to Normal if (init_minimize && isTransient()) { auto mainclients = mainClients(); - for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) - if ((*it)->isShown()) + for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) { + if ((*it)->isShown()) { init_minimize = false; // SELI TODO: Even e.g. for NET::Utility? + } + } } // If a dialog is shown for minimized window, minimize it too if (!init_minimize && isTransient() && mainClients().count() > 0 && workspace()->sessionManager()->state() != SessionState::Saving) { @@ -768,17 +792,20 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) // Use allMainClients(), to include also main clients of group transients // that have been optimized out in X11Client::checkGroupTransients() auto mainclients = allMainClients(); - for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) - if ((*it)->isShown()) + for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) { + if ((*it)->isShown()) { visible_parent = true; + } + } if (!visible_parent) { init_minimize = true; demandAttention(); } } - if (init_minimize) + if (init_minimize) { minimize(true); // No animation + } // Other settings from the previous session if (session) { @@ -816,8 +843,9 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) // Either hints were set to maximize, or is forced to maximize, // or is forced to non-maximize and hints were set to maximize - if (forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore) + if (forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore) { maximize(forced_maxmode); + } // Read other initial states setShade(rules()->checkShade(info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped)); @@ -826,10 +854,12 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) setOriginalSkipTaskbar(rules()->checkSkipTaskbar(info->state() & NET::SkipTaskbar, !isMapped)); setSkipPager(rules()->checkSkipPager(info->state() & NET::SkipPager, !isMapped)); setSkipSwitcher(rules()->checkSkipSwitcher(info->state() & NET::SkipSwitcher, !isMapped)); - if (info->state() & NET::DemandsAttention) + if (info->state() & NET::DemandsAttention) { demandAttention(); - if (info->state() & NET::Modal) + } + if (info->state() & NET::Modal) { setModal(true); + } setOpacity(info->opacityF()); setFullScreen(rules()->checkFullScreen(info->state() & NET::FullScreen, !isMapped), false); @@ -849,26 +879,29 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) workspace()->restoreSessionStackingOrder(this); } - if (Compositor::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(); - else + } else { ready_for_painting = true; // set to true in case compositing is turned on later. bug #160393 + } if (isShown()) { bool allow; - if (session) + if (session) { allow = session->active && (!workspace()->wasUserInteraction() || workspace()->activeClient() == nullptr || workspace()->activeClient()->isDesktop()); - else + } else { allow = workspace()->allowClientActivation(this, userTime(), false); + } const bool isSessionSaving = workspace()->sessionManager()->state() == SessionState::Saving; // If session saving, force showing new windows (i.e. "save file?" dialogs etc.) // also force if activation is allowed - if (!isOnCurrentDesktop() && !isMapped && !session && (allow || isSessionSaving)) + if (!isOnCurrentDesktop() && !isMapped && !session && (allow || isSessionSaving)) { VirtualDesktopManager::self()->setCurrent(desktop()); + } // If the window is on an inactive activity during session saving, temporarily force it to show. if (!isMapped && !session && isSessionSaving && !isOnCurrentActivity()) { @@ -881,21 +914,26 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) } } - if (isOnCurrentDesktop() && !isMapped && !allow && (!session || session->stackingOrder < 0)) + if (isOnCurrentDesktop() && !isMapped && !allow && (!session || session->stackingOrder < 0)) { workspace()->restackClientUnderActive(this); + } updateVisibility(); if (!isMapped) { if (allow && isOnCurrentDesktop()) { - if (!isSpecialWindow()) - if (options->focusPolicyIsReasonable() && wantsTabFocus()) + if (!isSpecialWindow()) { + if (options->focusPolicyIsReasonable() && wantsTabFocus()) { workspace()->requestFocus(this); - } else if (!session && !isSpecialWindow()) + } + } + } else if (!session && !isSpecialWindow()) { demandAttention(); + } } - } else + } else { updateVisibility(); + } Q_ASSERT(mapping_state != Withdrawn); m_managed = true; blockGeometryUpdates(false); @@ -903,8 +941,9 @@ bool X11Client::manage(xcb_window_t w, bool isMapped) if (m_userTime == XCB_TIME_CURRENT_TIME || m_userTime == -1U) { // No known user time, set something old m_userTime = xTime() - 1000000; - if (m_userTime == XCB_TIME_CURRENT_TIME || m_userTime == -1U) // Let's be paranoid + if (m_userTime == XCB_TIME_CURRENT_TIME || m_userTime == -1U) { // Let's be paranoid m_userTime = xTime() - 1000000 + 10; + } } // sendSyntheticConfigureNotify(); // Done when setting mapping state @@ -1014,8 +1053,9 @@ void X11Client::embedClient(xcb_window_t w, xcb_visualid_t visualid, xcb_colorma void X11Client::updateInputWindow() { - if (!Xcb::Extensions::self()->isShapeInputAvailable()) + if (!Xcb::Extensions::self()->isShapeInputAvailable()) { return; + } if (kwinApp()->operationMode() != Application::OperationModeX11) { return; @@ -1057,8 +1097,9 @@ void X11Client::updateInputWindow() const uint32_t values[] = {true, XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION}; m_decoInputExtent.create(bounds, XCB_WINDOW_CLASS_INPUT_ONLY, mask, values); - if (mapping_state == Mapped) + if (mapping_state == Mapped) { m_decoInputExtent.map(); + } } else { m_decoInputExtent.setGeometry(bounds); } @@ -1070,19 +1111,23 @@ void X11Client::updateInputWindow() void X11Client::updateDecoration(bool check_workspace_pos, bool force) { - if (!force && ((!isDecorated() && noBorder()) || (isDecorated() && !noBorder()))) + if (!force && ((!isDecorated() && noBorder()) || (isDecorated() && !noBorder()))) { return; + } QRect oldgeom = frameGeometry(); blockGeometryUpdates(true); - if (force) + if (force) { destroyDecoration(); + } if (!noBorder()) { createDecoration(oldgeom); - } else + } else { destroyDecoration(); + } updateShadow(); - if (check_workspace_pos) + if (check_workspace_pos) { checkWorkspacePosition(oldgeom); + } updateInputWindow(); blockGeometryUpdates(false); updateFrameExtents(); @@ -1264,11 +1309,13 @@ bool X11Client::userCanSetNoBorder() const void X11Client::setNoBorder(bool set) { - if (!userCanSetNoBorder()) + if (!userCanSetNoBorder()) { return; + } set = rules()->checkNoBorder(set); - if (noborder == set) + if (noborder == set) { return; + } noborder = set; updateDecoration(true, false); updateWindowRules(Rules::NoBorder); @@ -1320,8 +1367,9 @@ void X11Client::cleanupX11() void X11Client::updateInputShape() { - if (hiddenPreview()) // Sets it to none, don't change + if (hiddenPreview()) { // Sets it to none, don't change return; + } if (Xcb::Extensions::self()->isShapeInputAvailable()) { // There appears to be no way to find out if a window has input // shape set or not, so always propagate the input shape @@ -1333,8 +1381,9 @@ void X11Client::updateInputShape() // until the real shape of the client is added and that can make // the window lose focus (which is a problem with mouse focus policies) // TODO: It seems there is, after all - XShapeGetRectangles() - but maybe this is better - if (!shape_helper_window.isValid()) + if (!shape_helper_window.isValid()) { shape_helper_window.create(QRect(0, 0, 1, 1)); + } shape_helper_window.resize(m_bufferGeometry.size()); xcb_connection_t *c = kwinApp()->x11Connection(); xcb_shape_combine(c, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_SHAPE_SK_BOUNDING, @@ -1390,20 +1439,25 @@ void X11Client::finishCompositing(ReleaseReason releaseReason) */ bool X11Client::isMinimizable() const { - if (isSpecialWindow() && !isTransient()) + if (isSpecialWindow() && !isTransient()) { return false; - if (!rules()->checkMinimize(true)) + } + if (!rules()->checkMinimize(true)) { return false; + } if (isTransient()) { // #66868 - Let other xmms windows be minimized when the mainwindow is minimized bool shown_mainwindow = false; auto mainclients = mainClients(); - for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) - if ((*it)->isShown()) + for (auto it = mainclients.constBegin(); it != mainclients.constEnd(); ++it) { + if ((*it)->isShown()) { shown_mainwindow = true; - if (!shown_mainwindow) + } + } + if (!shown_mainwindow) { return true; + } } #if 0 // This is here because kicker's taskbar doesn't provide separate entries @@ -1414,8 +1468,9 @@ bool X11Client::isMinimizable() const if (transientFor() != NULL) return false; #endif - if (!wantsTabFocus()) // SELI, TODO: - NET::Utility? why wantsTabFocus() - skiptaskbar? ? + if (!wantsTabFocus()) { // SELI, TODO: - NET::Utility? why wantsTabFocus() - skiptaskbar? ? return false; + } return true; } @@ -1434,9 +1489,9 @@ QRect X11Client::iconGeometry() const { NETRect r = info->iconGeometry(); QRect geom(r.pos.x, r.pos.y, r.size.width, r.size.height); - if (geom.isValid()) + if (geom.isValid()) { return geom; - else { + } else { // Check all mainwindows of this window (recursively) const auto &clients = mainClients(); for (AbstractClient *amainwin : clients) { @@ -1445,8 +1500,9 @@ QRect X11Client::iconGeometry() const continue; } geom = mainwin->iconGeometry(); - if (geom.isValid()) + if (geom.isValid()) { return geom; + } } // No mainwindow (or their parents) with icon geometry was found return AbstractClient::iconGeometry(); @@ -1476,23 +1532,27 @@ void X11Client::doSetShade(ShadeMode previousShadeMode) resize(s); shade_geometry_change = false; if (previousShadeMode == ShadeHover) { - if (shade_below && workspace()->stackingOrder().indexOf(shade_below) > -1) + if (shade_below && workspace()->stackingOrder().indexOf(shade_below) > -1) { workspace()->restack(this, shade_below, true); - if (isActive()) + } + if (isActive()) { workspace()->activateNextClient(this); + } } else if (isActive()) { workspace()->focusToNull(); } } else { shade_geometry_change = true; - if (decoratedClient()) + if (decoratedClient()) { decoratedClient()->signalShadeChange(); + } QSize s(implicitSize()); shade_geometry_change = false; resize(s); setGeometryRestore(frameGeometry()); - if ((shadeMode() == ShadeHover || shadeMode() == ShadeActivated) && rules()->checkAcceptFocus(info->input())) + if ((shadeMode() == ShadeHover || shadeMode() == ShadeActivated) && rules()->checkAcceptFocus(info->input())) { setActive(true); + } if (shadeMode() == ShadeHover) { QList order = workspace()->stackingOrder(); // invalidate, since "this" could be the topmost toplevel and shade_below dangeling @@ -1504,16 +1564,18 @@ void X11Client::doSetShade(ShadeMode previousShadeMode) break; } } - if (shade_below && shade_below->isNormalWindow()) + if (shade_below && shade_below->isNormalWindow()) { workspace()->raiseClient(this); - else + } else { shade_below = nullptr; + } } m_wrapper.map(); m_client.map(); exportMappingState(XCB_ICCCM_WM_STATE_NORMAL); - if (isActive()) + if (isActive()) { workspace()->requestFocus(this); + } } info->setState(isShade() ? NET::Shaded : NET::States(), NET::Shaded); info->setState((isShade() || !isShown()) ? NET::Hidden : NET::States(), NET::Hidden); @@ -1524,39 +1586,44 @@ void X11Client::doSetShade(ShadeMode previousShadeMode) void X11Client::updateVisibility() { - if (isZombie()) + if (isZombie()) { return; + } if (hidden) { info->setState(NET::Hidden, NET::Hidden); setSkipTaskbar(true); // Also hide from taskbar - if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) + if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) { internalKeep(); - else + } else { internalHide(); + } return; } setSkipTaskbar(originalSkipTaskbar()); // Reset from 'hidden' if (isMinimized()) { info->setState(NET::Hidden, NET::Hidden); - if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) + if (Compositor::compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) { internalKeep(); - else + } else { internalHide(); + } return; } info->setState(NET::States(), NET::Hidden); if (!isOnCurrentDesktop()) { - if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) + if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) { internalKeep(); - else + } else { internalHide(); + } return; } if (!isOnCurrentActivity()) { - if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) + if (Compositor::compositing() && options->hiddenPreviews() != HiddenPreviewsNever) { internalKeep(); - else + } else { internalHide(); + } return; } internalShow(); @@ -1584,12 +1651,14 @@ void X11Client::exportMappingState(int s) void X11Client::internalShow() { - if (mapping_state == Mapped) + if (mapping_state == Mapped) { return; + } MappingState old = mapping_state; mapping_state = Mapped; - if (old == Unmapped || old == Withdrawn) + if (old == Unmapped || old == Withdrawn) { map(); + } if (old == Kept) { m_decoInputExtent.map(); updateHiddenPreview(); @@ -1599,14 +1668,17 @@ void X11Client::internalShow() void X11Client::internalHide() { - if (mapping_state == Unmapped) + if (mapping_state == Unmapped) { return; + } MappingState old = mapping_state; mapping_state = Unmapped; - if (old == Mapped || old == Kept) + if (old == Mapped || old == Kept) { unmap(); - if (old == Kept) + } + if (old == Kept) { updateHiddenPreview(); + } addWorkspaceRepaint(visibleGeometry()); workspace()->clientHidden(this); Q_EMIT windowHidden(this); @@ -1615,15 +1687,18 @@ void X11Client::internalHide() void X11Client::internalKeep() { Q_ASSERT(Compositor::compositing()); - if (mapping_state == Kept) + if (mapping_state == Kept) { return; + } MappingState old = mapping_state; mapping_state = Kept; - if (old == Unmapped || old == Withdrawn) + if (old == Unmapped || old == Withdrawn) { map(); + } m_decoInputExtent.unmap(); - if (isActive()) + if (isActive()) { workspace()->focusToNull(); // get rid of input focus, bug #317484 + } updateHiddenPreview(); addWorkspaceRepaint(visibleGeometry()); workspace()->clientHidden(this); @@ -1639,16 +1714,18 @@ 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 (Compositor::compositing()) + if (Compositor::compositing()) { discardWindowPixmap(); + } m_frame.map(); if (!isShade()) { m_wrapper.map(); m_client.map(); m_decoInputExtent.map(); exportMappingState(XCB_ICCCM_WM_STATE_NORMAL); - } else + } else { exportMappingState(XCB_ICCCM_WM_STATE_ICONIC); + } addLayerRepaint(visibleGeometry()); } @@ -1735,8 +1812,9 @@ bool X11Client::isCloseable() const */ void X11Client::closeWindow() { - if (!isCloseable()) + if (!isCloseable()) { return; + } // Update user time, because the window may create a confirming dialog. updateUserTime(); @@ -1744,9 +1822,10 @@ void X11Client::closeWindow() if (info->supportsProtocol(NET::DeleteWindowProtocol)) { sendClientMessage(window(), atoms->wm_protocols, atoms->wm_delete_window); pingWindow(); - } else // Client will not react on wm_delete_window. We have not choice + } else { // Client will not react on wm_delete_window. We have not choice // but destroy his connection to the XServer. killWindow(); + } } /** @@ -1766,12 +1845,15 @@ void X11Client::killWindow() */ void X11Client::pingWindow() { - if (!info->supportsProtocol(NET::PingProtocol)) + if (!info->supportsProtocol(NET::PingProtocol)) { return; // Can't ping :( - if (options->killPingTimeout() == 0) + } + if (options->killPingTimeout() == 0) { return; // Turned off - if (ping_timer != nullptr) + } + if (ping_timer != nullptr) { return; // Pinging already + } ping_timer = new QTimer(this); connect(ping_timer, &QTimer::timeout, this, [this]() { if (unresponsive()) { @@ -1798,8 +1880,9 @@ void X11Client::pingWindow() void X11Client::gotPing(xcb_timestamp_t timestamp) { // Just plain compare is not good enough because of 64bit and truncating and whatnot - if (NET::timestampCompare(timestamp, m_pingTimestamp) != 0) + if (NET::timestampCompare(timestamp, m_pingTimestamp) != 0) { return; + } delete ping_timer; ping_timer = nullptr; @@ -1813,20 +1896,23 @@ void X11Client::gotPing(xcb_timestamp_t timestamp) void X11Client::killProcess(bool ask, xcb_timestamp_t timestamp) { - if (m_killHelperPID && !::kill(m_killHelperPID, 0)) // means the process is alive + if (m_killHelperPID && !::kill(m_killHelperPID, 0)) { // means the process is alive return; + } Q_ASSERT(!ask || timestamp != XCB_TIME_CURRENT_TIME); pid_t pid = info->pid(); - if (pid <= 0 || clientMachine()->hostName().isEmpty()) // Needed properties missing + if (pid <= 0 || clientMachine()->hostName().isEmpty()) { // Needed properties missing return; + } qCDebug(KWIN_CORE) << "Kill process:" << pid << "(" << clientMachine()->hostName() << ")"; if (!ask) { if (!clientMachine()->isLocal()) { QStringList lst; lst << QString::fromUtf8(clientMachine()->hostName()) << QStringLiteral("kill") << QString::number(pid); QProcess::startDetached(QStringLiteral("xon"), lst); - } else + } else { ::kill(pid, SIGTERM); + } } else { QString hostname = clientMachine()->isLocal() ? QStringLiteral("localhost") : QString::fromUtf8(clientMachine()->hostName()); // execute helper from build dir or the system installed one @@ -1945,8 +2031,9 @@ bool X11Client::takeFocus() } } } - if (breakShowingDesktop) + if (breakShowingDesktop) { workspace()->setShowingDesktop(false); + } return true; } @@ -2004,9 +2091,9 @@ static inline QString readNameProperty(xcb_window_t w, xcb_atom_t atom) QString X11Client::readName() const { - if (info->name() && info->name()[0] != '\0') + if (info->name() && info->name()[0] != '\0') { return QString::fromUtf8(info->name()).simplified(); - else { + } else { return readNameProperty(window(), XCB_ATOM_WM_NAME); } } @@ -2048,8 +2135,9 @@ void X11Client::setCaption(const QString &_s, bool force) cap_suffix.clear(); QString machine_suffix; if (!options->condensedTitle()) { // machine doesn't qualify for "clean" - if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal()) + if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal()) { machine_suffix = QLatin1String(" <@") + QString::fromUtf8(clientMachine()->hostName()) + QLatin1Char('>') + LRM; + } } QString shortcut_suffix = shortcutCaptionSuffix(); cap_suffix = machine_suffix + shortcut_suffix; @@ -2066,9 +2154,10 @@ void X11Client::setCaption(const QString &_s, bool force) // If it was new window, it may have old value still set, if the window is reused info->setVisibleName(""); info->setVisibleIconName(""); - } else if (!cap_suffix.isEmpty() && !cap_iconic.isEmpty()) + } else if (!cap_suffix.isEmpty() && !cap_iconic.isEmpty()) { // Keep the same suffix in iconic name if it's set info->setVisibleIconName(QString(cap_iconic + cap_suffix).toUtf8().constData()); + } Q_EMIT captionChanged(); } @@ -2081,28 +2170,32 @@ void X11Client::updateCaption() void X11Client::fetchIconicName() { QString s; - if (info->iconName() && info->iconName()[0] != '\0') + if (info->iconName() && info->iconName()[0] != '\0') { s = QString::fromUtf8(info->iconName()); - else + } else { s = readNameProperty(window(), XCB_ATOM_WM_ICON_NAME); + } if (s != cap_iconic) { bool was_set = !cap_iconic.isEmpty(); cap_iconic = s; if (!cap_suffix.isEmpty()) { - if (!cap_iconic.isEmpty()) // Keep the same suffix in iconic name if it's set + if (!cap_iconic.isEmpty()) { // Keep the same suffix in iconic name if it's set info->setVisibleIconName(QString(s + cap_suffix).toUtf8().constData()); - else if (was_set) + } else if (was_set) { info->setVisibleIconName(""); + } } } } void X11Client::setClientShown(bool shown) { - if (isZombie()) + if (isZombie()) { return; // Don't change shown status if this client is being deleted - if (shown != hidden) + } + if (shown != hidden) { return; // nothing to change + } hidden = !shown; if (shown) { map(); @@ -2121,24 +2214,27 @@ void X11Client::getMotifHints() { const bool wasClosable = isCloseable(); const bool wasNoBorder = m_motif.noBorder(); - if (m_managed) // only on property change, initial read is prefetched + if (m_managed) { // only on property change, initial read is prefetched m_motif.fetch(); + } m_motif.read(); if (m_motif.hasDecoration() && m_motif.noBorder() != wasNoBorder) { // If we just got a hint telling us to hide decorations, we do so. - if (m_motif.noBorder()) + if (m_motif.noBorder()) { noborder = rules()->checkNoBorder(true); // If the Motif hint is now telling us to show decorations, we only do so if the app didn't // instruct us to hide decorations in some other way, though. - else if (!app_noborder) + } else if (!app_noborder) { noborder = rules()->checkNoBorder(false); + } } // mminimize; - Ignore, bogus - E.g. shading or sending to another desktop is "minimizing" too // mmaximize; - Ignore, bogus - Maximizing is basically just resizing const bool closabilityChanged = wasClosable != isCloseable(); - if (isManaged()) + if (isManaged()) { updateDecoration(true); // Check if noborder state has changed + } if (closabilityChanged) { Q_EMIT closeableChanged(isCloseable()); } @@ -2198,10 +2294,12 @@ bool X11Client::wantsSyncCounter() const void X11Client::getSyncCounter() { - if (!Xcb::Extensions::self()->isSyncAvailable()) + if (!Xcb::Extensions::self()->isSyncAvailable()) { return; - if (!wantsSyncCounter()) + } + if (!wantsSyncCounter()) { return; + } Xcb::Property syncProp(false, window(), atoms->net_wm_sync_request_counter, XCB_ATOM_CARDINAL, 0, 1); const xcb_sync_counter_t counter = syncProp.value(XCB_NONE); @@ -2313,28 +2411,37 @@ void X11Client::setBlockingCompositing(bool block) void X11Client::updateAllowedActions(bool force) { - if (!isManaged() && !force) + if (!isManaged() && !force) { return; + } NET::Actions old_allowed_actions = NET::Actions(allowed_actions); allowed_actions = NET::Actions(); - if (isMovable()) + if (isMovable()) { allowed_actions |= NET::ActionMove; - if (isResizable()) + } + if (isResizable()) { allowed_actions |= NET::ActionResize; - if (isMinimizable()) + } + if (isMinimizable()) { allowed_actions |= NET::ActionMinimize; - if (isShadeable()) + } + if (isShadeable()) { allowed_actions |= NET::ActionShade; + } // Sticky state not supported - if (isMaximizable()) + if (isMaximizable()) { allowed_actions |= NET::ActionMax; - if (userCanSetFullScreen()) + } + if (userCanSetFullScreen()) { allowed_actions |= NET::ActionFullScreen; + } allowed_actions |= NET::ActionChangeDesktop; // Always (Pagers shouldn't show Docks etc.) - if (isCloseable()) + if (isCloseable()) { allowed_actions |= NET::ActionClose; - if (old_allowed_actions == allowed_actions) + } + if (old_allowed_actions == allowed_actions) { return; + } // TODO: This could be delayed and compressed - It's only for pagers etc. anyway info->setAllowedActions(allowed_actions); @@ -2391,8 +2498,9 @@ void X11Client::readActivities(Xcb::StringProperty &property) newActivitiesList = prop.split(u','); - if (newActivitiesList == m_activityList) + if (newActivitiesList == m_activityList) { return; // expected change, it's ok. + } // otherwise, somebody else changed it. we need to validate before reacting. // if the activities are not synced, and there are existing clients with @@ -2488,8 +2596,9 @@ NET::WindowType X11Client::windowType(bool direct, int supportedTypes) const info->setWindowType(wt); // force hint change } // hacks here - if (wt == NET::Unknown) // this is more or less suggested in NETWM spec + if (wt == NET::Unknown) { // this is more or less suggested in NETWM spec wt = isTransient() ? NET::Dialog : NET::Normal; + } return wt; } @@ -2755,38 +2864,39 @@ bool X11Client::belongToSameApplication(const X11Client *c1, const X11Client *c2 bool same_app = false; // tests that definitely mean they belong together - if (c1 == c2) + if (c1 == c2) { same_app = true; - else if (c1->isTransient() && c2->hasTransient(c1, true)) + } else if (c1->isTransient() && c2->hasTransient(c1, true)) { same_app = true; // c1 has c2 as mainwindow - else if (c2->isTransient() && c1->hasTransient(c2, true)) + } else if (c2->isTransient() && c1->hasTransient(c2, true)) { same_app = true; // c2 has c1 as mainwindow - else if (c1->group() == c2->group()) + } else if (c1->group() == c2->group()) { same_app = true; // same group - else if (c1->wmClientLeader() == c2->wmClientLeader() - && c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(), - && c2->wmClientLeader() != c2->window()) // don't use in this test then + } else if (c1->wmClientLeader() == c2->wmClientLeader() + && c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(), + && c2->wmClientLeader() != c2->window()) { // don't use in this test then same_app = true; // same client leader // tests that mean they most probably don't belong together - else if ((c1->pid() != c2->pid() && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) - || c1->wmClientMachine(false) != c2->wmClientMachine(false)) + } else if ((c1->pid() != c2->pid() && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) + || c1->wmClientMachine(false) != c2->wmClientMachine(false)) { ; // different processes - else if (c1->wmClientLeader() != c2->wmClientLeader() - && c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(), - && c2->wmClientLeader() != c2->window() // don't use in this test then - && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) + } else if (c1->wmClientLeader() != c2->wmClientLeader() + && c1->wmClientLeader() != c1->window() // if WM_CLIENT_LEADER is not set, it returns window(), + && c2->wmClientLeader() != c2->window() // don't use in this test then + && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) { ; // different client leader - else if (!resourceMatch(c1, c2)) + } else if (!resourceMatch(c1, c2)) { ; // different apps - else if (!sameAppWindowRoleMatch(c1, c2, checks.testFlag(SameApplicationCheck::RelaxedForActive)) - && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) + } else if (!sameAppWindowRoleMatch(c1, c2, checks.testFlag(SameApplicationCheck::RelaxedForActive)) + && !checks.testFlag(SameApplicationCheck::AllowCrossProcesses)) { ; // "different" apps - else if (c1->pid() == 0 || c2->pid() == 0) + } else if (c1->pid() == 0 || c2->pid() == 0) { ; // old apps that don't have _NET_WM_PID, consider them different // if they weren't found to match above - else + } else { same_app = true; // looks like it's the same app + } return same_app; } @@ -2804,10 +2914,12 @@ bool X11Client::belongToSameApplication(const X11Client *c1, const X11Client *c2 bool X11Client::sameAppWindowRoleMatch(const X11Client *c1, const X11Client *c2, bool active_hack) { if (c1->isTransient()) { - while (const X11Client *t = dynamic_cast(c1->transientFor())) + while (const X11Client *t = dynamic_cast(c1->transientFor())) { c1 = t; - if (c1->groupTransient()) + } + if (c1->groupTransient()) { return c1->group() == c2->group(); + } #if 0 // if a group transient is in its own group, it didn't possibly have a group, // and therefore should be considered belonging to the same app like @@ -2816,10 +2928,12 @@ bool X11Client::sameAppWindowRoleMatch(const X11Client *c1, const X11Client *c2, #endif } if (c2->isTransient()) { - while (const X11Client *t = dynamic_cast(c2->transientFor())) + while (const X11Client *t = dynamic_cast(c2->transientFor())) { c2 = t; - if (c2->groupTransient()) + } + if (c2->groupTransient()) { return c1->group() == c2->group(); + } #if 0 || c1->group()->leaderClient() == c1 || c2->group()->leaderClient() == c2; #endif @@ -2827,12 +2941,14 @@ bool X11Client::sameAppWindowRoleMatch(const X11Client *c1, const X11Client *c2, int pos1 = c1->windowRole().indexOf('#'); int pos2 = c2->windowRole().indexOf('#'); if ((pos1 >= 0 && pos2 >= 0)) { - if (!active_hack) // without the active hack for focus stealing prevention, + if (!active_hack) { // without the active hack for focus stealing prevention, return c1 == c2; // different mainwindows are always different apps - if (!c1->isActive() && !c2->isActive()) + } + if (!c1->isActive() && !c2->isActive()) { return c1 == c2; - else + } else { return true; + } } return true; } @@ -2928,11 +3044,13 @@ void X11Client::setTransient(xcb_window_t new_transient_for_id) void X11Client::removeFromMainClients() { - if (transientFor()) + if (transientFor()) { transientFor()->removeTransient(this); + } if (groupTransient()) { - for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) + for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) { (*it)->removeTransient(this); + } } } @@ -2968,8 +3086,9 @@ void X11Client::cleanGrouping() if ((*it)->transientFor() == this) { removeTransient(*it); it = transients().constBegin(); // restart, just in case something more has changed with the list - } else + } else { ++it; + } } // qDebug() << "CLEANGROUPING3:" << this; // for ( auto it = group()->members().begin(); @@ -2989,8 +3108,9 @@ void X11Client::cleanGrouping() QList group_members = group()->members(); group()->removeMember(this); in_group = nullptr; - for (auto it = group_members.constBegin(); it != group_members.constEnd(); ++it) + for (auto it = group_members.constBegin(); it != group_members.constEnd(); ++it) { (*it)->removeTransient(this); + } // qDebug() << "CLEANGROUPING4:" << this; // for ( auto it = group_members.begin(); // it != group_members.end(); @@ -3006,12 +3126,14 @@ void X11Client::cleanGrouping() void X11Client::checkGroupTransients() { for (auto it1 = group()->members().constBegin(); it1 != group()->members().constEnd(); ++it1) { - if (!(*it1)->groupTransient()) // check all group transients in the group + if (!(*it1)->groupTransient()) { // check all group transients in the group continue; // TODO optimize to check only the changed ones? + } for (auto it2 = group()->members().constBegin(); it2 != group()->members().constEnd(); ++it2) { // group transients can be transient only for others in the group, // so don't make them transient for the ones that are transient for it - if (*it1 == *it2) + if (*it1 == *it2) { continue; + } for (AbstractClient *cl = (*it2)->transientFor(); cl != nullptr; cl = cl->transientFor()) { if (cl == *it1) { // don't use removeTransient(), that would modify *it2 too @@ -3023,21 +3145,25 @@ void X11Client::checkGroupTransients() // make only *it2 transient for *it1 (i.e. subwindow), as *it2 came later, // and should be therefore on top of *it1 // TODO This could possibly be optimized, it also requires hasTransient() to check for loops. - if ((*it2)->groupTransient() && (*it1)->hasTransient(*it2, true) && (*it2)->hasTransient(*it1, true)) + if ((*it2)->groupTransient() && (*it1)->hasTransient(*it2, true) && (*it2)->hasTransient(*it1, true)) { (*it2)->removeTransientFromList(*it1); + } // if there are already windows W1 and W2, W2 being transient for W1, and group transient W3 // is added, make it transient only for W2, not for W1, because it's already indirectly // transient for it - the indirect transiency actually shouldn't break anything, // but it can lead to exponentially expensive operations (#95231) // TODO this is pretty slow as well for (auto it3 = group()->members().constBegin(); it3 != group()->members().constEnd(); ++it3) { - if (*it1 == *it2 || *it2 == *it3 || *it1 == *it3) + if (*it1 == *it2 || *it2 == *it3 || *it1 == *it3) { continue; + } if ((*it2)->hasTransient(*it1, false) && (*it3)->hasTransient(*it1, false)) { - if ((*it2)->hasTransient(*it3, true)) + if ((*it2)->hasTransient(*it3, true)) { (*it2)->removeTransientFromList(*it1); - if ((*it3)->hasTransient(*it2, true)) + } + if ((*it3)->hasTransient(*it2, true)) { (*it3)->removeTransientFromList(*it1); + } } } } @@ -3052,13 +3178,15 @@ xcb_window_t X11Client::verifyTransientFor(xcb_window_t new_transient_for, bool xcb_window_t new_property_value = new_transient_for; // make sure splashscreens are shown above all their app's windows, even though // they're in Normal layer - if (isSplash() && new_transient_for == XCB_WINDOW_NONE) + if (isSplash() && new_transient_for == XCB_WINDOW_NONE) { new_transient_for = kwinApp()->x11RootWindow(); + } if (new_transient_for == XCB_WINDOW_NONE) { - if (set) // sometimes WM_TRANSIENT_FOR is set to None, instead of root window + if (set) { // sometimes WM_TRANSIENT_FOR is set to None, instead of root window new_property_value = new_transient_for = kwinApp()->x11RootWindow(); - else + } else { return XCB_WINDOW_NONE; + } } if (new_transient_for == window()) { // pointing to self // also fix the property itself @@ -3084,8 +3212,9 @@ xcb_window_t X11Client::verifyTransientFor(xcb_window_t new_transient_for, bool << before_search << ", child of " << new_transient_for_client << ", adjusting."; new_property_value = new_transient_for; // also fix the property } - } else + } else { new_transient_for = before_search; // nice try + } // loop detection // group transients cannot cause loops, because they're considered transient only for non-transient // windows in the group @@ -3093,8 +3222,9 @@ xcb_window_t X11Client::verifyTransientFor(xcb_window_t new_transient_for, bool xcb_window_t loop_pos = new_transient_for; while (loop_pos != XCB_WINDOW_NONE && loop_pos != kwinApp()->x11RootWindow()) { X11Client *pos = workspace()->findClient(Predicate::WindowMatch, loop_pos); - if (pos == nullptr) + if (pos == nullptr) { break; + } loop_pos = pos->m_transientForId; if (--count == 0 || pos == this) { qCWarning(KWIN_CORE) << "Client " << this << " caused WM_TRANSIENT_FOR loop."; @@ -3106,16 +3236,18 @@ xcb_window_t X11Client::verifyTransientFor(xcb_window_t new_transient_for, bool // it's transient for a specific window, but that window is not mapped new_transient_for = kwinApp()->x11RootWindow(); } - if (new_property_value != m_originalTransientForId) + if (new_property_value != m_originalTransientForId) { Xcb::setTransientFor(window(), new_property_value); + } return new_transient_for; } void X11Client::addTransient(AbstractClient *cl) { AbstractClient::addTransient(cl); - if (workspace()->mostRecentlyActivatedClient() == this && cl->isModal()) + if (workspace()->mostRecentlyActivatedClient() == this && cl->isModal()) { check_active_modal = true; + } // qDebug() << "ADDTRANS:" << this << ":" << cl; // qDebug() << kBacktrace(); // for ( auto it = transients_list.begin(); @@ -3144,8 +3276,9 @@ void X11Client::removeTransient(AbstractClient *cl) // A new window has been mapped. Check if it's not a mainwindow for this already existing window. void X11Client::checkTransient(xcb_window_t w) { - if (m_originalTransientForId != w) + if (m_originalTransientForId != w) { return; + } w = verifyTransientFor(w, true); setTransient(w); } @@ -3165,59 +3298,75 @@ bool X11Client::hasTransient(const AbstractClient *cl, bool indirect) const bool X11Client::hasTransientInternal(const X11Client *cl, bool indirect, QList &set) const { if (const X11Client *t = dynamic_cast(cl->transientFor())) { - if (t == this) + if (t == this) { return true; - if (!indirect) + } + if (!indirect) { return false; - if (set.contains(cl)) + } + if (set.contains(cl)) { return false; + } set.append(cl); return hasTransientInternal(t, indirect, set); } - if (!cl->isTransient()) + if (!cl->isTransient()) { return false; - if (group() != cl->group()) + } + if (group() != cl->group()) { return false; + } // cl is group transient, search from top - if (transients().contains(const_cast(cl))) + if (transients().contains(const_cast(cl))) { return true; - if (!indirect) + } + if (!indirect) { return false; - if (set.contains(this)) + } + if (set.contains(this)) { return false; + } set.append(this); for (auto it = transients().constBegin(); it != transients().constEnd(); ++it) { const X11Client *c = qobject_cast(*it); if (!c) { continue; } - if (c->hasTransientInternal(cl, indirect, set)) + if (c->hasTransientInternal(cl, indirect, set)) { return true; + } } return false; } QList X11Client::mainClients() const { - if (!isTransient()) + if (!isTransient()) { return QList(); - if (const AbstractClient *t = transientFor()) + } + if (const AbstractClient *t = transientFor()) { return QList{const_cast(t)}; + } QList result; Q_ASSERT(group()); - for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) - if ((*it)->hasTransient(this, false)) + for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) { + if ((*it)->hasTransient(this, false)) { result.append(*it); + } + } return result; } AbstractClient *X11Client::findModal(bool allow_itself) { - for (auto it = transients().constBegin(); it != transients().constEnd(); ++it) - if (AbstractClient *ret = (*it)->findModal(true)) + for (auto it = transients().constBegin(); it != transients().constEnd(); ++it) { + if (AbstractClient *ret = (*it)->findModal(true)) { return ret; - if (isModal() && allow_itself) + } + } + if (isModal() && allow_itself) { return this; + } return nullptr; } @@ -3227,12 +3376,14 @@ AbstractClient *X11Client::findModal(bool allow_itself) void X11Client::checkGroup(Group *set_group, bool force) { Group *old_group = in_group; - if (old_group != nullptr) + if (old_group != nullptr) { old_group->ref(); // turn off automatic deleting + } if (set_group != nullptr) { if (set_group != in_group) { - if (in_group != nullptr) + if (in_group != nullptr) { in_group->removeMember(this); + } in_group = set_group; in_group->addMember(this); } @@ -3244,11 +3395,13 @@ void X11Client::checkGroup(Group *set_group, bool force) // by different app, but transient for this one, so make it part of that group) new_group = t->group(); } - if (new_group == nullptr) // doesn't exist yet + if (new_group == nullptr) { // doesn't exist yet new_group = new Group(info->groupLeader()); + } if (new_group != in_group) { - if (in_group != nullptr) + if (in_group != nullptr) { in_group->removeMember(this); + } in_group = new_group; in_group->addMember(this); } @@ -3258,8 +3411,9 @@ void X11Client::checkGroup(Group *set_group, bool force) // so make it part of that group Group *new_group = t->group(); if (new_group != in_group) { - if (in_group != nullptr) + if (in_group != nullptr) { in_group->removeMember(this); + } in_group = t->group(); in_group->addMember(this); } @@ -3267,11 +3421,13 @@ void X11Client::checkGroup(Group *set_group, bool force) // group transient which actually doesn't have a group :( // try creating group with other windows with the same client leader Group *new_group = workspace()->findClientLeaderGroup(this); - if (new_group == nullptr) + if (new_group == nullptr) { new_group = new Group(XCB_WINDOW_NONE); + } if (new_group != in_group) { - if (in_group != nullptr) + if (in_group != nullptr) { in_group->removeMember(this); + } in_group = new_group; in_group->addMember(this); } @@ -3284,8 +3440,9 @@ void X11Client::checkGroup(Group *set_group, bool force) in_group->removeMember(this); in_group = nullptr; } - if (new_group == nullptr) + if (new_group == nullptr) { new_group = new Group(XCB_WINDOW_NONE); + } if (in_group != new_group) { in_group = new_group; in_group->addMember(this); @@ -3299,36 +3456,43 @@ void X11Client::checkGroup(Group *set_group, bool force) if (c->groupTransient() && c->group() != group()) { removeTransientFromList(c); it = transients().constBegin(); // restart, just in case something more has changed with the list - } else + } else { ++it; + } } if (groupTransient()) { // no longer transient for ones in the old group if (old_group != nullptr) { - for (auto it = old_group->members().constBegin(); it != old_group->members().constEnd(); ++it) + for (auto it = old_group->members().constBegin(); it != old_group->members().constEnd(); ++it) { (*it)->removeTransient(this); + } } // and make transient for all in the new group for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) { - if (*it == this) + if (*it == this) { break; // this means the window is only transient for windows mapped before it + } (*it)->addTransient(this); } } // group transient splashscreens should be transient even for windows // in group mapped later for (auto it = group()->members().constBegin(); it != group()->members().constEnd(); ++it) { - if (!(*it)->isSplash()) + if (!(*it)->isSplash()) { continue; - if (!(*it)->groupTransient()) + } + if (!(*it)->groupTransient()) { continue; - if (*it == this || hasTransient(*it, true)) // TODO indirect? + } + if (*it == this || hasTransient(*it, true)) { // TODO indirect? continue; + } addTransient(*it); } } - if (old_group != nullptr) + if (old_group != nullptr) { old_group->deref(); // can be now deleted if empty + } checkGroupTransients(); checkActiveModal(); updateLayer(); @@ -3338,11 +3502,13 @@ void X11Client::checkGroup(Group *set_group, bool force) void X11Client::changeClientLeaderGroup(Group *gr) { // transientFor() != NULL are in the group of their mainwindow, so keep them there - if (transientFor() != nullptr) + if (transientFor() != nullptr) { return; + } // also don't change the group for window which have group set - if (info->groupLeader()) + if (info->groupLeader()) { return; + } checkGroup(gr); // change group } @@ -3357,8 +3523,9 @@ void X11Client::checkActiveModal() if (check_modal != nullptr && check_modal->check_active_modal) { X11Client *new_modal = dynamic_cast(check_modal->findModal()); if (new_modal != nullptr && new_modal != check_modal) { - if (!new_modal->isManaged()) + if (!new_modal->isManaged()) { return; // postpone check until end of manage() + } workspace()->activateClient(new_modal); } check_modal->check_active_modal = false; @@ -3370,10 +3537,12 @@ QSize X11Client::constrainClientSize(const QSize &size, SizeMode mode) const int w = size.width(); int h = size.height(); - if (w < 1) + if (w < 1) { w = 1; - if (h < 1) + } + if (h < 1) { h = 1; + } // basesize, minsize, maxsize, paspect and resizeinc have all values defined, // even if they're not set in flags - see getWmNormalHints() @@ -3382,14 +3551,18 @@ QSize X11Client::constrainClientSize(const QSize &size, SizeMode mode) const if (isDecorated()) { QSize decominsize(0, 0); QSize border_size(borderLeft() + borderRight(), borderTop() + borderBottom()); - if (border_size.width() > decominsize.width()) // just in case + if (border_size.width() > decominsize.width()) { // just in case decominsize.setWidth(border_size.width()); - if (border_size.height() > decominsize.height()) + } + if (border_size.height() > decominsize.height()) { decominsize.setHeight(border_size.height()); - if (decominsize.width() > min_size.width()) + } + if (decominsize.width() > min_size.width()) { min_size.setWidth(decominsize.width()); - if (decominsize.height() > min_size.height()) + } + if (decominsize.height() > min_size.height()) { min_size.setHeight(decominsize.height()); + } } w = qMin(max_size.width(), w); h = qMin(max_size.height(), h); @@ -3546,11 +3719,13 @@ void X11Client::getWmNormalHints() // try to keep the window in its xinerama screen if possible, // if that fails at least keep it visible somewhere QRect area = workspace()->clientArea(MovementArea, this); - if (area.contains(origClientGeometry)) + if (area.contains(origClientGeometry)) { keepInArea(area); + } area = workspace()->clientArea(WorkArea, this); - if (area.contains(origClientGeometry)) + if (area.contains(origClientGeometry)) { keepInArea(area); + } } } } @@ -3667,10 +3842,11 @@ const QPoint X11Client::calculateGravitation(bool invert) const const int dx = adjustment.x() - borderLeft(); const int dy = adjustment.y() - borderTop(); - if (!invert) + if (!invert) { return QPoint(x() + dx, y() + dy); - else + } else { return QPoint(x() - dx, y() - dy); + } } void X11Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, int gravity, bool from_tool) @@ -3699,10 +3875,12 @@ void X11Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, // we cannot distinguish that from passing "false" for partially maximized windows. ignore = rules()->checkIgnoreGeometry(false); if (!ignore) { // the user is not interested, so we fix up dimensions - if (maximizeMode() == MaximizeVertical) + if (maximizeMode() == MaximizeVertical) { value_mask &= ~(XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_HEIGHT); - if (maximizeMode() == MaximizeHorizontal) + } + if (maximizeMode() == MaximizeHorizontal) { value_mask &= ~(XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_WIDTH); + } if (!(value_mask & configureGeometryMask)) { ignore = true; // the modification turned the request void } @@ -3716,8 +3894,9 @@ void X11Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, qCDebug(KWIN_CORE) << "PERMITTED" << this << bool(value_mask & configureGeometryMask); - if (gravity == 0) // default (nonsense) value for the argument + if (gravity == 0) { // default (nonsense) value for the argument gravity = m_geometryHints.windowGravity(); + } if (value_mask & configurePositionMask) { QPoint new_pos = framePosToClientPos(pos()); new_pos -= gravityAdjustment(xcb_gravity_t(gravity)); @@ -3763,15 +3942,17 @@ void X11Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, resize(requestedFrameSize); QRect area = workspace()->clientArea(WorkArea, this); if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen() - && area.contains(origClientGeometry)) + && area.contains(origClientGeometry)) { keepInArea(area); + } // this is part of the kicker-xinerama-hack... it should be // safe to remove when kicker gets proper ExtendedStrut support; // see Workspace::updateClientArea() and // X11Client::adjustedClientArea() - if (hasStrut()) + if (hasStrut()) { workspace()->updateClientArea(); + } } if (value_mask & configureSizeMask && !(value_mask & configurePositionMask)) { // pure resize @@ -3796,11 +3977,13 @@ void X11Client::configureRequest(int value_mask, int rx, int ry, int rw, int rh, // try to keep the window in its xinerama screen if possible, // if that fails at least keep it visible somewhere QRect area = workspace()->clientArea(MovementArea, this); - if (area.contains(origClientGeometry)) + if (area.contains(origClientGeometry)) { keepInArea(area); + } area = workspace()->clientArea(WorkArea, this); - if (area.contains(origClientGeometry)) + if (area.contains(origClientGeometry)) { keepInArea(area); + } } } } @@ -3821,10 +4004,12 @@ void X11Client::resizeWithChecks(int w, int h, xcb_gravity_t gravity) int newy = y(); QRect area = workspace()->clientArea(WorkArea, this); // don't allow growing larger than workarea - if (w > area.width()) + if (w > area.width()) { w = area.width(); - if (h > area.height()) + } + if (h > area.height()) { h = area.height(); + } QSize tmp = constrainFrameSize(QSize(w, h)); // checks size constraints, including min/max size w = tmp.width(); h = tmp.height(); @@ -3895,12 +4080,15 @@ bool X11Client::isMovable() const if (!hasNETSupport() && !m_motif.move()) { return false; } - if (isFullScreen()) + if (isFullScreen()) { return false; - if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :) + } + if (isSpecialWindow() && !isSplash() && !isToolbar()) { // allow moving of splashscreens :) return false; - if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position + } + if (rules()->checkPosition(invalidPoint) != invalidPoint) { // forced position return false; + } return true; } @@ -3909,10 +4097,12 @@ bool X11Client::isMovableAcrossScreens() const if (!hasNETSupport() && !m_motif.move()) { return false; } - if (isSpecialWindow() && !isSplash() && !isToolbar()) // allow moving of splashscreens :) + if (isSpecialWindow() && !isSplash() && !isToolbar()) { // allow moving of splashscreens :) return false; - if (rules()->checkPosition(invalidPoint) != invalidPoint) // forced position + } + if (rules()->checkPosition(invalidPoint) != invalidPoint) { // forced position return false; + } return true; } @@ -3921,12 +4111,15 @@ bool X11Client::isResizable() const if (!hasNETSupport() && !m_motif.resize()) { return false; } - if (isFullScreen()) + if (isFullScreen()) { return false; - if (isSpecialWindow() || isSplash() || isToolbar()) + } + if (isSpecialWindow() || isSplash() || isToolbar()) { return false; - if (rules()->checkSize(QSize()).isValid()) // forced size + } + if (rules()->checkSize(QSize()).isValid()) { // forced size return false; + } const Gravity gravity = interactiveMoveResizeGravity(); if ((gravity == Gravity::Top || gravity == Gravity::TopLeft || gravity == Gravity::TopRight || gravity == Gravity::Left || gravity == Gravity::BottomLeft) && rules()->checkPosition(invalidPoint) != invalidPoint) { return false; @@ -3939,10 +4132,12 @@ bool X11Client::isResizable() const bool X11Client::isMaximizable() const { - if (!isResizable() || isToolbar()) // SELI isToolbar() ? + if (!isResizable() || isToolbar()) { // SELI isToolbar() ? return false; - if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore && rules()->checkMaximize(MaximizeFull) != MaximizeRestore) + } + if (rules()->checkMaximize(MaximizeRestore) == MaximizeRestore && rules()->checkMaximize(MaximizeFull) != MaximizeRestore) { return true; + } return false; } @@ -3964,9 +4159,9 @@ void X11Client::moveResizeInternal(const QRect &rect, MoveResizeMode mode) QRect frameGeometry = rect; - if (shade_geometry_change) + if (shade_geometry_change) { ; // nothing - else if (isShade()) { + } else if (isShade()) { if (frameGeometry.height() == borderTop() + borderBottom()) { qCDebug(KWIN_CORE) << "Shaded geometry passed for size:"; } else { @@ -4064,25 +4259,30 @@ void X11Client::updateServerGeometry() static bool changeMaximizeRecursion = false; void X11Client::changeMaximize(bool horizontal, bool vertical, bool adjust) { - if (changeMaximizeRecursion) + if (changeMaximizeRecursion) { return; + } - if (!isResizable() || isToolbar()) // SELI isToolbar() ? + if (!isResizable() || isToolbar()) { // SELI isToolbar() ? return; + } QRect clientArea; - if (isElectricBorderMaximizing()) + if (isElectricBorderMaximizing()) { clientArea = workspace()->clientArea(MaximizeArea, this, Cursors::self()->mouse()->pos()); - else + } else { clientArea = workspace()->clientArea(MaximizeArea, this, moveResizeGeometry().center()); + } MaximizeMode old_mode = max_mode; // 'adjust == true' means to update the size only, e.g. after changing workspace size if (!adjust) { - if (vertical) + if (vertical) { max_mode = MaximizeMode(max_mode ^ MaximizeVertical); - if (horizontal) + } + if (horizontal) { max_mode = MaximizeMode(max_mode ^ MaximizeHorizontal); + } } // if the client insist on a fix aspect ratio, we check whether the maximizing will get us @@ -4095,19 +4295,22 @@ void X11Client::changeMaximize(bool horizontal, bool vertical, bool adjust) if (max_mode == MaximizeVertical || (old_mode & MaximizeVertical)) { const double fx = minAspect.width(); // use doubles, because the values can be MAX_INT const double fy = maxAspect.height(); // use doubles, because the values can be MAX_INT - if (fx * clientArea.height() / fy > clientArea.width()) // too big + if (fx * clientArea.height() / fy > clientArea.width()) { // too big max_mode = old_mode & MaximizeHorizontal ? MaximizeRestore : MaximizeFull; + } } else { // max_mode == MaximizeHorizontal const double fx = maxAspect.width(); const double fy = minAspect.height(); - if (fy * clientArea.width() / fx > clientArea.height()) // too big + if (fy * clientArea.width() / fx > clientArea.height()) { // too big max_mode = old_mode & MaximizeVertical ? MaximizeRestore : MaximizeFull; + } } } max_mode = rules()->checkMaximize(max_mode); - if (!adjust && max_mode == old_mode) + if (!adjust && max_mode == old_mode) { return; + } GeometryUpdatesBlocker blocker(this); @@ -4120,10 +4323,11 @@ void X11Client::changeMaximize(bool horizontal, bool vertical, bool adjust) // save sizes for restoring, if maximalizing QSize sz; - if (isShade()) + if (isShade()) { sz = implicitSize(); - else + } else { sz = size(); + } if (quickTileMode() == QuickTileMode(QuickTileFlag::None)) { QRect savedGeometry = geometryRestore(); @@ -4277,31 +4481,36 @@ void X11Client::changeMaximize(bool horizontal, bool vertical, bool adjust) const QRect screenArea = workspace()->clientArea(ScreenArea, this, clientArea.center()); if (closeHeight) { bool tryBottom = titlePos == Qt::BottomEdge; - if ((overHeight && titlePos == Qt::TopEdge) || screenArea.top() == clientArea.top()) + if ((overHeight && titlePos == Qt::TopEdge) || screenArea.top() == clientArea.top()) { r.setTop(clientArea.top()); - else + } else { tryBottom = true; - if (tryBottom && (overHeight || screenArea.bottom() == clientArea.bottom())) + } + if (tryBottom && (overHeight || screenArea.bottom() == clientArea.bottom())) { r.setBottom(clientArea.bottom()); + } } if (closeWidth) { bool tryLeft = titlePos == Qt::LeftEdge; - if ((overWidth && titlePos == Qt::RightEdge) || screenArea.right() == clientArea.right()) + if ((overWidth && titlePos == Qt::RightEdge) || screenArea.right() == clientArea.right()) { r.setRight(clientArea.right()); - else + } else { tryLeft = true; - if (tryLeft && (overWidth || screenArea.left() == clientArea.left())) + } + if (tryLeft && (overWidth || screenArea.left() == clientArea.left())) { r.setLeft(clientArea.left()); + } } } } r.moveTopLeft(rules()->checkPosition(r.topLeft())); } moveResize(r); - if (options->electricBorderMaximize() && r.top() == clientArea.top()) + if (options->electricBorderMaximize() && r.top() == clientArea.top()) { updateQuickTileMode(QuickTileFlag::Maximize); - else + } else { updateQuickTileMode(QuickTileFlag::None); + } info->setState(NET::Max, NET::Max); break; } @@ -4392,8 +4601,9 @@ void X11Client::updateFullscreenMonitors(NETFullscreenMonitors topology) } info->setFullscreenMonitors(topology); - if (isFullScreen()) + if (isFullScreen()) { moveResize(fullscreenMonitorsArea(topology)); + } } /** @@ -4457,8 +4667,9 @@ void X11Client::leaveInteractiveMoveResize() m_frame.move(m_bufferGeometry.topLeft()); needsXWindowMove = false; } - if (!isInteractiveResize()) + if (!isInteractiveResize()) { sendSyntheticConfigureNotify(); // tell the client about it's new final position + } if (kwinApp()->operationMode() == Application::OperationModeX11) { if (move_resize_has_keyboard_grab) { ungrabXKeyboard(); @@ -4555,32 +4766,36 @@ StrutRect X11Client::strutRect(StrutArea area) const NETExtendedStrut strutArea = strut(); switch (area) { case StrutAreaTop: - if (strutArea.top_width != 0) + if (strutArea.top_width != 0) { return StrutRect(QRect( strutArea.top_start, 0, strutArea.top_end - strutArea.top_start, strutArea.top_width), StrutAreaTop); + } break; case StrutAreaRight: - if (strutArea.right_width != 0) + if (strutArea.right_width != 0) { return StrutRect(QRect( displaySize.width() - strutArea.right_width, strutArea.right_start, strutArea.right_width, strutArea.right_end - strutArea.right_start), StrutAreaRight); + } break; case StrutAreaBottom: - if (strutArea.bottom_width != 0) + if (strutArea.bottom_width != 0) { return StrutRect(QRect( strutArea.bottom_start, displaySize.height() - strutArea.bottom_width, strutArea.bottom_end - strutArea.bottom_start, strutArea.bottom_width), StrutAreaBottom); + } break; case StrutAreaLeft: - if (strutArea.left_width != 0) + if (strutArea.left_width != 0) { return StrutRect(QRect( 0, strutArea.left_start, strutArea.left_width, strutArea.left_end - strutArea.left_start), StrutAreaLeft); + } break; default: Q_UNREACHABLE(); // Not valid @@ -4591,8 +4806,9 @@ StrutRect X11Client::strutRect(StrutArea area) const bool X11Client::hasStrut() const { NETExtendedStrut ext = strut(); - if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0) + if (ext.left_width == 0 && ext.right_width == 0 && ext.top_width == 0 && ext.bottom_width == 0) { return false; + } return true; } diff --git a/src/xdgshellclient.cpp b/src/xdgshellclient.cpp index 046d88b9ce..d62acae54a 100644 --- a/src/xdgshellclient.cpp +++ b/src/xdgshellclient.cpp @@ -1632,10 +1632,12 @@ void XdgToplevelClient::changeMaximize(bool horizontal, bool vertical, bool adju // 'adjust == true' means to update the size only, e.g. after changing workspace size if (!adjust) { - if (vertical) + if (vertical) { m_requestedMaximizeMode = MaximizeMode(m_requestedMaximizeMode ^ MaximizeVertical); - if (horizontal) + } + if (horizontal) { m_requestedMaximizeMode = MaximizeMode(m_requestedMaximizeMode ^ MaximizeHorizontal); + } } m_requestedMaximizeMode = rules()->checkMaximize(m_requestedMaximizeMode);