2007-11-27 19:40:25 +00:00
/********************************************************************
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 >
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-19 16:20:05 +00:00
# include "main.h"
2012-10-16 20:41:21 +00:00
# include "dbus.h"
2007-07-19 16:20:05 +00:00
2008-08-15 11:09:07 +00:00
# include "kwin_interface.h"
2012-04-27 09:03:26 +00:00
# include "kwinglobals.h"
2007-07-20 16:19:09 +00:00
2007-07-19 16:20:05 +00:00
# include <kaboutdata.h>
2011-02-27 22:39:32 +00:00
# include <kaction.h>
# include <kactioncollection.h>
2007-07-19 16:20:05 +00:00
# include <kconfig.h>
# include <kconfiggroup.h>
# include <kdebug.h>
2008-08-15 11:09:07 +00:00
# include <kmessagebox.h>
2007-07-19 16:20:05 +00:00
# include <ksettings/dispatcher.h>
2007-09-18 10:09:07 +00:00
# include <kpluginselector.h>
# include <kservicetypetrader.h>
# include <kplugininfo.h>
# include <kservice.h>
2008-10-14 13:23:50 +00:00
# include <ktitlewidget.h>
2009-04-01 16:24:40 +00:00
# include <knotification.h>
2012-10-26 11:08:00 +00:00
# include <KNS3/DownloadDialog>
2007-07-19 16:20:05 +00:00
# include <QtDBus/QtDBus>
2011-12-16 16:35:50 +00:00
# include <QPainter>
# include <QPaintEngine>
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>
2008-12-29 20:09:15 +00:00
# include <KIcon>
2007-07-19 16:20:05 +00:00
2007-08-28 13:01:13 +00:00
K_PLUGIN_FACTORY ( KWinCompositingConfigFactory ,
2011-01-30 14:34:42 +00:00
registerPlugin < KWin : : KWinCompositingConfig > ( ) ;
)
2007-08-28 13:01:13 +00:00
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 ( ) :
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 ) ;
2008-12-29 20:09:15 +00:00
setWindowIcon ( KIcon ( " preferences-desktop-effect " ) ) ;
2011-01-30 14:34:42 +00:00
}
2007-09-18 19:00:23 +00:00
2012-10-16 20:41:21 +00:00
KWinCompositingConfig : : KWinCompositingConfig ( QWidget * parent , const QVariantList & args )
2011-01-30 14:34:42 +00:00
: KCModule ( KWinCompositingConfigFactory : : componentData ( ) , parent )
, mKWinConfig ( KSharedConfig : : openConfig ( " kwinrc " ) )
, m_showConfirmDialog ( false )
2012-05-04 09:13:24 +00:00
, m_showDetailedErrors ( new QAction ( i18nc ( " Action to open a dialog showing detailed information why an effect could not be loaded " ,
" Details " ) , this ) )
2012-10-16 20:41:21 +00:00
, m_dontShowAgain ( new QAction ( i18nc ( " Prevent warning from bein displayed again " , " Don't show again! " ) , this ) )
2011-01-30 14:34:42 +00:00
{
2012-10-16 20:41:21 +00:00
QDBusConnection : : sessionBus ( ) . registerService ( " org.kde.kwinCompositingDialog " ) ;
QDBusConnection : : sessionBus ( ) . registerObject ( " /CompositorSettings " , this ) ;
new MainAdaptor ( this ) ;
2011-01-30 14:34:42 +00:00
KGlobal : : locale ( ) - > insertCatalog ( " kwin_effects " ) ;
2013-02-28 08:52:00 +00:00
KGlobal : : locale ( ) - > insertCatalog ( " kwin_scripting " ) ;
2007-07-19 16:20:05 +00:00
ui . setupUi ( this ) ;
2007-12-17 08:26:19 +00:00
layout ( ) - > setMargin ( 0 ) ;
2012-12-17 20:12:02 +00:00
layout ( ) - > activate ( ) ;
2007-09-18 10:09:07 +00:00
ui . tabWidget - > setCurrentIndex ( 0 ) ;
2008-10-14 13:23:50 +00:00
ui . statusTitleWidget - > hide ( ) ;
2011-04-03 19:59:57 +00:00
ui . rearmGlSupport - > hide ( ) ;
2012-05-04 09:13:24 +00:00
ui . messageBox - > setMessageType ( KMessageWidget : : Warning ) ;
2012-10-16 20:41:21 +00:00
ui . messageBox - > addAction ( m_dontShowAgain ) ;
foreach ( QWidget * w , m_dontShowAgain - > associatedWidgets ( ) )
w - > setVisible ( false ) ;
ui . messageBox - > addAction ( m_showDetailedErrors ) ;
bool showMessage = false ;
QString message , details , dontAgainKey ;
if ( args . count ( ) > 1 ) {
for ( int i = 0 ; i < args . count ( ) - 1 ; + + i ) {
if ( args . at ( i ) . toString ( ) = = " warn " ) {
showMessage = true ;
message = QString : : fromLocal8Bit ( QByteArray : : fromBase64 ( args . at ( i + 1 ) . toByteArray ( ) ) ) ;
} else if ( args . at ( i ) . toString ( ) = = " details " ) {
showMessage = true ;
details = QString : : fromLocal8Bit ( QByteArray : : fromBase64 ( args . at ( i + 1 ) . toByteArray ( ) ) ) ;
} else if ( args . at ( i ) . toString ( ) = = " dontagain " ) {
showMessage = true ;
dontAgainKey = args . at ( i + 1 ) . toString ( ) ;
}
}
}
if ( showMessage ) {
ui . messageBox - > setVisible ( showMessage ) ; // first show, animation is broken on init
warn ( message , details , dontAgainKey ) ;
} else
ui . messageBox - > setVisible ( false ) ;
2012-10-26 11:08:00 +00:00
ui . ghns - > setIcon ( KIcon ( " get-hot-new-stuff " ) ) ;
2007-07-19 16:20:05 +00:00
2010-11-12 05:36:07 +00:00
// For future use
2011-01-30 14:34:42 +00:00
( void ) I18N_NOOP ( " Use GLSL shaders " ) ;
2010-11-12 05:36:07 +00:00
2013-03-13 15:19:36 +00:00
# define OPENGL31_INDEX 0
# define OPENGL20_INDEX 1
# define OPENGL12_INDEX 2
# define XRENDER_INDEX 3
2008-12-08 10:48:38 +00:00
# ifndef KWIN_HAVE_XRENDER_COMPOSITING
2011-01-30 14:34:42 +00:00
ui . compositingType - > removeItem ( XRENDER_INDEX ) ;
2008-12-08 11:00:01 +00:00
# define XRENDER_INDEX -1
2008-12-08 10:48:38 +00:00
# endif
2013-03-06 21:05:34 +00:00
ui . glSwapStrategy - > addItem ( i18n ( " None " ) , " n " ) ;
ui . glSwapStrategy - > setItemData ( 0 , i18n ( " The painting is not synchronized with the screen. " ) , Qt : : ToolTipRole ) ;
ui . glSwapStrategy - > addItem ( i18n ( " Automatic " ) , " a " ) ;
2013-03-25 06:20:07 +00:00
ui . glSwapStrategy - > setItemData ( 1 , i18n ( " Tries to re-use older buffers and if that is not possible, \n picks a strategy matching your hardware. " ) , Qt : : ToolTipRole ) ;
2013-03-06 21:05:34 +00:00
ui . glSwapStrategy - > addItem ( i18n ( " Only when Cheap " ) , " e " ) ;
ui . glSwapStrategy - > setItemData ( 2 , i18n ( " When major regions of the screen are updated, \n the entire screen will be repainted. \n Can cause tearing with small updates. " ) , Qt : : ToolTipRole ) ;
ui . glSwapStrategy - > addItem ( i18n ( " Full scene repaints " ) , " p " ) ;
ui . glSwapStrategy - > setItemData ( 3 , i18n ( " The complete screen is repainted for every frame. \n Can be slow with large blurred areas. " ) , Qt : : ToolTipRole ) ;
ui . glSwapStrategy - > addItem ( i18n ( " Re-use screen content " ) , " c " ) ;
ui . glSwapStrategy - > setItemData ( 4 , i18n ( " WARNING: \n This strategy is usually slow with Open Source drivers. \n Undamaged pixels will be copied from GL_FRONT to GL_BACK " ) , Qt : : ToolTipRole ) ;
2007-09-20 13:21:49 +00:00
connect ( ui . tabWidget , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( currentTabChanged ( int ) ) ) ;
2007-07-19 16:20:05 +00:00
2011-04-03 19:59:57 +00:00
connect ( ui . rearmGlSupportButton , SIGNAL ( clicked ( ) ) , this , SLOT ( rearmGlSupport ( ) ) ) ;
2007-07-19 16:20:05 +00:00
connect ( ui . useCompositing , SIGNAL ( toggled ( bool ) ) , this , SLOT ( changed ( ) ) ) ;
2011-12-16 16:35:50 +00:00
connect ( ui . useCompositing , SIGNAL ( clicked ( bool ) ) , this , SLOT ( suggestGraphicsSystem ( ) ) ) ;
2007-07-21 20:54:50 +00:00
connect ( ui . effectWinManagement , 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 ( ) ) ) ;
2011-08-17 21:51:55 +00:00
connect ( ui . effectSelector , SIGNAL ( configCommitted ( QByteArray ) ) ,
this , SLOT ( reparseConfiguration ( QByteArray ) ) ) ;
2007-09-18 10:09:07 +00:00
2008-08-26 07:31:57 +00:00
connect ( ui . desktopSwitchingCombo , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2008-08-30 07:25:54 +00:00
connect ( ui . animationSpeedCombo , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2008-08-26 07:31:57 +00:00
2008-11-14 12:36:59 +00:00
connect ( ui . compositingType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2013-06-16 20:14:52 +00:00
connect ( ui . compositingType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( alignGuiToCompositingType ( int ) ) ) ;
2011-12-16 16:35:50 +00:00
connect ( ui . compositingType , SIGNAL ( activated ( int ) ) , this , SLOT ( suggestGraphicsSystem ( ) ) ) ;
connect ( ui . graphicsSystem , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2008-11-14 12:36:59 +00:00
connect ( ui . windowThumbnails , SIGNAL ( activated ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2010-09-17 17:46:34 +00:00
connect ( ui . unredirectFullscreen , SIGNAL ( toggled ( bool ) ) , this , SLOT ( changed ( ) ) ) ;
2010-11-11 19:53:19 +00:00
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
2013-03-06 21:05:34 +00:00
connect ( ui . glSwapStrategy , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( glSwapStrategyChanged ( int ) ) ) ;
connect ( ui . glSwapStrategy , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changed ( ) ) ) ;
2012-11-13 20:41:02 +00:00
connect ( ui . glColorCorrection , SIGNAL ( toggled ( bool ) ) , this , SLOT ( changed ( ) ) ) ;
2012-05-04 09:13:24 +00:00
connect ( m_showDetailedErrors , SIGNAL ( triggered ( bool ) ) , SLOT ( showDetailedEffectLoadingInformation ( ) ) ) ;
2012-10-16 20:41:21 +00:00
connect ( m_dontShowAgain , SIGNAL ( triggered ( bool ) ) , SLOT ( blockFutureWarnings ( ) ) ) ;
2012-10-26 11:08:00 +00:00
connect ( ui . ghns , SIGNAL ( clicked ( bool ) ) , SLOT ( slotGHNS ( ) ) ) ;
2008-11-14 12:36:59 +00:00
2008-12-08 05:08:31 +00:00
// 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 ( ) ) ;
2008-11-25 01:42:30 +00:00
2011-02-27 22:39:32 +00:00
// 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 ) ) ) ;
2011-02-27 22:39:32 +00:00
2011-04-03 19:59:57 +00:00
// Initialize the user interface with the config loaded from kwinrc.
load ( ) ;
2007-07-19 16:20:05 +00:00
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 " ) ) ;
2007-07-19 16:20:05 +00:00
about - > addAuthor ( ki18n ( " Rivo Laks " ) , KLocalizedString ( ) , " rivolaks@hot.ee " ) ;
setAboutData ( about ) ;
2008-08-26 07:31:57 +00:00
// search the effect names
KServiceTypeTrader * trader = KServiceTypeTrader : : self ( ) ;
KService : : List services ;
2011-11-10 20:29:45 +00:00
QString slide , cube , fadedesktop ;
2008-08-26 07:31:57 +00:00
// 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 ( ) )
2008-08-26 07:31:57 +00:00
slide = services . first ( ) - > name ( ) ;
2009-02-06 18:53:16 +00:00
services = trader - > query ( " KWin/Effect " , " [X-KDE-PluginInfo-Name] == 'kwin4_effect_cubeslide' " ) ;
2011-01-30 14:34:42 +00:00
if ( ! services . isEmpty ( ) )
2008-08-26 07:31:57 +00:00
cube = services . first ( ) - > name ( ) ;
2009-01-15 09:55:15 +00:00
services = trader - > query ( " KWin/Effect " , " [X-KDE-PluginInfo-Name] == 'kwin4_effect_fadedesktop' " ) ;
2011-01-30 14:34:42 +00:00
if ( ! services . isEmpty ( ) )
2009-01-15 09:55:15 +00:00
fadedesktop = services . first ( ) - > name ( ) ;
2008-08-26 07:31:57 +00:00
2012-05-19 11:36:28 +00:00
ui . desktopSwitchingCombo - > addItem ( i18n ( " No effect " ) ) ;
2008-08-26 07:31:57 +00:00
ui . desktopSwitchingCombo - > addItem ( slide ) ;
ui . desktopSwitchingCombo - > addItem ( cube ) ;
2009-01-15 09:55:15 +00:00
ui . desktopSwitchingCombo - > addItem ( fadedesktop ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
KWinCompositingConfig : : ~ KWinCompositingConfig ( )
2011-01-30 14:34:42 +00:00
{
}
2008-12-05 18:41:24 +00:00
2011-01-30 14:34:42 +00:00
void KWinCompositingConfig : : reparseConfiguration ( const QByteArray & conf )
{
KSettings : : Dispatcher : : reparseConfiguration ( conf ) ;
}
2007-09-18 10:09:07 +00:00
2011-01-30 14:34:42 +00:00
void KWinCompositingConfig : : showConfirmDialog ( bool reinitCompositing )
{
2008-12-08 05:08:31 +00:00
bool revert = false ;
// Feel free to extend this to support several kwin instances (multihead) if you
// think it makes sense.
2012-12-29 23:15:30 +00:00
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. " ) ) ;
2008-12-08 05:08:31 +00:00
revert = true ;
2011-01-30 14:34:42 +00:00
} else {
2008-12-08 05:08:31 +00:00
ConfirmDialog confirm ;
2011-01-30 14:34:42 +00:00
if ( ! confirm . exec ( ) )
2008-12-08 05:08:31 +00:00
revert = true ;
2011-01-30 14:34:42 +00:00
else {
2009-04-18 10:07:16 +00:00
// compositing is enabled now
2009-09-11 21:03:24 +00:00
checkLoadedEffects ( ) ;
2008-12-08 05:08:31 +00:00
}
2011-01-30 14:34:42 +00:00
}
if ( revert ) {
2008-12-08 05:08:31 +00:00
// 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 ) {
2008-12-08 05:08:31 +00:00
if ( it . value ( ) . isEmpty ( ) )
continue ;
config . writeEntry ( it . key ( ) , it . value ( ) ) ;
2011-01-30 14:34:42 +00:00
}
2008-12-08 05:08:31 +00:00
// Sync with KWin and reload
configChanged ( reinitCompositing ) ;
load ( ) ;
}
2011-01-30 14:34:42 +00:00
}
2008-12-08 05:08:31 +00:00
2007-09-18 10:09:07 +00:00
void KWinCompositingConfig : : initEffectSelector ( )
2011-01-30 14:34:42 +00:00
{
2007-09-18 10:09:07 +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
2008-12-08 05:08:31 +00:00
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
}
2007-09-18 10:09:07 +00:00
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : currentTabChanged ( int tab )
2011-01-30 14:34:42 +00:00
{
2008-07-20 12:38:33 +00:00
// block signals to don't emit the changed()-signal by just switching the current tab
blockSignals ( true ) ;
2008-11-25 01:45:09 +00:00
2008-07-20 12:38:33 +00:00
// write possible changes done to synchronize effect checkboxes and selector
2008-11-25 01:42:30 +00:00
// 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 ) {
2007-09-20 13:21:49 +00:00
// General tab was activated
saveEffectsTab ( ) ;
loadGeneralTab ( ) ;
2011-01-30 14:34:42 +00:00
} else if ( tab = = 1 ) {
2007-09-20 13:21:49 +00:00
// Effects tab was activated
saveGeneralTab ( ) ;
loadEffectsTab ( ) ;
2011-01-30 14:34:42 +00:00
}
2008-11-25 01:45:09 +00:00
2008-07-20 12:38:33 +00:00
blockSignals ( false ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : loadGeneralTab ( )
2011-01-30 14:34:42 +00:00
{
2008-12-08 05:08:31 +00:00
KConfigGroup config ( mKWinConfig , " Compositing " ) ;
2012-04-28 19:38:13 +00:00
bool enabled = config . readEntry ( " Enabled " , true ) ;
2011-01-30 14:34:42 +00:00
ui . useCompositing - > setChecked ( enabled ) ;
2011-02-27 22:39:32 +00:00
// 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 ) ) ;
2007-07-19 16:20:05 +00:00
2007-07-21 20:54:50 +00:00
// Load effect settings
2008-12-08 05:08:31 +00:00
KConfigGroup effectconfig ( mTmpConfig , " Plugins " ) ;
2007-09-20 13:21:49 +00:00
# define LOAD_EFFECT_CONFIG(effectname) effectconfig.readEntry("kwin4_effect_" effectname "Enabled", true)
2007-12-10 19:04:21 +00:00
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 ) {
2007-12-10 19:04:21 +00:00
ui . effectWinManagement - > setTristate ( true ) ;
ui . effectWinManagement - > setCheckState ( Qt : : PartiallyChecked ) ;
2011-01-30 14:34:42 +00:00
} else
2007-12-10 19:04:21 +00:00
ui . effectWinManagement - > setChecked ( winManagementEnabled ) ;
2007-07-21 20:54:50 +00:00
ui . effectAnimations - > setChecked ( LOAD_EFFECT_CONFIG ( " minimizeanimation " ) ) ;
2007-09-20 13:21:49 +00:00
# undef LOAD_EFFECT_CONFIG
2008-08-26 07:31:57 +00:00
// desktop switching
2008-11-25 01:42:30 +00:00
// 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 ) ;
}
2009-04-18 10:07:16 +00:00
2013-03-06 21:05:34 +00:00
void KWinCompositingConfig : : glSwapStrategyChanged ( int idx )
{
ui . glSwapStrategy - > setToolTip ( ui . glSwapStrategy - > itemData ( idx , Qt : : ToolTipRole ) . toString ( ) ) ;
}
2011-04-03 19:59:57 +00:00
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-12-16 16:35:50 +00:00
void KWinCompositingConfig : : suggestGraphicsSystem ( )
{
if ( ! ui . useCompositing - > isChecked ( ) | | ui . compositingType - > currentIndex ( ) = = XRENDER_INDEX )
ui . graphicsSystem - > setCurrentIndex ( 0 ) ;
}
2013-06-16 20:14:52 +00:00
void KWinCompositingConfig : : alignGuiToCompositingType ( int compositingType )
2010-11-11 19:53:19 +00:00
{
2013-03-13 15:19:36 +00:00
ui . glScaleFilter - > setVisible ( compositingType ! = XRENDER_INDEX ) ;
2011-01-30 14:34:42 +00:00
ui . xrScaleFilter - > setVisible ( compositingType = = XRENDER_INDEX ) ;
ui . scaleMethodLabel - > setBuddy ( compositingType = = XRENDER_INDEX ? ui . xrScaleFilter : ui . glScaleFilter ) ;
2013-06-16 20:14:52 +00:00
2013-03-13 15:19:36 +00:00
ui . glGroup - > setEnabled ( compositingType ! = XRENDER_INDEX ) ;
2013-06-16 20:14:52 +00:00
ui . glColorCorrection - > setEnabled ( compositingType = = OPENGL20_INDEX | |
compositingType = = OPENGL31_INDEX ) ;
2010-11-11 19:53:19 +00:00
}
2011-02-27 22:39:32 +00:00
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
{
2008-10-01 15:21:21 +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 ( ) )
2008-10-01 15:21:21 +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
}
2008-10-01 15:21:21 +00:00
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : loadEffectsTab ( )
2011-01-30 14:34:42 +00:00
{
2007-09-18 10:09:07 +00:00
ui . effectSelector - > load ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
2008-11-14 12:36:59 +00:00
void KWinCompositingConfig : : loadAdvancedTab ( )
2011-01-30 14:34:42 +00:00
{
2008-12-08 05:08:31 +00:00
KConfigGroup config ( mKWinConfig , " Compositing " ) ;
2008-11-14 12:36:59 +00:00
QString backend = config . readEntry ( " Backend " , " OpenGL " ) ;
2013-03-13 15:19:36 +00:00
if ( backend = = " OpenGL " ) {
int index = OPENGL20_INDEX ;
if ( config . readEntry < bool > ( " GLLegacy " , false ) )
index = OPENGL12_INDEX ;
2013-05-21 07:27:38 +00:00
else if ( config . readEntry < bool > ( " GLCore " , false ) )
2013-03-13 15:19:36 +00:00
index = OPENGL31_INDEX ;
ui . compositingType - > setCurrentIndex ( index ) ;
} else if ( backend = = " XRender " ) {
ui . compositingType - > setCurrentIndex ( XRENDER_INDEX ) ;
}
2011-12-16 16:35:50 +00:00
originalGraphicsSystem = config . readEntry ( " GraphicsSystem " , QString ( ) ) ;
if ( originalGraphicsSystem . isEmpty ( ) ) { // detect system default
QPixmap pix ( 1 , 1 ) ;
QPainter p ( & pix ) ;
originalGraphicsSystem = ( p . paintEngine ( ) - > type ( ) = = QPaintEngine : : X11 ) ? " native " : " raster " ;
p . end ( ) ;
}
ui . graphicsSystem - > setCurrentIndex ( ( originalGraphicsSystem = = " native " ) ? 0 : 1 ) ;
2008-11-14 12:36:59 +00:00
// 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 ) ;
2008-11-14 12:36:59 +00:00
else // shown, or default
2011-01-30 14:34:42 +00:00
ui . windowThumbnails - > setCurrentIndex ( 1 ) ;
2011-05-15 07:40:19 +00:00
ui . unredirectFullscreen - > setChecked ( config . readEntry ( " UnredirectFullscreen " , false ) ) ;
2008-11-14 12:36:59 +00:00
2010-11-11 19:53:19 +00:00
ui . xrScaleFilter - > setCurrentIndex ( ( int ) config . readEntry ( " XRenderSmoothScale " , false ) ) ;
ui . glScaleFilter - > setCurrentIndex ( config . readEntry ( " GLTextureFilter " , 2 ) ) ;
2011-01-30 14:34:42 +00:00
2013-03-06 21:05:34 +00:00
int swapStrategy = ui . glSwapStrategy - > findData ( config . readEntry ( " GLPreferBufferSwap " , " a " ) ) ;
if ( swapStrategy < 0 )
swapStrategy = ui . glSwapStrategy - > findData ( " n " ) ;
ui . glSwapStrategy - > setCurrentIndex ( swapStrategy ) ;
2012-11-13 20:41:02 +00:00
ui . glColorCorrection - > setChecked ( config . readEntry ( " GLColorCorrection " , false ) ) ;
2008-11-14 12:36:59 +00:00
2013-06-16 20:14:52 +00:00
alignGuiToCompositingType ( ui . compositingType - > currentIndex ( ) ) ;
2011-01-30 14:34:42 +00:00
}
2008-11-14 12:36:59 +00:00
2011-04-03 19:59:57 +00:00
void KWinCompositingConfig : : updateStatusUI ( bool compositingIsPossible )
{
if ( compositingIsPossible ) {
ui . compositingOptionsContainer - > show ( ) ;
ui . statusTitleWidget - > hide ( ) ;
ui . rearmGlSupport - > hide ( ) ;
}
else {
2012-12-29 23:15:30 +00:00
OrgKdeKWinInterface kwin ( " org.kde.KWin " , " /KWin " , QDBusConnection : : sessionBus ( ) ) ;
2011-04-03 19:59:57 +00:00
ui . compositingOptionsContainer - > hide ( ) ;
QString text = i18n ( " Desktop effects are not available on this system due to the following technical issues: " ) ;
text + = " <hr> " ;
2012-04-27 09:03:26 +00:00
text + = kwin . isValid ( ) ? kwin . compositingNotPossibleReason ( ) : i18nc ( " Reason shown when trying to activate desktop effects and KWin (most likely) crashes " ,
" Window Manager seems not to be running " ) ;
2011-04-03 19:59:57 +00:00
ui . statusTitleWidget - > setText ( text ) ;
ui . statusTitleWidget - > setPixmap ( KTitleWidget : : InfoMessage , KTitleWidget : : ImageLeft ) ;
ui . statusTitleWidget - > show ( ) ;
2012-04-27 09:03:26 +00:00
ui . rearmGlSupport - > setVisible ( kwin . isValid ( ) ? kwin . openGLIsBroken ( ) : true ) ;
2011-04-03 19:59:57 +00:00
}
}
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : load ( )
2011-01-30 14:34:42 +00:00
{
2011-04-03 19:59:57 +00:00
initEffectSelector ( ) ;
2008-12-08 05:08:31 +00:00
mKWinConfig - > reparseConfiguration ( ) ;
2012-12-29 23:15:30 +00:00
QDBusMessage msg = QDBusMessage : : createMethodCall ( " org.kde.KWin " , " /KWin " , " org.kde.KWin " , " compositingPossible " ) ;
2012-04-27 09:03:26 +00:00
QDBusConnection : : sessionBus ( ) . callWithCallback ( msg , this , SLOT ( updateStatusUI ( bool ) ) ) ;
2008-12-08 05:08:31 +00:00
// 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 )
2008-12-08 05:08:31 +00:00
tmpconfig . writeEntry ( it . key ( ) , it . value ( ) ) ;
2007-09-20 13:21:49 +00:00
loadGeneralTab ( ) ;
loadEffectsTab ( ) ;
2008-11-14 12:36:59 +00:00
loadAdvancedTab ( ) ;
2007-09-20 13:21:49 +00:00
2011-01-30 14:34:42 +00:00
emit changed ( false ) ;
}
2007-09-20 13:21:49 +00:00
2007-12-30 14:07:38 +00:00
void KWinCompositingConfig : : saveGeneralTab ( )
2011-01-30 14:34:42 +00:00
{
2008-12-08 05:08:31 +00:00
KConfigGroup config ( mKWinConfig , " Compositing " ) ;
// Check if any critical settings that need confirmation have changed
2007-07-19 16:20:05 +00:00
config . writeEntry ( " Enabled " , ui . useCompositing - > isChecked ( ) ) ;
2008-08-30 07:25:54 +00:00
config . writeEntry ( " AnimationSpeed " , ui . animationSpeedCombo - > currentIndex ( ) ) ;
2007-07-19 16:20:05 +00:00
2007-07-21 20:54:50 +00:00
// Save effects
2008-12-08 05:08:31 +00:00
KConfigGroup effectconfig ( mTmpConfig , " Plugins " ) ;
2007-09-20 13:21:49 +00:00
# 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 ) {
2007-12-10 19:04:21 +00:00
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
}
2007-07-21 20:54:50 +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
2008-08-26 07:31:57 +00:00
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 ;
2008-11-25 01:42:30 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : saveEffectsTab ( )
2011-01-30 14:34:42 +00:00
{
2007-09-18 10:09:07 +00:00
ui . effectSelector - > save ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-09-20 13:21:49 +00:00
2008-12-08 05:08:31 +00:00
bool KWinCompositingConfig : : saveAdvancedTab ( )
2011-01-30 14:34:42 +00:00
{
2008-12-08 05:08:31 +00:00
bool advancedChanged = false ;
2008-11-14 13:18:03 +00:00
static const int hps [ ] = { 6 /*always*/ , 5 /*shown*/ , 4 /*never*/ } ;
2008-11-14 12:36:59 +00:00
2008-12-08 05:08:31 +00:00
KConfigGroup config ( mKWinConfig , " Compositing " ) ;
2011-12-16 16:35:50 +00:00
QString graphicsSystem = ( ui . graphicsSystem - > currentIndex ( ) = = 0 ) ? " native " : " raster " ;
2008-11-14 12:36:59 +00:00
2013-03-13 15:19:36 +00:00
QString backend ;
bool glLegacy ;
bool glCore ;
switch ( ui . compositingType - > currentIndex ( ) ) {
case OPENGL12_INDEX :
backend = " OpenGL " ;
glLegacy = true ;
glCore = false ;
break ;
case OPENGL20_INDEX :
backend = " OpenGL " ;
glLegacy = false ;
glCore = false ;
break ;
case OPENGL31_INDEX :
backend = " OpenGL " ;
glLegacy = false ;
glCore = true ;
break ;
case XRENDER_INDEX :
backend = " XRender " ;
glLegacy = false ;
glCore = false ;
break ;
}
if ( config . readEntry ( " Backend " , " OpenGL " ) ! = backend | |
config . readEntry < bool > ( " GLLegacy " , false ) ! = glLegacy | |
config . readEntry < bool > ( " GLCore " , false ) ! = glCore | |
( ( config . readEntry ( " GLPreferBufferSwap " , " a " ) = = " n " ) xor ( ui . glSwapStrategy - > itemData ( ui . glSwapStrategy - > currentIndex ( ) ) = = " n " ) ) ) {
2008-12-08 05:08:31 +00:00
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 ( )
2011-12-16 16:35:50 +00:00
| | config . readEntry ( " GLTextureFilter " , 2 ) ! = ui . glScaleFilter - > currentIndex ( ) ) {
2008-12-08 05:08:31 +00:00
advancedChanged = true ;
2011-12-16 16:35:50 +00:00
} else if ( originalGraphicsSystem ! = graphicsSystem ) {
advancedChanged = true ;
}
2008-12-08 05:08:31 +00:00
2013-03-13 15:19:36 +00:00
config . writeEntry ( " Backend " , backend ) ;
if ( backend = = " OpenGL " ) {
config . writeEntry ( " GLLegacy " , glLegacy ) ;
config . writeEntry ( " GLCore " , glCore ) ;
}
2011-12-16 16:35:50 +00:00
config . writeEntry ( " GraphicsSystem " , graphicsSystem ) ;
2011-01-30 14:34:42 +00:00
config . writeEntry ( " HiddenPreviews " , hps [ ui . windowThumbnails - > currentIndex ( ) ] ) ;
config . writeEntry ( " UnredirectFullscreen " , ui . unredirectFullscreen - > isChecked ( ) ) ;
2008-11-14 12:36:59 +00:00
2010-11-11 19:53:19 +00:00
config . writeEntry ( " XRenderSmoothScale " , ui . xrScaleFilter - > currentIndex ( ) = = 1 ) ;
config . writeEntry ( " GLTextureFilter " , ui . glScaleFilter - > currentIndex ( ) ) ;
2013-03-06 21:05:34 +00:00
config . writeEntry ( " GLPreferBufferSwap " , ui . glSwapStrategy - > itemData ( ui . glSwapStrategy - > currentIndex ( ) ) . toString ( ) ) ;
2012-11-13 20:41:02 +00:00
config . writeEntry ( " GLColorCorrection " , ui . glColorCorrection - > isChecked ( ) ) ;
2008-12-08 05:08:31 +00:00
return advancedChanged ;
2011-01-30 14:34:42 +00:00
}
2008-11-14 12:36:59 +00:00
2007-09-20 13:21:49 +00:00
void KWinCompositingConfig : : save ( )
2011-01-30 14:34:42 +00:00
{
2012-12-29 23:15:30 +00:00
OrgKdeKWinInterface kwin ( " org.kde.KWin " , " /KWin " , QDBusConnection : : sessionBus ( ) ) ;
2013-03-13 15:19:36 +00:00
if ( ui . compositingType - > currentIndex ( ) ! = XRENDER_INDEX & &
2012-04-27 09:03:26 +00:00
kwin . openGLIsBroken ( ) & & ! ui . rearmGlSupport - > isVisible ( ) )
2011-04-03 19:59:57 +00:00
{
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 ;
}
2008-12-08 05:08:31 +00:00
// Save current config. We'll use this for restoring in case something goes wrong.
KConfigGroup config ( mKWinConfig , " Compositing " ) ;
mPreviousConfig = config . entryMap ( ) ;
2007-12-30 14:34:04 +00:00
// bah; tab content being dependent on the other is really bad; and
2009-02-07 01:12:28 +00:00
// deprecated in the HIG for a reason. It is confusing!
2007-12-30 14:34:04 +00:00
// 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
2007-12-30 14:34:04 +00:00
saveGeneralTab ( ) ;
loadEffectsTab ( ) ;
saveEffectsTab ( ) ;
2011-01-30 14:34:42 +00:00
} else {
2007-12-30 14:34:04 +00:00
saveEffectsTab ( ) ;
loadGeneralTab ( ) ;
saveGeneralTab ( ) ;
2011-01-30 14:34:42 +00:00
}
2008-12-08 05:08:31 +00:00
bool advancedChanged = saveAdvancedTab ( ) ;
2007-09-18 10:09:07 +00:00
2008-12-08 05:08:31 +00:00
// 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 )
2008-12-08 05:08:31 +00:00
realconfig . writeEntry ( it . key ( ) , it . value ( ) ) ;
2007-07-19 16:20:05 +00:00
2011-01-30 14:34:42 +00:00
emit changed ( false ) ;
2007-09-18 19:00:23 +00:00
2008-12-08 05:08:31 +00:00
configChanged ( advancedChanged ) ;
2009-06-26 15:29:00 +00:00
// 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. " ) ) ;
2009-06-26 15:29:00 +00:00
m_showConfirmDialog = false ; // Dangerous but there is no way to test if failsafe mode
2011-01-30 14:34:42 +00:00
}
2009-06-26 15:29:00 +00:00
2011-01-30 14:34:42 +00:00
if ( m_showConfirmDialog ) {
2008-12-08 05:08:31 +00:00
m_showConfirmDialog = false ;
2012-04-30 20:08:42 +00:00
if ( advancedChanged )
QTimer : : singleShot ( 1000 , this , SLOT ( confirmReInit ( ) ) ) ;
else
showConfirmDialog ( false ) ;
2008-12-08 05:08:31 +00:00
}
2011-01-30 14:34:42 +00:00
}
2008-12-08 05:08:31 +00:00
2009-09-11 21:03:24 +00:00
void KWinCompositingConfig : : checkLoadedEffects ( )
2011-01-30 14:34:42 +00:00
{
2009-04-01 16:24:40 +00:00
// check for effects not supported by Backend or hardware
// such effects are enabled but not returned by DBus method loadedEffects
2012-12-29 23:15:30 +00:00
OrgKdeKWinInterface kwin ( " org.kde.KWin " , " /KWin " , QDBusConnection : : sessionBus ( ) ) ;
2011-01-30 14:34:42 +00:00
KConfigGroup effectConfig = KConfigGroup ( mKWinConfig , " Compositing " ) ;
2012-04-28 19:38:13 +00:00
bool enabledAfter = effectConfig . readEntry ( " Enabled " , true ) ;
2011-01-30 14:34:42 +00:00
2012-05-04 09:13:24 +00:00
QDBusPendingReply < QStringList > reply = kwin . loadedEffects ( ) ;
if ( ! reply . isError ( ) & & enabledAfter & & ! getenv ( " KDE_FAILSAFE " ) ) {
2011-01-30 14:34:42 +00:00
effectConfig = KConfigGroup ( mKWinConfig , " Plugins " ) ;
2012-05-04 09:13:24 +00:00
QStringList loadedEffects = reply . value ( ) ;
2009-04-01 16:24:40 +00:00
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 ) ) {
2009-04-01 16:24:40 +00:00
disabledEffects < < effect ;
}
2011-01-30 14:34:42 +00:00
}
if ( ! disabledEffects . isEmpty ( ) ) {
2012-05-04 09:13:24 +00:00
m_showDetailedErrors - > setData ( disabledEffects ) ;
2012-10-16 20:41:21 +00:00
foreach ( QWidget * w , m_showDetailedErrors - > associatedWidgets ( ) )
w - > setVisible ( true ) ;
2012-05-04 09:13:24 +00:00
ui . messageBox - > setText ( i18ncp ( " Error Message shown when a desktop effect could not be loaded " ,
2012-05-19 11:36:28 +00:00
" One desktop effect could not be loaded. " ,
" %1 desktop effects could not be loaded. " , disabledEffects . count ( ) ) ) ;
2012-05-04 09:13:24 +00:00
ui . messageBox - > animatedShow ( ) ;
2012-10-16 20:41:21 +00:00
} else {
foreach ( QWidget * w , m_showDetailedErrors - > associatedWidgets ( ) )
w - > setVisible ( false ) ;
2012-05-04 09:13:24 +00:00
}
}
}
void KWinCompositingConfig : : showDetailedEffectLoadingInformation ( )
{
QStringList disabledEffects = m_showDetailedErrors - > data ( ) . toStringList ( ) ;
2012-12-29 23:15:30 +00:00
OrgKdeKWinInterface kwin ( " org.kde.KWin " , " /KWin " , QDBusConnection : : sessionBus ( ) ) ;
2012-05-04 09:13:24 +00:00
QDBusPendingReply < QString > pendingCompositingType = kwin . compositingType ( ) ;
QString compositingType = pendingCompositingType . isError ( ) ? " none " : pendingCompositingType . value ( ) ;
KServiceTypeTrader * trader = KServiceTypeTrader : : self ( ) ;
KService : : List services ;
const KLocalizedString unknownReason = ki18nc ( " Effect with given name could not be activated due to unknown reason " ,
2012-05-19 11:36:28 +00:00
" %1 effect failed to load due to unknown reason. " ) ;
2012-05-04 09:13:24 +00:00
const KLocalizedString requiresShaders = ki18nc ( " Effect with given name could not be activated as it requires hardware shaders " ,
2012-05-19 11:36:28 +00:00
" %1 effect requires hardware support. " ) ;
2012-05-04 09:13:24 +00:00
const KLocalizedString requiresOpenGL = ki18nc ( " Effect with given name could not be activated as it requires OpenGL " ,
2012-05-19 11:36:28 +00:00
" %1 effect requires OpenGL. " ) ;
2012-05-04 09:13:24 +00:00
const KLocalizedString requiresOpenGL2 = ki18nc ( " Effect with given name could not be activated as it requires OpenGL 2 " ,
" %1 effect requires OpenGL 2. " ) ;
KDialog * dialog = new KDialog ( this ) ;
2012-05-19 11:36:28 +00:00
dialog - > setWindowTitle ( i18nc ( " Window title " , " List of effects which could not be loaded " ) ) ;
2012-05-04 09:13:24 +00:00
dialog - > setButtons ( KDialog : : Ok ) ;
QWidget * mainWidget = new QWidget ( dialog ) ;
dialog - > setMainWidget ( mainWidget ) ;
QVBoxLayout * vboxLayout = new QVBoxLayout ( mainWidget ) ;
mainWidget - > setLayout ( vboxLayout ) ;
KTitleWidget * titleWidget = new KTitleWidget ( mainWidget ) ;
titleWidget - > setText ( i18n ( " For technical reasons it is not possible to determine all possible error causes. " ) ,
KTitleWidget : : InfoMessage ) ;
QLabel * label = new QLabel ( mainWidget ) ;
label - > setOpenExternalLinks ( true ) ;
vboxLayout - > addWidget ( titleWidget ) ;
vboxLayout - > addWidget ( label ) ;
2012-10-16 20:41:21 +00:00
if ( ! m_externErrorDetails . isNull ( ) ) {
label - > setText ( m_externErrorDetails ) ;
} else if ( compositingType ! = " none " ) {
2012-05-04 09:13:24 +00:00
QString text ;
if ( disabledEffects . count ( ) > 1 ) {
text = " <ul> " ;
}
foreach ( const QString & effect , disabledEffects ) {
QString message ;
services = trader - > query ( " KWin/Effect " , " [X-KDE-PluginInfo-Name] == ' " + effect + ' \' ' ) ;
if ( ! services . isEmpty ( ) ) {
KService : : Ptr service = services . first ( ) ;
if ( compositingType = = " xrender " ) {
// XRender compositing
QVariant openGL = service - > property ( " X-KWin-Requires-OpenGL " ) ;
QVariant openGL2 = service - > property ( " X-KWin-Requires-OpenGL2 " ) ;
if ( ( openGL . isValid ( ) & & openGL . toBool ( ) ) | |
( openGL2 . isValid ( ) & & openGL2 . toBool ( ) ) ) {
// effect requires OpenGL
message = requiresOpenGL . subs ( service - > name ( ) ) . toString ( ) ;
} else {
// effect does not require OpenGL, unknown reason
message = unknownReason . subs ( service - > name ( ) ) . toString ( ) ;
}
} else if ( compositingType = = " gl1 " ) {
// OpenGL 1 compositing
QVariant openGL2 = service - > property ( " X-KWin-Requires-OpenGL2 " ) ;
QVariant shaders = service - > property ( " X-KWin-Requires-Shaders " ) ;
if ( openGL2 . isValid ( ) & & openGL2 . toBool ( ) ) {
// effect requires OpenGL 2
message = requiresOpenGL2 . subs ( service - > name ( ) ) . toString ( ) ;
} else if ( shaders . isValid ( ) & & shaders . toBool ( ) ) {
// effect requires hardware shaders
message = requiresShaders . subs ( service - > name ( ) ) . toString ( ) ;
} else {
// unknown reason
message = unknownReason . subs ( service - > name ( ) ) . toString ( ) ;
}
} else {
// OpenGL 2 compositing - unknown reason
message = unknownReason . subs ( service - > name ( ) ) . toString ( ) ;
}
} else {
message = unknownReason . subs ( effect ) . toString ( ) ;
2009-04-01 16:24:40 +00:00
}
2012-05-04 09:13:24 +00:00
if ( disabledEffects . count ( ) > 1 ) {
text . append ( " <li> " ) ;
text . append ( message ) ;
text . append ( " </li> " ) ;
} else {
text = message ;
}
}
if ( disabledEffects . count ( ) > 1 ) {
text . append ( " </ul> " ) ;
2009-04-01 16:24:40 +00:00
}
2012-05-04 09:13:24 +00:00
label - > setText ( text ) ;
} else {
// compositing is not active - no effect can be active
2012-05-19 11:36:28 +00:00
label - > setText ( i18nc ( " Error Message shown when compositing is not active after tried activation " ,
" Desktop effect system is not running. " ) ) ;
2009-09-11 21:03:24 +00:00
}
2012-05-04 09:13:24 +00:00
dialog - > show ( ) ;
2011-01-30 14:34:42 +00:00
}
2009-04-01 16:24:40 +00:00
2012-10-16 20:41:21 +00:00
void KWinCompositingConfig : : warn ( QString message , QString details , QString dontAgainKey )
{
ui . messageBox - > setText ( message ) ;
m_dontShowAgain - > setData ( dontAgainKey ) ;
foreach ( QWidget * w , m_dontShowAgain - > associatedWidgets ( ) )
w - > setVisible ( ! dontAgainKey . isEmpty ( ) ) ;
m_externErrorDetails = details . isNull ( ) ? " " : details ;
foreach ( QWidget * w , m_showDetailedErrors - > associatedWidgets ( ) )
w - > setVisible ( ! m_externErrorDetails . isEmpty ( ) ) ;
ui . messageBox - > animatedShow ( ) ;
}
void KWinCompositingConfig : : blockFutureWarnings ( ) {
QString key ;
if ( QAction * act = qobject_cast < QAction * > ( sender ( ) ) )
key = act - > data ( ) . toString ( ) ;
if ( key . isEmpty ( ) )
return ;
QStringList l = key . split ( ' : ' , QString : : SkipEmptyParts ) ;
KConfig cfg ( l . count ( ) > 1 ? l . at ( 0 ) : " kwin_dialogsrc " ) ;
KConfigGroup ( & cfg , " Notification Messages " ) . writeEntry ( l . last ( ) , false ) ;
cfg . sync ( ) ;
ui . messageBox - > animatedHide ( ) ;
}
2009-09-11 21:03:24 +00:00
void KWinCompositingConfig : : configChanged ( bool reinitCompositing )
2011-01-30 14:34:42 +00:00
{
2009-09-11 21:03:24 +00:00
// Send signal to kwin
mKWinConfig - > sync ( ) ;
2011-04-03 19:59:57 +00:00
2009-09-11 21:03:24 +00:00
// 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 " ) ;
2009-09-11 21:03:24 +00:00
QDBusConnection : : sessionBus ( ) . send ( message ) ;
2011-04-03 19:59:57 +00:00
// maybe it's ok now?
if ( reinitCompositing & & ! ui . compositingOptionsContainer - > isVisible ( ) )
load ( ) ;
2009-09-11 21:03:24 +00:00
// 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 )
2009-09-11 21:03:24 +00:00
QTimer : : singleShot ( 1000 , this , SLOT ( checkLoadedEffects ( ) ) ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
2008-12-08 05:08:31 +00:00
2007-07-19 16:20:05 +00:00
void KWinCompositingConfig : : defaults ( )
2011-01-30 14:34:42 +00:00
{
2008-07-20 12:59:23 +00:00
ui . tabWidget - > setCurrentIndex ( 0 ) ;
2012-04-28 19:38:13 +00:00
ui . useCompositing - > setChecked ( true ) ;
2007-07-21 20:54:50 +00:00
ui . effectWinManagement - > setChecked ( true ) ;
ui . effectAnimations - > setChecked ( true ) ;
2007-09-18 10:09:07 +00:00
2011-01-30 14:34:42 +00:00
ui . desktopSwitchingCombo - > setCurrentIndex ( 1 ) ;
ui . animationSpeedCombo - > setCurrentIndex ( 3 ) ;
2008-08-26 07:31:57 +00:00
2007-09-18 10:09:07 +00:00
ui . effectSelector - > defaults ( ) ;
2008-11-06 10:42:36 +00:00
2013-03-13 15:19:36 +00:00
ui . compositingType - > setCurrentIndex ( OPENGL20_INDEX ) ;
2011-01-30 14:34:42 +00:00
ui . windowThumbnails - > setCurrentIndex ( 1 ) ;
2011-05-15 07:40:19 +00:00
ui . unredirectFullscreen - > setChecked ( false ) ;
2011-01-30 14:34:42 +00:00
ui . xrScaleFilter - > setCurrentIndex ( 0 ) ;
ui . glScaleFilter - > setCurrentIndex ( 2 ) ;
2013-03-06 21:05:34 +00:00
ui . glSwapStrategy - > setCurrentIndex ( ui . glSwapStrategy - > findData ( " a " ) ) ;
2012-11-13 20:41:02 +00:00
ui . glColorCorrection - > setChecked ( false ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
QString KWinCompositingConfig : : quickHelp ( ) const
2011-01-30 14:34:42 +00:00
{
2007-07-21 20:54:50 +00:00
return i18n ( " <h1>Desktop Effects</h1> " ) ;
2011-01-30 14:34:42 +00:00
}
2007-07-19 16:20:05 +00:00
2012-10-26 11:08:00 +00:00
void KWinCompositingConfig : : slotGHNS ( )
{
QPointer < KNS3 : : DownloadDialog > downloadDialog = new KNS3 : : DownloadDialog ( " kwineffect.knsrc " , this ) ;
if ( downloadDialog - > exec ( ) = = KDialog : : Accepted ) {
if ( ! downloadDialog - > changedEntries ( ) . isEmpty ( ) ) {
initEffectSelector ( ) ;
}
}
delete downloadDialog ;
}
2008-11-06 10:42:36 +00:00
} // namespace
2008-11-25 01:45:09 +00:00
2012-10-16 20:41:21 +00:00
# include "dbus.moc"
2007-07-19 16:20:05 +00:00
# include "main.moc"