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
This commit is contained in:
Arjen Hiemstra 2022-08-05 13:52:12 +00:00
parent 02f55e0e40
commit 77af052f9d
4 changed files with 56 additions and 4 deletions

View file

@ -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

View file

@ -22,9 +22,11 @@
<default code="true">QList&lt;int&gt;() &lt;&lt; int(ElectricTopLeft)</default>
</entry>
<entry name="BorderActivateClass" type="IntList" />
<entry name="BorderActivateClassCurrentDesktop" type="IntList" />
<entry name="TouchBorderActivate" type="IntList" />
<entry name="TouchBorderActivateAll" type="IntList" />
<entry name="TouchBorderActivateClass" type="IntList" />
<entry name="TouchBorderActivateClassCurrentDesktop" type="IntList" />
</group>
</kcfg>

View file

@ -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<WindowViewEffect>("org.kde.KWin.Effect.WindowView", 1, 0, "WindowView", QStringLiteral("WindowView cannot be created in QML"));
initConfig<WindowViewConfig>();
@ -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;
}

View file

@ -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<QKeySequence> m_shortcut;
QList<QKeySequence> m_shortcutAll;
QList<QKeySequence> m_shortcutClass;
QList<QKeySequence> m_shortcutClassCurrentDesktop;
QList<ElectricBorder> m_borderActivate;
QList<ElectricBorder> m_borderActivateAll;
QList<ElectricBorder> m_borderActivateClass;
QList<ElectricBorder> m_borderActivateClassCurrentDesktop;
QList<ElectricBorder> m_touchBorderActivate;
QList<ElectricBorder> m_touchBorderActivateAll;
QList<ElectricBorder> m_touchBorderActivateClass;
QList<ElectricBorder> m_touchBorderActivateClassCurrentDesktop;
QString m_searchText;
Status m_status = Status::Inactive;
qreal m_partialActivationFactor = 0;