Port window cascading from X11 desktop ids to VirtualDesktop

This commit is contained in:
Vlad Zahorodnii 2023-03-30 12:21:05 +03:00
parent 044e160a50
commit d76527e7e6
3 changed files with 23 additions and 22 deletions

View file

@ -31,7 +31,7 @@ namespace KWin
Placement::Placement()
{
reinitCascading(0);
reinitCascading();
}
/**
@ -335,24 +335,24 @@ void Placement::placeSmart(Window *window, const QRectF &area, PlacementPolicy /
window->move(QPoint(x_optimal, y_optimal));
}
void Placement::reinitCascading(int desktop)
void Placement::reinitCascading()
{
// desktop == 0 - reinit all
if (desktop == 0) {
cci.clear();
for (uint i = 0; i < VirtualDesktopManager::self()->count(); ++i) {
DesktopCascadingInfo inf;
inf.pos = QPoint(-1, -1);
inf.col = 0;
inf.row = 0;
cci.append(inf);
}
} else {
cci[desktop - 1].pos = QPoint(-1, -1);
cci[desktop - 1].col = cci[desktop - 1].row = 0;
cci.clear();
const auto desktops = VirtualDesktopManager::self()->desktops();
for (VirtualDesktop *desktop : desktops) {
reinitCascading(desktop);
}
}
void Placement::reinitCascading(VirtualDesktop *desktop)
{
cci[desktop] = DesktopCascadingInfo{
.pos = QPoint(-1, -1),
.col = 0,
.row = 0,
};
}
QPoint Workspace::cascadeOffset(const Window *c) const
{
QRect area = clientArea(PlacementArea, c, c->frameGeometry().center()).toRect();
@ -373,7 +373,7 @@ void Placement::placeCascaded(Window *c, const QRect &area, PlacementPolicy next
// CT how do I get from the 'Client' class the size that NW squarish "handle"
const QPoint delta = workspace()->cascadeOffset(c);
const int dn = c->desktop() == 0 || c->isOnAllDesktops() ? (VirtualDesktopManager::self()->current() - 1) : (c->desktop() - 1);
VirtualDesktop *dn = c->isOnCurrentDesktop() ? VirtualDesktopManager::self()->currentDesktop() : c->desktops().constLast();
if (nextPlacement == PlacementUnknown) {
nextPlacement = PlacementSmart;
@ -630,8 +630,7 @@ void Placement::cascadeIfCovering(Window *window, const QRectF &area)
void Placement::cascadeDesktop()
{
Workspace *ws = Workspace::self();
const int desktop = VirtualDesktopManager::self()->current();
reinitCascading(desktop);
reinitCascading(VirtualDesktopManager::self()->currentDesktop());
const auto stackingOrder = ws->stackingOrder();
for (Window *window : stackingOrder) {
if (!window->isClient() || (!window->isOnCurrentDesktop()) || (window->isMinimized()) || (window->isOnAllDesktops()) || (!window->isMovable())) {

View file

@ -22,6 +22,7 @@ class QObject;
namespace KWin
{
class VirtualDesktop;
class Window;
class KWIN_EXPORT Placement
@ -34,7 +35,8 @@ public:
void placeCentered(Window *c, const QRectF &area, PlacementPolicy next = PlacementUnknown);
void reinitCascading(int desktop);
void reinitCascading();
void reinitCascading(VirtualDesktop *desktop);
void cascadeIfCovering(Window *c, const QRectF &area);
@ -71,7 +73,7 @@ private:
int row;
};
QList<DesktopCascadingInfo> cci;
QHash<VirtualDesktop *, DesktopCascadingInfo> cci;
};
} // namespace

View file

@ -1384,7 +1384,7 @@ void Workspace::updateOutputs(const QVector<Output *> &outputOrder)
void Workspace::slotDesktopAdded(VirtualDesktop *desktop)
{
m_focusChain->addDesktop(desktop);
m_placement->reinitCascading(0);
m_placement->reinitCascading();
updateClientArea();
}
@ -1409,7 +1409,7 @@ void Workspace::slotDesktopRemoved(VirtualDesktop *desktop)
}
updateClientArea();
m_placement->reinitCascading(0);
m_placement->reinitCascading();
m_focusChain->removeDesktop(desktop);
}