Extend switch-layout action to accept layout index (#1045)
Browse files at this commit2 changed files +15 -2
- niri-ipc/src/lib.rs +6 -1
- src/input/mod.rs +9 -1
niri-ipc/src/lib.rsmodified+6 -1
| @@ -668,6 +668,8 @@ pub enum LayoutSwitchTarget { | ||
| 668 | 668 | Next, |
| 669 | 669 | /// The previous configured layout. |
| 670 | 670 | Prev, |
| 671 | + /// The specific layout by index. | |
| 672 | + Index(u8), | |
| 671 | 673 | } |
| 672 | 674 | |
| 673 | 675 | /// Output actions that niri can perform. |
| @@ -1174,7 +1176,10 @@ impl FromStr for LayoutSwitchTarget { | ||
| 1174 | 1176 | match s { |
| 1175 | 1177 | "next" => Ok(Self::Next), |
| 1176 | 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 | 17 | TabletToolTipState, TouchEvent, |
| 18 | 18 | }; |
| 19 | 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 | 21 | use smithay::input::pointer::{ |
| 22 | 22 | AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent, |
| 23 | 23 | GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, |
| @@ -691,6 +691,14 @@ impl State { | ||
| 691 | 691 | keyboard.with_xkb_state(self, |mut state| match action { |
| 692 | 692 | LayoutSwitchTarget::Next => state.cycle_next_layout(), |
| 693 | 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 | 704 | Action::MoveColumnLeft => { |