scripting: Use Toplevel::isOnOutput() in ClientFilterModel

This way, the ClientFilterModel will work as expected if there are
overlapping/cloned outputs.
This commit is contained in:
Vlad Zahorodnii 2021-10-20 17:24:44 +03:00
parent 0f71b27c71
commit 00273f10ff
4 changed files with 23 additions and 8 deletions

View file

@ -203,6 +203,17 @@ AbstractOutput *Platform::findOutput(const QUuid &uuid) const
return nullptr;
}
AbstractOutput *Platform::findOutput(const QString &name) const
{
const auto candidates = outputs();
for (AbstractOutput *candidate : candidates) {
if (candidate->name() == name) {
return candidate;
}
}
return nullptr;
}
AbstractOutput *Platform::outputAt(const QPoint &pos) const
{
AbstractOutput *bestOutput = nullptr;

View file

@ -355,6 +355,7 @@ public:
}
AbstractOutput *findOutput(int screenId) const;
AbstractOutput *findOutput(const QUuid &uuid) const;
AbstractOutput *findOutput(const QString &name) const;
AbstractOutput *outputAt(const QPoint &pos) const;
/**

View file

@ -7,6 +7,7 @@
#include "clientmodel.h"
#include "abstract_client.h"
#include "abstract_output.h"
#include "platform.h"
#include "virtualdesktops.h"
#include "workspace.h"
@ -180,13 +181,14 @@ void ClientFilterModel::setFilter(const QString &filter)
QString ClientFilterModel::screenName() const
{
return m_screenName.value_or(QString());
return m_output ? m_output->name() : QString();
}
void ClientFilterModel::setScreenName(const QString &screen)
{
if (m_screenName != screen) {
m_screenName = screen;
AbstractOutput *output = kwinApp()->platform()->findOutput(screen);
if (m_output != output) {
m_output = output;
Q_EMIT screenNameChanged();
invalidateFilter();
}
@ -194,8 +196,8 @@ void ClientFilterModel::setScreenName(const QString &screen)
void ClientFilterModel::resetScreenName()
{
if (m_screenName.has_value()) {
m_screenName.reset();
if (m_output) {
m_output = nullptr;
Q_EMIT screenNameChanged();
invalidateFilter();
}
@ -256,8 +258,8 @@ bool ClientFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
}
}
if (m_screenName.has_value()) {
if (client->output()->name() != m_screenName) {
if (m_output) {
if (!client->isOnOutput(m_output)) {
return false;
}
}

View file

@ -15,6 +15,7 @@
namespace KWin
{
class AbstractClient;
class AbstractOutput;
class VirtualDesktop;
namespace ScriptingModels::V3
@ -110,9 +111,9 @@ private:
ClientModel *m_clientModel = nullptr;
std::optional<QString> m_activity;
QPointer<AbstractOutput> m_output;
QPointer<VirtualDesktop> m_desktop;
QString m_filter;
std::optional<QString> m_screenName;
std::optional<WindowTypes> m_windowType;
};