我試圖找到所有監視器和它們的座標(寬度w
,高度h
,x原點/左上角最x
和y原點/左上角最y
),並使用此代碼,它在一些系統上運行良好。但在其他系統上,我得到錯誤和重複的條目。如果我測試顯示器是否鏡像,我是否能夠避免這些重複/虛假的顯示器條目?如何測試它的鏡像?X11 - Xrandr給我假監視器
所以這是我的代碼:
// start - get all monitor resolutions
var screen = XRRGetScreenResources(getXOpenDisplay(), getDefaultRootWindow(getXOpenDisplay()));
var noutputs = screen.noutput;
for (var i=noutputs-1; i>=0; i--) {
var info = XRRGetOutputInfo(getXOpenDisplay(), screen, screen.outputs[i]);
if (info.connection == RR_Connected) {
var ncrtcs = info.ncrtc;
for (var j=ncrtcs-1; j>=0; j--) {
var crtc_info = XRRGetCrtcInfo(getXOpenDisplay(), screen, infoCrtcs[j]);
console.info('screen #' + i + ' mon#' + j + ' details:', crtc_info.x, crtc_info.y, crtc_info.width, crtc_info.height);
collMonInfos.push({
x: crtc_info.x,
y: crtc_info.y,
w: crtc_info.width,
h: crtc_info.height
});
XRRFreeCrtcInfo(crtc_info);
}
}
XRRFreeOutputInfo(info);
}
XRRFreeScreenResources(screen);
console.info('JSON:', JSON.stringify(collMonInfos));
// end - get all monitor resolutions
而這個輸出到日誌:
"screen #4 mon#0 details:" 0 0 0 0
"screen #3 mon#1 details:" 0 0 1920 1200
"screen #3 mon#0 details:" 1920 469 1366 768
"screen #2 mon#1 details:" 0 0 1920 1200
"screen #2 mon#0 details:" 1920 469 1366 768
"screen #1 mon#1 details:" 0 0 1920 1200
"screen #1 mon#0 details:" 1920 469 1366 768
"screen #0 mon#1 details:" 0 0 1920 1200
"screen #0 mon#0 details:" 1920 469 1366 768
這是它的JSON格式:
[{
"x": 0,
"y": 0,
"w": 0,
"h": 0
}, {
"x": 0,
"y": 0,
"w": 1920,
"h": 1200
}, {
"x": 1920,
"y": 469,
"w": 1366,
"h": 768
}, {
"x": 0,
"y": 0,
"w": 1920,
"h": 1200
}, {
"x": 1920,
"y": 469,
"w": 1366,
"h": 768
}, {
"x": 0,
"y": 0,
"w": 1920,
"h": 1200
}, {
"x": 1920,
"y": 469,
"w": 1366,
"h": 768
}, {
"x": 0,
"y": 0,
"w": 1920,
"h": 1200
}, {
"x": 1920,
"y": 469,
"w": 1366,
"h": 768
}]
我真的只有2顯示器,1920x1200一個和1366x768一個。如何進行所有其他條目以及如何測試以避免(而不是基於重複或0 h/w的回溯過濾掉)?
爲什麼你用'c'標記? – nsilent22
可能是虛擬桌面? – fassl
Thanks @fassl我正在考慮類似的問題,並且想知道如何使它變得不同,然後在最後通過它們去掉所有重複項或者刪除重複項或者任何W/h爲0的東西。 – yatg