2009-07-12 12:21:57 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusConnection>
|
2009-10-01 11:14:52 +00:00
|
|
|
#include <QDBusInterface>
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2013-09-27 11:43:15 +00:00
|
|
|
#include <KAboutData>
|
2009-07-12 12:21:57 +00:00
|
|
|
#include <KAboutApplicationDialog>
|
|
|
|
#include <KActionCollection>
|
|
|
|
#include <KAction>
|
|
|
|
#include <KCModuleProxy>
|
2013-09-27 11:43:15 +00:00
|
|
|
#include <KDialog>
|
2009-08-16 12:19:07 +00:00
|
|
|
#include <KGlobalAccel>
|
2009-07-12 12:21:57 +00:00
|
|
|
#include <KPluginInfo>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KService>
|
|
|
|
#include <KServiceTypeTrader>
|
|
|
|
#include <KShortcutsEditor>
|
|
|
|
|
|
|
|
#include <QX11Info>
|
2013-11-18 12:50:18 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <fixx11h.h>
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
#include <netwm.h>
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
K_PLUGIN_FACTORY(KWinDesktopConfigFactory, registerPlugin<KWin::KWinDesktopConfig>();)
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWinDesktopConfigForm::KWinDesktopConfigForm(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
KWinDesktopConfig::KWinDesktopConfig(QWidget* parent, const QVariantList& args)
|
2013-09-27 11:43:15 +00:00
|
|
|
: KCModule(KAboutData::pluginData(QStringLiteral("kcm_kwindesktop")), parent, args)
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_config(KSharedConfig::openConfig("kwinrc"))
|
|
|
|
, m_actionCollection(NULL)
|
|
|
|
, m_switchDesktopCollection(NULL)
|
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
init();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::init()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
m_ui = new KWinDesktopConfigForm(this);
|
2009-07-12 12:21:57 +00:00
|
|
|
// TODO: there has to be a way to add the shortcuts editor to the ui file
|
2011-01-30 14:34:42 +00:00
|
|
|
m_editor = new KShortcutsEditor(m_ui, KShortcutsEditor::GlobalAction);
|
|
|
|
m_ui->editorFrame->setLayout(new QVBoxLayout());
|
|
|
|
m_ui->editorFrame->layout()->setMargin(0);
|
|
|
|
m_ui->editorFrame->layout()->addWidget(m_editor);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->desktopNames->setDesktopConfig(this);
|
|
|
|
m_ui->desktopNames->setMaxDesktops(maxDesktops);
|
|
|
|
m_ui->desktopNames->numberChanged(defaultDesktops);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(m_ui);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setQuickHelp(i18n("<h1>Multiple Desktops</h1>In this module, you can configure how many virtual desktops you want and how these should be labeled."));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// Shortcut config. The shortcut belongs to the component "kwin"!
|
2013-09-27 11:43:15 +00:00
|
|
|
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
2011-01-30 14:34:42 +00:00
|
|
|
m_actionCollection->setConfigGroup("Desktop Switching");
|
|
|
|
m_actionCollection->setConfigGlobal(true);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2013-09-27 11:43:15 +00:00
|
|
|
m_switchDesktopCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
2011-01-30 14:34:42 +00:00
|
|
|
m_switchDesktopCollection->setConfigGroup("Desktop Switching");
|
|
|
|
m_switchDesktopCollection->setConfigGlobal(true);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// actions for switch desktop collection - other action is filled dynamically
|
2013-01-09 07:50:58 +00:00
|
|
|
addAction("Switch to Next Desktop", i18n("Switch to Next Desktop"));
|
|
|
|
addAction("Switch to Previous Desktop", i18n("Switch to Previous Desktop"));
|
|
|
|
addAction("Switch One Desktop to the Right", i18n("Switch One Desktop to the Right"));
|
|
|
|
addAction("Switch One Desktop to the Left", i18n("Switch One Desktop to the Left"));
|
|
|
|
addAction("Switch One Desktop Up", i18n("Switch One Desktop Up"));
|
|
|
|
addAction("Switch One Desktop Down", i18n("Switch One Desktop Down"));
|
|
|
|
addAction("Walk Through Desktops", i18n("Walk Through Desktops"));
|
|
|
|
addAction("Walk Through Desktops (Reverse)", i18n("Walk Through Desktops (Reverse)"));
|
|
|
|
addAction("Walk Through Desktop List", i18n("Walk Through Desktop List"));
|
|
|
|
addAction("Walk Through Desktop List (Reverse)", i18n("Walk Through Desktop List (Reverse)"));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_editor->addCollection(m_switchDesktopCollection, i18n("Desktop Switching"));
|
2009-09-09 23:44:06 +00:00
|
|
|
|
|
|
|
// get number of desktops
|
2013-11-18 12:50:18 +00:00
|
|
|
NETRootInfo info(QX11Info::connection(), NET::NumberOfDesktops | NET::DesktopNames);
|
2009-09-09 23:44:06 +00:00
|
|
|
int n = info.numberOfDesktops();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 1; i <= n; ++i) {
|
2013-09-27 11:43:15 +00:00
|
|
|
QAction* a = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(i));
|
2009-09-09 23:44:06 +00:00
|
|
|
a->setProperty("isConfigurationAction", true);
|
2011-01-30 14:34:42 +00:00
|
|
|
a->setText(i18n("Switch to Desktop %1", i));
|
2013-09-27 11:43:15 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-09 23:44:06 +00:00
|
|
|
|
|
|
|
// This should be after the "Switch to Desktop %1" loop. It HAS to be
|
|
|
|
// there after numberSpinBox is connected to slotChangeShortcuts. We would
|
|
|
|
// overwrite the users settings if not,
|
|
|
|
m_ui->numberSpinBox->setValue(n);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_editor->addCollection(m_actionCollection, i18n("Desktop Switching"));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// search the effect names
|
|
|
|
// TODO: way to recognize if a effect is not found
|
|
|
|
KServiceTypeTrader* trader = KServiceTypeTrader::self();
|
|
|
|
KService::List services;
|
|
|
|
QString slide;
|
|
|
|
QString cube;
|
|
|
|
QString fadedesktop;
|
|
|
|
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_slide'");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!services.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
slide = services.first()->name();
|
|
|
|
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_cubeslide'");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!services.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
cube = services.first()->name();
|
|
|
|
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_fadedesktop'");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!services.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
fadedesktop = services.first()->name();
|
|
|
|
|
|
|
|
m_ui->effectComboBox->addItem(i18n("No Animation"));
|
|
|
|
m_ui->effectComboBox->addItem(slide);
|
|
|
|
m_ui->effectComboBox->addItem(cube);
|
|
|
|
m_ui->effectComboBox->addItem(fadedesktop);
|
|
|
|
|
|
|
|
// effect config and info button
|
2013-09-27 11:43:15 +00:00
|
|
|
m_ui->effectInfoButton->setIcon(QIcon::fromTheme("dialog-information"));
|
|
|
|
m_ui->effectConfigButton->setIcon(QIcon::fromTheme("configure"));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
connect(m_ui->rowsSpinBox, SIGNAL(valueChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->numberSpinBox, SIGNAL(valueChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->numberSpinBox, SIGNAL(valueChanged(int)), SLOT(slotChangeShortcuts(int)));
|
|
|
|
connect(m_ui->activityCheckBox, SIGNAL(stateChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->desktopNames, SIGNAL(changed()), SLOT(changed()));
|
|
|
|
connect(m_ui->popupInfoCheckBox, SIGNAL(toggled(bool)), SLOT(changed()));
|
|
|
|
connect(m_ui->popupHideSpinBox, SIGNAL(valueChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->desktopLayoutIndicatorCheckBox, SIGNAL(stateChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->wrapAroundBox, SIGNAL(stateChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_editor, SIGNAL(keyChange()), SLOT(changed()));
|
|
|
|
connect(m_ui->allShortcutsCheckBox, SIGNAL(stateChanged(int)), SLOT(slotShowAllShortcuts()));
|
|
|
|
connect(m_ui->effectComboBox, SIGNAL(currentIndexChanged(int)), SLOT(changed()));
|
|
|
|
connect(m_ui->effectComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotEffectSelectionChanged(int)));
|
|
|
|
connect(m_ui->effectInfoButton, SIGNAL(clicked()), SLOT(slotAboutEffectClicked()));
|
|
|
|
connect(m_ui->effectConfigButton, SIGNAL(clicked()), SLOT(slotConfigureEffectClicked()));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// Begin check for immutable - taken from old desktops kcm
|
2013-11-18 12:50:18 +00:00
|
|
|
int kwin_screen_number = QX11Info::appScreen();
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_config = KSharedConfig::openConfig("kwinrc");
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
QByteArray groupname;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (kwin_screen_number == 0)
|
2009-07-12 12:21:57 +00:00
|
|
|
groupname = "Desktops";
|
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
groupname = "Desktops-screen-" + QByteArray::number(kwin_screen_number);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_config->isGroupImmutable(groupname)) {
|
2009-07-12 12:21:57 +00:00
|
|
|
m_ui->nameGroup->setEnabled(false);
|
|
|
|
//number of desktops widgets
|
|
|
|
m_ui->numberLabel->setEnabled(false);
|
|
|
|
m_ui->numberSpinBox->setEnabled(false);
|
2011-07-24 12:59:39 +00:00
|
|
|
m_ui->rowsSpinBox->setEnabled(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-12 12:21:57 +00:00
|
|
|
KConfigGroup cfgGroup(m_config.data(), groupname.constData());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (cfgGroup.isEntryImmutable("Number")) {
|
2009-07-12 12:21:57 +00:00
|
|
|
//number of desktops widgets
|
|
|
|
m_ui->numberLabel->setEnabled(false);
|
|
|
|
m_ui->numberSpinBox->setEnabled(false);
|
2011-07-24 12:59:39 +00:00
|
|
|
m_ui->rowsSpinBox->setEnabled(false);
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
// End check for immutable
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
KWinDesktopConfig::~KWinDesktopConfig()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-09 23:44:08 +00:00
|
|
|
undo();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2013-01-09 07:50:58 +00:00
|
|
|
void KWinDesktopConfig::addAction(const QString &name, const QString &label)
|
|
|
|
{
|
2013-09-27 11:43:15 +00:00
|
|
|
QAction* a = m_switchDesktopCollection->addAction(name);
|
2013-01-09 07:50:58 +00:00
|
|
|
a->setProperty("isConfigurationAction", true);
|
|
|
|
a->setText(label);
|
2013-09-27 11:43:15 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
|
2013-01-09 07:50:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
void KWinDesktopConfig::defaults()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
// TODO: plasma stuff
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->numberSpinBox->setValue(defaultDesktops);
|
|
|
|
m_ui->desktopNames->numberChanged(defaultDesktops);
|
|
|
|
for (int i = 1; i <= maxDesktops; i++) {
|
|
|
|
m_desktopNames[i-1] = i18n("Desktop %1", i);
|
|
|
|
if (i <= defaultDesktops)
|
|
|
|
m_ui->desktopNames->setDefaultName(i);
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// popup info
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->popupInfoCheckBox->setChecked(false);
|
|
|
|
m_ui->popupHideSpinBox->setValue(1000);
|
|
|
|
m_ui->desktopLayoutIndicatorCheckBox->setChecked(true);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->effectComboBox->setCurrentIndex(1);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->wrapAroundBox->setChecked(true);
|
2009-11-08 12:18:59 +00:00
|
|
|
|
2011-07-24 12:59:39 +00:00
|
|
|
m_ui->rowsSpinBox->setValue(2);
|
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
m_editor->allDefault();
|
|
|
|
|
|
|
|
emit changed(true);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2009-09-09 23:44:06 +00:00
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
void KWinDesktopConfig::load()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-09 23:44:08 +00:00
|
|
|
// This method is called on reset(). So undo all changes.
|
|
|
|
undo();
|
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
// get number of desktops
|
2011-07-24 12:59:39 +00:00
|
|
|
unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout };
|
2013-11-18 12:50:18 +00:00
|
|
|
NETRootInfo info(QX11Info::connection(), properties, 2);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 1; i <= maxDesktops; i++) {
|
|
|
|
QString name = QString::fromUtf8(info.desktopName(i));
|
2009-07-12 12:21:57 +00:00
|
|
|
m_desktopNames << name;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->desktopNames->setName(i, name);
|
|
|
|
}
|
2011-07-24 12:59:39 +00:00
|
|
|
m_ui->rowsSpinBox->setValue(info.desktopLayoutColumnsRows().height());
|
2009-09-09 23:44:06 +00:00
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
// Popup info
|
2012-02-25 11:06:30 +00:00
|
|
|
KConfigGroup effectconfig(m_config, "Plugins");
|
|
|
|
KConfigGroup popupInfo(m_config, "Script-desktopchangeosd");
|
|
|
|
m_ui->popupInfoCheckBox->setChecked(effectconfig.readEntry("desktopchangeosdEnabled", false));
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->popupHideSpinBox->setValue(popupInfo.readEntry("PopupHideDelay", 1000));
|
|
|
|
m_ui->desktopLayoutIndicatorCheckBox->setChecked(!popupInfo.readEntry("TextOnly", false));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2009-11-08 12:18:59 +00:00
|
|
|
// Wrap Around on screen edge
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup windowConfig(m_config, "Windows");
|
|
|
|
m_ui->wrapAroundBox->setChecked(windowConfig.readEntry<bool>("RollOverDesktops", true));
|
2009-11-08 12:18:59 +00:00
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
// Effect for desktop switching
|
|
|
|
// Set current option to "none" if no plugin is activated.
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->effectComboBox->setCurrentIndex(0);
|
|
|
|
if (effectEnabled("slide", effectconfig))
|
|
|
|
m_ui->effectComboBox->setCurrentIndex(1);
|
|
|
|
if (effectEnabled("cubeslide", effectconfig))
|
|
|
|
m_ui->effectComboBox->setCurrentIndex(2);
|
|
|
|
if (effectEnabled("fadedesktop", effectconfig))
|
|
|
|
m_ui->effectComboBox->setCurrentIndex(3);
|
|
|
|
slotEffectSelectionChanged(m_ui->effectComboBox->currentIndex());
|
2009-07-12 12:21:57 +00:00
|
|
|
// TODO: plasma stuff
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QDBusInterface interface("org.kde.plasma-desktop", "/App");
|
|
|
|
if (interface.isValid()) {
|
|
|
|
bool perVirtualDesktopViews = interface.call("perVirtualDesktopViews").arguments().first().toBool();
|
|
|
|
m_ui->activityCheckBox->setEnabled(true);
|
|
|
|
m_ui->activityCheckBox->setChecked(perVirtualDesktopViews);
|
|
|
|
} else
|
|
|
|
m_ui->activityCheckBox->setEnabled(false);
|
2009-10-01 11:14:52 +00:00
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
emit changed(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::save()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
// TODO: plasma stuff
|
2011-07-24 12:59:39 +00:00
|
|
|
unsigned long properties[] = {NET::NumberOfDesktops | NET::DesktopNames, NET::WM2DesktopLayout };
|
2013-11-18 12:50:18 +00:00
|
|
|
NETRootInfo info(QX11Info::connection(), properties, 2);
|
2009-07-12 12:21:57 +00:00
|
|
|
// set desktop names
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 1; i <= maxDesktops; i++) {
|
2009-07-12 12:21:57 +00:00
|
|
|
QString desktopName = m_desktopNames[ i -1 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (i <= m_ui->numberSpinBox->value())
|
|
|
|
desktopName = m_ui->desktopNames->name(i);
|
|
|
|
info.setDesktopName(i, desktopName.toUtf8());
|
2009-07-12 12:21:57 +00:00
|
|
|
info.activate();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
// set number of desktops
|
2011-07-24 12:59:39 +00:00
|
|
|
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);
|
2009-07-12 12:21:57 +00:00
|
|
|
info.activate();
|
|
|
|
|
|
|
|
XSync(QX11Info::display(), false);
|
2011-07-24 12:59:39 +00:00
|
|
|
|
|
|
|
// save the desktops
|
|
|
|
QString groupname;
|
2013-11-18 12:50:18 +00:00
|
|
|
const int screenNumber = QX11Info::appScreen();
|
2011-07-24 12:59:39 +00:00
|
|
|
if (screenNumber == 0)
|
|
|
|
groupname = "Desktops";
|
|
|
|
else
|
|
|
|
groupname.sprintf("Desktops-screen-%d", screenNumber);
|
|
|
|
KConfigGroup group(m_config, groupname);
|
|
|
|
group.writeEntry("Rows", rows);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
// Popup info
|
2012-02-25 11:06:30 +00:00
|
|
|
KConfigGroup effectconfig(m_config, "Plugins");
|
|
|
|
KConfigGroup popupInfo(m_config, "Script-desktopchangeosd");
|
|
|
|
effectconfig.writeEntry("desktopchangeosdEnabled", m_ui->popupInfoCheckBox->isChecked());
|
2011-01-30 14:34:42 +00:00
|
|
|
popupInfo.writeEntry("PopupHideDelay", m_ui->popupHideSpinBox->value());
|
|
|
|
popupInfo.writeEntry("TextOnly", !m_ui->desktopLayoutIndicatorCheckBox->isChecked());
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2009-11-08 12:18:59 +00:00
|
|
|
// Wrap Around on screen edge
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup windowConfig(m_config, "Windows");
|
|
|
|
windowConfig.writeEntry("RollOverDesktops", m_ui->wrapAroundBox->isChecked());
|
2009-11-08 12:18:59 +00:00
|
|
|
|
2009-07-12 12:21:57 +00:00
|
|
|
// Effect desktop switching
|
|
|
|
int desktopSwitcher = m_ui->effectComboBox->currentIndex();
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(desktopSwitcher) {
|
|
|
|
case 0:
|
|
|
|
// no effect
|
|
|
|
effectconfig.writeEntry("kwin4_effect_slideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_cubeslideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_fadedesktopEnabled", false);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// slide
|
|
|
|
effectconfig.writeEntry("kwin4_effect_slideEnabled", true);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_cubeslideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_fadedesktopEnabled", false);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// cube
|
|
|
|
effectconfig.writeEntry("kwin4_effect_slideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_cubeslideEnabled", true);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_fadedesktopEnabled", false);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// fadedesktop
|
|
|
|
effectconfig.writeEntry("kwin4_effect_slideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_cubeslideEnabled", false);
|
|
|
|
effectconfig.writeEntry("kwin4_effect_fadedesktopEnabled", true);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
m_editor->save();
|
|
|
|
|
|
|
|
m_config->sync();
|
|
|
|
// Send signal to all kwin instances
|
2011-01-30 14:34:42 +00:00
|
|
|
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
2009-10-01 11:14:52 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QDBusInterface interface("org.kde.plasma-desktop", "/App");
|
|
|
|
interface.call("setPerVirtualDesktopViews", (m_ui->activityCheckBox->isChecked()));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
emit changed(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2009-09-09 23:44:08 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::undo()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-09 23:44:08 +00:00
|
|
|
// The global shortcuts editor makes changes active immediately. In case
|
|
|
|
// of undo we have to undo them manually
|
|
|
|
m_editor->undoChanges();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-09 23:44:08 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QString KWinDesktopConfig::cachedDesktopName(int desktop)
|
|
|
|
{
|
|
|
|
if (desktop > m_desktopNames.size())
|
2009-07-12 12:21:57 +00:00
|
|
|
return QString();
|
|
|
|
return m_desktopNames[ desktop -1 ];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QString KWinDesktopConfig::extrapolatedShortcut(int desktop) const
|
|
|
|
{
|
2009-08-16 12:19:07 +00:00
|
|
|
|
|
|
|
if (!desktop || desktop > m_actionCollection->count())
|
|
|
|
return QString();
|
|
|
|
if (desktop == 1)
|
|
|
|
return QString("Ctrl+F1");
|
|
|
|
|
2013-09-27 11:43:15 +00:00
|
|
|
QAction *beforeAction = m_actionCollection->actions().at(qMin(9, desktop - 2));
|
|
|
|
auto shortcuts = KGlobalAccel::self()->shortcut(beforeAction);
|
|
|
|
if (shortcuts.isEmpty()) {
|
|
|
|
shortcuts = KGlobalAccel::self()->defaultShortcut(beforeAction);
|
|
|
|
}
|
|
|
|
QString before;
|
|
|
|
if (!shortcuts.isEmpty()) {
|
|
|
|
before = shortcuts.first().toString(QKeySequence::NativeText);
|
|
|
|
}
|
2009-08-16 12:19:07 +00:00
|
|
|
|
|
|
|
QString seq;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (before.contains(QRegExp("F[0-9]{1,2}"))) {
|
|
|
|
if (desktop < 13) // 10?
|
2009-08-16 12:19:07 +00:00
|
|
|
seq = QString("F%1").arg(desktop);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (!before.contains("Shift"))
|
2009-08-16 12:19:07 +00:00
|
|
|
seq = "Shift+" + QString("F%1").arg(desktop - 10);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (before.contains(QRegExp("[0-9]"))) {
|
2009-08-16 12:19:07 +00:00
|
|
|
if (desktop == 10)
|
2009-10-30 06:51:59 +00:00
|
|
|
seq = '0';
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (desktop > 10) {
|
|
|
|
if (!before.contains("Shift"))
|
2009-08-16 12:19:07 +00:00
|
|
|
seq = "Shift+" + QString::number(desktop == 20 ? 0 : (desktop - 10));
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2009-08-16 12:19:07 +00:00
|
|
|
seq = QString::number(desktop);
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!seq.isEmpty()) {
|
2009-08-16 12:19:07 +00:00
|
|
|
if (before.contains("Ctrl"))
|
|
|
|
seq.prepend("Ctrl+");
|
|
|
|
if (before.contains("Alt"))
|
|
|
|
seq.prepend("Alt+");
|
|
|
|
if (before.contains("Shift"))
|
|
|
|
seq.prepend("Shift+");
|
|
|
|
if (before.contains("Meta"))
|
|
|
|
seq.prepend("Meta+");
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return seq;
|
|
|
|
}
|
2009-08-16 12:19:07 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KWinDesktopConfig::slotChangeShortcuts(int number)
|
|
|
|
{
|
|
|
|
if ((number < 1) || (number > maxDesktops))
|
2009-07-12 12:21:57 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_ui->allShortcutsCheckBox->isChecked())
|
2009-07-12 12:21:57 +00:00
|
|
|
number = maxDesktops;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
while (number != m_actionCollection->count()) {
|
|
|
|
if (number < m_actionCollection->count()) {
|
2009-09-10 00:24:45 +00:00
|
|
|
// Remove the action from the action collection. The action itself
|
|
|
|
// will still exist because that's the way kwin currently works.
|
|
|
|
// No need to remove/forget it. See kwinbindings.
|
2013-09-27 11:43:15 +00:00
|
|
|
QAction *a = m_actionCollection->takeAction(m_actionCollection->actions().last());
|
2009-09-10 00:24:45 +00:00
|
|
|
// Remove any associated global shortcut. Set it to ""
|
2013-09-27 11:43:15 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>(), KGlobalAccel::NoAutoloading);
|
2009-08-16 12:19:07 +00:00
|
|
|
m_ui->messageLabel->hide();
|
2009-09-10 00:24:45 +00:00
|
|
|
delete a;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-12 12:21:57 +00:00
|
|
|
// add desktop
|
|
|
|
int desktop = m_actionCollection->count() + 1;
|
2013-09-27 11:43:15 +00:00
|
|
|
QAction* action = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(desktop));
|
2009-09-09 23:43:58 +00:00
|
|
|
action->setProperty("isConfigurationAction", true);
|
2011-01-30 14:34:42 +00:00
|
|
|
action->setText(i18n("Switch to Desktop %1", desktop));
|
2013-09-27 11:43:15 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(action, QList<QKeySequence>());
|
2009-08-16 12:19:07 +00:00
|
|
|
QString shortcutString = extrapolatedShortcut(desktop);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (shortcutString.isEmpty()) {
|
|
|
|
m_ui->messageLabel->setText(i18n("No suitable Shortcut for Desktop %1 found", desktop));
|
2009-08-16 12:19:07 +00:00
|
|
|
m_ui->messageLabel->show();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2013-09-27 11:43:15 +00:00
|
|
|
QKeySequence shortcut(shortcutString);
|
|
|
|
if (!shortcut.isEmpty() || KGlobalAccel::self()->isGlobalShortcutAvailable(shortcut)) {
|
|
|
|
KGlobalAccel::self()->setShortcut(action, QList<QKeySequence>(), KGlobalAccel::NoAutoloading);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->messageLabel->setText(i18n("Assigned global Shortcut \"%1\" to Desktop %2", shortcutString, desktop));
|
2009-09-10 00:24:41 +00:00
|
|
|
m_ui->messageLabel->show();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
m_ui->messageLabel->setText(i18n("Shortcut conflict: Could not set Shortcut %1 for Desktop %2", shortcutString, desktop));
|
2009-09-10 00:24:41 +00:00
|
|
|
m_ui->messageLabel->show();
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_editor->clearCollections();
|
|
|
|
m_editor->addCollection(m_switchDesktopCollection, i18n("Desktop Switching"));
|
|
|
|
m_editor->addCollection(m_actionCollection, i18n("Desktop Switching"));
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::slotShowAllShortcuts()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
slotChangeShortcuts(m_ui->numberSpinBox->value());
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KWinDesktopConfig::slotEffectSelectionChanged(int index)
|
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
bool enabled = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index != 0)
|
2009-07-12 12:21:57 +00:00
|
|
|
enabled = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->effectInfoButton->setEnabled(enabled);
|
2009-07-12 12:21:57 +00:00
|
|
|
// only cube has config dialog
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index != 2)
|
2009-07-12 12:21:57 +00:00
|
|
|
enabled = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui->effectConfigButton->setEnabled(enabled);
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool KWinDesktopConfig::effectEnabled(const QString& effect, const KConfigGroup& cfg) const
|
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
KService::List services = KServiceTypeTrader::self()->query(
|
2011-01-30 14:34:42 +00:00
|
|
|
"KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_" + effect + '\'');
|
|
|
|
if (services.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
return false;
|
|
|
|
QVariant v = services.first()->property("X-KDE-PluginInfo-EnabledByDefault");
|
|
|
|
return cfg.readEntry("kwin4_effect_" + effect + "Enabled", v.toBool());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::slotAboutEffectClicked()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
KServiceTypeTrader* trader = KServiceTypeTrader::self();
|
|
|
|
KService::List services;
|
|
|
|
QString effect;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_ui->effectComboBox->currentIndex()) {
|
|
|
|
case 1:
|
|
|
|
effect = "slide";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
effect = "cubeslide";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
effect = "fadedesktop";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-10-30 06:51:59 +00:00
|
|
|
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_" + effect + '\'');
|
2011-01-30 14:34:42 +00:00
|
|
|
if (services.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
KPluginInfo pluginInfo(services.first());
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
const QString name = pluginInfo.name();
|
|
|
|
const QString comment = pluginInfo.comment();
|
|
|
|
const QString author = pluginInfo.author();
|
|
|
|
const QString email = pluginInfo.email();
|
|
|
|
const QString website = pluginInfo.website();
|
|
|
|
const QString version = pluginInfo.version();
|
|
|
|
const QString license = pluginInfo.license();
|
|
|
|
const QString icon = pluginInfo.icon();
|
|
|
|
|
2013-09-27 11:43:15 +00:00
|
|
|
KAboutData aboutData(name, name, name, version, comment, KAboutLicense::byKeyword(license).key(), QString(), QString(), website.toLatin1());
|
2011-01-30 14:34:42 +00:00
|
|
|
aboutData.setProgramIconName(icon);
|
2009-07-12 12:21:57 +00:00
|
|
|
const QStringList authors = author.split(',');
|
|
|
|
const QStringList emails = email.split(',');
|
|
|
|
int i = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (authors.count() == emails.count()) {
|
|
|
|
foreach (const QString & author, authors) {
|
|
|
|
if (!author.isEmpty()) {
|
2013-09-27 11:43:15 +00:00
|
|
|
aboutData.addAuthor(i18n(author.toUtf8()), QString(), emails[i]);
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
i++;
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2013-09-27 11:43:15 +00:00
|
|
|
QPointer<KAboutApplicationDialog> aboutPlugin = new KAboutApplicationDialog(aboutData, this);
|
2009-12-17 21:04:32 +00:00
|
|
|
aboutPlugin->exec();
|
|
|
|
delete aboutPlugin;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
void KWinDesktopConfig::slotConfigureEffectClicked()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
QString effect;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_ui->effectComboBox->currentIndex()) {
|
|
|
|
case 2:
|
|
|
|
effect = "cubeslide_config";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KCModuleProxy* proxy = new KCModuleProxy(effect);
|
|
|
|
QPointer< KDialog > configDialog = new KDialog(this);
|
|
|
|
configDialog->setWindowTitle(m_ui->effectComboBox->currentText());
|
|
|
|
configDialog->setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default);
|
2009-12-17 21:04:32 +00:00
|
|
|
connect(configDialog, SIGNAL(defaultClicked()), proxy, SLOT(defaults()));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QWidget *showWidget = new QWidget(configDialog);
|
2009-07-12 12:21:57 +00:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
2011-01-30 14:34:42 +00:00
|
|
|
showWidget->setLayout(layout);
|
|
|
|
layout->addWidget(proxy);
|
|
|
|
layout->insertSpacing(-1, KDialog::marginHint());
|
|
|
|
configDialog->setMainWidget(showWidget);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (configDialog->exec() == QDialog::Accepted) {
|
2009-07-12 12:21:57 +00:00
|
|
|
proxy->save();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-12 12:21:57 +00:00
|
|
|
proxy->load();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
delete configDialog;
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "main.moc"
|