aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--niri-ipc/src/lib.rs7
-rw-r--r--src/input/mod.rs10
2 files changed, 15 insertions, 2 deletions
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs
index 44ef1d94..5d611c5a 100644
--- a/niri-ipc/src/lib.rs
+++ b/niri-ipc/src/lib.rs
@@ -668,6 +668,8 @@ pub enum LayoutSwitchTarget {
Next,
/// The previous configured layout.
Prev,
+ /// The specific layout by index.
+ Index(u8),
}
/// Output actions that niri can perform.
@@ -1174,7 +1176,10 @@ impl FromStr for LayoutSwitchTarget {
match s {
"next" => Ok(Self::Next),
"prev" => Ok(Self::Prev),
- _ => Err(r#"invalid layout action, can be "next" or "prev""#),
+ other => match other.parse() {
+ Ok(layout) => Ok(Self::Index(layout)),
+ _ => Err(r#"invalid layout action, can be "next", "prev" or a layout index"#),
+ },
}
}
}
diff --git a/src/input/mod.rs b/src/input/mod.rs
index c2691739..2604fd72 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -17,7 +17,7 @@ use smithay::backend::input::{
TabletToolTipState, TouchEvent,
};
use smithay::backend::libinput::LibinputInputBackend;
-use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
+use smithay::input::keyboard::{keysyms, FilterResult, Keysym, Layout, ModifiersState};
use smithay::input::pointer::{
AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
@@ -691,6 +691,14 @@ impl State {
keyboard.with_xkb_state(self, |mut state| match action {
LayoutSwitchTarget::Next => state.cycle_next_layout(),
LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
+ LayoutSwitchTarget::Index(layout) => {
+ let num_layouts = state.xkb().lock().unwrap().layouts().count();
+ if usize::from(layout) >= num_layouts {
+ warn!("requested layout doesn't exist")
+ } else {
+ state.set_layout(Layout(layout.into()))
+ }
+ }
});
}
Action::MoveColumnLeft => {