From 3ea8f0c2174a02a2d69f9c9cbd3828987320299b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 11 Feb 2014 15:27:28 +0100 Subject: [PATCH] [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. --- kcmkwin/kwindesktop/main.cpp | 66 +++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/kcmkwin/kwindesktop/main.cpp b/kcmkwin/kwindesktop/main.cpp index 28902b2943..24cdf4b0b6 100644 --- a/kcmkwin/kwindesktop/main.cpp +++ b/kcmkwin/kwindesktop/main.cpp @@ -107,8 +107,11 @@ void KWinDesktopConfig::init() m_editor->addCollection(m_switchDesktopCollection, i18n("Desktop Switching")); // get number of desktops - NETRootInfo info(QX11Info::connection(), NET::NumberOfDesktops | NET::DesktopNames); - int n = info.numberOfDesktops(); + int n = 1; + if (QX11Info::isPlatformX11()) { + NETRootInfo info(QX11Info::connection(), NET::NumberOfDesktops | NET::DesktopNames); + n = info.numberOfDesktops(); + } for (int i = 1; i <= n; ++i) { QAction* a = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(i)); @@ -241,16 +244,21 @@ void KWinDesktopConfig::load() // This method is called on reset(). So undo all changes. undo(); - // get number of desktops - unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; - NETRootInfo info(QX11Info::connection(), properties, 2); + if (QX11Info::isPlatformX11()) { + // get number of desktops + unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; + NETRootInfo info(QX11Info::connection(), properties, 2); - for (int i = 1; i <= maxDesktops; i++) { - QString name = QString::fromUtf8(info.desktopName(i)); - m_desktopNames << name; - m_ui->desktopNames->setName(i, name); + for (int i = 1; i <= maxDesktops; i++) { + QString name = QString::fromUtf8(info.desktopName(i)); + m_desktopNames << name; + m_ui->desktopNames->setName(i, name); + } + m_ui->rowsSpinBox->setValue(info.desktopLayoutColumnsRows().height()); + } else { + // TODO: proper implementation + m_ui->rowsSpinBox->setValue(1); } - m_ui->rowsSpinBox->setValue(info.desktopLayoutColumnsRows().height()); // Popup info KConfigGroup effectconfig(m_config, "Plugins"); @@ -289,31 +297,35 @@ void KWinDesktopConfig::load() void KWinDesktopConfig::save() { // TODO: plasma stuff - unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; - NETRootInfo info(QX11Info::connection(), properties, 2); - // set desktop names - for (int i = 1; i <= maxDesktops; i++) { - QString desktopName = m_desktopNames[ i -1 ]; - if (i <= m_ui->numberSpinBox->value()) - desktopName = m_ui->desktopNames->name(i); - info.setDesktopName(i, desktopName.toUtf8()); - info.activate(); - } - // set number of desktops + const int numberDesktops = m_ui->numberSpinBox->value(); - info.setNumberOfDesktops(numberDesktops); - info.activate(); - int rows =m_ui->rowsSpinBox->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++; } - info.setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft); - info.activate(); - XSync(QX11Info::display(), false); + if (QX11Info::isPlatformX11()) { + unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; + NETRootInfo info(QX11Info::connection(), properties, 2); + // set desktop names + for (int i = 1; i <= maxDesktops; i++) { + QString desktopName = m_desktopNames[ i -1 ]; + if (i <= m_ui->numberSpinBox->value()) + desktopName = m_ui->desktopNames->name(i); + info.setDesktopName(i, desktopName.toUtf8()); + info.activate(); + } + // set number of desktops + info.setNumberOfDesktops(numberDesktops); + info.activate(); + info.setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft); + info.activate(); + + XSync(QX11Info::display(), false); + } // save the desktops QString groupname;