Detect nvidia refresh rate using xvidmode
REVIEW: 104442
This commit is contained in:
parent
65819a0d68
commit
e89fc7333f
2 changed files with 49 additions and 14 deletions
|
@ -176,6 +176,13 @@ qt4_add_resources( kwin_KDEINIT_SRCS resources.qrc )
|
|||
|
||||
set(kwinLibs ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} kdeclarative kephal kworkspace kdecorations kwineffects ${X11_LIBRARIES} ${X11_Xrandr_LIB} ${X11_Xcomposite_LIB} ${X11_Xdamage_LIB} ${X11_Xrender_LIB} ${X11_Xfixes_LIB})
|
||||
|
||||
find_library(XF86VM_LIBRARY Xxf86vm)
|
||||
if (XF86VM_LIBRARY)
|
||||
set(kwinLibs ${kwinLibs} ${XF86VM_LIBRARY})
|
||||
else(XF86VM_LIBRARY)
|
||||
add_definitions(-DKWIN_NO_XF86VM)
|
||||
endif(XF86VM_LIBRARY)
|
||||
|
||||
if(KWIN_BUILD_SCRIPTING)
|
||||
set(kwinLibs ${kwinLibs} ${QT_QTSCRIPT_LIBRARY})
|
||||
endif(KWIN_BUILD_SCRIPTING)
|
||||
|
|
56
options.cpp
56
options.cpp
|
@ -42,8 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kephal/screens.h>
|
||||
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
||||
#ifndef KWIN_HAVE_OPENGLES
|
||||
#ifndef KWIN_NO_XF86VM
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //KCMRULES
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -57,17 +62,40 @@ int currentRefreshRate()
|
|||
rate = options->refreshRate();
|
||||
#ifndef KWIN_HAVE_OPENGLES
|
||||
else if (GLPlatform::instance()->driver() == Driver_NVidia) {
|
||||
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;
|
||||
const float frate = reply.split(' ').first().toFloat(&ok);
|
||||
if (!ok)
|
||||
rate = -1;
|
||||
else
|
||||
rate = qRound(frate);
|
||||
#ifndef KWIN_NO_XF86VM
|
||||
int major, event, error;
|
||||
if (XQueryExtension(display(), "XFree86-VidModeExtension", &major, &event, &error)) {
|
||||
XF86VidModeModeLine modeline;
|
||||
int dotclock, vtotal;
|
||||
if (XF86VidModeGetModeLine(display(), 0, &dotclock, &modeline)) {
|
||||
vtotal = modeline.vtotal;
|
||||
if (modeline.flags & 0x0010) // V_INTERLACE
|
||||
dotclock *= 2;
|
||||
if (modeline.flags & 0x0020) // V_DBLSCAN
|
||||
vtotal *= 2;
|
||||
rate = 1000*dotclock/(modeline.htotal*vtotal); // WTF was wikipedia 1998 when I nedded it?
|
||||
kDebug(1212) << "Vertical Refresh Rate (as detected by XF86VM): " << rate << "Hz";
|
||||
}
|
||||
}
|
||||
if (rate < 1)
|
||||
#endif
|
||||
{ // modeline approach failed
|
||||
QProcess nvidia_settings;
|
||||
QStringList env = QProcess::systemEnvironment();
|
||||
env << "LC_ALL=C";
|
||||
nvidia_settings.setEnvironment(env);
|
||||
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()).split(' ').first();
|
||||
bool ok;
|
||||
float frate = QLocale::c().toFloat(reply, &ok);
|
||||
if (!ok)
|
||||
rate = -1;
|
||||
else
|
||||
rate = qRound(frate);
|
||||
kDebug(1212) << "Vertical Refresh Rate (as detected by nvidia-settings): " << rate << "Hz";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -84,7 +112,7 @@ int currentRefreshRate()
|
|||
// however, additional throttling prevents very high rates from taking place anyway
|
||||
else if (rate > 1000)
|
||||
rate = 1000;
|
||||
kDebug(1212) << "Refresh rate " << rate << "Hz";
|
||||
kDebug(1212) << "Vertical Refresh rate " << rate << "Hz";
|
||||
return rate;
|
||||
}
|
||||
|
||||
|
@ -286,7 +314,7 @@ void Options::reloadCompositingSettings(bool force)
|
|||
if (!m_useCompositing)
|
||||
return; // not enforced or necessary and not "enabled" by setting
|
||||
|
||||
// from now on we've an initial setup and don't have to reload settigns on compositing activation
|
||||
// from now on we've an initial setup and don't have to reload settings on compositing activation
|
||||
// see Workspace::setupCompositing(), composite.cpp
|
||||
m_compositingInitialized = true;
|
||||
|
||||
|
|
Loading…
Reference in a new issue