rust-x-bindings / rust-xcb

Rust bindings and wrapper for XCB.
MIT License
165 stars 64 forks source link

Correct way to get the screen's refresh rate? #75

Closed crsaracco closed 4 years ago

crsaracco commented 4 years ago

I'm attempting to get the refresh rate of the screen, similar to the info that xrandr gives you.

Here's what I have so far (not final API for what I'm doing, but good enough to post here):

fn refresh_rate(&self) {
    let conn = Application::get_connection();

    let cookie = xcb::randr::get_screen_info(&conn, self.window_id);
    let reply = cookie.get_reply().unwrap();

    let rates = reply.rates();
    for (i, rate) in rates.enumerate() {
        println!("{:?}", rate.rates());
    }
}

That println gives me [50], but xrandr is giving me 60.00.

Questions:

Thanks!

rtbo commented 4 years ago

Hi, What I get with get_screen_info.rates seems completely erratic (thousands of fields, most of them are zero ?? could be a bug here...). This is not the right way to do.

Looking at the source of xrandr, the refresh rate is obtained from randr::get_screen_resources, then modes. The actual rate is calculated by mode_refresh