Fix missing KeyboardLayoutSwitched event on XKB switch
Browse files at this commit5460c792bd4bde8f03e68446b6bb053501e368bbParent: e5ecd273 changed files +25 -24
- src/input/mod.rs +4 -11
- src/ipc/server.rs +20 -9
- src/niri.rs +1 -4
src/input/mod.rsmodified+4 -11
| @@ -16,7 +16,7 @@ use smithay::backend::input::{ | ||
| 16 | 16 | TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent, |
| 17 | 17 | }; |
| 18 | 18 | use smithay::backend::libinput::LibinputInputBackend; |
| 19 | -use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState, XkbContextHandler}; | |
| 19 | +use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState}; | |
| 20 | 20 | use smithay::input::pointer::{ |
| 21 | 21 | AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent, |
| 22 | 22 | GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, |
| @@ -540,17 +540,10 @@ impl State { | ||
| 540 | 540 | } |
| 541 | 541 | Action::SwitchLayout(action) => { |
| 542 | 542 | let keyboard = &self.niri.seat.get_keyboard().unwrap(); |
| 543 | - let new_idx = keyboard.with_xkb_state(self, |mut state| { | |
| 544 | - match action { | |
| 545 | - LayoutSwitchTarget::Next => state.cycle_next_layout(), | |
| 546 | - LayoutSwitchTarget::Prev => state.cycle_prev_layout(), | |
| 547 | - }; | |
| 548 | - state.active_layout().0 | |
| 543 | + keyboard.with_xkb_state(self, |mut state| match action { | |
| 544 | + LayoutSwitchTarget::Next => state.cycle_next_layout(), | |
| 545 | + LayoutSwitchTarget::Prev => state.cycle_prev_layout(), | |
| 549 | 546 | }); |
| 550 | - | |
| 551 | - if let Some(server) = &self.niri.ipc_server { | |
| 552 | - server.keyboard_layout_switched(new_idx as u8); | |
| 553 | - } | |
| 554 | 547 | } |
| 555 | 548 | Action::MoveColumnLeft => { |
| 556 | 549 | self.niri.layout.move_left(); |
src/ipc/server.rsmodified+20 -9
| @@ -116,15 +116,6 @@ impl IpcServer { | ||
| 116 | 116 | let _ = stream.disconnect.send_blocking(()); |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | - | |
| 120 | - pub fn keyboard_layout_switched(&self, new_idx: u8) { | |
| 121 | - let mut state = self.event_stream_state.borrow_mut(); | |
| 122 | - let state = &mut state.keyboard_layouts; | |
| 123 | - | |
| 124 | - let event = Event::KeyboardLayoutSwitched { idx: new_idx }; | |
| 125 | - state.apply(event.clone()); | |
| 126 | - self.send_event(event); | |
| 127 | - } | |
| 128 | 119 | } |
| 129 | 120 | |
| 130 | 121 | impl Drop for IpcServer { |
| @@ -413,6 +404,26 @@ impl State { | ||
| 413 | 404 | server.send_event(event); |
| 414 | 405 | } |
| 415 | 406 | |
| 407 | + pub fn ipc_refresh_keyboard_layout_index(&mut self) { | |
| 408 | + let keyboard = self.niri.seat.get_keyboard().unwrap(); | |
| 409 | + let idx = keyboard.with_xkb_state(self, |context| context.active_layout().0 as u8); | |
| 410 | + | |
| 411 | + let Some(server) = &self.niri.ipc_server else { | |
| 412 | + return; | |
| 413 | + }; | |
| 414 | + | |
| 415 | + let mut state = server.event_stream_state.borrow_mut(); | |
| 416 | + let state = &mut state.keyboard_layouts; | |
| 417 | + | |
| 418 | + if state.keyboard_layouts.as_ref().unwrap().current_idx == idx { | |
| 419 | + return; | |
| 420 | + } | |
| 421 | + | |
| 422 | + let event = Event::KeyboardLayoutSwitched { idx }; | |
| 423 | + state.apply(event.clone()); | |
| 424 | + server.send_event(event); | |
| 425 | + } | |
| 426 | + | |
| 416 | 427 | pub fn ipc_refresh_layout(&mut self) { |
| 417 | 428 | self.ipc_refresh_workspaces(); |
| 418 | 429 | self.ipc_refresh_windows(); |
src/niri.rsmodified+1 -4
| @@ -543,6 +543,7 @@ impl State { | ||
| 543 | 543 | self.niri.refresh_window_rules(); |
| 544 | 544 | self.refresh_ipc_outputs(); |
| 545 | 545 | self.ipc_refresh_layout(); |
| 546 | + self.ipc_refresh_keyboard_layout_index(); | |
| 546 | 547 | |
| 547 | 548 | #[cfg(feature = "xdp-gnome-screencast")] |
| 548 | 549 | self.niri.refresh_mapped_cast_outputs(); |
| @@ -911,10 +912,6 @@ impl State { | ||
| 911 | 912 | keyboard.with_xkb_state(self, |mut context| { |
| 912 | 913 | context.set_layout(new_layout); |
| 913 | 914 | }); |
| 914 | - | |
| 915 | - if let Some(server) = &self.niri.ipc_server { | |
| 916 | - server.keyboard_layout_switched(new_layout.0 as u8); | |
| 917 | - } | |
| 918 | 915 | } |
| 919 | 916 | } |
| 920 | 917 |