forge
Explore
Log in

Don't you dare go Hollow

Fix missing KeyboardLayoutSwitched event on XKB switch

Browse files at this commit

5460c792bd4bde8f03e68446b6bb053501e368bbIvan MolodetskikhParent: e5ecd27
src/input/mod.rsmodified+4 -11
@@ -16,7 +16,7 @@ use smithay::backend::input::{
1616 TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,
1717 };
1818 use smithay::backend::libinput::LibinputInputBackend;
19-use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState, XkbContextHandler};
19+use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
2020 use smithay::input::pointer::{
2121 AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
2222 GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
@@ -540,17 +540,10 @@ impl State {
540540 }
541541 Action::SwitchLayout(action) => {
542542 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(),
549546 });
550-
551- if let Some(server) = &self.niri.ipc_server {
552- server.keyboard_layout_switched(new_idx as u8);
553- }
554547 }
555548 Action::MoveColumnLeft => {
556549 self.niri.layout.move_left();
src/ipc/server.rsmodified+20 -9
@@ -116,15 +116,6 @@ impl IpcServer {
116116 let _ = stream.disconnect.send_blocking(());
117117 }
118118 }
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- }
128119 }
129120
130121 impl Drop for IpcServer {
@@ -413,6 +404,26 @@ impl State {
413404 server.send_event(event);
414405 }
415406
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+
416427 pub fn ipc_refresh_layout(&mut self) {
417428 self.ipc_refresh_workspaces();
418429 self.ipc_refresh_windows();
src/niri.rsmodified+1 -4
@@ -543,6 +543,7 @@ impl State {
543543 self.niri.refresh_window_rules();
544544 self.refresh_ipc_outputs();
545545 self.ipc_refresh_layout();
546+ self.ipc_refresh_keyboard_layout_index();
546547
547548 #[cfg(feature = "xdp-gnome-screencast")]
548549 self.niri.refresh_mapped_cast_outputs();
@@ -911,10 +912,6 @@ impl State {
911912 keyboard.with_xkb_state(self, |mut context| {
912913 context.set_layout(new_layout);
913914 });
914-
915- if let Some(server) = &self.niri.ipc_server {
916- server.keyboard_layout_switched(new_layout.0 as u8);
917- }
918915 }
919916 }
920917