c++ - 命令行 XRandR 和自己的代码之间的差异

标签 c++ c linux opensuse xrandr

我需要以编程方式获取显示器的刷新率。

当我在命令行输入xrandr(1.4.1,opensuse 13)时,我得到:

Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 16384 x 16384
VGA-0 disconnected primary (normal left inverted right x axis y axis)
DVI-D-0 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
   1920x1200      60.0*+
   1920x1080      60.0
   1680x1050      60.0
   1600x1200      60.0
   1280x1024      60.0
   1280x960       60.0
   1024x768       60.0
   800x600        60.3
   640x480        59.9
HDMI-0 disconnected (normal left inverted right x axis y axis)

此结果由 nvidia-settings -q RefreshRate 等确认。

可是…… 当我运行以下代码(来源:https://github.com/raboof/xrandr/blob/master/xrandr.c)时,使用 g++ 4.8.1(使用 -lX11 -lXext -lXrandr)编译:

int nsize;
int nrate;
short *rates;
XRRScreenSize *sizes;
Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);

XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root);
printf ("Current rate: %d\n",XRRConfigCurrentRate(conf));

sizes = XRRConfigSizes(conf, &nsize);
printf(" SZ:    Pixels          Refresh\n");
for (int i = 0; i < nsize; i++) {
    printf("%-2d %5d x %-5d", i, sizes[i].width, sizes[i].height);
    rates = XRRConfigRates(conf, i, &nrate);
    if (nrate)
        printf("  ");
    for (int j = 0; j < nrate; j++)
        printf("%-4d", rates[j]);
    printf("\n");
}

XRRFreeScreenConfigInfo(conf);

我得到:

Current rate: 50
SZ:    Pixels       Refresh
0   1920 x 1200   50
1   1920 x 1080   51
2   1680 x 1050   52
3   1600 x 1200   53
4   1280 x 1024   54
5   1280 x 960    55
6   1024 x 768    56
7    800 x 600    57
8    640 x 480    58
9   1440 x 900    59
10  1366 x 768    60
11  1280 x 800    61
12  1280 x 720    62

为什么我会得到这个结果? 我做错了什么?

该软件使用 OpenGL 和 GLEW。这有什么影响吗? 我们确实调用了 glXQueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &val) 但之后,我认为这不会有任何影响。

最佳答案

我找到了答案:

如果 XRandR 服务器支持协议(protocol)的 1.2 版,则需要使用适当的函数(我计划通过从 https://github.com/raboof/xrandr/blob/master/xrandr.c 复制代码片段来实现,其中 has_1_2/strong> 是真的)。​​

我在问题中的代码使用协议(protocol) 1.1 版的函数,因此仅返回元模式。

作为简单的检查,我尝试了以下两个命令:

xrandr --q1

xrandr --q12

事实上,第一个给我的结果与我以编程方式获得的结果相同。

学分转到http://www.ogre3d.org/forums/viewtopic.php?f=4&t=65010&start=200

关于c++ - 命令行 XRandR 和自己的代码之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37995551/

相关文章:

c++ - 为什么在 C++ 中键入 void main() 是不好的

c++ - 一个类似 DSL 的小型 lisp,可以编译成 C/C++ 代码——Antlr 是一个不错的选择吗?

python - 如何编写一个函数来接受 SWIG 中的 Fraction 对象?

c - 用C语言制作一个液晶屏定时器

C语言: buffer size, 为什么当输入超过缓冲区大小时仍然有效?

c - 宏计数参数

c++ - 将 apache 请求转发给 C++ 程序

linux - 为 OracleCloud 设置适用于 Linux 的 Cloudberry Backup

c++ - 如何在构造函数中初始化类类型的 vector

linux - Bash 脚本变量行为异常