2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-07-20 16:19:09 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +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/>.
|
|
|
|
*********************************************************************/
|
2007-07-20 16:19:09 +00:00
|
|
|
|
|
|
|
#include "advanced.h"
|
2007-07-21 10:20:51 +00:00
|
|
|
#include "advanced.moc"
|
2007-07-20 16:19:09 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
|
2007-09-20 17:19:19 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2008-08-15 11:09:07 +00:00
|
|
|
#include <kmessagebox.h>
|
2007-09-20 17:19:19 +00:00
|
|
|
|
2007-09-18 14:32:37 +00:00
|
|
|
#include "compositingprefs.h"
|
2007-09-20 20:34:24 +00:00
|
|
|
#include "main.h"
|
2008-08-15 11:09:07 +00:00
|
|
|
#include "kwin_interface.h"
|
2007-09-18 14:32:37 +00:00
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-09-18 14:32:37 +00:00
|
|
|
KWinAdvancedCompositingOptions::KWinAdvancedCompositingOptions(QWidget* parent, KSharedConfigPtr config, CompositingPrefs* defaults) :
|
2007-07-20 16:19:09 +00:00
|
|
|
KDialog(parent)
|
|
|
|
{
|
|
|
|
mKWinConfig = config;
|
2007-09-18 14:32:37 +00:00
|
|
|
mDefaultPrefs = defaults;
|
2007-07-20 16:19:09 +00:00
|
|
|
|
2007-10-16 15:36:27 +00:00
|
|
|
setCaption(i18n("Advanced Compositing Options"));
|
2007-07-20 16:19:09 +00:00
|
|
|
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
|
|
|
|
setModal(true);
|
|
|
|
|
|
|
|
QWidget* mainWidget = new QWidget(this);
|
|
|
|
ui.setupUi(mainWidget);
|
|
|
|
setMainWidget(mainWidget);
|
|
|
|
|
2007-08-27 12:53:56 +00:00
|
|
|
connect(ui.compositingType, SIGNAL(currentIndexChanged(int)), this, SLOT(compositingModeChanged()));
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
connect(ui.compositingType, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
|
2008-08-12 11:02:58 +00:00
|
|
|
connect(ui.windowThumbnails, SIGNAL(activated(int)), this, SLOT(changed()));
|
2007-07-20 18:50:51 +00:00
|
|
|
connect(ui.glMode, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
|
2007-08-24 17:34:09 +00:00
|
|
|
connect(ui.glTextureFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
|
2007-07-20 18:50:51 +00:00
|
|
|
connect(ui.glDirect, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
|
|
|
connect(ui.glVSync, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
2007-07-20 16:19:09 +00:00
|
|
|
|
2008-08-03 12:37:28 +00:00
|
|
|
connect(ui.xrenderSmoothScale, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
connect(this, SIGNAL(okClicked()), this, SLOT(save()));
|
|
|
|
connect(this, SIGNAL(applyClicked()), this, SLOT(save()));
|
|
|
|
|
|
|
|
load();
|
|
|
|
|
|
|
|
enableButtonApply(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
KWinAdvancedCompositingOptions::~KWinAdvancedCompositingOptions()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinAdvancedCompositingOptions::changed()
|
|
|
|
{
|
|
|
|
enableButtonApply(true);
|
|
|
|
}
|
|
|
|
|
2007-08-27 12:53:56 +00:00
|
|
|
void KWinAdvancedCompositingOptions::compositingModeChanged()
|
|
|
|
{
|
|
|
|
ui.glGroup->setEnabled(ui.compositingType->currentIndex() == 0);
|
2007-09-21 13:27:56 +00:00
|
|
|
ui.xrenderGroup->setEnabled(ui.compositingType->currentIndex() == 1);
|
2007-08-27 12:53:56 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 20:34:24 +00:00
|
|
|
void KWinAdvancedCompositingOptions::showConfirmDialog()
|
|
|
|
{
|
2008-08-15 11:09:07 +00:00
|
|
|
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());
|
|
|
|
if( !kwin.compositingActive().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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfirmDialog confirm;
|
|
|
|
if( !confirm.exec())
|
|
|
|
revert = true;
|
|
|
|
}
|
|
|
|
if( revert )
|
2007-09-20 20:34:24 +00:00
|
|
|
{
|
|
|
|
// Revert settings
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
|
|
|
config.deleteGroup();
|
|
|
|
QMap<QString, QString>::const_iterator it = mPreviousConfig.constBegin();
|
|
|
|
for(; it != mPreviousConfig.constEnd(); ++it)
|
|
|
|
{
|
2007-12-30 14:07:38 +00:00
|
|
|
if (it.value().isEmpty())
|
|
|
|
continue;
|
2007-09-20 20:34:24 +00:00
|
|
|
config.writeEntry(it.key(), it.value());
|
|
|
|
}
|
|
|
|
// Reinit KWin compositing and reload (old) settings
|
|
|
|
reinitKWinCompositing();
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
void KWinAdvancedCompositingOptions::load()
|
|
|
|
{
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
|
|
|
QString backend = config.readEntry("Backend", "OpenGL");
|
|
|
|
ui.compositingType->setCurrentIndex((backend == "XRender") ? 1 : 0);
|
2008-08-12 11:02:58 +00:00
|
|
|
int hps = config.readEntry("HiddenPreviews", 0);
|
|
|
|
if( hps == 1 ) // always
|
|
|
|
ui.windowThumbnails->setCurrentIndex( 0 );
|
|
|
|
else if( hps == 0 ) // never
|
|
|
|
ui.windowThumbnails->setCurrentIndex( 2 );
|
|
|
|
else // shown, or default
|
|
|
|
ui.windowThumbnails->setCurrentIndex( 1 );
|
2007-09-21 13:27:56 +00:00
|
|
|
|
2007-07-20 18:50:51 +00:00
|
|
|
QString glMode = config.readEntry("GLMode", "TFP");
|
|
|
|
ui.glMode->setCurrentIndex((glMode == "TFP") ? 0 : ((glMode == "SHM") ? 1 : 2));
|
2007-08-24 17:34:09 +00:00
|
|
|
ui.glTextureFilter->setCurrentIndex(config.readEntry("GLTextureFilter", 1));
|
2007-09-18 14:32:37 +00:00
|
|
|
ui.glDirect->setChecked(config.readEntry("GLDirect", mDefaultPrefs->enableDirectRendering()));
|
|
|
|
ui.glVSync->setChecked(config.readEntry("GLVSync", mDefaultPrefs->enableVSync()));
|
2007-09-21 13:27:56 +00:00
|
|
|
|
|
|
|
ui.xrenderSmoothScale->setChecked(config.readEntry("XRenderSmoothScale", false));
|
|
|
|
|
|
|
|
compositingModeChanged();
|
2007-07-20 16:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinAdvancedCompositingOptions::save()
|
|
|
|
{
|
|
|
|
// Is this ok?
|
|
|
|
if (!isButtonEnabled(KDialog::Apply)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup config(mKWinConfig, "Compositing");
|
2007-09-20 20:34:24 +00:00
|
|
|
mPreviousConfig = config.entryMap();
|
2008-08-15 11:10:00 +00:00
|
|
|
bool showConfirm = false;
|
|
|
|
QString glModes[] = { "TFP", "SHM", "Fallback" };
|
|
|
|
|
|
|
|
if( config.readEntry("Backend", "OpenGL")
|
|
|
|
!= ((ui.compositingType->currentIndex() == 0) ? "OpenGL" : "XRender")
|
|
|
|
|| config.readEntry("GLMode", "TFP") != glModes[ui.glMode->currentIndex()]
|
|
|
|
|| config.readEntry("GLDirect", mDefaultPrefs->enableDirectRendering())
|
|
|
|
!= ui.glDirect->isChecked()
|
|
|
|
|| config.readEntry("GLVSync", mDefaultPrefs->enableVSync()) != ui.glVSync->isChecked())
|
|
|
|
{
|
|
|
|
showConfirm = true;
|
|
|
|
}
|
2007-09-20 20:34:24 +00:00
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
config.writeEntry("Backend", (ui.compositingType->currentIndex() == 0) ? "OpenGL" : "XRender");
|
2008-08-12 11:02:58 +00:00
|
|
|
static const int hps[] = { 1 /*always*/, 3 /*shown*/, 0 /*never*/ };
|
|
|
|
config.writeEntry("HiddenPreviews", hps[ ui.windowThumbnails->currentIndex() ] );
|
2007-09-21 13:27:56 +00:00
|
|
|
|
2007-07-20 18:50:51 +00:00
|
|
|
config.writeEntry("GLMode", glModes[ui.glMode->currentIndex()]);
|
2007-08-24 17:34:09 +00:00
|
|
|
config.writeEntry("GLTextureFilter", ui.glTextureFilter->currentIndex());
|
2007-07-20 18:50:51 +00:00
|
|
|
config.writeEntry("GLDirect", ui.glDirect->isChecked());
|
|
|
|
config.writeEntry("GLVSync", ui.glVSync->isChecked());
|
2007-07-20 16:19:09 +00:00
|
|
|
|
2007-09-21 13:27:56 +00:00
|
|
|
config.writeEntry("XRenderSmoothScale", ui.xrenderSmoothScale->isChecked());
|
|
|
|
|
2007-07-20 16:19:09 +00:00
|
|
|
enableButtonApply(false);
|
2007-09-20 17:19:19 +00:00
|
|
|
|
2007-09-20 20:34:24 +00:00
|
|
|
reinitKWinCompositing();
|
2008-08-15 11:10:00 +00:00
|
|
|
if( showConfirm )
|
|
|
|
showConfirmDialog();
|
2007-09-20 20:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinAdvancedCompositingOptions::reinitKWinCompositing()
|
|
|
|
{
|
2007-09-20 17:19:19 +00:00
|
|
|
// Send signal to kwin
|
|
|
|
mKWinConfig->sync();
|
|
|
|
// Send signal to all kwin instances
|
2008-08-15 11:09:07 +00:00
|
|
|
// If this ever changes to using the 'reconfigure' DBUS call, change the compositingActive()
|
|
|
|
// check above.
|
2007-09-20 17:19:19 +00:00
|
|
|
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reinitCompositing");
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
2007-07-20 16:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|