Add action to switch layouts

Allow users to trigger layout change with custom bindings.
This commit is contained in:
Kirill Chibisov
2023-11-02 00:09:31 +04:00
committed by Ivan Molodetskikh
parent 195ca80c39
commit eb7d20c638
3 changed files with 27 additions and 1 deletions
+8
View File
@@ -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; }
+7
View File
@@ -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.)]
+12 -1
View File
@@ -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