x11/wayland: route modifier/led status change to window

refs: https://github.com/wez/wezterm/issues/3444
This commit is contained in:
Wez Furlong committed 2023-04-16 20:37:45 -07:00
1 parent 075388fbe5
commit f3ee5e57f0
4 files changed
+39 -5

No files matched your search

+11
View File
@@ -466,8 +466,19 @@ impl WaylandWindowInner {
..
} => {
mapper.update_modifier_state(mods_depressed, mods_latched, mods_locked, group);
let mods = mapper.get_key_modifiers();
let leds = mapper.get_led_status();
let changed = (mods != self.modifiers) || (leds != self.leds);
self.modifiers = mapper.get_key_modifiers();
self.leds = mapper.get_led_status();
if changed {
self.events
.dispatch(WindowEvent::AdviseModifiersLedStatus(mods, leds));
}
}
_ => {}
}
+12 -1
View File
@@ -507,7 +507,18 @@ impl XConnection {
// xkbcommon depends on those events in order to:
// - update modifiers state
// - update keymap/state on keyboard changes
self.keyboard.process_xkb_event(&self.conn, event)?;
if let Some((mods, leds)) = self.keyboard.process_xkb_event(&self.conn, event)? {
// route changed state to the window with focus
for window in self.windows.borrow().values() {
let mut window = window.lock().unwrap();
if window.has_focus == Some(true) {
window
.events
.dispatch(crate::WindowEvent::AdviseModifiersLedStatus(mods, leds));
break;
}
}
}
}
Ok(())
}
+14 -2
View File
@@ -21,6 +21,7 @@ pub struct Keyboard {
state: RefCell<xkb::State>,
compose_state: RefCell<Compose>,
phys_code_map: RefCell<HashMap<xkb::Keycode, PhysKeyCode>>,
mods_leds: RefCell<(Modifiers, KeyboardLedStatus)>,
}
struct Compose {
@@ -159,6 +160,7 @@ impl Keyboard {
composition: String::new(),
}),
phys_code_map: RefCell::new(phys_code_map),
mods_leds: RefCell::new(Default::default()),
})
}
@@ -223,6 +225,7 @@ impl Keyboard {
composition: String::new(),
}),
phys_code_map: RefCell::new(phys_code_map),
mods_leds: RefCell::new(Default::default()),
};
Ok((kbd, first_ev))
@@ -426,7 +429,9 @@ impl Keyboard {
&self,
connection: &xcb::Connection,
event: &xcb::Event,
) -> anyhow::Result<()> {
) -> anyhow::Result<Option<(Modifiers, KeyboardLedStatus)>> {
let before = self.mods_leds.borrow().clone();
match event {
xcb::Event::Xkb(xcb::xkb::Event::StateNotify(e)) => {
self.update_state(e);
@@ -438,7 +443,14 @@ impl Keyboard {
}
_ => {}
}
Ok(())
let after = (self.get_key_modifiers(), self.get_led_status());
if after != before {
*self.mods_leds.borrow_mut() = after.clone();
Ok(Some(after))
} else {
Ok(None)
}
}
pub fn update_modifier_state(
+2 -2
View File
@@ -59,7 +59,7 @@ impl CopyAndPaste {
pub(crate) struct XWindowInner {
pub window_id: xcb::x::Window,
conn: Weak<XConnection>,
events: WindowEventSender,
pub events: WindowEventSender,
width: u16,
height: u16,
last_wm_state: WindowState,
@@ -69,7 +69,7 @@ pub(crate) struct XWindowInner {
config: ConfigHandle,
appearance: Appearance,
title: String,
has_focus: Option<bool>,
pub has_focus: Option<bool>,
verify_focus: bool,
last_cursor_position: Rect,
invalidated: bool,