diff options
| -rw-r--r-- | resources/default-config.kdl | 8 | ||||
| -rw-r--r-- | src/config.rs | 7 | ||||
| -rw-r--r-- | src/input.rs | 13 |
3 files changed, 27 insertions, 1 deletions
diff --git a/resources/default-config.kdl b/resources/default-config.kdl index 4878646c..cede85b5 100644 --- a/resources/default-config.kdl +++ b/resources/default-config.kdl @@ -230,6 +230,14 @@ binds { Mod+Shift+Minus { set-window-height "-10%"; } Mod+Shift+Equal { set-window-height "+10%"; } + // Actions to switch layouts. + // Note: if you uncomment these, make sure you do NOT have + // a matching layout switch hotkey configured in xkb options above. + // Having both at once on the same hotkey will break the switching, + // since it will switch twice upon pressing the hotkey (once by xkb, once by niri). + // Mod+Space { switch-layout "next"; } + // Mod+Shift+Space { switch-layout "prev"; } + Print { screenshot; } Ctrl+Print { screenshot-screen; } Alt+Print { screenshot-window; } diff --git a/src/config.rs b/src/config.rs index 1ad27ed7..ac1917bc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -288,6 +288,7 @@ pub enum Action { SwitchPresetColumnWidth, MaximizeColumn, SetColumnWidth(#[knuffel(argument, str)] SizeChange), + SwitchLayout(#[knuffel(argument)] LayoutAction), } #[derive(Debug, Clone, Copy, PartialEq)] @@ -298,6 +299,12 @@ pub enum SizeChange { AdjustProportion(f64), } +#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)] +pub enum LayoutAction { + Next, + Prev, +} + #[derive(knuffel::Decode, Debug, PartialEq)] pub struct DebugConfig { #[knuffel(child, unwrap(argument), default = 1.)] diff --git a/src/input.rs b/src/input.rs index b57c4c20..83f186fd 100644 --- a/src/input.rs +++ b/src/input.rs @@ -17,7 +17,7 @@ use smithay::input::pointer::{ use smithay::utils::SERIAL_COUNTER; use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; -use crate::config::{Action, Binds, Modifiers}; +use crate::config::{Action, Binds, LayoutAction, Modifiers}; use crate::niri::State; use crate::screenshot_ui::ScreenshotUi; use crate::utils::{center, get_monotonic_time, spawn}; @@ -90,6 +90,7 @@ impl State { | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors + | Action::SwitchLayout(_) ) { return; @@ -186,6 +187,16 @@ impl State { self.niri.layout.toggle_fullscreen(&window); } } + Action::SwitchLayout(action) => { + self.niri + .seat + .get_keyboard() + .unwrap() + .with_kkb_state(self, |mut state| match action { + LayoutAction::Next => state.cycle_next_layout(), + LayoutAction::Prev => state.cycle_prev_layout(), + }); + } Action::MoveColumnLeft => { self.niri.layout.move_left(); // FIXME: granular |
