scripting: Port ClientModel V2 from Screens
This commit is contained in:
parent
018a41a123
commit
a5ac7cf0ae
8 changed files with 32 additions and 101 deletions
|
@ -11,7 +11,6 @@
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "screens.h"
|
|
||||||
#include "virtualdesktops.h"
|
#include "virtualdesktops.h"
|
||||||
#include "wayland_server.h"
|
#include "wayland_server.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
@ -195,15 +194,11 @@ void PlasmaSurfaceTest::testOSDPlacement()
|
||||||
QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 100 / 2, 2 * 1024 / 3 - 50 / 2, 100, 50));
|
QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 100 / 2, 2 * 1024 / 3 - 50 / 2, 100, 50));
|
||||||
|
|
||||||
// change the screen size
|
// change the screen size
|
||||||
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
|
|
||||||
QVERIFY(screensChangedSpy.isValid());
|
|
||||||
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
|
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
|
||||||
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
||||||
Qt::DirectConnection,
|
Qt::DirectConnection,
|
||||||
Q_ARG(int, 2),
|
Q_ARG(int, 2),
|
||||||
Q_ARG(QVector<QRect>, geometries));
|
Q_ARG(QVector<QRect>, geometries));
|
||||||
QVERIFY(screensChangedSpy.wait());
|
|
||||||
QCOMPARE(screensChangedSpy.count(), 2);
|
|
||||||
const auto outputs = workspace()->outputs();
|
const auto outputs = workspace()->outputs();
|
||||||
QCOMPARE(outputs.count(), 2);
|
QCOMPARE(outputs.count(), 2);
|
||||||
QCOMPARE(outputs[0]->geometry(), geometries[0]);
|
QCOMPARE(outputs[0]->geometry(), geometries[0]);
|
||||||
|
|
|
@ -390,14 +390,11 @@ void PointerInputTest::testUpdateFocusAfterScreenChange()
|
||||||
QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos()));
|
QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos()));
|
||||||
QVERIFY(leftSpy.wait());
|
QVERIFY(leftSpy.wait());
|
||||||
|
|
||||||
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
|
|
||||||
QVERIFY(screensChangedSpy.isValid());
|
|
||||||
// now let's remove the screen containing the cursor
|
// now let's remove the screen containing the cursor
|
||||||
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
||||||
Qt::DirectConnection,
|
Qt::DirectConnection,
|
||||||
Q_ARG(int, 1),
|
Q_ARG(int, 1),
|
||||||
Q_ARG(QVector<QRect>, QVector<QRect>{QRect(0, 0, 1280, 1024)}));
|
Q_ARG(QVector<QRect>, QVector<QRect>{QRect(0, 0, 1280, 1024)}));
|
||||||
QVERIFY(screensChangedSpy.wait());
|
|
||||||
QCOMPARE(workspace()->outputs().count(), 1);
|
QCOMPARE(workspace()->outputs().count(), 1);
|
||||||
|
|
||||||
// this should have warped the cursor
|
// this should have warped the cursor
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "screens.h"
|
|
||||||
#include "wayland_server.h"
|
#include "wayland_server.h"
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
|
|
||||||
|
@ -87,15 +86,11 @@ void ScreenChangesTest::testScreenAddRemove()
|
||||||
outputAnnouncedSpy.clear();
|
outputAnnouncedSpy.clear();
|
||||||
|
|
||||||
// let's announce a new output
|
// let's announce a new output
|
||||||
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
|
|
||||||
QVERIFY(screensChangedSpy.isValid());
|
|
||||||
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
|
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
|
||||||
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
|
||||||
Qt::DirectConnection,
|
Qt::DirectConnection,
|
||||||
Q_ARG(int, 2),
|
Q_ARG(int, 2),
|
||||||
Q_ARG(QVector<QRect>, geometries));
|
Q_ARG(QVector<QRect>, geometries));
|
||||||
QVERIFY(screensChangedSpy.wait());
|
|
||||||
QCOMPARE(screensChangedSpy.count(), 2);
|
|
||||||
auto outputs = workspace()->outputs();
|
auto outputs = workspace()->outputs();
|
||||||
QCOMPARE(outputs.count(), 2);
|
QCOMPARE(outputs.count(), 2);
|
||||||
QCOMPARE(outputs[0]->geometry(), geometries[0]);
|
QCOMPARE(outputs[0]->geometry(), geometries[0]);
|
||||||
|
@ -154,7 +149,6 @@ void ScreenChangesTest::testScreenAddRemove()
|
||||||
// now let's try to remove one output again
|
// now let's try to remove one output again
|
||||||
outputAnnouncedSpy.clear();
|
outputAnnouncedSpy.clear();
|
||||||
outputRemovedSpy.clear();
|
outputRemovedSpy.clear();
|
||||||
screensChangedSpy.clear();
|
|
||||||
|
|
||||||
QSignalSpy o1RemovedSpy(o1.get(), &KWayland::Client::Output::removed);
|
QSignalSpy o1RemovedSpy(o1.get(), &KWayland::Client::Output::removed);
|
||||||
QVERIFY(o1RemovedSpy.isValid());
|
QVERIFY(o1RemovedSpy.isValid());
|
||||||
|
@ -166,8 +160,6 @@ void ScreenChangesTest::testScreenAddRemove()
|
||||||
Qt::DirectConnection,
|
Qt::DirectConnection,
|
||||||
Q_ARG(int, 1),
|
Q_ARG(int, 1),
|
||||||
Q_ARG(QVector<QRect>, geometries2));
|
Q_ARG(QVector<QRect>, geometries2));
|
||||||
QVERIFY(screensChangedSpy.wait());
|
|
||||||
QCOMPARE(screensChangedSpy.count(), 2);
|
|
||||||
outputs = workspace()->outputs();
|
outputs = workspace()->outputs();
|
||||||
QCOMPARE(outputs.count(), 1);
|
QCOMPARE(outputs.count(), 1);
|
||||||
QCOMPARE(outputs[0]->geometry(), geometries2.at(0));
|
QCOMPARE(outputs[0]->geometry(), geometries2.at(0));
|
||||||
|
|
|
@ -34,7 +34,6 @@ private Q_SLOTS:
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void testSize_data();
|
void testSize_data();
|
||||||
void testSize();
|
void testSize();
|
||||||
void testCount();
|
|
||||||
void testCurrent_data();
|
void testCurrent_data();
|
||||||
void testCurrent();
|
void testCurrent();
|
||||||
void testCurrentWithFollowsMouse_data();
|
void testCurrentWithFollowsMouse_data();
|
||||||
|
@ -118,28 +117,6 @@ void ScreensTest::testSize()
|
||||||
QTEST(workspace()->screens()->size(), "expectedSize");
|
QTEST(workspace()->screens()->size(), "expectedSize");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreensTest::testCount()
|
|
||||||
{
|
|
||||||
QSignalSpy countChangedSpy(workspace()->screens(), &Screens::countChanged);
|
|
||||||
QVERIFY(countChangedSpy.isValid());
|
|
||||||
|
|
||||||
// the test environments has two outputs
|
|
||||||
QCOMPARE(workspace()->screens()->count(), 2);
|
|
||||||
|
|
||||||
// change to one screen
|
|
||||||
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::QueuedConnection, Q_ARG(int, 1));
|
|
||||||
QVERIFY(countChangedSpy.wait());
|
|
||||||
QCOMPARE(countChangedSpy.count(), 1);
|
|
||||||
QCOMPARE(workspace()->screens()->count(), 1);
|
|
||||||
|
|
||||||
// setting the same geometries shouldn't emit the signal, but we should get a changed signal
|
|
||||||
QSignalSpy changedSpy(workspace()->screens(), &Screens::changed);
|
|
||||||
QVERIFY(changedSpy.isValid());
|
|
||||||
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::QueuedConnection, Q_ARG(int, 1));
|
|
||||||
QVERIFY(changedSpy.wait());
|
|
||||||
QCOMPARE(countChangedSpy.count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreensTest::testCurrent_data()
|
void ScreensTest::testCurrent_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("currentId");
|
QTest::addColumn<int>("currentId");
|
||||||
|
|
|
@ -22,17 +22,13 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
Screens::Screens()
|
Screens::Screens()
|
||||||
: m_count(0)
|
: m_maxScale(1.0)
|
||||||
, m_maxScale(1.0)
|
|
||||||
{
|
{
|
||||||
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::updateCount);
|
|
||||||
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::changed);
|
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screens::init()
|
void Screens::init()
|
||||||
{
|
{
|
||||||
updateCount();
|
|
||||||
connect(this, &Screens::countChanged, this, &Screens::changed, Qt::QueuedConnection);
|
|
||||||
connect(this, &Screens::changed, this, &Screens::updateSize);
|
connect(this, &Screens::changed, this, &Screens::updateSize);
|
||||||
connect(this, &Screens::sizeChanged, this, &Screens::geometryChanged);
|
connect(this, &Screens::sizeChanged, this, &Screens::geometryChanged);
|
||||||
|
|
||||||
|
@ -64,7 +60,7 @@ void Screens::updateSize()
|
||||||
{
|
{
|
||||||
QRect bounding;
|
QRect bounding;
|
||||||
qreal maxScale = 1.0;
|
qreal maxScale = 1.0;
|
||||||
for (int i = 0; i < count(); ++i) {
|
for (int i = 0; i < workspace()->outputs().count(); ++i) {
|
||||||
bounding = bounding.united(geometry(i));
|
bounding = bounding.united(geometry(i));
|
||||||
maxScale = qMax(maxScale, scale(i));
|
maxScale = qMax(maxScale, scale(i));
|
||||||
}
|
}
|
||||||
|
@ -78,31 +74,11 @@ void Screens::updateSize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screens::updateCount()
|
|
||||||
{
|
|
||||||
setCount(workspace()->outputs().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Screens::setCount(int count)
|
|
||||||
{
|
|
||||||
if (m_count == count) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const int previous = m_count;
|
|
||||||
m_count = count;
|
|
||||||
Q_EMIT countChanged(previous, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
Output *Screens::findOutput(int screen) const
|
Output *Screens::findOutput(int screen) const
|
||||||
{
|
{
|
||||||
return workspace()->outputs().value(screen);
|
return workspace()->outputs().value(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Screens::count() const
|
|
||||||
{
|
|
||||||
return m_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize Screens::size() const
|
QSize Screens::size() const
|
||||||
{
|
{
|
||||||
return m_boundingSize;
|
return m_boundingSize;
|
||||||
|
|
|
@ -29,14 +29,12 @@ class Platform;
|
||||||
class KWIN_EXPORT Screens : public QObject
|
class KWIN_EXPORT Screens : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Screens();
|
explicit Screens();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
int count() const;
|
|
||||||
QRect geometry(int screen) const;
|
QRect geometry(int screen) const;
|
||||||
/**
|
/**
|
||||||
* The bounding geometry of all screens combined. Overlapping areas
|
* The bounding geometry of all screens combined. Overlapping areas
|
||||||
|
@ -67,7 +65,6 @@ public:
|
||||||
QSize size() const;
|
QSize size() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void countChanged(int previousCount, int newCount);
|
|
||||||
/**
|
/**
|
||||||
* Emitted whenever the screens are changed either count or geometry.
|
* Emitted whenever the screens are changed either count or geometry.
|
||||||
*/
|
*/
|
||||||
|
@ -90,17 +87,12 @@ Q_SIGNALS:
|
||||||
*/
|
*/
|
||||||
void maxScaleChanged();
|
void maxScaleChanged();
|
||||||
|
|
||||||
protected Q_SLOTS:
|
|
||||||
void setCount(int count);
|
|
||||||
void updateCount();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateSize();
|
void updateSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Output *findOutput(int screenId) const;
|
Output *findOutput(int screenId) const;
|
||||||
|
|
||||||
int m_count;
|
|
||||||
QSize m_boundingSize;
|
QSize m_boundingSize;
|
||||||
qreal m_maxScale;
|
qreal m_maxScale;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
|
|
||||||
#include <config-kwin.h>
|
#include <config-kwin.h>
|
||||||
|
|
||||||
#include "window.h"
|
|
||||||
#if KWIN_BUILD_ACTIVITIES
|
#if KWIN_BUILD_ACTIVITIES
|
||||||
#include "activities.h"
|
#include "activities.h"
|
||||||
#endif
|
#endif
|
||||||
#include "screens.h"
|
#include "output.h"
|
||||||
#include "virtualdesktops.h"
|
#include "virtualdesktops.h"
|
||||||
|
#include "window.h"
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
|
|
||||||
namespace KWin::ScriptingModels::V2
|
namespace KWin::ScriptingModels::V2
|
||||||
|
@ -324,7 +324,7 @@ AbstractLevel *AbstractLevel::create(const QList<ClientModel::LevelRestriction>
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
case ClientModel::ScreenRestriction:
|
case ClientModel::ScreenRestriction:
|
||||||
for (int i = 0; i < workspace()->screens()->count(); ++i) {
|
for (int i = 0; i < workspace()->outputs().count(); ++i) {
|
||||||
AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
|
AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
|
||||||
if (!childLevel) {
|
if (!childLevel) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -398,7 +398,8 @@ ForkLevel::ForkLevel(const QList<ClientModel::LevelRestriction> &childRestrictio
|
||||||
, m_childRestrictions(childRestrictions)
|
, m_childRestrictions(childRestrictions)
|
||||||
{
|
{
|
||||||
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::countChanged, this, &ForkLevel::desktopCountChanged);
|
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::countChanged, this, &ForkLevel::desktopCountChanged);
|
||||||
connect(workspace()->screens(), &Screens::countChanged, this, &ForkLevel::screenCountChanged);
|
connect(workspace(), &Workspace::outputAdded, this, &ForkLevel::outputAdded);
|
||||||
|
connect(workspace(), &Workspace::outputRemoved, this, &ForkLevel::outputRemoved);
|
||||||
#if KWIN_BUILD_ACTIVITIES
|
#if KWIN_BUILD_ACTIVITIES
|
||||||
if (Activities *activities = Workspace::self()->activities()) {
|
if (Activities *activities = Workspace::self()->activities()) {
|
||||||
connect(activities, &Activities::added, this, &ForkLevel::activityAdded);
|
connect(activities, &Activities::added, this, &ForkLevel::activityAdded);
|
||||||
|
@ -442,36 +443,36 @@ void ForkLevel::desktopCountChanged(uint previousCount, uint newCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForkLevel::screenCountChanged(int previousCount, int newCount)
|
void ForkLevel::outputAdded()
|
||||||
{
|
{
|
||||||
if (restriction() != ClientModel::ClientModel::ClientModel::ScreenRestriction) {
|
if (restriction() != ClientModel::ClientModel::ClientModel::ScreenRestriction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (newCount == previousCount || previousCount != count()) {
|
|
||||||
|
const int row = count();
|
||||||
|
|
||||||
|
AbstractLevel *childLevel = AbstractLevel::create(m_childRestrictions, restrictions(), model(), this);
|
||||||
|
if (!childLevel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Q_EMIT beginInsert(row, row, id());
|
||||||
|
childLevel->setScreen(row);
|
||||||
|
childLevel->init();
|
||||||
|
addChild(childLevel);
|
||||||
|
Q_EMIT endInsert();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ForkLevel::outputRemoved()
|
||||||
|
{
|
||||||
|
if (restriction() != ClientModel::ClientModel::ClientModel::ScreenRestriction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousCount > newCount) {
|
const int row = count() - 1;
|
||||||
// screens got removed
|
|
||||||
Q_EMIT beginRemove(newCount, previousCount - 1, id());
|
Q_EMIT beginRemove(row, row, id());
|
||||||
while (m_children.count() > newCount) {
|
delete m_children.takeLast();
|
||||||
delete m_children.takeLast();
|
Q_EMIT endRemove();
|
||||||
}
|
|
||||||
Q_EMIT endRemove();
|
|
||||||
} else {
|
|
||||||
// screens got added
|
|
||||||
Q_EMIT beginInsert(previousCount, newCount - 1, id());
|
|
||||||
for (int i = previousCount; i < newCount; ++i) {
|
|
||||||
AbstractLevel *childLevel = AbstractLevel::create(m_childRestrictions, restrictions(), model(), this);
|
|
||||||
if (!childLevel) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
childLevel->setScreen(i);
|
|
||||||
childLevel->init();
|
|
||||||
addChild(childLevel);
|
|
||||||
}
|
|
||||||
Q_EMIT endInsert();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForkLevel::activityAdded(const QString &activityId)
|
void ForkLevel::activityAdded(const QString &activityId)
|
||||||
|
|
|
@ -187,9 +187,10 @@ public:
|
||||||
Window *clientForId(quint32 child) const override;
|
Window *clientForId(quint32 child) const override;
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void desktopCountChanged(uint previousCount, uint newCount);
|
void desktopCountChanged(uint previousCount, uint newCount);
|
||||||
void screenCountChanged(int previousCount, int newCount);
|
|
||||||
void activityAdded(const QString &id);
|
void activityAdded(const QString &id);
|
||||||
void activityRemoved(const QString &id);
|
void activityRemoved(const QString &id);
|
||||||
|
void outputAdded();
|
||||||
|
void outputRemoved();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<AbstractLevel *> m_children;
|
QList<AbstractLevel *> m_children;
|
||||||
|
|
Loading…
Reference in a new issue