From 1eb0c0929226ff8c5943ee93cd2e8fbb4a6fb617 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 19 Aug 2021 18:28:54 +0300 Subject: [PATCH] scripting: Make ClientFilterModel take VirtualDesktop --- src/effects/overview/qml/ScreenView.qml | 2 +- src/scripting/v3/clientmodel.cpp | 17 +++++++---------- src/scripting/v3/clientmodel.h | 10 ++++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/effects/overview/qml/ScreenView.qml b/src/effects/overview/qml/ScreenView.qml index dfef6d0dd3..910be20739 100644 --- a/src/effects/overview/qml/ScreenView.qml +++ b/src/effects/overview/qml/ScreenView.qml @@ -89,7 +89,7 @@ FocusScope { Repeater { model: KWinComponents.ClientFilterModel { - desktop: KWinComponents.Workspace.currentDesktop + desktop: KWinComponents.Workspace.currentVirtualDesktop screenName: targetScreen.name clientModel: stackModel windowType: KWinComponents.ClientFilterModel.Dock diff --git a/src/scripting/v3/clientmodel.cpp b/src/scripting/v3/clientmodel.cpp index 90a0d2e22d..456cfc051e 100644 --- a/src/scripting/v3/clientmodel.cpp +++ b/src/scripting/v3/clientmodel.cpp @@ -7,6 +7,7 @@ #include "clientmodel.h" #include "abstract_client.h" #include "screens.h" +#include "virtualdesktops.h" #include "workspace.h" namespace KWin::ScriptingModels::V3 @@ -143,12 +144,12 @@ void ClientFilterModel::resetActivity() } } -int ClientFilterModel::desktop() const +VirtualDesktop *ClientFilterModel::desktop() const { - return m_desktop.value_or(0); + return m_desktop; } -void ClientFilterModel::setDesktop(int desktop) +void ClientFilterModel::setDesktop(VirtualDesktop *desktop) { if (m_desktop != desktop) { m_desktop = desktop; @@ -159,11 +160,7 @@ void ClientFilterModel::setDesktop(int desktop) void ClientFilterModel::resetDesktop() { - if (m_desktop.has_value()) { - m_desktop.reset(); - Q_EMIT desktopChanged(); - invalidateFilter(); - } + setDesktop(nullptr); } QString ClientFilterModel::filter() const @@ -253,8 +250,8 @@ bool ClientFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourc } } - if (m_desktop.has_value()) { - if (!client->isOnDesktop(*m_desktop)) { + if (m_desktop) { + if (!client->isOnDesktop(m_desktop)) { return false; } } diff --git a/src/scripting/v3/clientmodel.h b/src/scripting/v3/clientmodel.h index c63ce107e4..18b363bd3e 100644 --- a/src/scripting/v3/clientmodel.h +++ b/src/scripting/v3/clientmodel.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -14,6 +15,7 @@ namespace KWin { class AbstractClient; +class VirtualDesktop; namespace ScriptingModels::V3 { @@ -51,7 +53,7 @@ class ClientFilterModel : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY(ClientModel *clientModel READ clientModel WRITE setClientModel NOTIFY clientModelChanged) Q_PROPERTY(QString activity READ activity WRITE setActivity RESET resetActivity NOTIFY activityChanged) - Q_PROPERTY(int desktop READ desktop WRITE setDesktop RESET resetDesktop NOTIFY desktopChanged) + Q_PROPERTY(KWin::VirtualDesktop *desktop READ desktop WRITE setDesktop RESET resetDesktop NOTIFY desktopChanged) Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QString screenName READ screenName WRITE setScreenName RESET resetScreenName NOTIFY screenNameChanged) Q_PROPERTY(WindowTypes windowType READ windowType WRITE setWindowType RESET resetWindowType NOTIFY windowTypeChanged) @@ -77,8 +79,8 @@ public: void setActivity(const QString &activity); void resetActivity(); - int desktop() const; - void setDesktop(int desktop); + VirtualDesktop *desktop() const; + void setDesktop(VirtualDesktop *desktop); void resetDesktop(); QString filter() const; @@ -108,7 +110,7 @@ private: ClientModel *m_clientModel = nullptr; std::optional m_activity; - std::optional m_desktop; + QPointer m_desktop; QString m_filter; std::optional m_screenName; std::optional m_windowType;