Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to perform equivalent of shm::query_version(&conn) ? #15

Open
liftoff opened this issue Aug 31, 2017 · 0 comments
Open

How to perform equivalent of shm::query_version(&conn) ? #15

liftoff opened this issue Aug 31, 2017 · 0 comments

Comments

@liftoff
Copy link

liftoff commented Aug 31, 2017

I was very excited to find this project but alas it's too early for me to use! That's OK though: I'm willing to help but I'm just getting started with Tokio so I need a gentle shove in the right direction. How would I go about implementing the various 'query_version' functions present in the various X11 extensions?

For reference, here's how I'm currently doing it with the xcb crate:

if let Ok((conn, screen_num)) = xcb::Connection::connect(None) {
    let conn = Arc::new(conn);
    let cloned_conn = conn.clone();
    let setup = conn.get_setup();
    let screen = setup.roots().nth(screen_num as usize).unwrap();
    let root = screen.root();
    let fd: i32;
    unsafe {
        fd = xcb::ffi::base::xcb_get_file_descriptor(conn.get_raw_conn());
    }
    println!(
        "Connected to X on screen \"{}\" (XCB Socket FD: {:?})",
        screen_num,
        fd
    );
    println!("");
    println!("Informations of screen {}:", screen.root());
    println!("  width..........: {}", screen.width_in_pixels());
    println!("  height.........: {}", screen.height_in_pixels());
    let _first_ev = match conn.get_extension_data(shm::id()) {
        Some(r) => r.first_event(),
        None => {
            panic!("XKB extension not supported by X server!");
        }
    };
    {
        let cookie = shm::query_version(&conn);
        if let Ok(reply) = cookie.get_reply() {
            println!(
                "SHM Version: {}.{}",
                reply.major_version(),
                reply.minor_version()
            );
        } else {
            panic!("SHM extension not installed");
        }
    }
    // The DAMAGE extension doesn't seem to work right unless you query the version before start watching for damage:
    let damage_event = match conn.get_extension_data(damage::id()) {
        Some(r) => r.first_event(),
        None => {
            panic!("DAMAGE extension not supported by X server!");
        }
    };
    println!("Damage Event ID: {:?}", damage_event); // Was 91 when I tested it
    {
        let cookie = damage::query_version(&conn, damage::MAJOR_VERSION, damage::MINOR_VERSION);
        if let Ok(reply) = cookie.get_reply() {
            println!(
                "DAMAGE Version: {}.{}",
                reply.major_version(),
                reply.minor_version()
            );
        } else {
            panic!("DAMAGE extension not installed");
        }
    }
    damage_id = conn.generate_id();
    let report_level = damage::REPORT_LEVEL_RAW_RECTANGLES as u8; // Only report level that actually works!
    let _ = damage::create(&conn, damage_id, root, report_level); // Watch for damage on the root window
    let width = screen.width_in_pixels();
    let height = screen.height_in_pixels();
    // Setup our shared memory segment
    let image_size = width as u32 * height as u32 * 4;
    let seg = XCBSHMSegment::new(&conn, image_size as usize).unwrap();
}

Note: That's just a snippet of code (obviously).

I need to be able to query the versions of those extensions in order for the X11 server to start letting me do things with them (well, the DAMAGE extension works that way).

I'll also need to be able to automatically call functions/do things when DAMAGE events are detected (so I can take screenshots) but I'll settle for just querying the versions for now... Because I can probably implement those things for you (though maybe not we'll see).

Writing an XCB lib is usually more tedious than mental (I've done it before, haha) so even though I'm new to Rust I can still help out. Here's to hoping...

Can you give an example or point me in the right direction? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant