X スクリーンではなく、モニター、つまり実際の物理デバイスのジオメトリに関心があると思います。
In that case, the root window is not what you are interested in. ここでは、基本的に 2 つの異なる点を考慮する必要があります。
あらゆる種類の詳細を照会する方法を学ぶには、これを行うプログラムを調べることをお勧めします。標準的な提案は、実際には Xinerama と RandR の両方をサポートする i3 ウィンドウ マネージャーなど、マルチヘッド セットアップをサポートするウィンドウ マネージャーであるため、両方のソース コードを確認できます。
お探しの情報は、 および にsrc/randr.c
ありsrc/xinerama.c
ます。必要な RandR API 呼び出しは次のとおりです。
xcb_randr_get_screen_resources_current
xcb_randr_get_screen_resources_current_outputs
xcb_randr_get_output_info
xcb_randr_get_crtc_info
後者は、出力の位置とサイズを含む出力の CRTC 情報を提供します。
RandR 実装の別のソースはxedgewarp:src/randr.c * です。そのソース コードからの大幅に短縮された抜粋をここに含めます。
xcb_randr_get_screen_resources_current_reply_t *reply = xcb_randr_get_screen_resources_current_reply(
connection, xcb_randr_get_screen_resources_current(connection, root), NULL);
xcb_timestamp_t timestamp = reply->config_timestamp;
int len = xcb_randr_get_screen_resources_current_outputs_length(reply);
xcb_randr_output_t *randr_outputs = xcb_randr_get_screen_resources_current_outputs(reply);
for (int i = 0; i < len; i++) {
xcb_randr_get_output_info_reply_t *output = xcb_randr_get_output_info_reply(
connection, xcb_randr_get_output_info(connection, randr_outputs[i], timestamp), NULL);
if (output == NULL)
continue;
if (output->crtc == XCB_NONE || output->connection == XCB_RANDR_CONNECTION_DISCONNECTED)
continue;
xcb_randr_get_crtc_info_reply_t *crtc = xcb_randr_get_crtc_info_reply(connection,
xcb_randr_get_crtc_info(connection, output->crtc, timestamp), NULL);
fprintf(stderr, "x = %d | y = %d | w = %d | h = %d\n",
crtc->x, crtc->y, crtc->width, crtc->height);
FREE(crtc);
FREE(output);
}
FREE(reply);
*) 免責事項: 私はそのツールの作成者です。
編集:情報を最新の状態に保つことに関心がある場合は、画面変更イベントをリッスンしてから出力を再度クエリする必要があることに注意してください。