Commit a5ac7cf0 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

scripting: Port ClientModel V2 from Screens

parent 018a41a1
Pipeline #223670 passed with stage
in 15 minutes and 11 seconds
......@@ -11,7 +11,6 @@
#include "cursor.h"
#include "output.h"
#include "platform.h"
#include "screens.h"
#include "virtualdesktops.h"
#include "wayland_server.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));
// 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)};
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
Qt::DirectConnection,
Q_ARG(int, 2),
Q_ARG(QVector<QRect>, geometries));
QVERIFY(screensChangedSpy.wait());
QCOMPARE(screensChangedSpy.count(), 2);
const auto outputs = workspace()->outputs();
QCOMPARE(outputs.count(), 2);
QCOMPARE(outputs[0]->geometry(), geometries[0]);
......
......@@ -390,14 +390,11 @@ void PointerInputTest::testUpdateFocusAfterScreenChange()
QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos()));
QVERIFY(leftSpy.wait());
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(screensChangedSpy.isValid());
// now let's remove the screen containing the cursor
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
Qt::DirectConnection,
Q_ARG(int, 1),
Q_ARG(QVector<QRect>, QVector<QRect>{QRect(0, 0, 1280, 1024)}));
QVERIFY(screensChangedSpy.wait());
QCOMPARE(workspace()->outputs().count(), 1);
// this should have warped the cursor
......
......@@ -11,7 +11,6 @@
#include "cursor.h"
#include "output.h"
#include "platform.h"
#include "screens.h"
#include "wayland_server.h"
#include "workspace.h"
......@@ -87,15 +86,11 @@ void ScreenChangesTest::testScreenAddRemove()
outputAnnouncedSpy.clear();
// 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)};
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
Qt::DirectConnection,
Q_ARG(int, 2),
Q_ARG(QVector<QRect>, geometries));
QVERIFY(screensChangedSpy.wait());
QCOMPARE(screensChangedSpy.count(), 2);
auto outputs = workspace()->outputs();
QCOMPARE(outputs.count(), 2);
QCOMPARE(outputs[0]->geometry(), geometries[0]);
......@@ -154,7 +149,6 @@ void ScreenChangesTest::testScreenAddRemove()
// now let's try to remove one output again
outputAnnouncedSpy.clear();
outputRemovedSpy.clear();
screensChangedSpy.clear();
QSignalSpy o1RemovedSpy(o1.get(), &KWayland::Client::Output::removed);
QVERIFY(o1RemovedSpy.isValid());
......@@ -166,8 +160,6 @@ void ScreenChangesTest::testScreenAddRemove()
Qt::DirectConnection,
Q_ARG(int, 1),
Q_ARG(QVector<QRect>, geometries2));
QVERIFY(screensChangedSpy.wait());
QCOMPARE(screensChangedSpy.count(), 2);
outputs = workspace()->outputs();
QCOMPARE(outputs.count(), 1);
QCOMPARE(outputs[0]->geometry(), geometries2.at(0));
......
......@@ -34,7 +34,6 @@ private Q_SLOTS:
void cleanup();
void testSize_data();
void testSize();
void testCount();
void testCurrent_data();
void testCurrent();
void testCurrentWithFollowsMouse_data();
......@@ -118,28 +117,6 @@ void ScreensTest::testSize()
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()
{
QTest::addColumn<int>("currentId");
......
......@@ -22,17 +22,13 @@ namespace KWin
{
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);
}
void Screens::init()
{
updateCount();
connect(this, &Screens::countChanged, this, &Screens::changed, Qt::QueuedConnection);
connect(this, &Screens::changed, this, &Screens::updateSize);
connect(this, &Screens::sizeChanged, this, &Screens::geometryChanged);
......@@ -64,7 +60,7 @@ void Screens::updateSize()
{
QRect bounding;
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));
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
{
return workspace()->outputs().value(screen);
}
int Screens::count() const
{
return m_count;
}
QSize Screens::size() const
{
return m_boundingSize;
......
......@@ -29,14 +29,12 @@ class Platform;
class KWIN_EXPORT Screens : public QObject
{
Q_OBJECT
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
public:
explicit Screens();
void init();
int count() const;
QRect geometry(int screen) const;
/**
* The bounding geometry of all screens combined. Overlapping areas
......@@ -67,7 +65,6 @@ public:
QSize size() const;
Q_SIGNALS:
void countChanged(int previousCount, int newCount);
/**
* Emitted whenever the screens are changed either count or geometry.
*/
......@@ -90,17 +87,12 @@ Q_SIGNALS:
*/
void maxScaleChanged();
protected Q_SLOTS:
void setCount(int count);
void updateCount();
private Q_SLOTS:
void updateSize();
private:
Output *findOutput(int screenId) const;
int m_count;
QSize m_boundingSize;
qreal m_maxScale;
};
......
......@@ -10,12 +10,12 @@
#include <config-kwin.h>
#include "window.h"
#if KWIN_BUILD_ACTIVITIES
#include "activities.h"
#endif
#include "screens.h"
#include "output.h"
#include "virtualdesktops.h"
#include "window.h"
#include "workspace.h"
namespace KWin::ScriptingModels::V2
......@@ -324,7 +324,7 @@ AbstractLevel *AbstractLevel::create(const QList<ClientModel::LevelRestriction>
#endif
}
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);
if (!childLevel) {
continue;
......@@ -398,7 +398,8 @@ ForkLevel::ForkLevel(const QList<ClientModel::LevelRestriction> &childRestrictio
, m_childRestrictions(childRestrictions)
{
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 (Activities *activities = Workspace::self()->activities()) {
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) {
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();
}
if (previousCount > newCount) {
// screens got removed
Q_EMIT beginRemove(newCount, previousCount - 1, id());
while (m_children.count() > newCount) {
delete m_children.takeLast();
}
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::outputRemoved()
{
if (restriction() != ClientModel::ClientModel::ClientModel::ScreenRestriction) {
return;
}
const int row = count() - 1;
Q_EMIT beginRemove(row, row, id());
delete m_children.takeLast();
Q_EMIT endRemove();
}
void ForkLevel::activityAdded(const QString &activityId)
......
......@@ -187,9 +187,10 @@ public:
Window *clientForId(quint32 child) const override;
private Q_SLOTS:
void desktopCountChanged(uint previousCount, uint newCount);
void screenCountChanged(int previousCount, int newCount);
void activityAdded(const QString &id);
void activityRemoved(const QString &id);
void outputAdded();
void outputRemoved();
private:
QList<AbstractLevel *> m_children;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment