X11rb DPMS Help

This might be a bit of a noobish question for here, so sorry if it's the wrong place for it. I'm working on a personal project and part of what I want to do is turn the screen on and off when I get certain events. I've got it working using std::command and running xset -display :0 dpms force off/on. I'd like to try to use x11rb to see if that's faster. When I use the code below nothing happens, but I don't get any errors, so I don't know why it's not working. I'm not too experienced at using x in code. If anyone knows, what I'm doing wrong, I'd really appreciate your help.

use x11rb::{self, protocol::dpms};

fn main() {
    let (conn, screen_num) = x11rb::connect(Some(":0")).unwrap();
    dpms::force_level(&conn, dpms::DPMSMode::OFF);

You can use the VoidCookie::check method to check for errors. This returns a Result, so you can either use unwrap() to print the error and panic, or you could match on the result if you want to do something else with it.

    let reply = dpms::force_level(&conn, dpms::DPMSMode::OFF).unwrap();

It looks like just checking the void cookie at all fixed the problem. Thanks for your help.

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.