c++ - 在第二个监视器中显示图像的 C++ 列表屏幕
问题描述
我想在第二台显示器上显示图像。我在 Ubuntu 中有两个 1920x1080 像素的显示器连接并正确检测到。
我列出了带有以下代码的屏幕。问题是我总是只列出一个屏幕0:1920x1080 用于单显示器配置,3840x1080 用于多显示器(扩展或复制)。
如何获取两个显示器的列表以便仅选择 screen1(第二个显示器 1920x1080)?
Display *myDisplay = XOpenDisplay(NULL);
unsigned int numScreens = ScreenCount(myDisplay);
for(unsigned int i=0; i<numScreens; i++){
Screen *myScreen = ScreenOfDisplay(myDisplay, i);
ScreenInfo screen;
screen.resX = myScreen->width;
screen.resY = myScreen->height;
char screenName[50];
sprintf(screenName, "Screen number %d", i);
screen.name = screenName;
}
更新:这是我的 xrandr 输出,显示两个显示器正确连接,我可以相应地使用它。但是,如果我访问可用的显示器,我只能得到:0 一个屏幕,3840x1080。如何获得两个显示(:0和:1)?
vo@vo-ubuntu:~$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00*+ 60.00 50.00 50.00 59.94
1920x1080i 60.00 60.00 50.00 59.94
1600x1200 60.00
1680x1050 59.88
1400x1050 59.95
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1152x864 75.00
1280x720 60.00 60.00 50.00 59.94
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
720x576 50.00 50.00
720x576i 50.00 50.00
720x480 60.00 60.00 59.94 59.94 59.94
720x480i 60.00 60.00 59.94 59.94
640x480 75.00 72.81 66.67 60.00 59.94 59.94
720x400 70.08
HDMI-2 disconnected (normal left inverted right x axis y axis)
DP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00*+
1600x1200 60.00
1680x1050 59.95
1400x1050 59.98
1600x900 60.00
1280x1024 75.02 60.02
1440x900 59.89
1280x960 60.00
1152x864 75.00
1280x720 60.00
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
640x480 75.00 72.81 66.67 59.94
720x400 70.08
DVI-D-1-1 disconnected (normal left inverted right x axis y axis)
HDMI-1-3 disconnected (normal left inverted right x axis y axis)
DP-1-2 disconnected (normal left inverted right x axis y axis)
检查可用的 X 显示器不返回两个连接的显示器,
vo@vo-ubuntu:~$ cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done
:0
:1024
vo@vo-ubuntu:/tmp/.X11-unix$
解决方案
您可能需要查询 Xinerama,这可能会将您的显示器拼接在一起。
这个答案对我有用。我编译了他们的样本:
g++ xinerama.c `pkg-config --cflags --libs x11 xinerama` -o test
推荐阅读
- javascript - Primefaces 在 Javascript 中获取更新的 bean 属性
- excel - 循环遍历值并用它们过滤 VBA - 我需要知道如何
- python - Python + OpenCV 人脸识别
- php - 雄辩的 sortBy() 访问器不排序
- php - 在 Woocommerce 电子邮件模板中获取订单详细信息
- ionic3 - Ionic 3 (ion-datetime) 可以同时显示预分配的值和占位符吗?
- html - 日期字段显示远离该字段的日历
- python - ConverterError:TOCO 失败。有关信息,请参见控制台
- formatting - 有没有办法格式化 snmptrap?
- python - Tensorflow - 可训练变量不会随时间变化