Skip to content

Commit

Permalink
Use the currently active keyboard layout on X11
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKovacs committed Jul 4, 2021
1 parent 7b5a309 commit 9486ac0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/platform_impl/linux/common/xkb_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ impl KbState {
);
assert_ne!(keymap, ptr::null_mut());
self.xkb_keymap = keymap;

self.post_init(keymap);
self.xkb_state =
(XKBXH.xkb_x11_state_new_from_device)(keymap, self.xcb_connection, core_keyboard_id);
self.mods_state.update_with(self.xkb_state);
}

#[cfg(feature = "wayland")]
Expand Down Expand Up @@ -567,6 +568,14 @@ impl<'a> KeyEventResults<'a> {
None
};

// let key_text = state.keysym_to_utf8_raw(keysym);
// unsafe {
// let layout_id = (XKBH.xkb_state_serialize_layout)(state.xkb_state, xkb_state_component::XKB_STATE_LAYOUT_EFFECTIVE);
// let layout_name_cstr = (XKBH.xkb_keymap_layout_get_name)(state.xkb_keymap, layout_id);
// let layout_name = std::ffi::CStr::from_ptr(layout_name_cstr as *mut _);
// debug!("KeyEventResults::new {:?}, {:?}", key_text, layout_name);
// }

KeyEventResults {
state,
keycode,
Expand Down
18 changes: 17 additions & 1 deletion src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,23 @@ impl<T: 'static> EventProcessor<T> {
ffi::XkbStateNotify => {
let xev =
unsafe { &*(xev as *const _ as *const ffi::XkbStateNotifyEvent) };
if matches!(xev.event_type, 2 | 3) {
debug!(
"XkbStateNotify. group: {}, event_type: {}",
xev.group, xev.event_type
);
if xev.event_type == 0 {
// This probably indicates that the keyboard layout was switched.
// Let's update the groups (i.e. the layout)
self.kb_state.update_modifiers(
xev.base_mods,
xev.latched_mods,
xev.locked_mods,
xev.base_group as u32,
xev.latched_group as u32,
xev.locked_group as u32,
);
}
if matches!(xev.event_type as i32, ffi::KeyPress | ffi::KeyRelease) {
self.kb_state.update_modifiers(
xev.base_mods,
xev.latched_mods,
Expand Down

0 comments on commit 9486ac0

Please sign in to comment.