From fb4d148f5316a93755e36c99e84131f7590919e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 24 Jul 2011 14:59:39 +0200 Subject: [PATCH] Move control of desktop layout from pager to KWin The desktop layout (number of rows) should be controlled by the window manager as it is also responsible for the number of desktops and the names of them. The setting for the rows is moved from the pager UI to the virtual desktops KCM. The desktop layout is set when KWin starts and updated by the KCM. With this change there is no process claiming the manager selection for pager any more. This means the KDE Plasma Workspaces are no longer compliant to the complete section of _NET_DESKTOP_LAYOUT in the EWMH. REVIEW: 102073 BUG: 277965 FEATURE: 105779 FEATURE: 213353 FIXED-IN: 4.8.0 --- kcmkwin/kwindesktop/main.cpp | 38 ++++++++++++++++++++++++++++-------- kcmkwin/kwindesktop/main.ui | 4 ++-- workspace.cpp | 10 ++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/kcmkwin/kwindesktop/main.cpp b/kcmkwin/kwindesktop/main.cpp index ee5c504554..21ff017ded 100644 --- a/kcmkwin/kwindesktop/main.cpp +++ b/kcmkwin/kwindesktop/main.cpp @@ -76,11 +76,6 @@ void KWinDesktopConfig::init() m_ui->desktopNames->setMaxDesktops(maxDesktops); m_ui->desktopNames->numberChanged(defaultDesktops); - // number of rows are still missing in Plasma - hide them for now - // TODO: bring them back when trunk is open and bug Plasma devs ;-) - m_ui->label->hide(); - m_ui->rowsSpinBox->hide(); - QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_ui); @@ -210,12 +205,14 @@ void KWinDesktopConfig::init() //number of desktops widgets m_ui->numberLabel->setEnabled(false); m_ui->numberSpinBox->setEnabled(false); + m_ui->rowsSpinBox->setEnabled(false); } else { KConfigGroup cfgGroup(m_config.data(), groupname.constData()); if (cfgGroup.isEntryImmutable("Number")) { //number of desktops widgets m_ui->numberLabel->setEnabled(false); m_ui->numberSpinBox->setEnabled(false); + m_ui->rowsSpinBox->setEnabled(false); } } // End check for immutable @@ -246,6 +243,8 @@ void KWinDesktopConfig::defaults() m_ui->wrapAroundBox->setChecked(true); + m_ui->rowsSpinBox->setValue(2); + m_editor->allDefault(); emit changed(true); @@ -259,13 +258,15 @@ void KWinDesktopConfig::load() #ifdef Q_WS_X11 // get number of desktops - NETRootInfo info(QX11Info::display(), NET::NumberOfDesktops | NET::DesktopNames); + unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; + NETRootInfo info(QX11Info::display(), 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); } + m_ui->rowsSpinBox->setValue(info.desktopLayoutColumnsRows().height()); #endif // Popup info @@ -306,7 +307,8 @@ void KWinDesktopConfig::save() { // TODO: plasma stuff #ifdef Q_WS_X11 - NETRootInfo info(QX11Info::display(), NET::NumberOfDesktops | NET::DesktopNames); + unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout }; + NETRootInfo info(QX11Info::display(), properties, 2); // set desktop names for (int i = 1; i <= maxDesktops; i++) { QString desktopName = m_desktopNames[ i -1 ]; @@ -316,10 +318,30 @@ void KWinDesktopConfig::save() info.activate(); } // set number of desktops - info.setNumberOfDesktops(m_ui->numberSpinBox->value()); + 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; + const int screenNumber = DefaultScreen(QX11Info::display()); + if (screenNumber == 0) + groupname = "Desktops"; + else + groupname.sprintf("Desktops-screen-%d", screenNumber); + KConfigGroup group(m_config, groupname); + group.writeEntry("Rows", rows); #endif // Popup info diff --git a/kcmkwin/kwindesktop/main.ui b/kcmkwin/kwindesktop/main.ui index e431d642e5..e8f71ede34 100644 --- a/kcmkwin/kwindesktop/main.ui +++ b/kcmkwin/kwindesktop/main.ui @@ -65,7 +65,7 @@ - false + true Number of rows: @@ -78,7 +78,7 @@ - false + true diff --git a/workspace.cpp b/workspace.cpp index 1d3c5ea88d..5cf293acae 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -1093,6 +1093,16 @@ void Workspace::loadDesktopSettings() rootInfo->setDesktopName(i, s.toUtf8().data()); desktop_focus_chain[i-1] = i; } + + int rows = group.readEntry("Rows", 2); + rows = qBound(1, rows, n); + // avoid weird cases like having 3 rows for 4 desktops, where the last row is unused + int columns = n / rows; + if (n % rows > 0) { + columns++; + } + rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft); + rootInfo->activate(); _loading_desktop_settings = false; }