xrandr の呼び出し例を次に示します。
$ xrandr --output LVDS --mode 1680x1050 --pos 0x0 --rotate normal --output S-video --off --output DVI-0 --mode 1024x768 --pos 1680x104 --rotate normal
その呼び出しが成功するシステムについて考えてみてください。異なる解像度で動作する 2 つの画面 (LVDS と DVI-0) があります。DVI-0 は中央に配置された右側にあります。
Cプログラムでこのすべての情報を取得するにはどうすればよいですか? xrandr ソースコードを確認しましたが、読みにくく、--pos 値を照会する明白な方法がありません (編集: ernesopheles の回答のおかげで、わかりにくく隠されています)。
XGetWindowProperty で _NET_WORKAREA を要求できることはわかっていますが、私が見た限りでは、画面の位置はわかりません。それらすべてを含む理想的な四角形のサイズだけです。
xrandr コードの他の調査の後、このコードは解決策の一歩前進のようです。それでも確信が持てません.2940行目あたりのxrandr.cは、crtc_infoが利用できない可能性があると想定しています。解像度と位置を取得する他の方法がまだ恋しいです。
#include <stdio.h>
#include <X11/extensions/Xrandr.h>
int main() {
表示 *disp;
XRRScreenResources *スクリーン;
XRROutputInfo *info;
XRRCrtcInfo *crtc_info;
int インクレス;
int icrtc;
disp = XOpenDisplay(0);
screen = XRRGetScreenResources (disp, DefaultRootWindow(disp));
for (iscres = screen->noutput; iscres > 0; ) {
--iscres;
info = XRRGetOutputInfo (disp, screen, screen->outputs[iscres]);
もし (情報 -> 接続 == 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 (情報);
}
XRRFreeScreenResources(スクリーン);
0 を返します。
}