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 {
668 Next,668 Next,
669 /// The previous configured layout.669 /// The previous configured layout.
670 Prev,670 Prev,
671+ /// The specific layout by index.
672+ Index(u8),
671 }673 }
672 674
673 /// Output actions that niri can perform.675 /// Output actions that niri can perform.
@@ -1174,7 +1176,10 @@ impl FromStr for LayoutSwitchTarget {
1174 match s {1176 match s {
1175 "next" => Ok(Self::Next),1177 "next" => Ok(Self::Next),
1176 "prev" => Ok(Self::Prev),1178 "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+ },
1178 }1183 }
1179 }1184 }
1180 }1185 }
src/input/mod.rsmodified+9 -1
@@ -17,7 +17,7 @@ use smithay::backend::input::{
17 TabletToolTipState, TouchEvent,17 TabletToolTipState, TouchEvent,
18 };18 };
19 use smithay::backend::libinput::LibinputInputBackend;19 use smithay::backend::libinput::LibinputInputBackend;
20-use smithay::input::keyboard::{keysyms, FilterResult, Keysym, ModifiersState};20+use smithay::input::keyboard::{keysyms, FilterResult, Keysym, Layout, ModifiersState};
21 use smithay::input::pointer::{21 use smithay::input::pointer::{
22 AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,22 AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent,
23 GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,23 GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
@@ -691,6 +691,14 @@ impl State {
691 keyboard.with_xkb_state(self, |mut state| match action {691 keyboard.with_xkb_state(self, |mut state| match action {
692 LayoutSwitchTarget::Next => state.cycle_next_layout(),692 LayoutSwitchTarget::Next => state.cycle_next_layout(),
693 LayoutSwitchTarget::Prev => state.cycle_prev_layout(),693 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+ }
694 });702 });
695 }703 }
696 Action::MoveColumnLeft => {704 Action::MoveColumnLeft => {