Commit 7e8facc3 authored by David Edmundson's avatar David Edmundson Committed by Marco Martin

[wayland] Use the new plasma virtual desktop protocol

Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)

Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)

Test Plan: used a bit a plasma session together with D12820, D13748 and D13746

Reviewers: #plasma, #kwin, graesslin, davidedmundson

Reviewed By: #plasma, #kwin, davidedmundson

Subscribers: hein, zzag, davidedmundson, kwin

Tags: #kwin

Maniphest Tasks: T4457

Differential Revision: https://phabricator.kde.org/D13887
parent e0aa3a30
......@@ -381,6 +381,7 @@ add_subdirectory(helpers)
set(kwin_KDEINIT_SRCS
workspace.cpp
dbusinterface.cpp
virtualdesktopsdbustypes.cpp
abstract_client.cpp
client.cpp
client_machine.cpp
......@@ -533,6 +534,7 @@ qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Compositing.xml dbusinterfa
qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.ColorCorrect.xml colorcorrection/colorcorrectdbusinterface.h KWin::ColorCorrect::ColorCorrectDBusInterface )
qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS ${kwin_effects_dbus_xml} effects.h KWin::EffectsHandlerImpl )
qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.OrientationSensor.xml orientation_sensor.h KWin::OrientationSensor)
qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.VirtualDesktopManager.xml dbusinterface.h KWin::VirtualDesktopManagerDBusInterface )
qt5_add_dbus_interface( kwin_KDEINIT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.ScreenSaver.xml screenlocker_interface)
......@@ -671,6 +673,7 @@ install(
org.kde.kwin.Compositing.xml
org.kde.kwin.ColorCorrect.xml
org.kde.kwin.Effects.xml
org.kde.KWin.VirtualDesktopManager.xml
DESTINATION
${KDE_INSTALL_DBUSINTERFACEDIR}
)
......
......@@ -489,16 +489,44 @@ void AbstractClient::setDesktop(int desktop)
if (desktop != NET::OnAllDesktops) // Do range check
desktop = qMax(1, qMin(numberOfDesktops, desktop));
desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop));
if (m_desktop == desktop)
VirtualDesktop *virtualDesktop = desktop == NET::OnAllDesktops ? nullptr : VirtualDesktopManager::self()->desktopForX11Id(desktop);
// Don't do anything if we're already there, if the desktop is already in desktops or if the desktop is NET::OnAllDesktops and m_desktops is already empty.
if (m_desktops.contains(virtualDesktop) ||
(desktop == NET::OnAllDesktops && m_desktops.isEmpty())) {
return;
}
int was_desk = m_desktop;
const bool wasOnCurrentDesktop = isOnCurrentDesktop();
m_desktop = desktop;
int was_desk = AbstractClient::desktop();
const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0;
//on x11 we can have only one desktop at a time
if (kwinApp()->operationMode() == Application::OperationModeX11) {
m_desktops.clear();
}
if (desktop == NET::OnAllDesktops) {
m_desktops.clear();
} else {
//if would become on all desktops, clear the list, as empty == on all desktops
if (m_desktops.count() > 1 && static_cast<uint>(m_desktops.count()) == VirtualDesktopManager::self()->count() - 1) {
m_desktops.clear();
} else {
m_desktops << virtualDesktop;
}
}
if (windowManagementInterface()) {
if (m_desktops.isEmpty()) {
windowManagementInterface()->setOnAllDesktops(true);
} else {
windowManagementInterface()->addPlasmaVirtualDesktop(virtualDesktop->id());
}
}
if (info) {
info->setDesktop(desktop);
}
if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) {
// onAllDesktops changed
workspace()->updateOnAllDesktopsOfTransients(this);
......@@ -526,6 +554,7 @@ void AbstractClient::setDesktop(int desktop)
emit desktopChanged();
if (wasOnCurrentDesktop != isOnCurrentDesktop())
emit desktopPresenceChanged(this, was_desk);
emit x11DesktopIdsChanged();
}
void AbstractClient::doSetDesktop(int desktop, int was_desk)
......@@ -534,6 +563,34 @@ void AbstractClient::doSetDesktop(int desktop, int was_desk)
Q_UNUSED(was_desk)
}
void AbstractClient::unSetDesktop(int desktop)
{
// Case in which we are on all desktops and gets asked to unset
if (desktop == NET::OnAllDesktops) {
if (m_desktops.isEmpty()) {
setOnAllDesktops(false);
}
return;
}
// Out of range
if (desktop < 1 || desktop > VirtualDesktopManager::self()->count()) {
return;
}
VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop);
m_desktops.removeAll(virtualDesktop);
if (!windowManagementInterface()) {
return;
}
windowManagementInterface()->removePlasmaVirtualDesktop(virtualDesktop->id());
emit x11DesktopIdsChanged();
}
void AbstractClient::setOnAllDesktops(bool b)
{
if ((b && isOnAllDesktops()) ||
......@@ -545,6 +602,20 @@ void AbstractClient::setOnAllDesktops(bool b)
setDesktop(VirtualDesktopManager::self()->current());
}
QList<int> AbstractClient::x11DesktopIds() const
{
const auto desks = desktops();
QList<int> x11Ids;
x11Ids.reserve(desks.count());
std::transform(desks.constBegin(), desks.constEnd(),
std::back_inserter(x11Ids),
[] (const VirtualDesktop *vd) {
return vd->x11DesktopNumber();
}
);
return x11Ids;
}
bool AbstractClient::isShadeable() const
{
return false;
......@@ -808,16 +879,7 @@ void AbstractClient::setupWindowManagementInterface()
}
);
connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); });
connect(this, &AbstractClient::desktopChanged, w,
[w, this] {
if (isOnAllDesktops()) {
w->setOnAllDesktops(true);
return;
}
w->setVirtualDesktop(desktop() - 1);
w->setOnAllDesktops(false);
}
);
connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); });
connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); });
connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove);
......@@ -912,6 +974,48 @@ void AbstractClient::setupWindowManagementInterface()
setShade(set);
}
);
for (const auto vd : m_desktops) {
w->addPlasmaVirtualDesktop(vd->id());
}
//this is only for the legacy
connect(this, &AbstractClient::desktopChanged, w,
[w, this] {
if (isOnAllDesktops()) {
w->setOnAllDesktops(true);
return;
}
w->setVirtualDesktop(desktop() - 1);
w->setOnAllDesktops(false);
}
);
//Plasma Virtual desktop management
//show/hide when the window enters/exits from desktop
connect(w, &PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested, this,
[this] (const QString &desktopId) {
VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8());
if (vd) {
workspace()->sendClientToDesktop(this, vd->x11DesktopNumber(), false);
}
}
);
connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this,
[this] () {
VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1);
workspace()->sendClientToDesktop(this, VirtualDesktopManager::self()->count(), false);
}
);
connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this,
[this] (const QString &desktopId) {
VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8());
if (vd) {
unSetDesktop(vd->x11DesktopNumber());
}
}
);
m_windowManagementInterface = w;
}
......
......@@ -84,12 +84,17 @@ class KWIN_EXPORT AbstractClient : public Toplevel
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
/**
* The desktop this Client is on. If the Client is on all desktops the property has value -1.
* This is a legacy property, use x11DesktopIds instead
**/
Q_PROPERTY(int desktop READ desktop WRITE setDesktop NOTIFY desktopChanged)
/**
* Whether the Client is on all desktops. That is desktop is -1.
**/
Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops WRITE setOnAllDesktops NOTIFY desktopChanged)
/**
* The x11 ids for all desktops this client is in. On X11 this list will always have a length of 1
**/
Q_PROPERTY(QList<int> x11DesktopIds READ x11DesktopIds NOTIFY x11DesktopIdsChanged)
/**
* Indicates that the window should not be included on a taskbar.
**/
......@@ -423,9 +428,18 @@ public:
virtual bool performMouseCommand(Options::MouseCommand, const QPoint &globalPos);
void setOnAllDesktops(bool set);
void setDesktop(int);
Q_INVOKABLE virtual void unSetDesktop(int desktop);
int desktop() const override {
return m_desktop;
return m_desktops.isEmpty() ? (int)NET::OnAllDesktops : m_desktops.last()->x11DesktopNumber();
}
virtual QList<VirtualDesktop *> desktops() const {
return m_desktops;
}
void removeDesktop(VirtualDesktop *desktop) {
m_desktops.removeAll(desktop);
}
QList<int> x11DesktopIds() const;
void setMinimized(bool set);
/**
* Minimizes this client plus its transients
......@@ -757,6 +771,7 @@ Q_SIGNALS:
void demandsAttentionChanged();
void desktopPresenceChanged(KWin::AbstractClient*, int); // to be forwarded by Workspace
void desktopChanged();
void x11DesktopIdsChanged();
void shadeChanged();
void minimizedChanged();
void clientMinimized(KWin::AbstractClient* client, bool animate);
......@@ -1107,7 +1122,7 @@ private:
bool m_demandsAttention = false;
bool m_minimized = false;
QTimer *m_autoRaiseTimer = nullptr;
int m_desktop = 0; // 0 means not on any desktop yet
QList <VirtualDesktop *> m_desktops;
QString m_colorScheme;
std::shared_ptr<Decoration::DecorationPalette> m_palette;
......
......@@ -43,6 +43,7 @@ target_link_libraries( testVirtualDesktops
KF5::GlobalAccel
KF5::ConfigCore
KF5::WindowSystem
KF5::WaylandServer
)
add_test(NAME kwin-testVirtualDesktops COMMAND testVirtualDesktops)
ecm_mark_as_test(testVirtualDesktops)
......@@ -336,6 +337,7 @@ target_link_libraries(testScreenEdges
KF5::GlobalAccel
KF5::Notifications
KF5::WindowSystem
KF5::WaylandServer
XCB::XCB
XCB::RANDR
XCB::XFIXES
......
......@@ -43,6 +43,10 @@ private Q_SLOTS:
void testNetCurrentDesktop();
void testLastDesktopRemoved_data();
void testLastDesktopRemoved();
void testWindowOnMultipleDesktops_data();
void testWindowOnMultipleDesktops();
void testRemoveDesktopWithWindow_data();
void testRemoveDesktopWithWindow();
};
void VirtualDesktopTest::initTestCase()
......@@ -157,12 +161,154 @@ void VirtualDesktopTest::testLastDesktopRemoved()
QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged);
QVERIFY(desktopPresenceChangedSpy.isValid());
QCOMPARE(client->desktops().count(), 1u);
QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first());
// and remove last desktop
VirtualDesktopManager::self()->setCount(1);
QCOMPARE(VirtualDesktopManager::self()->count(), 1u);
// now the client should be moved as well
QTRY_COMPARE(desktopPresenceChangedSpy.count(), 1);
QCOMPARE(client->desktop(), 1);
QCOMPARE(client->desktops().count(), 1u);
QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first());
}
void VirtualDesktopTest::testWindowOnMultipleDesktops_data()
{
QTest::addColumn<Test::ShellSurfaceType>("type");
QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell;
QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5;
QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6;
}
void VirtualDesktopTest::testWindowOnMultipleDesktops()
{
// first create two new desktops
QCOMPARE(VirtualDesktopManager::self()->count(), 1u);
VirtualDesktopManager::self()->setCount(3);
QCOMPARE(VirtualDesktopManager::self()->count(), 3u);
// switch to last desktop
VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().last());
QCOMPARE(VirtualDesktopManager::self()->current(), 3u);
// now create a window on this desktop
QScopedPointer<Surface> surface(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data()));
auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(client);
QCOMPARE(client->desktop(), 3u);
QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged);
QVERIFY(desktopPresenceChangedSpy.isValid());
QCOMPARE(client->desktops().count(), 1u);
QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first());
//Set the window on desktop 2 as well
client->setDesktop(2u);
QCOMPARE(client->desktops().count(), 2u);
QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]);
QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]);
QVERIFY(client->isOnDesktop(2));
QVERIFY(client->isOnDesktop(3));
//leave desktop 3
client->unSetDesktop(3);
QCOMPARE(client->desktops().count(), 1u);
//leave desktop 2
client->unSetDesktop(2);
QCOMPARE(client->desktops().count(), 0u);
//we should be on all desktops now
QVERIFY(client->isOnAllDesktops());
//put on desktop 1
client->setDesktop(1);
QVERIFY(client->isOnDesktop(1));
QVERIFY(!client->isOnDesktop(2));
QVERIFY(!client->isOnDesktop(3));
QCOMPARE(client->desktops().count(), 1u);
//put on desktop 2
client->setDesktop(2);
QVERIFY(client->isOnDesktop(1));
QVERIFY(client->isOnDesktop(2));
QVERIFY(!client->isOnDesktop(3));
QCOMPARE(client->desktops().count(), 2u);
//put on desktop 3
client->setDesktop(3);
QVERIFY(client->isOnDesktop(1));
QVERIFY(client->isOnDesktop(2));
QVERIFY(client->isOnDesktop(3));
QVERIFY(client->isOnAllDesktops());
//when it gets on all desktops, it loses all desktops()
QCOMPARE(client->desktops().count(), 0u);
}
void VirtualDesktopTest::testRemoveDesktopWithWindow_data()
{
QTest::addColumn<Test::ShellSurfaceType>("type");
QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell;
QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5;
QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6;
}
void VirtualDesktopTest::testRemoveDesktopWithWindow()
{
// first create two new desktops
QCOMPARE(VirtualDesktopManager::self()->count(), 1u);
VirtualDesktopManager::self()->setCount(3);
QCOMPARE(VirtualDesktopManager::self()->count(), 3u);
// switch to last desktop
VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().last());
QCOMPARE(VirtualDesktopManager::self()->current(), 3u);
// now create a window on this desktop
QScopedPointer<Surface> surface(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data()));
auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(client);
QCOMPARE(client->desktop(), 3u);
QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged);
QVERIFY(desktopPresenceChangedSpy.isValid());
QCOMPARE(client->desktops().count(), 1u);
QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first());
//Set the window on desktop 2 as well
client->setDesktop(2u);
QCOMPARE(client->desktops().count(), 2u);
QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]);
QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]);
QVERIFY(client->isOnDesktop(2));
QVERIFY(client->isOnDesktop(3));
//remove desktop 3
VirtualDesktopManager::self()->setCount(2);
QCOMPARE(client->desktops().count(), 1u);
//window is only on desktop 2
QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[0]);
//Again 3 desktops
VirtualDesktopManager::self()->setCount(3);
//move window to be only on desktop 3
client->setDesktop(3);
client->unSetDesktop(2);
QCOMPARE(client->desktops().count(), 1u);
//window is only on desktop 3
QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]);
//remove desktop 3
VirtualDesktopManager::self()->setCount(2);
QCOMPARE(client->desktops().count(), 1u);
//window is only on desktop 2
QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[0]);
}
WAYLANDTEST_MAIN(VirtualDesktopTest)
......
......@@ -132,8 +132,10 @@ void TestVirtualDesktops::count()
vds->setCount(s_countInitValue);
QSignalSpy spy(vds, SIGNAL(countChanged(uint,uint)));
QSignalSpy desktopsRemoved(vds, SIGNAL(desktopsRemoved(uint)));
QSignalSpy desktopsRemoved(vds, SIGNAL(desktopRemoved(KWin::VirtualDesktop *)));
auto vdToRemove = vds->desktops().last();
QFETCH(uint, request);
QFETCH(uint, result);
QFETCH(bool, signal);
......@@ -153,8 +155,7 @@ void TestVirtualDesktops::count()
if (!desktopsRemoved.isEmpty()) {
QList<QVariant> arguments = desktopsRemoved.takeFirst();
QCOMPARE(arguments.count(), 1);
QCOMPARE(arguments.at(0).type(), QVariant::UInt);
QCOMPARE(arguments.at(0).toUInt(), s_countInitValue);
QCOMPARE(arguments.at(0).value<KWin::VirtualDesktop*>(), vdToRemove);
}
}
......
......@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include <kwineffects.h>
#include "../virtualdesktops.h"
#include <QVector2D>
#include <QGraphicsRotation>
......@@ -72,6 +73,7 @@ public:
virtual void setData(int role, const QVariant &data);
virtual void referencePreviousWindowPixmap() {}
virtual void unreferencePreviousWindowPixmap() {}
QList<int> desktops() const { return {};}
};
MockEffectWindow::MockEffectWindow(QObject *parent)
......
......@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// own
#include "dbusinterface.h"
#include "compositingadaptor.h"
#include "virtualdesktopmanageradaptor.h"
// kwin
#include "abstract_client.h"
......@@ -315,4 +316,180 @@ QStringList CompositorDBusInterface::supportedOpenGLPlatformInterfaces() const
return interfaces;
}
VirtualDesktopManagerDBusInterface::VirtualDesktopManagerDBusInterface(VirtualDesktopManager *parent)
: QObject(parent)
, m_manager(parent)
{
qDBusRegisterMetaType<KWin::DBusDesktopDataStruct>();
qDBusRegisterMetaType<KWin::DBusDesktopDataVector>();
new VirtualDesktopManagerAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/VirtualDesktopManager"),
QStringLiteral("org.kde.KWin.VirtualDesktopManager"),
this
);
connect(m_manager, &VirtualDesktopManager::currentChanged, this,
[this](uint previousDesktop, uint newDesktop) {
Q_UNUSED(previousDesktop);
Q_UNUSED(newDesktop);
emit currentChanged(m_manager->currentDesktop()->id());
}
);
connect(m_manager, &VirtualDesktopManager::countChanged, this,
[this](uint previousCount, uint newCount) {
Q_UNUSED(previousCount);
emit countChanged(newCount);
emit desktopsChanged(desktops());
}
);
connect(m_manager, &VirtualDesktopManager::navigationWrappingAroundChanged, this,
[this]() {
emit navigationWrappingAroundChanged(isNavigationWrappingAround());
}
);
connect(m_manager, &VirtualDesktopManager::rowsChanged, this, &VirtualDesktopManagerDBusInterface::rowsChanged);
for (auto *vd : m_manager->desktops()) {
connect(vd, &VirtualDesktop::x11DesktopNumberChanged, this,
[this, vd]() {
DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
emit desktopDataChanged(vd->id(), data);
emit desktopsChanged(desktops());
}
);
connect(vd, &VirtualDesktop::nameChanged, this,
[this, vd]() {
DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
emit desktopDataChanged(vd->id(), data);
emit desktopsChanged(desktops());
}
);
}
connect(m_manager, &VirtualDesktopManager::desktopCreated, this,
[this](VirtualDesktop *vd) {
connect(vd, &VirtualDesktop::x11DesktopNumberChanged, this,
[this, vd]() {
DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
emit desktopDataChanged(vd->id(), data);
emit desktopsChanged(desktops());
}
);
connect(vd, &VirtualDesktop::nameChanged, this,
[this, vd]() {
DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
emit desktopDataChanged(vd->id(), data);
emit desktopsChanged(desktops());
}
);
DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
emit desktopCreated(vd->id(), data);
emit desktopsChanged(desktops());
}
);
connect(m_manager, &VirtualDesktopManager::desktopRemoved, this,
[this](VirtualDesktop *vd) {
emit desktopRemoved(vd->id());
emit desktopsChanged(desktops());
}
);
}
uint VirtualDesktopManagerDBusInterface::count() const
{
return m_manager->count();
}
void VirtualDesktopManagerDBusInterface::setRows(uint rows)
{
if (static_cast<uint>(m_manager->grid().height()) == rows) {
return;
}
m_manager->setRows(rows);
m_manager->save();
}
uint VirtualDesktopManagerDBusInterface::rows() const
{
return m_manager->rows();
}
void VirtualDesktopManagerDBusInterface::setCurrent(const QString &id)
{
if (m_manager->currentDesktop()->id() == id) {
return;
}
auto *vd = m_manager->desktopForId(id.toUtf8());
if (vd) {
m_manager->setCurrent(vd);
}
}
QString VirtualDesktopManagerDBusInterface::current() const
{
return m_manager->currentDesktop()->id();
}
void VirtualDesktopManagerDBusInterface::setNavigationWrappingAround(bool wraps)
{
if (m_manager->isNavigationWrappingAround() == wraps) {
return;
}
m_manager->setNavigationWrappingAround(wraps);
}
bool VirtualDesktopManagerDBusInterface::isNavigationWrappingAround() const
{
return m_manager->isNavigationWrappingAround();
}
DBusDesktopDataVector VirtualDesktopManagerDBusInterface::desktops() const
{
const auto desks = m_manager->desktops();
DBusDesktopDataVector desktopVect;
desktopVect.reserve(m_manager->count());
std::transform(desks.constBegin(), desks.constEnd(),
std::back_inserter(desktopVect),
[] (const VirtualDesktop *vd) {
return DBusDesktopDataStruct{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()};
}
);
return desktopVect;
}
void VirtualDesktopManagerDBusInterface::createDesktop(uint position, const QString &name)
{
m_manager->createVirtualDesktop(position + 1, name);
}
void VirtualDesktopManagerDBusInterface::setDesktopName(const QString &id, const QString &name)
{
VirtualDesktop *vd = m_manager->desktopForId(id.toUtf8());
if (!vd) {
return;
}
if (vd->name() == name) {
return;
}
vd->setName(name);
m_manager->save();
}
void VirtualDesktopManagerDBusInterface::removeDesktop(const QString &id)
{
m_manager->removeVirtualDesktop(id.toUtf8());
}