Add action to switch layouts
Browse files at this commiteb7d20c638e8912747ee21a4b8de95dd27bb7abaParent: 195ca803 changed files +27 -1
- resources/default-config.kdl +8 -0
- src/config.rs +7 -0
- src/input.rs +12 -1
resources/default-config.kdlmodified+8 -0
| @@ -230,6 +230,14 @@ binds { | ||
| 230 | 230 | Mod+Shift+Minus { set-window-height "-10%"; } |
| 231 | 231 | Mod+Shift+Equal { set-window-height "+10%"; } |
| 232 | 232 | |
| 233 | + // Actions to switch layouts. | |
| 234 | + // Note: if you uncomment these, make sure you do NOT have | |
| 235 | + // a matching layout switch hotkey configured in xkb options above. | |
| 236 | + // Having both at once on the same hotkey will break the switching, | |
| 237 | + // since it will switch twice upon pressing the hotkey (once by xkb, once by niri). | |
| 238 | + // Mod+Space { switch-layout "next"; } | |
| 239 | + // Mod+Shift+Space { switch-layout "prev"; } | |
| 240 | + | |
| 233 | 241 | Print { screenshot; } |
| 234 | 242 | Ctrl+Print { screenshot-screen; } |
| 235 | 243 | Alt+Print { screenshot-window; } |
src/config.rsmodified+7 -0
| @@ -288,6 +288,7 @@ pub enum Action { | ||
| 288 | 288 | SwitchPresetColumnWidth, |
| 289 | 289 | MaximizeColumn, |
| 290 | 290 | SetColumnWidth(#[knuffel(argument, str)] SizeChange), |
| 291 | + SwitchLayout(#[knuffel(argument)] LayoutAction), | |
| 291 | 292 | } |
| 292 | 293 | |
| 293 | 294 | #[derive(Debug, Clone, Copy, PartialEq)] |
| @@ -298,6 +299,12 @@ pub enum SizeChange { | ||
| 298 | 299 | AdjustProportion(f64), |
| 299 | 300 | } |
| 300 | 301 | |
| 302 | +#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)] | |
| 303 | +pub enum LayoutAction { | |
| 304 | + Next, | |
| 305 | + Prev, | |
| 306 | +} | |
| 307 | + | |
| 301 | 308 | #[derive(knuffel::Decode, Debug, PartialEq)] |
| 302 | 309 | pub struct DebugConfig { |
| 303 | 310 | #[knuffel(child, unwrap(argument), default = 1.)] |
src/input.rsmodified+12 -1
| @@ -17,7 +17,7 @@ use smithay::input::pointer::{ | ||
| 17 | 17 | use smithay::utils::SERIAL_COUNTER; |
| 18 | 18 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; |
| 19 | 19 | |
| 20 | -use crate::config::{Action, Binds, Modifiers}; | |
| 20 | +use crate::config::{Action, Binds, LayoutAction, Modifiers}; | |
| 21 | 21 | use crate::niri::State; |
| 22 | 22 | use crate::screenshot_ui::ScreenshotUi; |
| 23 | 23 | use crate::utils::{center, get_monotonic_time, spawn}; |
| @@ -90,6 +90,7 @@ impl State { | ||
| 90 | 90 | | Action::ChangeVt(_) |
| 91 | 91 | | Action::Suspend |
| 92 | 92 | | Action::PowerOffMonitors |
| 93 | + | Action::SwitchLayout(_) | |
| 93 | 94 | ) |
| 94 | 95 | { |
| 95 | 96 | return; |
| @@ -186,6 +187,16 @@ impl State { | ||
| 186 | 187 | self.niri.layout.toggle_fullscreen(&window); |
| 187 | 188 | } |
| 188 | 189 | } |
| 190 | + Action::SwitchLayout(action) => { | |
| 191 | + self.niri | |
| 192 | + .seat | |
| 193 | + .get_keyboard() | |
| 194 | + .unwrap() | |
| 195 | + .with_kkb_state(self, |mut state| match action { | |
| 196 | + LayoutAction::Next => state.cycle_next_layout(), | |
| 197 | + LayoutAction::Prev => state.cycle_prev_layout(), | |
| 198 | + }); | |
| 199 | + } | |
| 189 | 200 | Action::MoveColumnLeft => { |
| 190 | 201 | self.niri.layout.move_left(); |
| 191 | 202 | // FIXME: granular |