[kwin/kcmdesktop] Don't crash if run on platform Wayland

Not much use currently as we don't have any desktops to configure,
but not crashing is nevertheless quite nice.
This commit is contained in:
Martin Gräßlin 2014-02-11 15:27:28 +01:00
parent f67e67e5f0
commit 3ea8f0c217

View file

@ -107,8 +107,11 @@ void KWinDesktopConfig::init()
m_editor->addCollection(m_switchDesktopCollection, i18n("Desktop Switching"));
// get number of desktops
int n = 1;
if (QX11Info::isPlatformX11()) {
NETRootInfo info(QX11Info::connection(), NET::NumberOfDesktops | NET::DesktopNames);
int n = info.numberOfDesktops();
n = info.numberOfDesktops();
}
for (int i = 1; i <= n; ++i) {
QAction* a = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(i));
@ -241,6 +244,7 @@ void KWinDesktopConfig::load()
// This method is called on reset(). So undo all changes.
undo();
if (QX11Info::isPlatformX11()) {
// get number of desktops
unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout };
NETRootInfo info(QX11Info::connection(), properties, 2);
@ -251,6 +255,10 @@ void KWinDesktopConfig::load()
m_ui->desktopNames->setName(i, name);
}
m_ui->rowsSpinBox->setValue(info.desktopLayoutColumnsRows().height());
} else {
// TODO: proper implementation
m_ui->rowsSpinBox->setValue(1);
}
// Popup info
KConfigGroup effectconfig(m_config, "Plugins");
@ -289,6 +297,17 @@ void KWinDesktopConfig::load()
void KWinDesktopConfig::save()
{
// TODO: plasma stuff
const int numberDesktops = m_ui->numberSpinBox->value();
int rows = m_ui->rowsSpinBox->value();
rows = qBound(1, rows, numberDesktops);
// avoid weird cases like having 3 rows for 4 desktops, where the last row is unused
int columns = numberDesktops / rows;
if (numberDesktops % rows > 0) {
columns++;
}
if (QX11Info::isPlatformX11()) {
unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout };
NETRootInfo info(QX11Info::connection(), properties, 2);
// set desktop names
@ -300,20 +319,13 @@ void KWinDesktopConfig::save()
info.activate();
}
// set number of desktops
const int numberDesktops = m_ui->numberSpinBox->value();
info.setNumberOfDesktops(numberDesktops);
info.activate();
int rows =m_ui->rowsSpinBox->value();
rows = qBound(1, rows, numberDesktops);
// avoid weird cases like having 3 rows for 4 desktops, where the last row is unused
int columns = numberDesktops / rows;
if (numberDesktops % rows > 0) {
columns++;
}
info.setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft);
info.activate();
XSync(QX11Info::display(), false);
}
// save the desktops
QString groupname;