mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Correctly handle parsing of Binds and DefaultColumnWidth (#234)
* add dev dependencies to flake * parse only one default-column-width * require exactly one action per bind, and unique keys for binds * use proper filename for config errors if possible * fix duplicate keybinds after invalid action, lose some sanity
This commit is contained in:
@@ -81,7 +81,7 @@ pub fn resolve_window_rules(
|
||||
if let Some(x) = rule
|
||||
.default_column_width
|
||||
.as_ref()
|
||||
.map(|d| d.0.first().copied().map(ColumnWidth::from))
|
||||
.map(|d| d.0.map(ColumnWidth::from))
|
||||
{
|
||||
resolved.default_width = Some(x);
|
||||
}
|
||||
|
||||
+7
-7
@@ -1650,7 +1650,7 @@ fn bound_action(
|
||||
}
|
||||
|
||||
if bind_modifiers == modifiers {
|
||||
return bind.actions.first().cloned();
|
||||
return Some(bind.action.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1815,7 +1815,7 @@ mod tests {
|
||||
keysym: close_keysym,
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
|
||||
},
|
||||
actions: vec![Action::CloseWindow],
|
||||
action: Action::CloseWindow,
|
||||
}]);
|
||||
|
||||
let comp_mod = CompositorMod::Super;
|
||||
@@ -1937,35 +1937,35 @@ mod tests {
|
||||
keysym: Keysym::q,
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
actions: vec![Action::CloseWindow],
|
||||
action: Action::CloseWindow,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
keysym: Keysym::h,
|
||||
modifiers: Modifiers::SUPER,
|
||||
},
|
||||
actions: vec![Action::FocusColumnLeft],
|
||||
action: Action::FocusColumnLeft,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
keysym: Keysym::j,
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
actions: vec![Action::FocusWindowDown],
|
||||
action: Action::FocusWindowDown,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
keysym: Keysym::k,
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
|
||||
},
|
||||
actions: vec![Action::FocusWindowUp],
|
||||
action: Action::FocusWindowUp,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
keysym: Keysym::l,
|
||||
modifiers: Modifiers::SUPER | Modifiers::ALT,
|
||||
},
|
||||
actions: vec![Action::FocusColumnRight],
|
||||
action: Action::FocusColumnRight,
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
+1
-1
@@ -200,7 +200,7 @@ impl Options {
|
||||
let default_width = layout
|
||||
.default_column_width
|
||||
.as_ref()
|
||||
.map(|w| w.0.first().copied().map(ColumnWidth::from))
|
||||
.map(|w| w.0.map(ColumnWidth::from))
|
||||
.unwrap_or(Some(ColumnWidth::Proportion(0.5)));
|
||||
|
||||
Self {
|
||||
|
||||
+10
-19
@@ -159,15 +159,9 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
|
||||
|
||||
// Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to
|
||||
// Quit(false).
|
||||
if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::Quit(false)))
|
||||
{
|
||||
if binds.iter().any(|bind| bind.action == Action::Quit(false)) {
|
||||
actions.push(&Action::Quit(false));
|
||||
} else if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::Quit(true)))
|
||||
{
|
||||
} else if binds.iter().any(|bind| bind.action == Action::Quit(true)) {
|
||||
actions.push(&Action::Quit(true));
|
||||
} else {
|
||||
actions.push(&Action::Quit(false));
|
||||
@@ -186,12 +180,12 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
|
||||
// Prefer move-column-to-workspace-down, but fall back to move-window-to-workspace-down.
|
||||
if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::MoveColumnToWorkspaceDown))
|
||||
.any(|bind| bind.action == Action::MoveColumnToWorkspaceDown)
|
||||
{
|
||||
actions.push(&Action::MoveColumnToWorkspaceDown);
|
||||
} else if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::MoveWindowToWorkspaceDown))
|
||||
.any(|bind| bind.action == Action::MoveWindowToWorkspaceDown)
|
||||
{
|
||||
actions.push(&Action::MoveWindowToWorkspaceDown);
|
||||
} else {
|
||||
@@ -201,12 +195,12 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
|
||||
// Same for -up.
|
||||
if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::MoveColumnToWorkspaceUp))
|
||||
.any(|bind| bind.action == Action::MoveColumnToWorkspaceUp)
|
||||
{
|
||||
actions.push(&Action::MoveColumnToWorkspaceUp);
|
||||
} else if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::MoveWindowToWorkspaceUp))
|
||||
.any(|bind| bind.action == Action::MoveWindowToWorkspaceUp)
|
||||
{
|
||||
actions.push(&Action::MoveWindowToWorkspaceUp);
|
||||
} else {
|
||||
@@ -221,22 +215,19 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
|
||||
]);
|
||||
|
||||
// Screenshot is not as important, can omit if not bound.
|
||||
if binds
|
||||
.iter()
|
||||
.any(|bind| bind.actions.first() == Some(&Action::Screenshot))
|
||||
{
|
||||
if binds.iter().any(|bind| bind.action == Action::Screenshot) {
|
||||
actions.push(&Action::Screenshot);
|
||||
}
|
||||
|
||||
// Add the spawn actions.
|
||||
let mut spawn_actions = Vec::new();
|
||||
for bind in binds.iter().filter(|bind| {
|
||||
matches!(bind.actions.first(), Some(Action::Spawn(_)))
|
||||
matches!(bind.action, Action::Spawn(_))
|
||||
// Only show binds with Mod or Super to filter out stuff like volume up/down.
|
||||
&& (bind.key.modifiers.contains(Modifiers::COMPOSITOR)
|
||||
|| bind.key.modifiers.contains(Modifiers::SUPER))
|
||||
}) {
|
||||
let action = bind.actions.first().unwrap();
|
||||
let action = &bind.action;
|
||||
|
||||
// We only show one bind for each action, so we need to deduplicate the Spawn actions.
|
||||
if !spawn_actions.contains(&action) {
|
||||
@@ -252,7 +243,7 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
|
||||
.binds
|
||||
.0
|
||||
.iter()
|
||||
.find(|bind| bind.actions.first() == Some(action))
|
||||
.find(|bind| bind.action == *action)
|
||||
.map(|bind| key_name(comp_mod, &bind.key))
|
||||
.unwrap_or_else(|| String::from("(not bound)"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user