首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Xinerama的多种显示器的可能分辨率

使用Xinerama的多种显示器的可能分辨率
EN

Stack Overflow用户
提问于 2014-05-26 15:33:49
回答 1查看 451关注 0票数 0

我试着用辛纳麦和克伦特列出所有的展品。这就是应该这样做的代码:

代码语言:javascript
复制
int i, j, screenCount, sizeCount, eventBase, errorBase;
char displayName[64];
DIR *dir;
struct dirent *direntry;
XRRScreenSize *sizes;
XRRScreenConfiguration *screenConfig;
XineramaScreenInfo *xineramaInfo;
Display *disp;
Window root;

dir = opendir("/tmp/.X11-unix");
while((direntry = readdir(dir)) != NULL){
    if(direntry->d_name[0] != 'X'){
        continue;
    }
    snprintf(displayName, 64, ":%s", direntry->d_name + 1);
    disp = XOpenDisplay(displayName);
    if(disp != NULL){
        if(XineramaQueryExtension(disp, &eventBase, &errorBase) && XineramaIsActive(disp)){
            xineramaInfo = XineramaQueryScreens(disp, &screenCount);
        }else{
            break;
        }
        printf("Display %s has %d screens\n", displayName, screenCount);
        for(i = 0; i < screenCount; i++){
            root = RootWindow(disp, i);
            screenConfig = XRRGetScreenInfo(disp, root);
            sizes = XRRConfigSizes(screenConfig, &sizeCount);
            for(j = 0; j < sizeCount; j++){
                printf("%d x %d\n", sizes[j].width, sizes[j].height);
            }
        }
        XCloseDisplay(disp);
        XFree(xineramaInfo);
    }
}

但它会引发以下错误:

代码语言:javascript
复制
Display :0 has 3 screens
1680 x 1050
1600 x 1200
1280 x 1024
1024 x 768
832 x 624
800 x 600
640 x 480
720 x 400
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  5 (RRGetScreenInfo)
  Resource id in failed request:  0x18
  Serial number of failed request:  16
  Current serial number in output stream:  16

我的代码有问题吗?还是不能列出所有显示的所有分辨率?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-03 15:40:31

在长时间地查看了found的源代码之后,我找到了解决方案:

代码语言:javascript
复制
bool findResolutions(Display *display)
{
    int i, j, k, eventBase, errorBase;
    Window root;
    XRRScreenResources *resources;
    XRROutputInfo *outputInfo;

    if(!XineramaQueryExtension(display, &eventBase, &errorBase) || !XineramaIsActive(display)){
        printf("Xinerama not supported or active\n");
        return false;
    }

    root = RootWindow(display, 0);
    resources = XRRGetScreenResources(display, root);

    for(i = 0; i < resources->noutput; i++){
        outputInfo = XRRGetOutputInfo(display, resources, resources->outputs[i]);
        for(j = 0; j < outputInfo->nmode; j++){
            for(k = 0; k < resources->nmode; k++){
                if(outputInfo->modes[j] == resources->modes[k].id){
                    printf("%dx%d", resources->modes[k].width, resources->modes[k].height);
                    break;
                }
            }
        }

        XRRFreeOutputInfo(outputInfo);
    }

    XRRFreeScreenResources(resources);

    return true;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23873493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档