workspace: Route user-triggered requests to change desktop through Workspace

When we change a Virtual Desktop for a window there are implications on the
stacking order and focus. We need to separate the low level action of
updating just the window and the more general request.
wilder/Plasma/6.3
David Edmundson 2 years ago
parent 1e0816139a
commit de59a15efe
  1. 10
      src/useractions.cpp
  2. 7
      src/window.cpp
  3. 20
      src/workspace.cpp
  4. 2
      src/workspace.h

@ -562,9 +562,9 @@ void UserActionsMenu::multipleDesktopsPopupAboutToShow()
connect(action, &QAction::triggered, this, [this, desktop]() {
if (m_window) {
if (m_window->desktops().contains(desktop)) {
m_window->leaveDesktop(desktop);
Workspace::self()->removeWindowFromDesktop(m_window, desktop);
} else {
m_window->enterDesktop(desktop);
Workspace::self()->addWindowToDesktop(m_window, desktop);
}
}
});
@ -581,7 +581,7 @@ void UserActionsMenu::multipleDesktopsPopupAboutToShow()
QAction *action = m_multipleDesktopsMenu->addAction(name);
connect(action, &QAction::triggered, this, [this, desktop]() {
if (m_window) {
m_window->setDesktops({desktop});
Workspace::self()->sendWindowToDesktops(m_window, {desktop}, false);
}
});
}
@ -597,7 +597,7 @@ void UserActionsMenu::multipleDesktopsPopupAboutToShow()
}
VirtualDesktop *desktop = vds->createVirtualDesktop(vds->count());
if (desktop) {
m_window->enterDesktop(desktop);
Workspace::self()->addWindowToDesktop(m_window, desktop);
}
});
action->setEnabled(allowNewDesktops);
@ -609,7 +609,7 @@ void UserActionsMenu::multipleDesktopsPopupAboutToShow()
}
VirtualDesktop *desktop = vds->createVirtualDesktop(vds->count());
if (desktop) {
m_window->setDesktops({desktop});
Workspace::self()->sendWindowToDesktops(m_window, {desktop}, false);
}
});
action->setEnabled(allowNewDesktops);

@ -1893,17 +1893,18 @@ void Window::setupWindowManagementInterface()
connect(w, &PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested, this, [this](const QString &desktopId) {
VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId);
if (vd) {
enterDesktop(vd);
Workspace::self()->addWindowToDesktop(this, vd);
}
});
connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this, [this]() {
VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1);
enterDesktop(VirtualDesktopManager::self()->desktops().last());
auto vd = VirtualDesktopManager::self()->desktops().last();
Workspace::self()->addWindowToDesktop(this, vd);
});
connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this, [this](const QString &desktopId) {
VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId);
if (vd) {
leaveDesktop(vd);
Workspace::self()->removeWindowFromDesktop(this, vd);
}
});

@ -1443,6 +1443,26 @@ void Workspace::selectWmInputEventMask()
}
#endif
void Workspace::addWindowToDesktop(Window *window, VirtualDesktop *desktop)
{
auto desktops = window->desktops();
if (desktops.contains(desktop)) {
return;
}
desktops.append(desktop);
sendWindowToDesktops(window, desktops, false);
}
void Workspace::removeWindowFromDesktop(Window *window, VirtualDesktop *desktop)
{
auto desktops = window->desktops();
if (!desktops.contains(desktop)) {
return;
}
desktops.removeOne(desktop);
sendWindowToDesktops(window, desktops, false);
}
/**
* Sends window \a window to desktop \a desk.
*

@ -306,6 +306,8 @@ public:
Window *topWindowOnDesktop(VirtualDesktop *desktop, Output *output = nullptr, bool unconstrained = false,
bool only_normal = true) const;
Window *findDesktop(bool topmost, VirtualDesktop *desktop) const;
void addWindowToDesktop(Window *window, VirtualDesktop *desktop);
void removeWindowFromDesktop(Window *window, VirtualDesktop *desktop);
void sendWindowToDesktops(Window *window, const QList<VirtualDesktop *> &desktops, bool dont_activate);
void windowToPreviousDesktop(Window *window);
void windowToNextDesktop(Window *window);

Loading…
Cancel
Save