Skip to content

Commit

Permalink
Fix missing KeyboardLayoutSwitched event on XKB switch
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Sep 4, 2024
1 parent e5ecd27 commit 5460c79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
15 changes: 4 additions & 11 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use smithay::backend::input::{
TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,
};
use smithay::backend::libinput::LibinputInputBackend;
use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState, XkbContextHandler};
use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
use smithay::input::pointer::{
AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
Expand Down Expand Up @@ -540,17 +540,10 @@ impl State {
}
Action::SwitchLayout(action) => {
let keyboard = &self.niri.seat.get_keyboard().unwrap();
let new_idx = keyboard.with_xkb_state(self, |mut state| {
match action {
LayoutSwitchTarget::Next => state.cycle_next_layout(),
LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
};
state.active_layout().0
keyboard.with_xkb_state(self, |mut state| match action {
LayoutSwitchTarget::Next => state.cycle_next_layout(),
LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
});

if let Some(server) = &self.niri.ipc_server {
server.keyboard_layout_switched(new_idx as u8);
}
}
Action::MoveColumnLeft => {
self.niri.layout.move_left();
Expand Down
29 changes: 20 additions & 9 deletions src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ impl IpcServer {
let _ = stream.disconnect.send_blocking(());
}
}

pub fn keyboard_layout_switched(&self, new_idx: u8) {
let mut state = self.event_stream_state.borrow_mut();
let state = &mut state.keyboard_layouts;

let event = Event::KeyboardLayoutSwitched { idx: new_idx };
state.apply(event.clone());
self.send_event(event);
}
}

impl Drop for IpcServer {
Expand Down Expand Up @@ -413,6 +404,26 @@ impl State {
server.send_event(event);
}

pub fn ipc_refresh_keyboard_layout_index(&mut self) {
let keyboard = self.niri.seat.get_keyboard().unwrap();
let idx = keyboard.with_xkb_state(self, |context| context.active_layout().0 as u8);

let Some(server) = &self.niri.ipc_server else {
return;
};

let mut state = server.event_stream_state.borrow_mut();
let state = &mut state.keyboard_layouts;

if state.keyboard_layouts.as_ref().unwrap().current_idx == idx {
return;
}

let event = Event::KeyboardLayoutSwitched { idx };
state.apply(event.clone());
server.send_event(event);
}

pub fn ipc_refresh_layout(&mut self) {
self.ipc_refresh_workspaces();
self.ipc_refresh_windows();
Expand Down
5 changes: 1 addition & 4 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ impl State {
self.niri.refresh_window_rules();
self.refresh_ipc_outputs();
self.ipc_refresh_layout();
self.ipc_refresh_keyboard_layout_index();

#[cfg(feature = "xdp-gnome-screencast")]
self.niri.refresh_mapped_cast_outputs();
Expand Down Expand Up @@ -911,10 +912,6 @@ impl State {
keyboard.with_xkb_state(self, |mut context| {
context.set_layout(new_layout);
});

if let Some(server) = &self.niri.ipc_server {
server.keyboard_layout_switched(new_layout.0 as u8);
}
}
}

Expand Down

0 comments on commit 5460c79

Please sign in to comment.