From 77af052f9d9bcf1cb397ed61b91d40e6e3f7849c Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 5 Aug 2022 13:52:12 +0000 Subject: [PATCH] WindowView: Add "show windows from class on current desktop" mode We currently have "windows from current desktop" and "windows from class" but not one combining both. This adds that mode along with a (default empty) shortcut and border activation. BUG: 413342 --- src/effects/windowview/qml/main.qml | 20 +++++++++++-- src/effects/windowview/windowviewconfig.kcfg | 2 ++ src/effects/windowview/windowvieweffect.cpp | 31 +++++++++++++++++++- src/effects/windowview/windowvieweffect.h | 7 ++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/effects/windowview/qml/main.qml b/src/effects/windowview/qml/main.qml index b7ed45ec04..72f4e53df9 100644 --- a/src/effects/windowview/qml/main.qml +++ b/src/effects/windowview/qml/main.qml @@ -146,7 +146,15 @@ Item { animationDuration: container.animationDuration animationEnabled: container.animationEnabled organized: container.organized - showOnly: container.effect.mode === WindowView.ModeWindowClass ? "activeClass" : selectedIds + showOnly: { + switch (container.effect.mode) { + case WindowView.ModeWindowClass: + case WindowView.ModeWindowClassCurrentDesktop: + return "activeClass" + default: + return selectedIds + } + } layout.mode: effect.layout onWindowClicked: { if (eventPoint.event.button !== Qt.MiddleButton) { @@ -156,7 +164,15 @@ Item { } model: KWinComponents.ClientFilterModel { activity: KWinComponents.Workspace.currentActivity - desktop: container.effect.mode == WindowView.ModeCurrentDesktop ? KWinComponents.Workspace.currentVirtualDesktop : undefined + desktop: { + switch (container.effect.mode) { + case WindowView.ModeCurrentDesktop: + case WindowView.ModeWindowClassCurrentDesktop: + return KWinComponents.Workspace.currentVirtualDesktop + default: + return undefined + } + } screenName: targetScreen.name clientModel: stackModel filter: effect.searchText diff --git a/src/effects/windowview/windowviewconfig.kcfg b/src/effects/windowview/windowviewconfig.kcfg index d37697677d..35564f5a4a 100644 --- a/src/effects/windowview/windowviewconfig.kcfg +++ b/src/effects/windowview/windowviewconfig.kcfg @@ -22,9 +22,11 @@ QList<int>() << int(ElectricTopLeft) + + diff --git a/src/effects/windowview/windowvieweffect.cpp b/src/effects/windowview/windowvieweffect.cpp index 7c651869fa..09e291e3e0 100644 --- a/src/effects/windowview/windowvieweffect.cpp +++ b/src/effects/windowview/windowvieweffect.cpp @@ -26,6 +26,7 @@ WindowViewEffect::WindowViewEffect() , m_exposeAction(new QAction(this)) , m_exposeAllAction(new QAction(this)) , m_exposeClassAction(new QAction(this)) + , m_exposeClassCurrentDesktopAction(new QAction(this)) { qmlRegisterUncreatableType("org.kde.KWin.Effect.WindowView", 1, 0, "WindowView", QStringLiteral("WindowView cannot be created in QML")); initConfig(); @@ -68,6 +69,14 @@ WindowViewEffect::WindowViewEffect() connect(m_exposeClassAction, &QAction::triggered, this, [this]() { toggleMode(ModeWindowClass); }); + + m_exposeClassCurrentDesktopAction->setObjectName(QStringLiteral("ExposeClassCurrentDesktop")); + m_exposeClassAction->setText(i18n("Toggle Present Windows (Window class on current desktop)")); + effects->registerGlobalShortcut(QKeySequence{}, m_exposeClassAction); + connect(m_exposeClassAction, &QAction::triggered, this, [this]() { + toggleMode(ModeWindowClassCurrentDesktop); + }); + connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, [this](QAction *action, const QKeySequence &seq) { if (action->objectName() == QStringLiteral("Expose")) { m_shortcut.clear(); @@ -78,6 +87,9 @@ WindowViewEffect::WindowViewEffect() } else if (action->objectName() == QStringLiteral("ExposeClass")) { m_shortcutClass.clear(); m_shortcutClass.append(seq); + } else if (action->objectName() == QStringLiteral("ExposeClassCurrentDesktop")) { + m_shortcutClassCurrentDesktop.clear(); + m_shortcutClassCurrentDesktop.append(seq); } }); @@ -201,6 +213,11 @@ void WindowViewEffect::reconfigure(ReconfigureFlags) m_borderActivateClass.append(ElectricBorder(i)); effects->reserveElectricBorder(ElectricBorder(i), this); } + const auto activateClassCurrentDesktop = WindowViewConfig::borderActivateClassCurrentDesktop(); + for (int i : activateClassCurrentDesktop) { + m_borderActivateClassCurrentDesktop.append(ElectricBorder(i)); + effects->reserveElectricBorder(ElectricBorder(i), this); + } auto touchCallback = [this](ElectricBorder border, const QSizeF &deltaProgress, const EffectScreen *screen) { Q_UNUSED(screen) @@ -213,6 +230,8 @@ void WindowViewEffect::reconfigure(ReconfigureFlags) setMode(ModeAllDesktops); } else if (m_touchBorderActivateClass.contains(border)) { setMode(ModeWindowClass); + } else if (m_touchBorderActivateClassCurrentDesktop.contains(border)) { + setMode(ModeWindowClassCurrentDesktop); } const int maxDelta = 500; // Arbitrary logical pixels value seems to behave better than scaledScreenSize if (border == ElectricTop || border == ElectricBottom) { @@ -234,7 +253,12 @@ void WindowViewEffect::reconfigure(ReconfigureFlags) } touchActivateBorders = WindowViewConfig::touchBorderActivateClass(); for (const int &border : touchActivateBorders) { - m_touchBorderActivateAll.append(ElectricBorder(border)); + m_touchBorderActivateClass.append(ElectricBorder(border)); + effects->registerRealtimeTouchBorder(ElectricBorder(border), m_realtimeToggleAction, touchCallback); + } + touchActivateBorders = WindowViewConfig::touchBorderActivateClassCurrentDesktop(); + for (const int &border : touchActivateBorders) { + m_touchBorderActivateClassCurrentDesktop.append(ElectricBorder(border)); effects->registerRealtimeTouchBorder(ElectricBorder(border), m_realtimeToggleAction, touchCallback); } } @@ -253,6 +277,9 @@ void WindowViewEffect::grabbedKeyboardEvent(QKeyEvent *e) } else if (m_mode == ModeWindowClass && m_shortcutClass.contains(e->key() | e->modifiers())) { toggleMode(ModeWindowClass); return; + } else if (m_mode == ModeWindowClassCurrentDesktop && m_shortcutClassCurrentDesktop.contains(e->key() | e->modifiers())) { + toggleMode(ModeWindowClassCurrentDesktop); + return; } else if (e->key() == Qt::Key_Escape) { deactivate(animationDuration()); } @@ -426,6 +453,8 @@ bool WindowViewEffect::borderActivated(ElectricBorder border) toggleMode(ModeAllDesktops); } else if (m_borderActivateClass.contains(border)) { toggleMode(ModeWindowClass); + } else if (m_touchBorderActivateClassCurrentDesktop.contains(border)) { + toggleMode(ModeWindowClassCurrentDesktop); } else { return false; } diff --git a/src/effects/windowview/windowvieweffect.h b/src/effects/windowview/windowvieweffect.h index 03e791a927..124ade3e43 100644 --- a/src/effects/windowview/windowvieweffect.h +++ b/src/effects/windowview/windowvieweffect.h @@ -31,7 +31,8 @@ public: ModeAllDesktops, // Shows windows of all desktops ModeCurrentDesktop, // Shows windows on current desktop ModeWindowGroup, // Shows windows selected via property - ModeWindowClass // Shows all windows of same class as selected class + ModeWindowClass, // Shows all windows of same class as selected class + ModeWindowClassCurrentDesktop, // Shows windows of same class on current desktop }; Q_ENUM(PresentWindowsMode) @@ -100,17 +101,21 @@ private: QAction *m_exposeAction = nullptr; QAction *m_exposeAllAction = nullptr; QAction *m_exposeClassAction = nullptr; + QAction *m_exposeClassCurrentDesktopAction = nullptr; QAction *m_realtimeToggleAction = nullptr; // Shortcut - needed to toggle the effect QList m_shortcut; QList m_shortcutAll; QList m_shortcutClass; + QList m_shortcutClassCurrentDesktop; QList m_borderActivate; QList m_borderActivateAll; QList m_borderActivateClass; + QList m_borderActivateClassCurrentDesktop; QList m_touchBorderActivate; QList m_touchBorderActivateAll; QList m_touchBorderActivateClass; + QList m_touchBorderActivateClassCurrentDesktop; QString m_searchText; Status m_status = Status::Inactive; qreal m_partialActivationFactor = 0;