Correctly handle parsing of Binds and DefaultColumnWidth (#234)
Browse files at this commit6 changed files +232 -59
- flake.nix +4 -0
- niri-config/src/lib.rs +209 -31
- src/handlers/xdg_shell.rs +1 -1
- src/input.rs +7 -7
- src/layout/mod.rs +1 -1
- src/ui/hotkey_overlay.rs +10 -19
flake.nixmodified+4 -0
| @@ -51,6 +51,10 @@ | |||
| 51 | pkg-config | 51 | pkg-config |
| 52 | autoPatchelfHook | 52 | autoPatchelfHook |
| 53 | clang | 53 | clang |
| 54 | + gdk-pixbuf | ||
| 55 | + graphene | ||
| 56 | + gtk4 | ||
| 57 | + libadwaita | ||
| 54 | ]; | 58 | ]; |
| 55 | 59 | ||
| 56 | buildInputs = with pkgs; [ | 60 | buildInputs = with pkgs; [ |
niri-config/src/lib.rsmodified+209 -31
| @@ -1,10 +1,13 @@ | |||
| 1 | #[macro_use] | 1 | #[macro_use] |
| 2 | extern crate tracing; | 2 | extern crate tracing; |
| 3 | 3 | ||
| 4 | +use std::collections::HashSet; | ||
| 5 | +use std::ffi::OsStr; | ||
| 4 | use std::path::{Path, PathBuf}; | 6 | use std::path::{Path, PathBuf}; |
| 5 | use std::str::FromStr; | 7 | use std::str::FromStr; |
| 6 | 8 | ||
| 7 | use bitflags::bitflags; | 9 | use bitflags::bitflags; |
| 10 | +use knuffel::errors::DecodeError; | ||
| 8 | use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler}; | 11 | use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler}; |
| 9 | use niri_ipc::{LayoutSwitchTarget, SizeChange}; | 12 | use niri_ipc::{LayoutSwitchTarget, SizeChange}; |
| 10 | use regex::Regex; | 13 | use regex::Regex; |
| @@ -474,8 +477,8 @@ pub enum PresetWidth { | |||
| 474 | Fixed(#[knuffel(argument)] i32), | 477 | Fixed(#[knuffel(argument)] i32), |
| 475 | } | 478 | } |
| 476 | 479 | ||
| 477 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | 480 | +#[derive(Debug, Clone, PartialEq)] |
| 478 | -pub struct DefaultColumnWidth(#[knuffel(children)] pub Vec<PresetWidth>); | 481 | +pub struct DefaultColumnWidth(pub Option<PresetWidth>); |
| 479 | 482 | ||
| 480 | #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)] | 483 | #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)] |
| 481 | pub struct Struts { | 484 | pub struct Struts { |
| @@ -621,25 +624,23 @@ impl PartialEq for Match { | |||
| 621 | } | 624 | } |
| 622 | } | 625 | } |
| 623 | 626 | ||
| 624 | -#[derive(knuffel::Decode, Debug, Default, PartialEq)] | 627 | +#[derive(Debug, Default, PartialEq)] |
| 625 | -pub struct Binds(#[knuffel(children)] pub Vec<Bind>); | 628 | +pub struct Binds(pub Vec<Bind>); |
| 626 | 629 | ||
| 627 | -#[derive(knuffel::Decode, Debug, PartialEq)] | 630 | +#[derive(Debug, PartialEq)] |
| 628 | pub struct Bind { | 631 | pub struct Bind { |
| 629 | - #[knuffel(node_name)] | ||
| 630 | pub key: Key, | 632 | pub key: Key, |
| 631 | - #[knuffel(children)] | 633 | + pub action: Action, |
| 632 | - pub actions: Vec<Action>, | ||
| 633 | } | 634 | } |
| 634 | 635 | ||
| 635 | -#[derive(Debug, PartialEq, Eq)] | 636 | +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] |
| 636 | pub struct Key { | 637 | pub struct Key { |
| 637 | pub keysym: Keysym, | 638 | pub keysym: Keysym, |
| 638 | pub modifiers: Modifiers, | 639 | pub modifiers: Modifiers, |
| 639 | } | 640 | } |
| 640 | 641 | ||
| 641 | bitflags! { | 642 | bitflags! { |
| 642 | - #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 643 | + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 643 | pub struct Modifiers : u8 { | 644 | pub struct Modifiers : u8 { |
| 644 | const CTRL = 1; | 645 | const CTRL = 1; |
| 645 | const SHIFT = 2; | 646 | const SHIFT = 2; |
| @@ -825,7 +826,13 @@ impl Config { | |||
| 825 | .into_diagnostic() | 826 | .into_diagnostic() |
| 826 | .with_context(|| format!("error reading {path:?}"))?; | 827 | .with_context(|| format!("error reading {path:?}"))?; |
| 827 | 828 | ||
| 828 | - let config = Self::parse("config.kdl", &contents).context("error parsing")?; | 829 | + let config = Self::parse( |
| 830 | + path.file_name() | ||
| 831 | + .and_then(OsStr::to_str) | ||
| 832 | + .unwrap_or("config.kdl"), | ||
| 833 | + &contents, | ||
| 834 | + ) | ||
| 835 | + .context("error parsing")?; | ||
| 829 | debug!("loaded config from {path:?}"); | 836 | debug!("loaded config from {path:?}"); |
| 830 | Ok(config) | 837 | Ok(config) |
| 831 | } | 838 | } |
| @@ -882,10 +889,10 @@ where | |||
| 882 | fn decode_node( | 889 | fn decode_node( |
| 883 | node: &knuffel::ast::SpannedNode<S>, | 890 | node: &knuffel::ast::SpannedNode<S>, |
| 884 | ctx: &mut knuffel::decode::Context<S>, | 891 | ctx: &mut knuffel::decode::Context<S>, |
| 885 | - ) -> Result<Self, knuffel::errors::DecodeError<S>> { | 892 | + ) -> Result<Self, DecodeError<S>> { |
| 886 | // Check for unexpected type name. | 893 | // Check for unexpected type name. |
| 887 | if let Some(type_name) = &node.type_name { | 894 | if let Some(type_name) = &node.type_name { |
| 888 | - ctx.emit_error(knuffel::errors::DecodeError::unexpected( | 895 | + ctx.emit_error(DecodeError::unexpected( |
| 889 | type_name, | 896 | type_name, |
| 890 | "type name", | 897 | "type name", |
| 891 | "no type name expected for this node", | 898 | "no type name expected for this node", |
| @@ -894,13 +901,13 @@ where | |||
| 894 | 901 | ||
| 895 | // Get the first argument. | 902 | // Get the first argument. |
| 896 | let mut iter_args = node.arguments.iter(); | 903 | let mut iter_args = node.arguments.iter(); |
| 897 | - let val = iter_args.next().ok_or_else(|| { | 904 | + let val = iter_args |
| 898 | - knuffel::errors::DecodeError::missing(node, "additional argument is required") | 905 | + .next() |
| 899 | - })?; | 906 | + .ok_or_else(|| DecodeError::missing(node, "additional argument is required"))?; |
| 900 | 907 | ||
| 901 | // Check for unexpected type name. | 908 | // Check for unexpected type name. |
| 902 | if let Some(typ) = &val.type_name { | 909 | if let Some(typ) = &val.type_name { |
| 903 | - ctx.emit_error(knuffel::errors::DecodeError::TypeName { | 910 | + ctx.emit_error(DecodeError::TypeName { |
| 904 | span: typ.span().clone(), | 911 | span: typ.span().clone(), |
| 905 | found: Some((**typ).clone()), | 912 | found: Some((**typ).clone()), |
| 906 | expected: knuffel::errors::ExpectedType::no_type(), | 913 | expected: knuffel::errors::ExpectedType::no_type(), |
| @@ -911,15 +918,16 @@ where | |||
| 911 | // Check the argument type. | 918 | // Check the argument type. |
| 912 | let rv = match *val.literal { | 919 | let rv = match *val.literal { |
| 913 | // If it's a string, use FromStr. | 920 | // If it's a string, use FromStr. |
| 914 | - knuffel::ast::Literal::String(ref s) => Color::from_str(s) | 921 | + knuffel::ast::Literal::String(ref s) => { |
| 915 | - .map_err(|e| knuffel::errors::DecodeError::conversion(&val.literal, e)), | 922 | + Color::from_str(s).map_err(|e| DecodeError::conversion(&val.literal, e)) |
| 923 | + } | ||
| 916 | // Otherwise, fall back to the 4-argument RGBA form. | 924 | // Otherwise, fall back to the 4-argument RGBA form. |
| 917 | _ => return ColorRgba::decode_node(node, ctx).map(Color::from), | 925 | _ => return ColorRgba::decode_node(node, ctx).map(Color::from), |
| 918 | }?; | 926 | }?; |
| 919 | 927 | ||
| 920 | // Check for unexpected following arguments. | 928 | // Check for unexpected following arguments. |
| 921 | if let Some(val) = iter_args.next() { | 929 | if let Some(val) = iter_args.next() { |
| 922 | - ctx.emit_error(knuffel::errors::DecodeError::unexpected( | 930 | + ctx.emit_error(DecodeError::unexpected( |
| 923 | &val.literal, | 931 | &val.literal, |
| 924 | "argument", | 932 | "argument", |
| 925 | "unexpected argument", | 933 | "unexpected argument", |
| @@ -928,14 +936,14 @@ where | |||
| 928 | 936 | ||
| 929 | // Check for unexpected properties and children. | 937 | // Check for unexpected properties and children. |
| 930 | for name in node.properties.keys() { | 938 | for name in node.properties.keys() { |
| 931 | - ctx.emit_error(knuffel::errors::DecodeError::unexpected( | 939 | + ctx.emit_error(DecodeError::unexpected( |
| 932 | name, | 940 | name, |
| 933 | "property", | 941 | "property", |
| 934 | format!("unexpected property `{}`", name.escape_default()), | 942 | format!("unexpected property `{}`", name.escape_default()), |
| 935 | )); | 943 | )); |
| 936 | } | 944 | } |
| 937 | for child in node.children.as_ref().map(|lst| &lst[..]).unwrap_or(&[]) { | 945 | for child in node.children.as_ref().map(|lst| &lst[..]).unwrap_or(&[]) { |
| 938 | - ctx.emit_error(knuffel::errors::DecodeError::unexpected( | 946 | + ctx.emit_error(DecodeError::unexpected( |
| 939 | child, | 947 | child, |
| 940 | "node", | 948 | "node", |
| 941 | format!("unexpected node `{}`", child.node_name.escape_default()), | 949 | format!("unexpected node `{}`", child.node_name.escape_default()), |
| @@ -946,6 +954,176 @@ where | |||
| 946 | } | 954 | } |
| 947 | } | 955 | } |
| 948 | 956 | ||
| 957 | +fn expect_only_children<S>( | ||
| 958 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 959 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 960 | +) where | ||
| 961 | + S: knuffel::traits::ErrorSpan, | ||
| 962 | +{ | ||
| 963 | + if let Some(type_name) = &node.type_name { | ||
| 964 | + ctx.emit_error(DecodeError::unexpected( | ||
| 965 | + type_name, | ||
| 966 | + "type name", | ||
| 967 | + "no type name expected for this node", | ||
| 968 | + )); | ||
| 969 | + } | ||
| 970 | + | ||
| 971 | + for val in node.arguments.iter() { | ||
| 972 | + ctx.emit_error(DecodeError::unexpected( | ||
| 973 | + &val.literal, | ||
| 974 | + "argument", | ||
| 975 | + "no arguments expected for this node", | ||
| 976 | + )) | ||
| 977 | + } | ||
| 978 | + | ||
| 979 | + for name in node.properties.keys() { | ||
| 980 | + ctx.emit_error(DecodeError::unexpected( | ||
| 981 | + name, | ||
| 982 | + "property", | ||
| 983 | + "no properties expected for this node", | ||
| 984 | + )) | ||
| 985 | + } | ||
| 986 | +} | ||
| 987 | + | ||
| 988 | +impl<S> knuffel::Decode<S> for DefaultColumnWidth | ||
| 989 | +where | ||
| 990 | + S: knuffel::traits::ErrorSpan, | ||
| 991 | +{ | ||
| 992 | + fn decode_node( | ||
| 993 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 994 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 995 | + ) -> Result<Self, DecodeError<S>> { | ||
| 996 | + expect_only_children(node, ctx); | ||
| 997 | + | ||
| 998 | + let mut children = node.children(); | ||
| 999 | + | ||
| 1000 | + if let Some(child) = children.next() { | ||
| 1001 | + if let Some(unwanted_child) = children.next() { | ||
| 1002 | + ctx.emit_error(DecodeError::unexpected( | ||
| 1003 | + unwanted_child, | ||
| 1004 | + "node", | ||
| 1005 | + "expected no more than one child", | ||
| 1006 | + )); | ||
| 1007 | + } | ||
| 1008 | + PresetWidth::decode_node(child, ctx).map(Some).map(Self) | ||
| 1009 | + } else { | ||
| 1010 | + Ok(Self(None)) | ||
| 1011 | + } | ||
| 1012 | + } | ||
| 1013 | +} | ||
| 1014 | + | ||
| 1015 | +impl<S> knuffel::Decode<S> for Binds | ||
| 1016 | +where | ||
| 1017 | + S: knuffel::traits::ErrorSpan, | ||
| 1018 | +{ | ||
| 1019 | + fn decode_node( | ||
| 1020 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 1021 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 1022 | + ) -> Result<Self, DecodeError<S>> { | ||
| 1023 | + expect_only_children(node, ctx); | ||
| 1024 | + | ||
| 1025 | + let mut seen_keys = HashSet::new(); | ||
| 1026 | + | ||
| 1027 | + let mut binds = Vec::new(); | ||
| 1028 | + | ||
| 1029 | + for child in node.children() { | ||
| 1030 | + match Bind::decode_node(child, ctx) { | ||
| 1031 | + Err(e) => { | ||
| 1032 | + ctx.emit_error(e); | ||
| 1033 | + } | ||
| 1034 | + Ok(bind) => { | ||
| 1035 | + if seen_keys.insert(bind.key) { | ||
| 1036 | + binds.push(bind); | ||
| 1037 | + } else { | ||
| 1038 | + // ideally, this error should point to the previous instance of this keybind | ||
| 1039 | + // | ||
| 1040 | + // i (sodiboo) have tried to implement this in various ways: | ||
| 1041 | + // miette!(), #[derive(Diagnostic)] | ||
| 1042 | + // DecodeError::Custom, DecodeError::Conversion | ||
| 1043 | + // nothing seems to work, and i suspect it's not possible. | ||
| 1044 | + // | ||
| 1045 | + // DecodeError is fairly restrictive. | ||
| 1046 | + // even DecodeError::Custom just wraps a std::error::Error | ||
| 1047 | + // and this erases all rich information from miette. (why???) | ||
| 1048 | + // | ||
| 1049 | + // why does knuffel do this? | ||
| 1050 | + // from what i can tell, it doesn't even use DecodeError for much. | ||
| 1051 | + // it only ever converts them to a Report anyways! | ||
| 1052 | + // https://github.com/tailhook/knuffel/blob/c44c6b0c0f31ea6d1174d5d2ed41064922ea44ca/src/wrappers.rs#L55-L58 | ||
| 1053 | + // | ||
| 1054 | + // besides like, allowing downstream users (such as us!) | ||
| 1055 | + // to match on parse failure, i don't understand why | ||
| 1056 | + // it doesn't just use a generic error type | ||
| 1057 | + // | ||
| 1058 | + // even the matching isn't consistent, | ||
| 1059 | + // because errors can also be omitted as ctx.emit_error. | ||
| 1060 | + // why does *that one* especially, require a DecodeError? | ||
| 1061 | + // | ||
| 1062 | + // anyways if you can make it format nicely, definitely do fix this | ||
| 1063 | + ctx.emit_error(DecodeError::unexpected( | ||
| 1064 | + &child.node_name, | ||
| 1065 | + "keybind", | ||
| 1066 | + "duplicate keybind", | ||
| 1067 | + )); | ||
| 1068 | + } | ||
| 1069 | + } | ||
| 1070 | + } | ||
| 1071 | + } | ||
| 1072 | + | ||
| 1073 | + Ok(Self(binds)) | ||
| 1074 | + } | ||
| 1075 | +} | ||
| 1076 | + | ||
| 1077 | +impl<S> knuffel::Decode<S> for Bind | ||
| 1078 | +where | ||
| 1079 | + S: knuffel::traits::ErrorSpan, | ||
| 1080 | +{ | ||
| 1081 | + fn decode_node( | ||
| 1082 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 1083 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 1084 | + ) -> Result<Self, DecodeError<S>> { | ||
| 1085 | + expect_only_children(node, ctx); | ||
| 1086 | + | ||
| 1087 | + let key = node | ||
| 1088 | + .node_name | ||
| 1089 | + .parse::<Key>() | ||
| 1090 | + .map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?; | ||
| 1091 | + | ||
| 1092 | + let mut children = node.children(); | ||
| 1093 | + | ||
| 1094 | + // If the action is invalid but the key is fine, we still want to return something. | ||
| 1095 | + // That way, the parent can handle the existence of duplicate keybinds, | ||
| 1096 | + // even if their contents are not valid. | ||
| 1097 | + let dummy = Self { | ||
| 1098 | + key, | ||
| 1099 | + action: Action::Spawn(vec![]), | ||
| 1100 | + }; | ||
| 1101 | + | ||
| 1102 | + if let Some(child) = children.next() { | ||
| 1103 | + for unwanted_child in children { | ||
| 1104 | + ctx.emit_error(DecodeError::unexpected( | ||
| 1105 | + unwanted_child, | ||
| 1106 | + "node", | ||
| 1107 | + "only one action is allowed per keybind", | ||
| 1108 | + )); | ||
| 1109 | + } | ||
| 1110 | + match Action::decode_node(child, ctx) { | ||
| 1111 | + Ok(action) => Ok(Self { key, action }), | ||
| 1112 | + Err(e) => { | ||
| 1113 | + ctx.emit_error(e); | ||
| 1114 | + Ok(dummy) | ||
| 1115 | + } | ||
| 1116 | + } | ||
| 1117 | + } else { | ||
| 1118 | + ctx.emit_error(DecodeError::missing( | ||
| 1119 | + node, | ||
| 1120 | + "expected an action for this keybind", | ||
| 1121 | + )); | ||
| 1122 | + Ok(dummy) | ||
| 1123 | + } | ||
| 1124 | + } | ||
| 1125 | +} | ||
| 1126 | + | ||
| 949 | impl FromStr for Mode { | 1127 | impl FromStr for Mode { |
| 950 | type Err = miette::Error; | 1128 | type Err = miette::Error; |
| 951 | 1129 | ||
| @@ -1302,9 +1480,9 @@ mod tests { | |||
| 1302 | PresetWidth::Fixed(960), | 1480 | PresetWidth::Fixed(960), |
| 1303 | PresetWidth::Fixed(1280), | 1481 | PresetWidth::Fixed(1280), |
| 1304 | ], | 1482 | ], |
| 1305 | - default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion( | 1483 | + default_column_width: Some(DefaultColumnWidth(Some(PresetWidth::Proportion( |
| 1306 | 0.25, | 1484 | 0.25, |
| 1307 | - )])), | 1485 | + )))), |
| 1308 | gaps: 8, | 1486 | gaps: 8, |
| 1309 | struts: Struts { | 1487 | struts: Struts { |
| 1310 | left: 1, | 1488 | left: 1, |
| @@ -1369,49 +1547,49 @@ mod tests { | |||
| 1369 | keysym: Keysym::t, | 1547 | keysym: Keysym::t, |
| 1370 | modifiers: Modifiers::COMPOSITOR, | 1548 | modifiers: Modifiers::COMPOSITOR, |
| 1371 | }, | 1549 | }, |
| 1372 | - actions: vec![Action::Spawn(vec!["alacritty".to_owned()])], | 1550 | + action: Action::Spawn(vec!["alacritty".to_owned()]), |
| 1373 | }, | 1551 | }, |
| 1374 | Bind { | 1552 | Bind { |
| 1375 | key: Key { | 1553 | key: Key { |
| 1376 | keysym: Keysym::q, | 1554 | keysym: Keysym::q, |
| 1377 | modifiers: Modifiers::COMPOSITOR, | 1555 | modifiers: Modifiers::COMPOSITOR, |
| 1378 | }, | 1556 | }, |
| 1379 | - actions: vec![Action::CloseWindow], | 1557 | + action: Action::CloseWindow, |
| 1380 | }, | 1558 | }, |
| 1381 | Bind { | 1559 | Bind { |
| 1382 | key: Key { | 1560 | key: Key { |
| 1383 | keysym: Keysym::h, | 1561 | keysym: Keysym::h, |
| 1384 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT, | 1562 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT, |
| 1385 | }, | 1563 | }, |
| 1386 | - actions: vec![Action::FocusMonitorLeft], | 1564 | + action: Action::FocusMonitorLeft, |
| 1387 | }, | 1565 | }, |
| 1388 | Bind { | 1566 | Bind { |
| 1389 | key: Key { | 1567 | key: Key { |
| 1390 | keysym: Keysym::l, | 1568 | keysym: Keysym::l, |
| 1391 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL, | 1569 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL, |
| 1392 | }, | 1570 | }, |
| 1393 | - actions: vec![Action::MoveWindowToMonitorRight], | 1571 | + action: Action::MoveWindowToMonitorRight, |
| 1394 | }, | 1572 | }, |
| 1395 | Bind { | 1573 | Bind { |
| 1396 | key: Key { | 1574 | key: Key { |
| 1397 | keysym: Keysym::comma, | 1575 | keysym: Keysym::comma, |
| 1398 | modifiers: Modifiers::COMPOSITOR, | 1576 | modifiers: Modifiers::COMPOSITOR, |
| 1399 | }, | 1577 | }, |
| 1400 | - actions: vec![Action::ConsumeWindowIntoColumn], | 1578 | + action: Action::ConsumeWindowIntoColumn, |
| 1401 | }, | 1579 | }, |
| 1402 | Bind { | 1580 | Bind { |
| 1403 | key: Key { | 1581 | key: Key { |
| 1404 | keysym: Keysym::_1, | 1582 | keysym: Keysym::_1, |
| 1405 | modifiers: Modifiers::COMPOSITOR, | 1583 | modifiers: Modifiers::COMPOSITOR, |
| 1406 | }, | 1584 | }, |
| 1407 | - actions: vec![Action::FocusWorkspace(1)], | 1585 | + action: Action::FocusWorkspace(1), |
| 1408 | }, | 1586 | }, |
| 1409 | Bind { | 1587 | Bind { |
| 1410 | key: Key { | 1588 | key: Key { |
| 1411 | keysym: Keysym::e, | 1589 | keysym: Keysym::e, |
| 1412 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT, | 1590 | modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT, |
| 1413 | }, | 1591 | }, |
| 1414 | - actions: vec![Action::Quit(true)], | 1592 | + action: Action::Quit(true), |
| 1415 | }, | 1593 | }, |
| 1416 | ]), | 1594 | ]), |
| 1417 | debug: DebugConfig { | 1595 | debug: DebugConfig { |
src/handlers/xdg_shell.rsmodified+1 -1
| @@ -81,7 +81,7 @@ pub fn resolve_window_rules( | |||
| 81 | if let Some(x) = rule | 81 | if let Some(x) = rule |
| 82 | .default_column_width | 82 | .default_column_width |
| 83 | .as_ref() | 83 | .as_ref() |
| 84 | - .map(|d| d.0.first().copied().map(ColumnWidth::from)) | 84 | + .map(|d| d.0.map(ColumnWidth::from)) |
| 85 | { | 85 | { |
| 86 | resolved.default_width = Some(x); | 86 | resolved.default_width = Some(x); |
| 87 | } | 87 | } |
src/input.rsmodified+7 -7
| @@ -1650,7 +1650,7 @@ fn bound_action( | |||
| 1650 | } | 1650 | } |
| 1651 | 1651 | ||
| 1652 | if bind_modifiers == modifiers { | 1652 | if bind_modifiers == modifiers { |
| 1653 | - return bind.actions.first().cloned(); | 1653 | + return Some(bind.action.clone()); |
| 1654 | } | 1654 | } |
| 1655 | } | 1655 | } |
| 1656 | 1656 | ||
| @@ -1815,7 +1815,7 @@ mod tests { | |||
| 1815 | keysym: close_keysym, | 1815 | keysym: close_keysym, |
| 1816 | modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL, | 1816 | modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL, |
| 1817 | }, | 1817 | }, |
| 1818 | - actions: vec![Action::CloseWindow], | 1818 | + action: Action::CloseWindow, |
| 1819 | }]); | 1819 | }]); |
| 1820 | 1820 | ||
| 1821 | let comp_mod = CompositorMod::Super; | 1821 | let comp_mod = CompositorMod::Super; |
| @@ -1937,35 +1937,35 @@ mod tests { | |||
| 1937 | keysym: Keysym::q, | 1937 | keysym: Keysym::q, |
| 1938 | modifiers: Modifiers::COMPOSITOR, | 1938 | modifiers: Modifiers::COMPOSITOR, |
| 1939 | }, | 1939 | }, |
| 1940 | - actions: vec![Action::CloseWindow], | 1940 | + action: Action::CloseWindow, |
| 1941 | }, | 1941 | }, |
| 1942 | Bind { | 1942 | Bind { |
| 1943 | key: Key { | 1943 | key: Key { |
| 1944 | keysym: Keysym::h, | 1944 | keysym: Keysym::h, |
| 1945 | modifiers: Modifiers::SUPER, | 1945 | modifiers: Modifiers::SUPER, |
| 1946 | }, | 1946 | }, |
| 1947 | - actions: vec![Action::FocusColumnLeft], | 1947 | + action: Action::FocusColumnLeft, |
| 1948 | }, | 1948 | }, |
| 1949 | Bind { | 1949 | Bind { |
| 1950 | key: Key { | 1950 | key: Key { |
| 1951 | keysym: Keysym::j, | 1951 | keysym: Keysym::j, |
| 1952 | modifiers: Modifiers::empty(), | 1952 | modifiers: Modifiers::empty(), |
| 1953 | }, | 1953 | }, |
| 1954 | - actions: vec![Action::FocusWindowDown], | 1954 | + action: Action::FocusWindowDown, |
| 1955 | }, | 1955 | }, |
| 1956 | Bind { | 1956 | Bind { |
| 1957 | key: Key { | 1957 | key: Key { |
| 1958 | keysym: Keysym::k, | 1958 | keysym: Keysym::k, |
| 1959 | modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER, | 1959 | modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER, |
| 1960 | }, | 1960 | }, |
| 1961 | - actions: vec![Action::FocusWindowUp], | 1961 | + action: Action::FocusWindowUp, |
| 1962 | }, | 1962 | }, |
| 1963 | Bind { | 1963 | Bind { |
| 1964 | key: Key { | 1964 | key: Key { |
| 1965 | keysym: Keysym::l, | 1965 | keysym: Keysym::l, |
| 1966 | modifiers: Modifiers::SUPER | Modifiers::ALT, | 1966 | modifiers: Modifiers::SUPER | Modifiers::ALT, |
| 1967 | }, | 1967 | }, |
| 1968 | - actions: vec![Action::FocusColumnRight], | 1968 | + action: Action::FocusColumnRight, |
| 1969 | }, | 1969 | }, |
| 1970 | ]); | 1970 | ]); |
| 1971 | 1971 | ||
src/layout/mod.rsmodified+1 -1
| @@ -200,7 +200,7 @@ impl Options { | |||
| 200 | let default_width = layout | 200 | let default_width = layout |
| 201 | .default_column_width | 201 | .default_column_width |
| 202 | .as_ref() | 202 | .as_ref() |
| 203 | - .map(|w| w.0.first().copied().map(ColumnWidth::from)) | 203 | + .map(|w| w.0.map(ColumnWidth::from)) |
| 204 | .unwrap_or(Some(ColumnWidth::Proportion(0.5))); | 204 | .unwrap_or(Some(ColumnWidth::Proportion(0.5))); |
| 205 | 205 | ||
| 206 | Self { | 206 | Self { |
src/ui/hotkey_overlay.rsmodified+10 -19
| @@ -159,15 +159,9 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul | |||
| 159 | 159 | ||
| 160 | // Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to | 160 | // Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to |
| 161 | // Quit(false). | 161 | // Quit(false). |
| 162 | - if binds | 162 | + if binds.iter().any(|bind| bind.action == Action::Quit(false)) { |
| 163 | - .iter() | ||
| 164 | - .any(|bind| bind.actions.first() == Some(&Action::Quit(false))) | ||
| 165 | - { | ||
| 166 | actions.push(&Action::Quit(false)); | 163 | actions.push(&Action::Quit(false)); |
| 167 | - } else if binds | 164 | + } else if binds.iter().any(|bind| bind.action == Action::Quit(true)) { |
| 168 | - .iter() | ||
| 169 | - .any(|bind| bind.actions.first() == Some(&Action::Quit(true))) | ||
| 170 | - { | ||
| 171 | actions.push(&Action::Quit(true)); | 165 | actions.push(&Action::Quit(true)); |
| 172 | } else { | 166 | } else { |
| 173 | actions.push(&Action::Quit(false)); | 167 | actions.push(&Action::Quit(false)); |
| @@ -186,12 +180,12 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul | |||
| 186 | // Prefer move-column-to-workspace-down, but fall back to move-window-to-workspace-down. | 180 | // Prefer move-column-to-workspace-down, but fall back to move-window-to-workspace-down. |
| 187 | if binds | 181 | if binds |
| 188 | .iter() | 182 | .iter() |
| 189 | - .any(|bind| bind.actions.first() == Some(&Action::MoveColumnToWorkspaceDown)) | 183 | + .any(|bind| bind.action == Action::MoveColumnToWorkspaceDown) |
| 190 | { | 184 | { |
| 191 | actions.push(&Action::MoveColumnToWorkspaceDown); | 185 | actions.push(&Action::MoveColumnToWorkspaceDown); |
| 192 | } else if binds | 186 | } else if binds |
| 193 | .iter() | 187 | .iter() |
| 194 | - .any(|bind| bind.actions.first() == Some(&Action::MoveWindowToWorkspaceDown)) | 188 | + .any(|bind| bind.action == Action::MoveWindowToWorkspaceDown) |
| 195 | { | 189 | { |
| 196 | actions.push(&Action::MoveWindowToWorkspaceDown); | 190 | actions.push(&Action::MoveWindowToWorkspaceDown); |
| 197 | } else { | 191 | } else { |
| @@ -201,12 +195,12 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul | |||
| 201 | // Same for -up. | 195 | // Same for -up. |
| 202 | if binds | 196 | if binds |
| 203 | .iter() | 197 | .iter() |
| 204 | - .any(|bind| bind.actions.first() == Some(&Action::MoveColumnToWorkspaceUp)) | 198 | + .any(|bind| bind.action == Action::MoveColumnToWorkspaceUp) |
| 205 | { | 199 | { |
| 206 | actions.push(&Action::MoveColumnToWorkspaceUp); | 200 | actions.push(&Action::MoveColumnToWorkspaceUp); |
| 207 | } else if binds | 201 | } else if binds |
| 208 | .iter() | 202 | .iter() |
| 209 | - .any(|bind| bind.actions.first() == Some(&Action::MoveWindowToWorkspaceUp)) | 203 | + .any(|bind| bind.action == Action::MoveWindowToWorkspaceUp) |
| 210 | { | 204 | { |
| 211 | actions.push(&Action::MoveWindowToWorkspaceUp); | 205 | actions.push(&Action::MoveWindowToWorkspaceUp); |
| 212 | } else { | 206 | } else { |
| @@ -221,22 +215,19 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul | |||
| 221 | ]); | 215 | ]); |
| 222 | 216 | ||
| 223 | // Screenshot is not as important, can omit if not bound. | 217 | // Screenshot is not as important, can omit if not bound. |
| 224 | - if binds | 218 | + if binds.iter().any(|bind| bind.action == Action::Screenshot) { |
| 225 | - .iter() | ||
| 226 | - .any(|bind| bind.actions.first() == Some(&Action::Screenshot)) | ||
| 227 | - { | ||
| 228 | actions.push(&Action::Screenshot); | 219 | actions.push(&Action::Screenshot); |
| 229 | } | 220 | } |
| 230 | 221 | ||
| 231 | // Add the spawn actions. | 222 | // Add the spawn actions. |
| 232 | let mut spawn_actions = Vec::new(); | 223 | let mut spawn_actions = Vec::new(); |
| 233 | for bind in binds.iter().filter(|bind| { | 224 | for bind in binds.iter().filter(|bind| { |
| 234 | - matches!(bind.actions.first(), Some(Action::Spawn(_))) | 225 | + matches!(bind.action, Action::Spawn(_)) |
| 235 | // Only show binds with Mod or Super to filter out stuff like volume up/down. | 226 | // Only show binds with Mod or Super to filter out stuff like volume up/down. |
| 236 | && (bind.key.modifiers.contains(Modifiers::COMPOSITOR) | 227 | && (bind.key.modifiers.contains(Modifiers::COMPOSITOR) |
| 237 | || bind.key.modifiers.contains(Modifiers::SUPER)) | 228 | || bind.key.modifiers.contains(Modifiers::SUPER)) |
| 238 | }) { | 229 | }) { |
| 239 | - let action = bind.actions.first().unwrap(); | 230 | + let action = &bind.action; |
| 240 | 231 | ||
| 241 | // We only show one bind for each action, so we need to deduplicate the Spawn actions. | 232 | // We only show one bind for each action, so we need to deduplicate the Spawn actions. |
| 242 | if !spawn_actions.contains(&action) { | 233 | if !spawn_actions.contains(&action) { |
| @@ -252,7 +243,7 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul | |||
| 252 | .binds | 243 | .binds |
| 253 | .0 | 244 | .0 |
| 254 | .iter() | 245 | .iter() |
| 255 | - .find(|bind| bind.actions.first() == Some(action)) | 246 | + .find(|bind| bind.action == *action) |
| 256 | .map(|bind| key_name(comp_mod, &bind.key)) | 247 | .map(|bind| key_name(comp_mod, &bind.key)) |
| 257 | .unwrap_or_else(|| String::from("(not bound)")); | 248 | .unwrap_or_else(|| String::from("(not bound)")); |
| 258 | 249 | ||