use x11rb::connection::Connection as _;
use x11rb::protocol::randr::ConnectionExt as _;
pub fn is_plain_x11() -> bool {
std::env::var_os("WAYLAND_DISPLAY").is_none() && std::env::var_os("DISPLAY").is_some()
}
pub fn has_xft_dpi() -> Option<bool> {
let (conn, _) = x11rb::connect(None).ok()?;
let db = x11rb::resource_manager::new_from_default(&conn).ok()?;
Some(db.get_string("Xft.dpi", "").is_some())
}
pub fn winit_monitor_rects() -> Option<Vec<(i32, i32, u32, u32)>> {
let (conn, screen) = x11rb::connect(None).ok()?;
let root = conn.setup().roots.get(screen)?.root;
let version = conn.randr_query_version(1, 3).ok()?.reply().ok()?;
let crtcs = if (version.major_version, version.minor_version) >= (1, 3) {
conn.randr_get_screen_resources_current(root)
.ok()?
.reply()
.ok()?
.crtcs
} else {
conn.randr_get_screen_resources(root)
.ok()?
.reply()
.ok()?
.crtcs
};
let mut rects = Vec::with_capacity(crtcs.len());
for crtc in crtcs {
let info = conn
.randr_get_crtc_info(crtc, x11rb::CURRENT_TIME)
.ok()?
.reply()
.ok()?;
if info.width == 0 || info.height == 0 || info.outputs.is_empty() {
continue;
}
rects.push((
i32::from(info.x),
i32::from(info.y),
u32::from(info.width),
u32::from(info.height),
));
}
Some(rects)
}