2007-07-19 16:20:05 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
#include "advanced.h"
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <ksettings/dispatcher.h>
|
2007-09-18 10:09:07 +00:00
|
|
|
#include <kpluginselector.h>
|
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
#include <kplugininfo.h>
|
|
|
|
#include <kservice.h>
|
2007-07-19 16:20:05 +00:00
|
|
|
|
|
|
|
#include <QtDBus/QtDBus>
|
2007-09-18 19:00:23 +00:00
|
|
|
#include <QTimer>
|
2007-09-18 19:38:57 +00:00
|
|
|
#include <QLabel>
|
2007-08-28 13:01:13 +00:00
|
|
|
#include <KPluginFactory>
|
|
|
|
#include <KPluginLoader>
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2007-08-28 13:01:13 +00:00
|
|
|
K_PLUGIN_FACTORY(KWinCompositingConfigFactory,
|
|
|
|
registerPlugin<KWin::KWinCompositingConfig>();
|
|
|
|
)
|
|
|
|
K_EXPORT_PLUGIN(KWinCompositingConfigFactory("kcmkwincompositing"))
|
2007-07-19 16:20:05 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2007-09-18 19:00:23 +00:00
|
|
|
ConfirmDialog::ConfirmDialog() :
|
2007-09-18 19:38:57 +00:00
|
|
|
KDialog()
|
2007-09-18 19:00:23 +00:00
|
|
|
{
|
2007-09-18 19:38:57 +00:00
|
|
|
setCaption( i18n( "Compositing settings changed" ));
|
2007-09-18 19:47:54 +00:00
|
|
|
setButtons( KDialog::Yes | KDialog::No | KDialog::Cancel );
|
2007-09-18 19:38:57 +00:00
|
|
|
setDefaultButton(KDialog::No);
|
2007-09-18 19:51:54 +00:00
|
|
|
setButtonFocus(KDialog::No);
|
2007-09-18 19:47:54 +00:00
|
|
|
setEscapeButton(KDialog::Cancel);
|
2007-09-18 19:38:57 +00:00
|
|
|
|
|
|
|
mTextLabel = new QLabel(this);
|
|
|
|
setMainWidget(mTextLabel);
|
|
|
|
|
2007-09-18 19:00:23 +00:00
|
|
|
mSecondsToLive = 10+1;
|
|
|
|
advanceTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmDialog::advanceTimer()
|
|
|
|
{
|
|
|
|
mSecondsToLive--;
|
|
|
|
if(mSecondsToLive > 0)
|
|
|
|
{
|
|
|
|
QString text = i18n("Compositing settings have changed.\n"
|
|
|
|
"Do you want to keep the new settings?\n"
|
|
|
|
"They will be automatically reverted in %1 seconds", mSecondsToLive);
|
2007-09-18 19:38:57 +00:00
|
|
|
mTextLabel->setText(text);
|
2007-09-18 19:00:23 +00:00
|
|
|
QTimer::singleShot(1000, this, SLOT(advanceTimer()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-18 19:38:57 +00:00
|
|
|
slotButtonClicked(KDialog::No);
|
2007-09-18 19:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-28 13:01:13 +00:00
|
|
|
KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList &)
|
2007-07-19 16:20:05 +00:00
|
|
|
: KCModule( KWinCompositingConfigFactory::componentData(), parent),
|
|
|
|
mKWinConfig(KSharedConfig::openConfig("kwinrc"))
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2007-09-18 10:09:07 +00:00
|
|
|
ui.tabWidget->setCurrentIndex(0);
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2007-09-18 14:32:37 +00:00
|
|
|
// Driver-specific config detection
|
|
|
|
mDefaultPrefs.detect();
|
|
|
|
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
connect(ui.advancedOptions, SIGNAL(clicked()), this, SLOT(showAdvancedOptions()));
|
2007-09-18 10:09:07 +00:00
|
|
|
connect(ui.useCompositing, SIGNAL(toggled(bool)), this, SLOT(compositingEnabled(bool)));
|
2007-07-19 16:20:05 +00:00
|
|
|
|
|
|
|
connect(ui.useCompositing, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
2007-07-21 20:54:50 +00:00
|
|
|
connect(ui.effectWinManagement, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
|
|
|
connect(ui.effectShadows, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
|
|
|
connect(ui.effectAnimations, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2007-09-18 10:09:07 +00:00
|
|
|
connect(ui.effectSelector, SIGNAL(changed(bool)), this, SLOT(changed()));
|
|
|
|
connect(ui.effectSelector, SIGNAL(configCommitted(const QByteArray&)),
|
|
|
|
this, SLOT(reparseConfiguration(const QByteArray&)));
|
|
|
|
|
|
|
|
initEffectSelector();
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
// Load config
|
|
|
|
load();
|
|
|
|
|
|
|
|
KAboutData *about = new KAboutData(I18N_NOOP("kcmkwincompositing"), 0,
|
2007-07-20 16:19:09 +00:00
|
|
|
ki18n("KWin Desktop Effects Configuration Module"),
|
2007-07-19 16:20:05 +00:00
|
|
|
0, KLocalizedString(), KAboutData::License_GPL, ki18n("(c) 2007 Rivo Laks"));
|
|
|
|
about->addAuthor(ki18n("Rivo Laks"), KLocalizedString(), "rivolaks@hot.ee");
|
|
|
|
setAboutData(about);
|
|
|
|
}
|
|
|
|
|
|
|
|
KWinCompositingConfig::~KWinCompositingConfig()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinCompositingConfig::reparseConfiguration(const QByteArray&conf)
|
|
|
|
{
|
2007-09-18 10:09:07 +00:00
|
|
|
KSettings::Dispatcher::reparseConfiguration(conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinCompositingConfig::compositingEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
ui.compositingOptionsContainer->setEnabled(enabled);
|
|
|
|
ui.tabWidget->setTabEnabled(1, enabled);
|
2007-07-19 16:20:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
void KWinCompositingConfig::showAdvancedOptions()
|
|
|
|
{
|
2007-09-18 14:32:37 +00:00
|
|
|
KWinAdvancedCompositingOptions* dialog = new KWinAdvancedCompositingOptions(this, mKWinConfig, &mDefaultPrefs);
|
2007-07-20 16:19:09 +00:00
|
|
|
|
|
|
|
dialog->show();
|
|
|
|
connect(dialog, SIGNAL(configSaved()), this, SLOT(configChanged()));
|
|
|
|
}
|
|
|
|
|
2007-09-18 19:00:23 +00:00
|
|
|
void KWinCompositingConfig::showConfirmDialog()
|
|
|
|
{
|
|
|
|
ConfirmDialog confirm;
|
|
|
|
int result = confirm.exec();
|
|
|
|
kDebug() << "result:" << result;
|
2007-09-18 19:38:57 +00:00
|
|
|
if(result != KDialog::Yes)
|
2007-09-18 19:00:23 +00:00
|
|
|
{
|
|
|
|
// Revert settings
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
|
|
|
config.deleteGroup();
|
|
|
|
QMap<QString, QString>::const_iterator i = mPreviousConfig.constBegin();
|
|
|
|
while (i != mPreviousConfig.constEnd()) {
|
|
|
|
config.writeEntry(i.key(), i.value());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
config.sync();
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 10:09:07 +00:00
|
|
|
void KWinCompositingConfig::initEffectSelector()
|
|
|
|
{
|
|
|
|
// Find all .desktop files of the effects
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("KWin/Effect");
|
|
|
|
QList<KPluginInfo> effectinfos = KPluginInfo::fromServices(offers);
|
|
|
|
|
|
|
|
// Add them to the plugin selector
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Appearance"), "Appearance", mKWinConfig);
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Accessibility"), "Accessibility", mKWinConfig);
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Window Management"), "Window Management", mKWinConfig);
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Demos"), "Demos", mKWinConfig);
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Tests"), "Tests", mKWinConfig);
|
|
|
|
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Misc"), "Misc", mKWinConfig);
|
|
|
|
}
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
void KWinCompositingConfig::load()
|
|
|
|
{
|
2007-08-20 21:33:48 +00:00
|
|
|
kDebug() ;
|
2007-07-19 16:20:05 +00:00
|
|
|
mKWinConfig->reparseConfiguration();
|
|
|
|
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
2007-09-18 14:32:37 +00:00
|
|
|
ui.useCompositing->setChecked(config.readEntry("Enabled", mDefaultPrefs.enableCompositing()));
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2007-07-21 20:54:50 +00:00
|
|
|
// Load effect settings
|
|
|
|
config.changeGroup("Plugins");
|
|
|
|
#define LOAD_EFFECT_CONFIG(effectname) config.readEntry("kwin4_effect_" effectname "Enabled", true)
|
|
|
|
bool winManagementEnabled = LOAD_EFFECT_CONFIG("presentwindows");
|
|
|
|
winManagementEnabled &= LOAD_EFFECT_CONFIG("boxswitch");
|
|
|
|
winManagementEnabled &= LOAD_EFFECT_CONFIG("desktopgrid");
|
|
|
|
winManagementEnabled &= LOAD_EFFECT_CONFIG("dialogparent");
|
|
|
|
ui.effectWinManagement->setChecked(winManagementEnabled);
|
|
|
|
ui.effectShadows->setChecked(LOAD_EFFECT_CONFIG("shadow"));
|
|
|
|
ui.effectAnimations->setChecked(LOAD_EFFECT_CONFIG("minimizeanimation"));
|
|
|
|
|
2007-09-18 10:09:07 +00:00
|
|
|
ui.effectSelector->load();
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
emit changed( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinCompositingConfig::save()
|
|
|
|
{
|
2007-08-20 21:33:48 +00:00
|
|
|
kDebug() ;
|
2007-07-19 16:20:05 +00:00
|
|
|
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
2007-09-18 19:00:23 +00:00
|
|
|
// Save current config. We'll use this for restoring in case something
|
|
|
|
// goes wrong.
|
|
|
|
mPreviousConfig = config.entryMap();
|
|
|
|
// Check if any critical settings that need confirmation have changed
|
|
|
|
bool confirm = false;
|
|
|
|
confirm |= (ui.useCompositing->isChecked() != config.readEntry("Enabled", mDefaultPrefs.enableCompositing()));
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
config.writeEntry("Enabled", ui.useCompositing->isChecked());
|
|
|
|
|
2007-07-21 20:54:50 +00:00
|
|
|
// Save effects
|
|
|
|
config.changeGroup("Plugins");
|
|
|
|
#define WRITE_EFFECT_CONFIG(effectname, widget) config.writeEntry("kwin4_effect_" effectname "Enabled", widget->isChecked())
|
|
|
|
WRITE_EFFECT_CONFIG("presentwindows", ui.effectWinManagement);
|
|
|
|
WRITE_EFFECT_CONFIG("boxswitch", ui.effectWinManagement);
|
|
|
|
WRITE_EFFECT_CONFIG("desktopgrid", ui.effectWinManagement);
|
|
|
|
WRITE_EFFECT_CONFIG("dialogparent", ui.effectWinManagement);
|
|
|
|
WRITE_EFFECT_CONFIG("shadow", ui.effectShadows);
|
|
|
|
// TODO: maybe also do some effect-specific configuration here, e.g.
|
|
|
|
// enable/disable desktopgrid's animation according to this setting
|
|
|
|
WRITE_EFFECT_CONFIG("minimizeanimation", ui.effectAnimations);
|
|
|
|
#undef WRITE_EFFECT_CONFIG
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2007-09-18 10:09:07 +00:00
|
|
|
ui.effectSelector->save();
|
|
|
|
|
2007-07-19 16:20:05 +00:00
|
|
|
emit changed( false );
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
configChanged();
|
2007-09-18 19:00:23 +00:00
|
|
|
|
|
|
|
if(confirm)
|
|
|
|
{
|
|
|
|
showConfirmDialog();
|
|
|
|
}
|
2007-07-20 16:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinCompositingConfig::configChanged()
|
|
|
|
{
|
2007-07-19 16:20:05 +00:00
|
|
|
// Send signal to kwin
|
|
|
|
mKWinConfig->sync();
|
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinCompositingConfig::defaults()
|
|
|
|
{
|
2007-08-20 21:33:48 +00:00
|
|
|
kDebug() ;
|
2007-09-18 14:32:37 +00:00
|
|
|
ui.useCompositing->setChecked(mDefaultPrefs.enableCompositing());
|
2007-07-21 20:54:50 +00:00
|
|
|
ui.effectWinManagement->setChecked(true);
|
|
|
|
ui.effectShadows->setChecked(true);
|
|
|
|
ui.effectAnimations->setChecked(true);
|
2007-09-18 10:09:07 +00:00
|
|
|
|
|
|
|
ui.effectSelector->defaults();
|
2007-07-19 16:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KWinCompositingConfig::quickHelp() const
|
|
|
|
{
|
2007-08-20 21:33:48 +00:00
|
|
|
kDebug() ;
|
2007-07-21 20:54:50 +00:00
|
|
|
return i18n("<h1>Desktop Effects</h1>");
|
2007-07-19 16:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "main.moc"
|