rust-x-bindings / rust-xcb

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

Consider `impl Raw<xcb_generic_event_t> for Event` #188

Closed wez closed 2 years ago

wez commented 2 years ago

I'm excited to upgrade wezterm to the v1 API, but it's been a bit of a slog as wezterm also uses the xcb-util and xcb-imdkit crates. The latter needs to forward requests to XIM in order to allow the IME to process them. The underlying C API wants the generic events for this, so I'm faced with the arduous task of writing a function like this to extract it from the event:

fn raw_event(event: &Event) -> Option<*mut xcb::ffi::xcb_generic_event_t> {
    match event {
        Event::X(xcb::x::Event::KeyPress(e)) => Some(e.as_raw()),
        Event::X(xcb::x::Event::KeyRelease(e)) => Some(e.as_raw()),
        Event::X(xcb::x::Event::ButtonPress(e)) => Some(e.as_raw()),
        Event::X(xcb::x::Event::ButtonRelease(e)) => Some(e.as_raw()),
...

it's a bit problematic as the Event enum covers all possible event types, but the total set of enum variants varies depending on the features enabled in the xcb crate.

Could Raw<xcb_generic_event_t> be implemented on Event itself to avoid this?