2012-12-04 2 views
9

xrandr를 위해 예시적인 호출이다xrandr를, C 프로그래밍은 여기

 
$ xrandr --output LVDS --mode 1680x1050 --pos 0x0 --rotate normal --output S-video --off --output DVI-0 --mode 1024x768 --pos 1680x104 --rotate normal 

그 호출 성공을 가지는 시스템에 대해 생각해; 서로 다른 해상도로 작동하는 두 개의 화면 (LVDS 및 DVI-0)이 있습니다. DVI-0 하나가 가운데에 놓인 오른쪽에 있습니다.

C 프로그램에서이 모든 정보를 어떻게 얻을 수 있습니까? xrandr 소스 코드를 검사했지만 읽는 것이 어려워서 --pos 값을 쿼리 할 명백한 방법이 없다는 것을 알았습니다. (편집 : 평범한 광경에 감추어 져 있습니다.

나는 XGetWindowProperty로 _NET_WORKAREA를 물어볼 수 있지만, 내가 본 바로는 화면 위치를 알려주지 않고 모든 것을 포함하는 이상적인 사각형의 크기 만 알 수있다.

xrandr 코드에 대한 다른 연구가 있은 후이 코드는 한 단계 진전 된 것처럼 보입니다. 그러나 2950 줄 주변의 xrandr.c는 crtc_info를 사용할 수 없다고 생각합니다. 나는 여전히 해상도와 위치를 얻는 다른 방법을 놓친다.

 

    #include <stdio.h> 
    #include <X11/extensions/Xrandr.h> 

    int main() { 
     Display *disp; 
     XRRScreenResources *screen; 
     XRROutputInfo *info; 
     XRRCrtcInfo *crtc_info; 
     int iscres; 
     int icrtc; 

     disp = XOpenDisplay(0); 
     screen = XRRGetScreenResources (disp, DefaultRootWindow(disp)); 
     for (iscres = screen->noutput; iscres > 0;) { 
      --iscres; 

      info = XRRGetOutputInfo (disp, screen, screen->outputs[iscres]); 
      if (info->connection == RR_Connected) { 
       for (icrtc = info->ncrtc; icrtc > 0;) { 
        --icrtc; 

        crtc_info = XRRGetCrtcInfo (disp, screen, screen->crtcs[icrtc]); 
        fprintf(stderr, "==> %dx%d+%dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height); 

        XRRFreeCrtcInfo(crtc_info); 
       } 
      } 
      XRRFreeOutputInfo (info); 
     } 
     XRRFreeScreenResources(screen); 

     return 0; 
    } 

+0

안녕하세요 궁금 라이브러리를 링크 -lX11 -lXrandr 컴파일? 아니면 더 나은 방법을 찾았습니까? – yatg

+0

xrandr을 사용할 수없는 경우 xinerma와 combination을 사용하려고 생각했습니다. http://stackoverflow.com/a/836376/5062337 – yatg

답변

1

잘 모르겠는지 확실하지 않습니다.

xrandr -q
및 출력 구문 분석 :

첫 화면
LVDS connected 1680x1050+0+0 (normal left inverted right x axis y axis) 123mm x 123mm 
[...] 

TV_SVIDEO connected 1024x768+1680x104 (normal left inverted right x axis y axis) 123mm x 123mm 
[...] 

에 대한 가정, 당신은 X 서버의 현재 상태의 매개 변수를 읽어 다음과 같은 명령을 사용합니다 두번째. 명령을 실행하고이 C로 작성된 프로그램 내에서 수행 할 수 있습니다 구문 분석

당신이 수행하여 각각의 화면 해상도를 얻을 수 있습니다
+0

답장을 보내 주셔서 감사합니다. 위치 값은 해상도 근처에 있습니다. 적어도 xrandr 코드가 어떻게 결정하는지 확인할 수 있습니다. –

5

: 모니터와 crtc_info->x의 폭을 포함하는 crtc_info->width

Display *dpy; 
XRRScreenResources *screen; 
XRRCrtcInfo *crtc_info; 

dpy = XOpenDisplay(":0"); 
screen = XRRGetScreenResources (dpy, DefaultRootWindow(dpy)); 
//0 to get the first monitor 
crtc_info = XRRGetCrtcInfo (dpy, screen, screen->crtcs[0]);  

을 x 위치.

는 포함 잊지 말아 :

#include <X11/Xlib.h> 
#include <X11/extensions/Xrandr.h> 

을 당신이 당신의 코드를 오늘에 대한 확신한다면이