fix & cleanup Workspace::setNumberOfDesktops()

encapsulate all relevant (vector resizing) code to
Workspace::setNumberOfDesktops and invoke it from
Workspace::loadDesktopSettigns, this will likely
fix
CCBUG:200213
This commit is contained in:
Thomas Lübking 2011-03-07 18:41:17 +01:00
parent f8cab9a6da
commit b32331afcf

View file

@ -1169,20 +1169,8 @@ void Workspace::loadDesktopSettings()
else
groupname.sprintf("Desktops-screen-%d", screen_number);
KConfigGroup group(c, groupname);
int n = group.readEntry("Number", 4);
desktopCount_ = n;
workarea.clear();
workarea.resize(n + 1);
restrictedmovearea.clear();
restrictedmovearea.resize(n + 1);
oldrestrictedmovearea.clear();
oldrestrictedmovearea.resize(n + 1);
screenarea.clear();
rootInfo->setNumberOfDesktops(n);
desktop_focus_chain.resize(n);
// Make it +1, so that it can be accessed as [1..numberofdesktops]
focus_chain.resize(n + 1);
const int n = group.readEntry("Number", 4);
setNumberOfDesktops(n);
for (int i = 1; i <= n; i++) {
QString s = group.readEntry(QString("Name_%1").arg(i), i18n("Desktop %1", i));
rootInfo->setDesktopName(i, s.toUtf8().data());
@ -1642,40 +1630,33 @@ void Workspace::setNumberOfDesktops(int n)
desktopCount_ = n;
updateDesktopLayout(); // Make sure the layout is still valid
if (currentDesktop() > numberOfDesktops())
setCurrentDesktop(numberOfDesktops());
if (currentDesktop() > n)
setCurrentDesktop(n);
// If increasing the number, do the resizing now, otherwise
// after the moving of windows to still existing desktops
if (old_number_of_desktops < numberOfDesktops()) {
rootInfo->setNumberOfDesktops(numberOfDesktops());
NETPoint* viewports = new NETPoint[numberOfDesktops()];
rootInfo->setDesktopViewport(numberOfDesktops(), *viewports);
delete[] viewports;
updateClientArea(true);
focus_chain.resize(numberOfDesktops() + 1);
}
// If the number of desktops decreased, move all windows
// that would be hidden to the last visible desktop
// move all windows that would be hidden to the last visible desktop
if (old_number_of_desktops > numberOfDesktops()) {
for (ClientList::ConstIterator it = clients.constBegin();
it != clients.constEnd();
++it)
for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) {
if (!(*it)->isOnAllDesktops() && (*it)->desktop() > numberOfDesktops())
sendClientToDesktop(*it, numberOfDesktops(), true);
// TODO: Tile should have a method allClients, push them into other tiles
}
if (old_number_of_desktops > numberOfDesktops()) {
rootInfo->setNumberOfDesktops(numberOfDesktops());
NETPoint* viewports = new NETPoint[numberOfDesktops()];
rootInfo->setDesktopViewport(numberOfDesktops(), *viewports);
delete[] viewports;
updateClientArea(true);
focus_chain.resize(numberOfDesktops() + 1);
// TODO: Tile should have a method allClients, push them into other tiles
}
}
rootInfo->setNumberOfDesktops(n);
NETPoint* viewports = new NETPoint[n];
rootInfo->setDesktopViewport(n, *viewports);
delete[] viewports;
updateClientArea(true);
saveDesktopSettings();
// Make it +1, so that it can be accessed as [1..numberofdesktops]
focus_chain.resize(n + 1);
workarea.clear();
workarea.resize(n + 1);
restrictedmovearea.clear();
restrictedmovearea.resize(n + 1);
oldrestrictedmovearea.clear();
oldrestrictedmovearea.resize(n + 1);
screenarea.clear();
// Resize and reset the desktop focus chain.
desktop_focus_chain.resize(n);
@ -1686,6 +1667,8 @@ void Workspace::setNumberOfDesktops(int n)
// reset the desktop change osd
desktop_change_osd->numberDesktopsChanged();
saveDesktopSettings();
emit numberDesktopsChanged(old_number_of_desktops);
}