forge
Explore
Log in

Don't you dare go Hollow

Extend switch-layout action to accept layout index (#1045)

Browse files at this commit

baa051891237054f2d4db86d7bcfe0f17440c35fUnverifiedEvgeny Zemtsov and Ivan MolodetskikhParent: d665079
* Extend switch-layout action to accept layout index

* Update src/input/mod.rs

---------
niri-ipc/src/lib.rsmodified+6 -1
@@ -668,6 +668,8 @@ pub enum LayoutSwitchTarget {
668668 Next,
669669 /// The previous configured layout.
670670 Prev,
671+ /// The specific layout by index.
672+ Index(u8),
671673 }
672674
673675 /// Output actions that niri can perform.
@@ -1174,7 +1176,10 @@ impl FromStr for LayoutSwitchTarget {
11741176 match s {
11751177 "next" => Ok(Self::Next),
11761178 "prev" => Ok(Self::Prev),
1177- _ => Err(r#"invalid layout action, can be "next" or "prev""#),
1179+ other => match other.parse() {
1180+ Ok(layout) => Ok(Self::Index(layout)),
1181+ _ => Err(r#"invalid layout action, can be "next", "prev" or a layout index"#),
1182+ },
11781183 }
11791184 }
11801185 }
src/input/mod.rsmodified+9 -1
@@ -17,7 +17,7 @@ use smithay::backend::input::{
1717 TabletToolTipState, TouchEvent,
1818 };
1919 use smithay::backend::libinput::LibinputInputBackend;
20-use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};
20+use smithay::input::keyboard::{keysyms, FilterResult, Keysym, Layout, ModifiersState};
2121 use smithay::input::pointer::{
2222 AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
2323 GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
@@ -691,6 +691,14 @@ impl State {
691691 keyboard.with_xkb_state(self, |mut state| match action {
692692 LayoutSwitchTarget::Next => state.cycle_next_layout(),
693693 LayoutSwitchTarget::Prev => state.cycle_prev_layout(),
694+ LayoutSwitchTarget::Index(layout) => {
695+ let num_layouts = state.xkb().lock().unwrap().layouts().count();
696+ if usize::from(layout) >= num_layouts {
697+ warn!("requested layout doesn't exist")
698+ } else {
699+ state.set_layout(Layout(layout.into()))
700+ }
701+ }
694702 });
695703 }
696704 Action::MoveColumnLeft => {