diff --git a/composite.cpp b/composite.cpp index 1944787f5b..4449bf2509 100644 --- a/composite.cpp +++ b/composite.cpp @@ -77,6 +77,8 @@ along with this program. If not, see . namespace KWin { +extern int currentRefreshRate(); + //**************************************** // Workspace //**************************************** @@ -195,30 +197,7 @@ void Workspace::setupCompositing() delete cm_selection; return; } - int rate = 0; - if( options->refreshRate > 0 ) - { // use manually configured refresh rate - rate = options->refreshRate; - } -#ifdef HAVE_XRANDR - else - { // autoconfigure refresh rate based on XRandR info - if( Extensions::randrAvailable() ) - { - XRRScreenConfiguration *config = XRRGetScreenInfo( display(), rootWindow() ); - rate = xrrRefreshRate = XRRConfigCurrentRate( config ); - XRRFreeScreenConfigInfo( config ); - } - } -#endif - // 0Hz or less is invalid, so we fallback to a default rate - if( rate <= 0 ) - rate = 50; - // QTimer gives us 1msec (1000Hz) at best, so we ignore anything higher; - // however, additional throttling prevents very high rates from taking place anyway - else if( rate > 1000 ) - rate = 1000; - kDebug( 1212 ) << "Refresh rate " << rate << "Hz"; + int rate = xrrRefreshRate = KWin::currentRefreshRate(); compositeRate = 1000 / rate; lastCompositePaint.start(); // fake a previous paint, so that the next starts right now diff --git a/events.cpp b/events.cpp index 2a92b496fe..81a6684be7 100644 --- a/events.cpp +++ b/events.cpp @@ -55,6 +55,8 @@ along with this program. If not, see . namespace KWin { +extern int currentRefreshRate(); + // **************************************** // WinInfo // **************************************** @@ -510,18 +512,16 @@ bool Workspace::workspaceEvent( XEvent * e ) { #ifdef HAVE_XRANDR XRRUpdateConfiguration( e ); +#endif if( compositing() ) { // desktopResized() should take care of when the size or // shape of the desktop has changed, but we also want to // catch refresh rate changes - XRRScreenConfiguration *config = XRRGetScreenInfo( display(), rootWindow() ); - bool changed = ( xrrRefreshRate != XRRConfigCurrentRate( config )); - XRRFreeScreenConfigInfo( config ); - if( changed ) + if( xrrRefreshRate != currentRefreshRate() ) compositeResetTimer.start( 0 ); } -#endif + } else if( e->type == Extensions::syncAlarmNotifyEvent() && Extensions::syncAvailable()) { diff --git a/options.cpp b/options.cpp index 4ec5e9316e..ae3e8db4c6 100644 --- a/options.cpp +++ b/options.cpp @@ -25,6 +25,7 @@ along with this program. If not, see . #include #include +#include #include #include #include @@ -37,6 +38,11 @@ along with this program. If not, see . #include +#ifdef HAVE_XRANDR +#include +#endif + + #endif namespace KWin @@ -44,6 +50,46 @@ namespace KWin #ifndef KCMRULES +static bool rrNvidia = false; +int currentRefreshRate() + { + int rate = -1; + if( options->refreshRate > 0 ) // use manually configured refresh rate + rate = options->refreshRate; + else if ( rrNvidia ) + { + QProcess nvidia_settings; + nvidia_settings.start( "nvidia-settings", QStringList() << "-t" << "-q" << "RefreshRate", QIODevice::ReadOnly ); + nvidia_settings.waitForFinished(); + if ( nvidia_settings.exitStatus() == QProcess::NormalExit ) + { + QString reply = QString::fromLocal8Bit( nvidia_settings.readAllStandardOutput() ); + bool ok; + rate = reply.split(' ').first().split(',').first().toUInt( &ok ); + if ( !ok ) + rate = -1; + } + } +#ifdef HAVE_XRANDR + else if( Extensions::randrAvailable() ) + { + XRRScreenConfiguration *config = XRRGetScreenInfo( display(), rootWindow() ); + rate = XRRConfigCurrentRate( config ); + XRRFreeScreenConfigInfo( config ); + } +#endif + + // 0Hz or less is invalid, so we fallback to a default rate + if( rate <= 0 ) + rate = 50; + // QTimer gives us 1msec (1000Hz) at best, so we ignore anything higher; + // however, additional throttling prevents very high rates from taking place anyway + else if( rate > 1000 ) + rate = 1000; + kDebug( 1212 ) << "Refresh rate " << rate << "Hz"; + return rate; + } + Options::Options() : electric_borders( 0 ) , electric_border_delay( 0 ) @@ -248,6 +294,7 @@ void Options::reloadCompositingSettings() // Compositing settings CompositingPrefs prefs; prefs.detect(); + rrNvidia = prefs.driver() == "nvidia"; useCompositing = config.readEntry( "Enabled" , prefs.recommendCompositing()); QString compositingBackend = config.readEntry("Backend", "OpenGL");