VirtualDesktops: POC per-output desktops

This commit is contained in:
Yuki Joou 2024-09-11 23:52:42 +02:00
parent 2fb6271c02
commit 128dfe09fd
3 changed files with 56 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#include "virtualdesktops.h"
#include "input.h"
#include "wayland/plasmavirtualdesktop.h"
#include "workspace.h"
// KDE
#include <KConfigGroup>
#include <KGlobalAccel>
@ -519,6 +520,15 @@ VirtualDesktop *VirtualDesktopManager::currentDesktop() const
return m_current;
}
VirtualDesktop *VirtualDesktopManager::currentDesktop(Output *output) const
{
if (!m_currentForOutput.contains(output)) {
qInfo("Output not in list :/");
return m_current;
}
return m_currentForOutput[output];
}
bool VirtualDesktopManager::setCurrent(uint newDesktop)
{
if (newDesktop < 1 || newDesktop > count()) {
@ -538,6 +548,33 @@ bool VirtualDesktopManager::setCurrent(VirtualDesktop *newDesktop)
VirtualDesktop *oldDesktop = currentDesktop();
m_current = newDesktop;
Q_EMIT currentChanged(oldDesktop, newDesktop);
for (auto *output : Workspace::self()->outputs()) {
m_currentForOutput[output] = m_current;
}
return true;
}
bool VirtualDesktopManager::setCurrentForOutput(uint newDesktop, Output *targetOutput)
{
if (newDesktop < 1 || newDesktop > count()) {
return false;
}
auto d = desktopForX11Id(newDesktop);
Q_ASSERT(d);
return setCurrentForOutput(d, targetOutput);
}
bool VirtualDesktopManager::setCurrentForOutput(VirtualDesktop *newDesktop, Output *targetOutput)
{
Q_ASSERT(newDesktop);
Q_ASSERT(targetOutput);
Q_ASSERT(m_currentForOutput.contains(targetOutput));
if (m_currentForOutput[targetOutput] == newDesktop) {
return false;
}
VirtualDesktop *oldDesktop = m_currentForOutput[targetOutput];
m_currentForOutput[targetOutput] = newDesktop;
Q_EMIT currentChanged(oldDesktop, newDesktop);
return true;
}
@ -594,6 +631,12 @@ void VirtualDesktopManager::setCount(uint count)
updateLayout();
updateRootInfo();
// TODO: Figure out a better place
qInfo("setCount()");
for (Output *output : Workspace::self()->outputs()) {
m_currentForOutput[output] = m_current;
}
if (!s_loadingDesktopSettings) {
save();
}
@ -883,7 +926,9 @@ void VirtualDesktopManager::slotSwitchTo()
if (!ok) {
return;
}
setCurrent(i);
qInfo("Active output: %p", Workspace::self()->activeOutput());
qInfo("Setting to desktop %d on output %p", i, Workspace::self()->activeOutput());
setCurrentForOutput(i, Workspace::self()->activeOutput());
}
void VirtualDesktopManager::setNavigationWrappingAround(bool enabled)

View file

@ -30,6 +30,7 @@ namespace KWin
class Options;
class PlasmaVirtualDesktopManagementInterface;
class Output;
class KWIN_EXPORT VirtualDesktop : public QObject
{
@ -197,6 +198,8 @@ public:
*/
VirtualDesktop *currentDesktop() const;
VirtualDesktop *currentDesktop(Output *output) const;
/**
* Moves to the desktop through the algorithm described by Direction.
* @param wrap If @c true wraps around to the other side of the layout
@ -352,6 +355,9 @@ public Q_SLOTS:
*/
bool setCurrent(VirtualDesktop *current);
bool setCurrentForOutput(VirtualDesktop *current, Output *output);
bool setCurrentForOutput(uint current, Output *output);
/**
* Updates the layout to a new number of rows. The number of columns will be calculated accordingly
*/
@ -515,6 +521,7 @@ private:
QList<VirtualDesktop *> m_desktops;
QPointer<VirtualDesktop> m_current;
QHash<Output *, QPointer<VirtualDesktop>> m_currentForOutput;
quint32 m_rows = 2;
bool m_navigationWrapsAround;
VirtualDesktopGrid m_grid;

View file

@ -834,7 +834,9 @@ bool Window::isOnDesktop(VirtualDesktop *desktop) const
bool Window::isOnCurrentDesktop() const
{
return isOnDesktop(VirtualDesktopManager::self()->currentDesktop());
bool is = isOnDesktop(VirtualDesktopManager::self()->currentDesktop(output()));
qInfo("isOnDesktop %d", is);
return isOnDesktop(VirtualDesktopManager::self()->currentDesktop(output()));
}
ShadeMode Window::shadeMode() const