forge
Explore
Log in

Don't you dare go Hollow

Add action to switch layouts

Browse files at this commit

eb7d20c638e8912747ee21a4b8de95dd27bb7abaKirill ChibisovParent: 195ca80
Allow users to trigger layout change with custom bindings.
resources/default-config.kdlmodified+8 -0
@@ -230,6 +230,14 @@ binds {
230230 Mod+Shift+Minus { set-window-height "-10%"; }
231231 Mod+Shift+Equal { set-window-height "+10%"; }
232232
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+
233241 Print { screenshot; }
234242 Ctrl+Print { screenshot-screen; }
235243 Alt+Print { screenshot-window; }
src/config.rsmodified+7 -0
@@ -288,6 +288,7 @@ pub enum Action {
288288 SwitchPresetColumnWidth,
289289 MaximizeColumn,
290290 SetColumnWidth(#[knuffel(argument, str)] SizeChange),
291+ SwitchLayout(#[knuffel(argument)] LayoutAction),
291292 }
292293
293294 #[derive(Debug, Clone, Copy, PartialEq)]
@@ -298,6 +299,12 @@ pub enum SizeChange {
298299 AdjustProportion(f64),
299300 }
300301
302+#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)]
303+pub enum LayoutAction {
304+ Next,
305+ Prev,
306+}
307+
301308 #[derive(knuffel::Decode, Debug, PartialEq)]
302309 pub struct DebugConfig {
303310 #[knuffel(child, unwrap(argument), default = 1.)]
src/input.rsmodified+12 -1
@@ -17,7 +17,7 @@ use smithay::input::pointer::{
1717 use smithay::utils::SERIAL_COUNTER;
1818 use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait};
1919
20-use crate::config::{Action, Binds, Modifiers};
20+use crate::config::{Action, Binds, LayoutAction, Modifiers};
2121 use crate::niri::State;
2222 use crate::screenshot_ui::ScreenshotUi;
2323 use crate::utils::{center, get_monotonic_time, spawn};
@@ -90,6 +90,7 @@ impl State {
9090 | Action::ChangeVt(_)
9191 | Action::Suspend
9292 | Action::PowerOffMonitors
93+ | Action::SwitchLayout(_)
9394 )
9495 {
9596 return;
@@ -186,6 +187,16 @@ impl State {
186187 self.niri.layout.toggle_fullscreen(&window);
187188 }
188189 }
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+ }
189200 Action::MoveColumnLeft => {
190201 self.niri.layout.move_left();
191202 // FIXME: granular