rust-x-bindings / rust-xcb

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

Can't find XCB_KEY_PRESS #219

Closed chiehw closed 1 year ago

chiehw commented 1 year ago

I didn't find XCB_KEY_PRESS. e.g. https://github.com/awesomeWM/awesome/blob/b54e50ad6cfdcd864a21970b31378f7c64adf3f4/root.c#LL301C16-L301C29 , any suggestions?

rtbo commented 1 year ago

You have it with <x::KeyPressEvent as base::BaseEvent>::NUMBER. While this syntax is impractical, it is not normally not needed as you match events with their types:

fn main() -> xcb::Result<()> {
    // ...
    loop {
        match conn.wait_for_event()? {
            xcb::Event::X(x::Event::KeyPress(key_press)) => {
                // do stuff
            }
            xcb::Event::Xkb(xkb::Event::MapNotify(ev)) => {
                // do other stuff (pass data to xkbcommon for example)
            }
            _ => {}
        }
    }
}