以编程方式确定Linux中的单个屏幕宽度/高度(带有Xinerama,TwinView和/或BigDesktop) [英] Programmatically determining individual screen widths/heights in Linux (w/Xinerama, TwinView, and/or BigDesktop)

查看:144
本文介绍了以编程方式确定Linux中的单个屏幕宽度/高度(带有Xinerama,TwinView和/或BigDesktop)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小项目,以在GNOME下在多个屏幕上显示多个墙纸(这显然是GNOME本身或其他任何事情都无法完成的).我已经弄清楚了如何做主要部分(出于好奇,使用了ImageMagick组件).我正在尝试使配置系统自动化.

I'm developing a little side-project to display multiple wallpapers on multiple screens under GNOME (something that apparently can't be done by GNOME itself or anything else). I've figured out how to do the main part of it (using the ImageMagick components, for the curious); I'm trying to automate the configuration system.

为此,我需要一种确定各个屏幕尺寸的方法.谁能给我一个在哪里找的提示?我认为X服务器本身具有该信息,但是我不确定我的程序如何要求它.

To do that, I need a way to determine the dimensions of the individual screens are. Can anyone give me a hint where to look for that? I presume the X server itself has the information, but I'm not sure how my program can ask for it.

推荐答案

似乎有一个libXinerama API可以检索该信息.我还没有找到任何详细的信息.

It looks like there's a libXinerama API that can retrieve that information. I haven't found any detailed information on it yet though.

可以在这里(PDF文件).可以在此处找到有关libXinerama提供的功能的信息. (联机帮助页的副本,其中没有很多信息.)

General X.org programming information can be found here (PDF file). Information on the functions provided by libXinerama can be found here (online copy of a manpage, not a lot of information in it).

这是一个小的C ++程序,我从那些引用中提取了这些代码,以检索连接到Xinerama的每个监视器的尺寸和偏移.它也适用于nVidia TwinView.我目前没有ATI卡在其BigDesktop系统上进行测试,但我怀疑它也可以在其上运行.

Here's a small C++ program that I whipped up from those references to retrieve the dimensions and offsets of each of the monitors hooked into Xinerama. It also works for nVidia TwinView; I don't presently have an ATI card to test it on their BigDesktop system, but I suspect it would work on it as well.

#include <cstdlib>
#include <iostream>

#include <X11/extensions/Xinerama.h>

using std::cout;
using std::endl;

int main(int argc, char *argv[]) {
    bool success=false;
    Display *d=XOpenDisplay(NULL);
    if (d) {
        int dummy1, dummy2;
        if (XineramaQueryExtension(d, &dummy1, &dummy2)) {
            if (XineramaIsActive(d)) {
                int heads=0;
                XineramaScreenInfo *p=XineramaQueryScreens(d, &heads);
                if (heads>0) {
                    for (int x=0; x<heads; ++x)
                        cout << "Head " << x+1 << " of " << heads << ": " <<
                            p[x].width << "x" << p[x].height << " at " <<
                            p[x].x_org << "," << p[x].y_org << endl;
                    success=true;
                } else cout << "XineramaQueryScreens says there aren't any" << endl;
                XFree(p);
            } else cout << "Xinerama not active" << endl;
        } else cout << "No Xinerama extension" << endl;
        XCloseDisplay(d);
    } else cout << "Can't open display" << endl;

    return (success ? EXIT_SUCCESS : EXIT_FAILURE);
}

这篇关于以编程方式确定Linux中的单个屏幕宽度/高度(带有Xinerama,TwinView和/或BigDesktop)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆