[英]How to get the monitor number using X11
我认为对于这个数字,我们可以只在 XRRGetMonitors(..) 返回的列表中获取监视器信息结构的位置
#include <X11/Xlib.h>
#include <iostream>
#include <X11/extensions/Xrandr.h>
using namespace std;
int main()
{
int monitor_count = 0;
auto display = XOpenDisplay(NULL);
if (display == NULL)
{
cout << "Failed to open display!" << endl;
return -1;
}
auto wnd = XDefaultRootWindow(display);
// 0 = active, 1 = inactive, call it twice to get a full list, if there are
// inactive monitors
XRRMonitorInfo *info = XRRGetMonitors(display, wnd, 0, &monitor_count);
cout << "There are " << monitor_count << " monitor(s) in system." << endl;
int i = 0;
while (i < monitor_count)
{
cout << "Monitor " << i++ << " : " << XGetAtomName(display, info->name) << endl;
info++;
}
XCloseDisplay(display);
}
upd:不,这不是一个正确的例子,因为 XRRGetMonitors 在我的配置中没有显示非活动监视器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.