How can I get the system resolution under(1920*1080) the linux os

How can I get the system resolution under the linux system, including mainstream distributions (fedora, ubuntu...): I know through searching information that I can call the api of linux: XDisplayWidth, but I don't know how to call it

The x11 crate has binding for the C API as x11::xlib::XDisplayWidth. See

1 Like

Thank you very much, does macos have a similar library

I don't know, I don't use mac. But if you have the name of a C library try searching for it on, most probably someone has already done the bindings.

1 Like


This function doesn't seem to be called because I can't get the parameters he needs

It needs a pointer to the Display and the screen number, as described here:

What exact error are you getting?

1 Like

With the xlib feature enabled for the x11 crate:

x11 = { version = "2.21.0", features = ["xlib"] }

this code works for me:

use x11::xlib::{XOpenDisplay, XDefaultScreen, XDisplayWidth};

fn main() {
    let d = unsafe { XOpenDisplay(std::ptr::null()) };
    let s = unsafe { XDefaultScreen(d) };
    let w = unsafe { XDisplayWidth(d, s) };

For something that deals with more than just raw pointers, and that is already cross-platform, the winit crate might work better for you.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.