Port Workspace::slotWindowToDesktop*() to VirtualDesktop

This commit is contained in:
Vlad Zahorodnii 2021-08-17 10:19:46 +03:00
parent b85edc08d2
commit ba0f5981bf
3 changed files with 33 additions and 25 deletions

View file

@ -908,7 +908,10 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop()
{
// this test verifies that when sending a client to a desktop all transients are also send to that desktop
VirtualDesktopManager::self()->setCount(2);
VirtualDesktopManager *vds = VirtualDesktopManager::self();
vds->setCount(2);
const QVector<VirtualDesktop *> desktops = vds->desktops();
QScopedPointer<Surface> surface{Test::createSurface()};
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
@ -926,14 +929,16 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop()
QCOMPARE(transient->transientFor(), c);
QVERIFY(c->transients().contains(transient));
QCOMPARE(c->desktop(), 1);
// initially, the parent and the transient are on the first virtual desktop
QCOMPARE(c->desktops(), QVector<VirtualDesktop *>{desktops[0]});
QVERIFY(!c->isOnAllDesktops());
QCOMPARE(transient->desktop(), 1);
QCOMPARE(transient->desktops(), QVector<VirtualDesktop *>{desktops[0]});
QVERIFY(!transient->isOnAllDesktops());
workspace()->slotWindowToDesktop(2);
QCOMPARE(c->desktop(), 1);
QCOMPARE(transient->desktop(), 2);
// send the transient to the second virtual desktop
workspace()->slotWindowToDesktop(desktops[1]);
QCOMPARE(c->desktops(), QVector<VirtualDesktop *>{desktops[0]});
QCOMPARE(transient->desktops(), QVector<VirtualDesktop *>{desktops[1]});
// activate c
workspace()->activateClient(c);
@ -941,13 +946,13 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop()
QVERIFY(c->isActive());
// and send it to the desktop it's already on
QCOMPARE(c->desktop(), 1);
QCOMPARE(transient->desktop(), 2);
workspace()->slotWindowToDesktop(1);
QCOMPARE(c->desktops(), QVector<VirtualDesktop *>{desktops[0]});
QCOMPARE(transient->desktops(), QVector<VirtualDesktop *>{desktops[1]});
workspace()->slotWindowToDesktop(desktops[0]);
// which should move the transient back to the desktop
QCOMPARE(c->desktop(), 1);
QCOMPARE(transient->desktop(), 1);
QCOMPARE(c->desktops(), QVector<VirtualDesktop *>{desktops[0]});
QCOMPARE(transient->desktops(), QVector<VirtualDesktop *>{desktops[0]});
}
void TestXdgShellClient::testMinimizeWindowWithTransients()

View file

@ -1068,8 +1068,15 @@ void Workspace::initShortcuts()
DEF2("Window On All Desktops", I18N_NOOP("Keep Window on All Desktops"),
0, slotWindowOnAllDesktops);
for (int i = 1; i < 21; ++i) {
DEF5(I18N_NOOP("Window to Desktop %1"), 0, std::bind(&Workspace::slotWindowToDesktop, this, i), i);
VirtualDesktopManager *vds = VirtualDesktopManager::self();
for (uint i = 0; i < vds->maximum(); ++i) {
auto handler = [this, i]() {
const QVector<VirtualDesktop *> desktops = VirtualDesktopManager::self()->desktops();
if (i < uint(desktops.count())) {
slotWindowToDesktop(desktops[i]);
}
};
DEF5(I18N_NOOP("Window to Desktop %1"), 0, handler, i + 1);
}
DEF(I18N_NOOP("Window to Next Desktop"), 0, slotWindowToNextDesktop);
DEF(I18N_NOOP("Window to Previous Desktop"), 0, slotWindowToPreviousDesktop);
@ -1105,7 +1112,7 @@ void Workspace::initShortcuts()
#ifdef KWIN_BUILD_TABBOX
TabBox::TabBox::self()->initShortcuts();
#endif
VirtualDesktopManager::self()->initShortcuts();
vds->initShortcuts();
m_userActionsMenu->discard(); // so that it's recreated next time
}
@ -1283,14 +1290,10 @@ static uint senderValue(QObject *sender)
#define USABLE_ACTIVE_CLIENT (active_client && !(active_client->isDesktop() || active_client->isDock()))
void Workspace::slotWindowToDesktop(uint i)
void Workspace::slotWindowToDesktop(VirtualDesktop *desktop)
{
if (USABLE_ACTIVE_CLIENT) {
if (i < 1)
return;
if (i >= 1 && i <= VirtualDesktopManager::self()->count())
sendClientToDesktop(active_client, i, true);
sendClientToDesktop(active_client, desktop->x11DesktopNumber(), true);
}
}
@ -1528,14 +1531,14 @@ void activeClientToDesktop()
{
VirtualDesktopManager *vds = VirtualDesktopManager::self();
Workspace *ws = Workspace::self();
const int current = vds->current();
VirtualDesktop *current = vds->currentDesktop();
Direction functor;
const int d = functor(current, options->isRollOverDesktops());
if (d == current) {
VirtualDesktop *newCurrent = functor(current, options->isRollOverDesktops());
if (newCurrent == current) {
return;
}
ws->setMoveResizeClient(ws->activeClient());
vds->setCurrent(d);
vds->setCurrent(newCurrent);
ws->setMoveResizeClient(nullptr);
}

View file

@ -413,7 +413,7 @@ public Q_SLOTS:
void performWindowOperation(KWin::AbstractClient* c, Options::WindowOperation op);
// Keybindings
//void slotSwitchToWindow( int );
void slotWindowToDesktop(uint i);
void slotWindowToDesktop(VirtualDesktop *desktop);
//void slotWindowToListPosition( int );
void slotSwitchToScreen();