fn hardware_keycode_to_keyval(keycode: u16) -> Option<u32> {
    unsafe {
        let keymap = gdk_sys::gdk_keymap_get_default();

        let mut nkeys = 0;
        let mut keys: *mut gdk_sys::GdkKeymapKey = ptr::null_mut();
        let mut keyvals: *mut c_uint = ptr::null_mut();

        // call into gdk to retrieve the keyvals and keymap keys
        gdk_sys::gdk_keymap_get_entries_for_keycode(
            keymap,
            c_uint::from(keycode),
            &mut keys as *mut *mut gdk_sys::GdkKeymapKey,
            &mut keyvals as *mut *mut c_uint,
            &mut nkeys as *mut c_int,
        );

        if nkeys > 0 {
            let keyvals_slice = slice::from_raw_parts(keyvals, nkeys as usize);
            let keys_slice = slice::from_raw_parts(keys, nkeys as usize);

            let resolved_keyval = keys_slice.iter().enumerate().find_map(|(i, key)| {
                if key.group == 0 && key.level == 0 {
                    Some(keyvals_slice[i])
                } else {
                    None
                }
            });

            // notify glib to free the allocated arrays
            glib_sys::g_free(keyvals as *mut c_void);
            glib_sys::g_free(keys as *mut c_void);

            resolved_keyval
        } else {
            None
        }
    }
}
/// Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the
/// keyval with the lowest group and level
Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the
keyval with the lowest group and level
Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the keyval with the lowest group and level
fn hardware_keycode_to_keyval(keycode: u16) -> Option<u32> {
    unsafe {
        let keymap = gdk_sys::gdk_keymap_get_default();
        let mut nkeys = 0;
        let mut keys: *mut gdk_sys::GdkKeymapKey = ptr::null_mut();
        let mut keyvals: *mut c_uint = ptr::null_mut();
        // call into gdk to retrieve the keyvals and keymap keys
        gdk_sys::gdk_keymap_get_entries_for_keycode(
            keymap,
            c_uint::from(keycode),
            &mut keys as *mut *mut gdk_sys::GdkKeymapKey,
            &mut keyvals as *mut *mut c_uint,
            &mut nkeys as *mut c_int,
        );
        if nkeys > 0 {
            let keyvals_slice = slice::from_raw_parts(keyvals, nkeys as usize);
            let keys_slice = slice::from_raw_parts(keys, nkeys as usize);
            let resolved_keyval = keys_slice.iter().enumerate().find_map(|(i, key)| {
                if key.group == 0 && key.level == 0 {
                    Some(keyvals_slice[i])
                } else {
                    None
                }
            });
            // notify glib to free the allocated arrays
            glib_sys::g_free(keyvals as *mut c_void);
            glib_sys::g_free(keys as *mut c_void);
            resolved_keyval
        } else {
            None
        }
    }
}
fn hardware_keycode_to_keyval ( keycode : u16 ) -> Option < u32 > { unsafe { let keymap = gdk_sys :: gdk_keymap_get_default ( ) ; let mut nkeys = 0 ; let mut keys : * mut gdk_sys :: GdkKeymapKey = ptr :: null_mut ( ) ; let mut keyvals : * mut c_uint = ptr :: null_mut ( ) ; // call into gdk to retrieve the keyvals and keymap keys gdk_sys :: gdk_keymap_get_entries_for_keycode ( keymap , c_uint :: from ( keycode ) , & mut keys as * mut * mut gdk_sys :: GdkKeymapKey , & mut keyvals as * mut * mut c_uint , & mut nkeys as * mut c_int , ) ; if nkeys > 0 { let keyvals_slice = slice :: from_raw_parts ( keyvals , nkeys as usize ) ; let keys_slice = slice :: from_raw_parts ( keys , nkeys as usize ) ; let resolved_keyval = keys_slice . iter ( ) . enumerate ( ) . find_map ( | ( i , key ) | { if key . group == 0 && key . level == 0 { Some ( keyvals_slice [ i ] ) } else { None } } ) ; // notify glib to free the allocated arrays glib_sys :: g_free ( keyvals as * mut c_void ) ; glib_sys :: g_free ( keys as * mut c_void ) ; resolved_keyval } else { None } } }
Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the
keyval with the lowest group and level
Map a hardware keycode to a keyval by performing a lookup in the keymap and finding the keyval with the lowest group and level
keycode
u16
keycode
u16