2014-11-15 03:14:34 +02:00
|
|
|
/***************************************************************************
|
|
|
|
componentchooserwm.cpp - description
|
|
|
|
-------------------
|
|
|
|
copyright : (C) 2002 by Joseph Wenninger
|
|
|
|
email : jowenn@kde.org
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License verstion 2 as *
|
|
|
|
* published by the Free Software Foundation *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "componentchooserwm.h"
|
2015-02-27 09:28:46 +00:00
|
|
|
#include "moc_componentchooserwm.cpp"
|
2014-11-15 03:14:34 +02:00
|
|
|
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <kstandarddirs.h>
|
2024-05-12 13:55:58 +03:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdebug.h>
|
2022-12-10 15:11:46 +02:00
|
|
|
#include <qfileinfo.h>
|
2024-05-12 13:55:58 +03:00
|
|
|
#include <qprocess.h>
|
2014-11-15 03:14:34 +02:00
|
|
|
#include <netwm.h>
|
2022-12-11 04:37:49 +02:00
|
|
|
|
2014-11-15 03:14:34 +02:00
|
|
|
CfgWm::CfgWm(QWidget *parent)
|
2022-12-10 14:26:38 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, Ui::WmConfig_UI()
|
|
|
|
, CfgPlugin()
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
connect(wmCombo,SIGNAL(activated(int)), this, SLOT(configChanged()));
|
|
|
|
connect(kwinRB,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
|
|
|
|
connect(differentRB,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
|
|
|
|
connect(differentRB,SIGNAL(toggled(bool)),this,SLOT(checkConfigureWm()));
|
|
|
|
connect(wmCombo,SIGNAL(activated(int)),this,SLOT(checkConfigureWm()));
|
|
|
|
connect(configureButton,SIGNAL(clicked()),this,SLOT(configureWm()));
|
|
|
|
|
2024-05-07 02:08:57 +03:00
|
|
|
KGlobal::dirs()->addResourceType("windowmanagers", "data", "plasma/windowmanagers");
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CfgWm::~CfgWm()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CfgWm::configChanged()
|
|
|
|
{
|
|
|
|
emit changed(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CfgWm::defaults()
|
|
|
|
{
|
|
|
|
wmCombo->setCurrentIndex( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CfgWm::load(KConfig *)
|
|
|
|
{
|
2024-05-07 02:08:57 +03:00
|
|
|
KConfig cfg("plasmarc", KConfig::NoGlobals);
|
2014-11-15 03:14:34 +02:00
|
|
|
KConfigGroup c( &cfg, "General");
|
|
|
|
loadWMs(c.readEntry("windowManager", "kwin"));
|
|
|
|
emit changed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CfgWm::save(KConfig *)
|
|
|
|
{
|
|
|
|
saveAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CfgWm::saveAndConfirm()
|
|
|
|
{
|
2024-05-07 02:08:57 +03:00
|
|
|
KConfig cfg("plasmarc", KConfig::NoGlobals);
|
2014-11-15 03:14:34 +02:00
|
|
|
KConfigGroup c( &cfg, "General");
|
|
|
|
c.writeEntry("windowManager", currentWm());
|
|
|
|
emit changed(false);
|
2022-12-10 14:26:38 +02:00
|
|
|
if (oldwm == currentWm()) {
|
2014-11-15 03:14:34 +02:00
|
|
|
return true;
|
2022-12-10 14:26:38 +02:00
|
|
|
}
|
2024-05-12 13:55:58 +03:00
|
|
|
oldwm = currentWm();
|
|
|
|
cfg.sync();
|
2022-12-10 14:26:38 +02:00
|
|
|
KMessageBox::information(
|
|
|
|
window(),
|
2024-05-12 13:55:58 +03:00
|
|
|
i18n(
|
|
|
|
"The change will take effect on the next KDE session."
|
|
|
|
),
|
|
|
|
i18n("Window Manager Changed"),
|
|
|
|
"restartafterwmchange"
|
2022-12-10 14:26:38 +02:00
|
|
|
);
|
2024-05-12 13:55:58 +03:00
|
|
|
return true;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2022-12-10 15:11:46 +02:00
|
|
|
void CfgWm::loadWMs(const QString ¤t)
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
|
|
|
WmData kwin;
|
|
|
|
kwin.internalName = "kwin";
|
|
|
|
kwin.exec = "kwin";
|
|
|
|
kwin.configureCommand = "";
|
|
|
|
kwin.parentArgument = "";
|
2022-12-10 15:11:46 +02:00
|
|
|
wms["KWin"] = kwin;
|
2014-11-15 03:14:34 +02:00
|
|
|
oldwm = "kwin";
|
2022-12-10 15:11:46 +02:00
|
|
|
kwinRB->setChecked(true);
|
|
|
|
wmCombo->setEnabled(false);
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2022-12-10 14:26:38 +02:00
|
|
|
QStringList list = KGlobal::dirs()->findAllResources("windowmanagers", QString(), KStandardDirs::NoDuplicates);
|
|
|
|
foreach (const QString& wmfile, list) {
|
2022-12-10 15:11:46 +02:00
|
|
|
KDesktopFile file(wmfile);
|
2022-12-10 14:26:38 +02:00
|
|
|
if (file.noDisplay())
|
2014-11-15 03:14:34 +02:00
|
|
|
continue;
|
2022-12-10 14:26:38 +02:00
|
|
|
if (!file.tryExec())
|
2014-11-15 03:14:34 +02:00
|
|
|
continue;
|
|
|
|
QString name = file.readName();
|
2022-12-10 14:26:38 +02:00
|
|
|
if (name.isEmpty())
|
2014-11-15 03:14:34 +02:00
|
|
|
continue;
|
2022-12-10 15:11:46 +02:00
|
|
|
QString wm = QFileInfo(file.name()).baseName();
|
2022-12-10 14:26:38 +02:00
|
|
|
if (wms.contains(name))
|
2014-11-15 03:14:34 +02:00
|
|
|
continue;
|
|
|
|
WmData data;
|
|
|
|
data.internalName = wm;
|
2022-12-10 15:11:46 +02:00
|
|
|
data.exec = file.desktopGroup().readEntry("Exec");
|
2022-12-10 14:26:38 +02:00
|
|
|
if (data.exec.isEmpty())
|
2014-11-15 03:14:34 +02:00
|
|
|
continue;
|
2022-12-10 14:26:38 +02:00
|
|
|
data.configureCommand = file.desktopGroup().readEntry("X-KDE-WindowManagerConfigure");
|
|
|
|
data.parentArgument = file.desktopGroup().readEntry("X-KDE-WindowManagerConfigureParentArgument");
|
|
|
|
wms[name] = data;
|
|
|
|
wmCombo->addItem(name);
|
2022-12-10 15:11:46 +02:00
|
|
|
if (wms[name].internalName == current) {
|
2022-12-10 14:26:38 +02:00
|
|
|
// make it selected
|
|
|
|
wmCombo->setCurrentIndex(wmCombo->count() - 1);
|
2014-11-15 03:14:34 +02:00
|
|
|
oldwm = wm;
|
2022-12-10 14:26:38 +02:00
|
|
|
differentRB->setChecked(true);
|
|
|
|
wmCombo->setEnabled(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-10 14:26:38 +02:00
|
|
|
differentRB->setEnabled(wmCombo->count() > 0);
|
2014-11-15 03:14:34 +02:00
|
|
|
checkConfigureWm();
|
|
|
|
}
|
|
|
|
|
|
|
|
CfgWm::WmData CfgWm::currentWmData() const
|
|
|
|
{
|
2022-12-10 14:26:38 +02:00
|
|
|
return kwinRB->isChecked() ? wms["KWin"] : wms[wmCombo->currentText()];
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CfgWm::currentWm() const
|
|
|
|
{
|
|
|
|
return currentWmData().internalName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CfgWm::checkConfigureWm()
|
|
|
|
{
|
2022-12-10 14:26:38 +02:00
|
|
|
configureButton->setEnabled(!currentWmData().configureCommand.isEmpty());
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CfgWm::configureWm()
|
|
|
|
{
|
2022-12-10 14:26:38 +02:00
|
|
|
if (oldwm != currentWm() && !saveAndConfirm()) {
|
|
|
|
// needs switching first
|
2014-11-15 03:14:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QStringList args;
|
2022-12-10 14:26:38 +02:00
|
|
|
if (!currentWmData().parentArgument.isEmpty()) {
|
|
|
|
args << currentWmData().parentArgument << QString::number(window()->winId());
|
|
|
|
}
|
|
|
|
if (!QProcess::startDetached(currentWmData().configureCommand, args)) {
|
|
|
|
KMessageBox::sorry(window(), i18n("Running the configuration tool failed"));
|
|
|
|
}
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|