kwin/kcmkwin/kwincompositing/main.cpp

725 lines
30 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
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 "kwin_interface.h"
#include <kaboutdata.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <ksettings/dispatcher.h>
#include <kpluginselector.h>
#include <kservicetypetrader.h>
#include <kplugininfo.h>
#include <kservice.h>
#include <ktitlewidget.h>
#include <knotification.h>
#include <QtDBus/QtDBus>
#include <QTimer>
#include <QLabel>
#include <KPluginFactory>
#include <KPluginLoader>
#include <KIcon>
K_PLUGIN_FACTORY(KWinCompositingConfigFactory,
2011-01-30 14:34:42 +00:00
registerPlugin<KWin::KWinCompositingConfig>();
)
K_EXPORT_PLUGIN(KWinCompositingConfigFactory("kcmkwincompositing"))
namespace KWin
{
ConfirmDialog::ConfirmDialog() :
2011-01-30 14:34:42 +00:00
KTimerDialog(10000, KTimerDialog::CountDown, 0,
i18n("Confirm Desktop Effects Change"), KTimerDialog::Ok | KTimerDialog::Cancel,
KTimerDialog::Cancel)
{
setObjectName(QLatin1String("mainKTimerDialog"));
setButtonGuiItem(KDialog::Ok, KGuiItem(i18n("&Accept Configuration"), "dialog-ok"));
setButtonGuiItem(KDialog::Cancel, KGuiItem(i18n("&Return to Previous Configuration"), "dialog-cancel"));
QLabel *label = new QLabel(i18n("Desktop effects settings have changed.\n"
"Do you want to keep the new settings?\n"
"They will be automatically reverted in 10 seconds."), this);
label->setWordWrap(true);
setMainWidget(label);
setWindowIcon(KIcon("preferences-desktop-effect"));
2011-01-30 14:34:42 +00:00
}
KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList &)
2011-01-30 14:34:42 +00:00
: KCModule(KWinCompositingConfigFactory::componentData(), parent)
, mKWinConfig(KSharedConfig::openConfig("kwinrc"))
, m_showConfirmDialog(false)
{
KGlobal::locale()->insertCatalog("kwin_effects");
ui.setupUi(this);
layout()->setMargin(0);
ui.tabWidget->setCurrentIndex(0);
ui.statusTitleWidget->hide();
ui.rearmGlSupport->hide();
// For future use
2011-01-30 14:34:42 +00:00
(void) I18N_NOOP("Use GLSL shaders");
#define OPENGL_INDEX 0
#define XRENDER_INDEX 1
#ifndef KWIN_HAVE_XRENDER_COMPOSITING
2011-01-30 14:34:42 +00:00
ui.compositingType->removeItem(XRENDER_INDEX);
ui.xrenderGroup->setEnabled(false);
#define XRENDER_INDEX -1
#endif
connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
connect(ui.rearmGlSupportButton, SIGNAL(clicked()), this, SLOT(rearmGlSupport()));
connect(ui.useCompositing, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(ui.effectWinManagement, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(ui.effectAnimations, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(ui.effectSelector, SIGNAL(changed(bool)), this, SLOT(changed()));
2011-08-17 21:51:55 +00:00
connect(ui.effectSelector, SIGNAL(configCommitted(QByteArray)),
this, SLOT(reparseConfiguration(QByteArray)));
connect(ui.windowSwitchingCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(ui.desktopSwitchingCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(ui.animationSpeedCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(ui.compositingType, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(ui.compositingType, SIGNAL(currentIndexChanged(int)), this, SLOT(toogleSmoothScaleUi(int)));
connect(ui.windowThumbnails, SIGNAL(activated(int)), this, SLOT(changed()));
connect(ui.unredirectFullscreen , SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(ui.glScaleFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(ui.xrScaleFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
2011-01-30 14:34:42 +00:00
connect(ui.glVSync, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(ui.glShaders, SIGNAL(toggled(bool)), this, SLOT(changed()));
// Open the temporary config file
// Temporary conf file is used to synchronize effect checkboxes with effect
// selector by loading/saving effects from/to temp config when active tab
// changes.
mTmpConfigFile.open();
mTmpConfig = KSharedConfig::openConfig(mTmpConfigFile.fileName());
// toggle effects shortcut button stuff - /HAS/ to happen before load!
m_actionCollection = new KActionCollection( this, KComponentData("kwin") );
m_actionCollection->setConfigGroup("Suspend Compositing");
m_actionCollection->setConfigGlobal(true);
KAction* a = static_cast<KAction*>(m_actionCollection->addAction( "Suspend Compositing" ));
a->setProperty("isConfigurationAction", true);
a->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_F12 ));
2011-08-17 21:51:55 +00:00
connect(ui.toggleEffectsShortcut, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(toggleEffectShortcutChanged(QKeySequence)));
// Initialize the user interface with the config loaded from kwinrc.
load();
KAboutData *about = new KAboutData(I18N_NOOP("kcmkwincompositing"), 0,
2011-01-30 14:34:42 +00:00
ki18n("KWin Desktop Effects Configuration Module"),
0, KLocalizedString(), KAboutData::License_GPL, ki18n("(c) 2007 Rivo Laks"));
about->addAuthor(ki18n("Rivo Laks"), KLocalizedString(), "rivolaks@hot.ee");
setAboutData(about);
// search the effect names
KServiceTypeTrader* trader = KServiceTypeTrader::self();
KService::List services;
QString boxswitch, presentwindows, coverswitch, flipswitch, slide, cube, fadedesktop;
// window switcher
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_boxswitch'");
2011-01-30 14:34:42 +00:00
if (!services.isEmpty())
boxswitch = services.first()->name();
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_presentwindows'");
2011-01-30 14:34:42 +00:00
if (!services.isEmpty())
presentwindows = services.first()->name();
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_coverswitch'");
2011-01-30 14:34:42 +00:00
if (!services.isEmpty())
coverswitch = services.first()->name();
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_flipswitch'");
2011-01-30 14:34:42 +00:00
if (!services.isEmpty())
flipswitch = services.first()->name();
// desktop switcher
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == 'kwin4_effect_slide'");
2011-01-30 14:34:42 +00:00
if (!services.isEmpty())
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())
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())
fadedesktop = services.first()->name();
// init the combo boxes
ui.windowSwitchingCombo->addItem(i18n("No Effect"));
ui.windowSwitchingCombo->addItem(boxswitch);
ui.windowSwitchingCombo->addItem(presentwindows);
ui.windowSwitchingCombo->addItem(coverswitch);
ui.windowSwitchingCombo->addItem(flipswitch);
ui.desktopSwitchingCombo->addItem(i18n("No Effect"));
ui.desktopSwitchingCombo->addItem(slide);
ui.desktopSwitchingCombo->addItem(cube);
ui.desktopSwitchingCombo->addItem(fadedesktop);
2011-01-30 14:34:42 +00:00
}
KWinCompositingConfig::~KWinCompositingConfig()
2011-01-30 14:34:42 +00:00
{
}
2011-01-30 14:34:42 +00:00
void KWinCompositingConfig::reparseConfiguration(const QByteArray& conf)
{
KSettings::Dispatcher::reparseConfiguration(conf);
}
2011-01-30 14:34:42 +00:00
void KWinCompositingConfig::showConfirmDialog(bool reinitCompositing)
{
bool revert = false;
// Feel free to extend this to support several kwin instances (multihead) if you
// think it makes sense.
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
2011-01-30 14:34:42 +00:00
if (reinitCompositing ? !kwin.compositingActive().value() : !kwin.waitForCompositingSetup().value()) {
KMessageBox::sorry(this, i18n(
"Failed to activate desktop effects using the given "
"configuration options. Settings will be reverted to their previous values.\n\n"
"Check your X configuration. You may also consider changing advanced options, "
"especially changing the compositing type."));
revert = true;
2011-01-30 14:34:42 +00:00
} else {
ConfirmDialog confirm;
2011-01-30 14:34:42 +00:00
if (!confirm.exec())
revert = true;
2011-01-30 14:34:42 +00:00
else {
// compositing is enabled now
checkLoadedEffects();
}
2011-01-30 14:34:42 +00:00
}
if (revert) {
// Revert settings
KConfigGroup config(mKWinConfig, "Compositing");
config.deleteGroup();
QMap<QString, QString>::const_iterator it = mPreviousConfig.constBegin();
2011-01-30 14:34:42 +00:00
for (; it != mPreviousConfig.constEnd(); ++it) {
if (it.value().isEmpty())
continue;
config.writeEntry(it.key(), it.value());
2011-01-30 14:34:42 +00:00
}
// Sync with KWin and reload
configChanged(reinitCompositing);
load();
}
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::initEffectSelector()
2011-01-30 14:34:42 +00:00
{
// 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", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Accessibility"), "Accessibility", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Focus"), "Focus", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Window Management"), "Window Management", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Candy"), "Candy", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Demos"), "Demos", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Tests"), "Tests", mTmpConfig);
ui.effectSelector->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Tools"), "Tools", mTmpConfig);
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::currentTabChanged(int tab)
2011-01-30 14:34:42 +00:00
{
// block signals to don't emit the changed()-signal by just switching the current tab
blockSignals(true);
// write possible changes done to synchronize effect checkboxes and selector
// TODO: This segment is prone to fail when the UI is changed;
// you'll most likely not think of the hard coded numbers here when just changing the order of the tabs.
2011-01-30 14:34:42 +00:00
if (tab == 0) {
// General tab was activated
saveEffectsTab();
loadGeneralTab();
2011-01-30 14:34:42 +00:00
} else if (tab == 1) {
// Effects tab was activated
saveGeneralTab();
loadEffectsTab();
2011-01-30 14:34:42 +00:00
}
blockSignals(false);
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::loadGeneralTab()
2011-01-30 14:34:42 +00:00
{
KConfigGroup config(mKWinConfig, "Compositing");
bool enabled = config.readEntry("Enabled", mDefaultPrefs.recommendCompositing());
2011-01-30 14:34:42 +00:00
ui.useCompositing->setChecked(enabled);
// this works by global shortcut magics - it will pick the current sc
// but the constructor line that adds the default alt+shift+f12 gsc is IMPORTANT!
if (KAction *a = qobject_cast<KAction*>(m_actionCollection->action("Suspend Compositing")))
ui.toggleEffectsShortcut->setKeySequence(a->globalShortcut().primary());
2011-01-30 14:34:42 +00:00
ui.animationSpeedCombo->setCurrentIndex(config.readEntry("AnimationSpeed", 3));
// Load effect settings
KConfigGroup effectconfig(mTmpConfig, "Plugins");
#define LOAD_EFFECT_CONFIG(effectname) effectconfig.readEntry("kwin4_effect_" effectname "Enabled", true)
int winManagementEnabled = LOAD_EFFECT_CONFIG("presentwindows")
2011-01-30 14:34:42 +00:00
+ LOAD_EFFECT_CONFIG("desktopgrid")
+ LOAD_EFFECT_CONFIG("dialogparent");
if (winManagementEnabled > 0 && winManagementEnabled < 3) {
ui.effectWinManagement->setTristate(true);
ui.effectWinManagement->setCheckState(Qt::PartiallyChecked);
2011-01-30 14:34:42 +00:00
} else
ui.effectWinManagement->setChecked(winManagementEnabled);
ui.effectAnimations->setChecked(LOAD_EFFECT_CONFIG("minimizeanimation"));
#undef LOAD_EFFECT_CONFIG
// window switching
// Set current option to "none" if no plugin is activated.
2011-01-30 14:34:42 +00:00
ui.windowSwitchingCombo->setCurrentIndex(0);
KConfigGroup boxswitchconfig(mKWinConfig, "Effect-BoxSwitch");
2011-01-30 14:34:42 +00:00
if (effectEnabled("boxswitch", effectconfig) && boxswitchconfig.readEntry("TabBox", true))
ui.windowSwitchingCombo->setCurrentIndex(1);
KConfigGroup coverswitchconfig(mKWinConfig, "Effect-CoverSwitch");
2011-01-30 14:34:42 +00:00
if (effectEnabled("coverswitch", effectconfig) && coverswitchconfig.readEntry("TabBox", false))
ui.windowSwitchingCombo->setCurrentIndex(3);
KConfigGroup flipswitchconfig(mKWinConfig, "Effect-FlipSwitch");
2011-01-30 14:34:42 +00:00
if (effectEnabled("flipswitch", effectconfig) && flipswitchconfig.readEntry("TabBox", false))
ui.windowSwitchingCombo->setCurrentIndex(4);
KConfigGroup presentwindowsconfig(mKWinConfig, "Effect-PresentWindows");
2011-01-30 14:34:42 +00:00
if (effectEnabled("presentwindows", effectconfig) && presentwindowsconfig.readEntry("TabBox", false))
ui.windowSwitchingCombo->setCurrentIndex(2);
// desktop switching
// Set current option to "none" if no plugin is activated.
2011-01-30 14:34:42 +00:00
ui.desktopSwitchingCombo->setCurrentIndex(0);
if (effectEnabled("slide", effectconfig))
ui.desktopSwitchingCombo->setCurrentIndex(1);
if (effectEnabled("cubeslide", effectconfig))
ui.desktopSwitchingCombo->setCurrentIndex(2);
if (effectEnabled("fadedesktop", effectconfig))
ui.desktopSwitchingCombo->setCurrentIndex(3);
}
void KWinCompositingConfig::rearmGlSupport()
{
// rearm config
KConfigGroup gl_workaround_config = KConfigGroup(mKWinConfig, "Compositing");
gl_workaround_config.writeEntry("OpenGLIsUnsafe", false);
gl_workaround_config.sync();
// save last changes
save();
// Initialize the user interface with the config loaded from kwinrc.
load();
}
2011-01-30 14:34:42 +00:00
void KWinCompositingConfig::toogleSmoothScaleUi(int compositingType)
{
2011-01-30 14:34:42 +00:00
ui.glScaleFilter->setVisible(compositingType == OPENGL_INDEX);
ui.xrScaleFilter->setVisible(compositingType == XRENDER_INDEX);
ui.scaleMethodLabel->setBuddy(compositingType == XRENDER_INDEX ? ui.xrScaleFilter : ui.glScaleFilter);
ui.glGroup->setEnabled(compositingType == OPENGL_INDEX);
}
void KWinCompositingConfig::toggleEffectShortcutChanged(const QKeySequence &seq)
{
if (KAction *a = qobject_cast<KAction*>(m_actionCollection->action("Suspend Compositing")))
a->setGlobalShortcut(KShortcut(seq), KAction::ActiveShortcut, KAction::NoAutoloading);
m_actionCollection->writeSettings();
}
2011-01-30 14:34:42 +00:00
bool KWinCompositingConfig::effectEnabled(const QString& effect, const KConfigGroup& cfg) const
{
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())
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
}
void KWinCompositingConfig::loadEffectsTab()
2011-01-30 14:34:42 +00:00
{
ui.effectSelector->load();
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::loadAdvancedTab()
2011-01-30 14:34:42 +00:00
{
KConfigGroup config(mKWinConfig, "Compositing");
QString backend = config.readEntry("Backend", "OpenGL");
ui.compositingType->setCurrentIndex((backend == "XRender") ? XRENDER_INDEX : 0);
// 4 - off, 5 - shown, 6 - always, other are old values
int hps = config.readEntry("HiddenPreviews", 5);
2011-01-30 14:34:42 +00:00
if (hps == 6) // always
ui.windowThumbnails->setCurrentIndex(0);
else if (hps == 4) // never
ui.windowThumbnails->setCurrentIndex(2);
else // shown, or default
2011-01-30 14:34:42 +00:00
ui.windowThumbnails->setCurrentIndex(1);
ui.unredirectFullscreen->setChecked(config.readEntry("UnredirectFullscreen", false));
ui.xrScaleFilter->setCurrentIndex((int)config.readEntry("XRenderSmoothScale", false));
ui.glScaleFilter->setCurrentIndex(config.readEntry("GLTextureFilter", 2));
2011-01-30 14:34:42 +00:00
ui.glVSync->setChecked(config.readEntry("GLVSync", mDefaultPrefs.enableVSync()));
ui.glShaders->setChecked(!config.readEntry<bool>("GLLegacy", false));
2011-01-30 14:34:42 +00:00
toogleSmoothScaleUi(ui.compositingType->currentIndex());
}
void KWinCompositingConfig::updateStatusUI(bool compositingIsPossible)
{
if (compositingIsPossible) {
ui.compositingOptionsContainer->show();
ui.statusTitleWidget->hide();
ui.rearmGlSupport->hide();
// Driver-specific config detection
mDefaultPrefs.detect();
}
else {
ui.compositingOptionsContainer->hide();
QString text = i18n("Desktop effects are not available on this system due to the following technical issues:");
text += "<hr>";
text += CompositingPrefs::compositingNotPossibleReason();
ui.statusTitleWidget->setText(text);
ui.statusTitleWidget->setPixmap(KTitleWidget::InfoMessage, KTitleWidget::ImageLeft);
ui.statusTitleWidget->show();
ui.rearmGlSupport->setVisible(CompositingPrefs::openGlIsBroken());
}
}
void KWinCompositingConfig::load()
2011-01-30 14:34:42 +00:00
{
initEffectSelector();
mKWinConfig->reparseConfiguration();
updateStatusUI(CompositingPrefs::compositingPossible());
// Copy Plugins group to temp config file
QMap<QString, QString> entries = mKWinConfig->entryMap("Plugins");
QMap<QString, QString>::const_iterator it = entries.constBegin();
KConfigGroup tmpconfig(mTmpConfig, "Plugins");
tmpconfig.deleteGroup();
2011-01-30 14:34:42 +00:00
for (; it != entries.constEnd(); ++it)
tmpconfig.writeEntry(it.key(), it.value());
loadGeneralTab();
loadEffectsTab();
loadAdvancedTab();
2011-01-30 14:34:42 +00:00
emit changed(false);
}
void KWinCompositingConfig::saveGeneralTab()
2011-01-30 14:34:42 +00:00
{
KConfigGroup config(mKWinConfig, "Compositing");
// Check if any critical settings that need confirmation have changed
config.writeEntry("Enabled", ui.useCompositing->isChecked());
config.writeEntry("AnimationSpeed", ui.animationSpeedCombo->currentIndex());
// Save effects
KConfigGroup effectconfig(mTmpConfig, "Plugins");
#define WRITE_EFFECT_CONFIG(effectname, widget) effectconfig.writeEntry("kwin4_effect_" effectname "Enabled", widget->isChecked())
2011-01-30 14:34:42 +00:00
if (ui.effectWinManagement->checkState() != Qt::PartiallyChecked) {
WRITE_EFFECT_CONFIG("presentwindows", ui.effectWinManagement);
WRITE_EFFECT_CONFIG("desktopgrid", ui.effectWinManagement);
WRITE_EFFECT_CONFIG("dialogparent", ui.effectWinManagement);
2011-01-30 14:34:42 +00:00
}
// 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
int windowSwitcher = ui.windowSwitchingCombo->currentIndex();
bool boxSwitch = false;
bool presentWindowSwitching = false;
bool coverSwitch = false;
bool flipSwitch = false;
2011-01-30 14:34:42 +00:00
switch(windowSwitcher) {
case 1:
boxSwitch = true;
break;
case 2:
presentWindowSwitching = true;
break;
case 3:
coverSwitch = true;
break;
case 4:
flipSwitch = true;
break;
default:
break; // nothing
}
// activate effects if not active
2011-01-30 14:34:42 +00:00
if (boxSwitch)
effectconfig.writeEntry("kwin4_effect_boxswitchEnabled", true);
2011-01-30 14:34:42 +00:00
if (presentWindowSwitching)
effectconfig.writeEntry("kwin4_effect_presentwindowsEnabled", true);
2011-01-30 14:34:42 +00:00
if (coverSwitch)
effectconfig.writeEntry("kwin4_effect_coverswitchEnabled", true);
2011-01-30 14:34:42 +00:00
if (flipSwitch)
effectconfig.writeEntry("kwin4_effect_flipswitchEnabled", true);
2011-01-30 14:34:42 +00:00
KConfigGroup boxswitchconfig(mKWinConfig, "Effect-BoxSwitch");
boxswitchconfig.writeEntry("TabBox", boxSwitch);
boxswitchconfig.sync();
2011-01-30 14:34:42 +00:00
KConfigGroup presentwindowsconfig(mKWinConfig, "Effect-PresentWindows");
presentwindowsconfig.writeEntry("TabBox", presentWindowSwitching);
presentwindowsconfig.sync();
2011-01-30 14:34:42 +00:00
KConfigGroup coverswitchconfig(mKWinConfig, "Effect-CoverSwitch");
coverswitchconfig.writeEntry("TabBox", coverSwitch);
coverswitchconfig.sync();
2011-01-30 14:34:42 +00:00
KConfigGroup flipswitchconfig(mKWinConfig, "Effect-FlipSwitch");
flipswitchconfig.writeEntry("TabBox", flipSwitch);
flipswitchconfig.sync();
int desktopSwitcher = ui.desktopSwitchingCombo->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;
}
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::saveEffectsTab()
2011-01-30 14:34:42 +00:00
{
ui.effectSelector->save();
2011-01-30 14:34:42 +00:00
}
bool KWinCompositingConfig::saveAdvancedTab()
2011-01-30 14:34:42 +00:00
{
bool advancedChanged = false;
static const int hps[] = { 6 /*always*/, 5 /*shown*/, 4 /*never*/ };
KConfigGroup config(mKWinConfig, "Compositing");
2011-01-30 14:34:42 +00:00
if (config.readEntry("Backend", "OpenGL")
!= ((ui.compositingType->currentIndex() == OPENGL_INDEX) ? "OpenGL" : "XRender")
2011-01-30 14:34:42 +00:00
|| config.readEntry("GLVSync", mDefaultPrefs.enableVSync()) != ui.glVSync->isChecked()
|| config.readEntry<bool>("GLLegacy", false) == ui.glShaders->isChecked()) {
m_showConfirmDialog = true;
advancedChanged = true;
2011-01-30 14:34:42 +00:00
} else if (config.readEntry("HiddenPreviews", 5) != hps[ ui.windowThumbnails->currentIndex()]
|| (int)config.readEntry("XRenderSmoothScale", false) != ui.xrScaleFilter->currentIndex()
|| config.readEntry("GLTextureFilter", 2) != ui.glScaleFilter->currentIndex())
advancedChanged = true;
config.writeEntry("Backend", (ui.compositingType->currentIndex() == OPENGL_INDEX) ? "OpenGL" : "XRender");
2011-01-30 14:34:42 +00:00
config.writeEntry("HiddenPreviews", hps[ ui.windowThumbnails->currentIndex()]);
config.writeEntry("UnredirectFullscreen", ui.unredirectFullscreen->isChecked());
config.writeEntry("XRenderSmoothScale", ui.xrScaleFilter->currentIndex() == 1);
config.writeEntry("GLTextureFilter", ui.glScaleFilter->currentIndex());
config.writeEntry("GLVSync", ui.glVSync->isChecked());
config.writeEntry("GLLegacy", !ui.glShaders->isChecked());
return advancedChanged;
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::save()
2011-01-30 14:34:42 +00:00
{
if (ui.compositingType->currentIndex() == OPENGL_INDEX &&
CompositingPrefs::openGlIsBroken() && !ui.rearmGlSupport->isVisible())
{
KConfigGroup config(mKWinConfig, "Compositing");
QString oldBackend = config.readEntry("Backend", "OpenGL");
config.writeEntry("Backend", "OpenGL");
config.sync();
updateStatusUI(false);
config.writeEntry("Backend", oldBackend);
config.sync();
ui.tabWidget->setCurrentIndex(0);
return;
}
// Save current config. We'll use this for restoring in case something goes wrong.
KConfigGroup config(mKWinConfig, "Compositing");
mPreviousConfig = config.entryMap();
// bah; tab content being dependent on the other is really bad; and
// deprecated in the HIG for a reason. It is confusing!
// Make sure we only call save on each tab once; as they are stateful due to the revert concept
2011-01-30 14:34:42 +00:00
if (ui.tabWidget->currentIndex() == 0) { // "General" tab was active
saveGeneralTab();
loadEffectsTab();
saveEffectsTab();
2011-01-30 14:34:42 +00:00
} else {
saveEffectsTab();
loadGeneralTab();
saveGeneralTab();
2011-01-30 14:34:42 +00:00
}
bool advancedChanged = saveAdvancedTab();
// Copy Plugins group from temp config to real config
QMap<QString, QString> entries = mTmpConfig->entryMap("Plugins");
QMap<QString, QString>::const_iterator it = entries.constBegin();
KConfigGroup realconfig(mKWinConfig, "Plugins");
realconfig.deleteGroup();
2011-01-30 14:34:42 +00:00
for (; it != entries.constEnd(); ++it)
realconfig.writeEntry(it.key(), it.value());
2011-01-30 14:34:42 +00:00
emit changed(false);
configChanged(advancedChanged);
// This assumes that this KCM is running with the same environment variables as KWin
// TODO: Detect KWIN_COMPOSE=N as well
2011-01-30 14:34:42 +00:00
if (!qgetenv("KDE_FAILSAFE").isNull() && ui.useCompositing->isChecked()) {
KMessageBox::sorry(this, i18n(
"Your settings have been saved but as KDE is currently running in failsafe "
"mode desktop effects cannot be enabled at this time.\n\n"
"Please exit failsafe mode to enable desktop effects."));
m_showConfirmDialog = false; // Dangerous but there is no way to test if failsafe mode
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (m_showConfirmDialog) {
m_showConfirmDialog = false;
showConfirmDialog(advancedChanged);
}
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::checkLoadedEffects()
2011-01-30 14:34:42 +00:00
{
// check for effects not supported by Backend or hardware
// such effects are enabled but not returned by DBus method loadedEffects
2011-01-30 14:34:42 +00:00
QDBusMessage message = QDBusMessage::createMethodCall("org.kde.kwin", "/KWin", "org.kde.KWin", "loadedEffects");
QDBusMessage reply = QDBusConnection::sessionBus().call(message);
KConfigGroup effectConfig = KConfigGroup(mKWinConfig, "Compositing");
bool enabledAfter = effectConfig.readEntry("Enabled", mDefaultPrefs.recommendCompositing());
if (reply.type() == QDBusMessage::ReplyMessage && enabledAfter && !getenv("KDE_FAILSAFE")) {
effectConfig = KConfigGroup(mKWinConfig, "Plugins");
QStringList loadedEffects = reply.arguments()[0].toStringList();
QStringList effects = effectConfig.keyList();
QStringList disabledEffects = QStringList();
2011-01-30 14:34:42 +00:00
foreach (QString effect, effects) { // krazy:exclude=foreach
QString temp = effect.mid(13, effect.length() - 13 - 7);
effect.truncate(effect.length() - 7);
if (effectEnabled(temp, effectConfig) && !loadedEffects.contains(effect)) {
disabledEffects << effect;
}
2011-01-30 14:34:42 +00:00
}
if (!disabledEffects.isEmpty()) {
KServiceTypeTrader* trader = KServiceTypeTrader::self();
KService::List services;
2011-01-30 14:34:42 +00:00
QString message = i18n("The following desktop effects could not be activated:");
message.append("<ul>");
foreach (const QString & effect, disabledEffects) {
services = trader->query("KWin/Effect", "[X-KDE-PluginInfo-Name] == '" + effect + '\'');
2011-01-30 14:34:42 +00:00
message.append("<li>");
if (!services.isEmpty())
message.append(services.first()->name());
else
2011-01-30 14:34:42 +00:00
message.append(effect);
message.append("</li>");
}
2011-01-30 14:34:42 +00:00
message.append("</ul>");
KNotification::event("effectsnotsupported", message, QPixmap(), NULL, KNotification::CloseOnTimeout, KComponentData("kwin"));
}
}
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::configChanged(bool reinitCompositing)
2011-01-30 14:34:42 +00:00
{
// Send signal to kwin
mKWinConfig->sync();
// Send signal to all kwin instances
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin",
2011-01-30 14:34:42 +00:00
reinitCompositing ? "reinitCompositing" : "reloadConfig");
QDBusConnection::sessionBus().send(message);
// maybe it's ok now?
if (reinitCompositing && !ui.compositingOptionsContainer->isVisible())
load();
// HACK: We can't just do this here, due to the asynchronous nature of signals.
// We also can't change reinitCompositing into a message (which would allow
// callWithCallbac() to do this neater) due to multiple kwin instances.
2011-01-30 14:34:42 +00:00
if (!m_showConfirmDialog)
QTimer::singleShot(1000, this, SLOT(checkLoadedEffects()));
2011-01-30 14:34:42 +00:00
}
void KWinCompositingConfig::defaults()
2011-01-30 14:34:42 +00:00
{
ui.tabWidget->setCurrentIndex(0);
ui.useCompositing->setChecked(mDefaultPrefs.recommendCompositing());
ui.effectWinManagement->setChecked(true);
ui.effectAnimations->setChecked(true);
2011-01-30 14:34:42 +00:00
ui.windowSwitchingCombo->setCurrentIndex(1);
ui.desktopSwitchingCombo->setCurrentIndex(1);
ui.animationSpeedCombo->setCurrentIndex(3);
ui.effectSelector->defaults();
2011-01-30 14:34:42 +00:00
ui.compositingType->setCurrentIndex(0);
ui.windowThumbnails->setCurrentIndex(1);
ui.unredirectFullscreen->setChecked(false);
2011-01-30 14:34:42 +00:00
ui.xrScaleFilter->setCurrentIndex(0);
ui.glScaleFilter->setCurrentIndex(2);
ui.glVSync->setChecked(mDefaultPrefs.enableVSync());
ui.glShaders->setChecked(true);
2011-01-30 14:34:42 +00:00
}
QString KWinCompositingConfig::quickHelp() const
2011-01-30 14:34:42 +00:00
{
return i18n("<h1>Desktop Effects</h1>");
2011-01-30 14:34:42 +00:00
}
} // namespace
#include "main.moc"