forge
Explore
Log in

Don't you dare go Hollow

Make binds accept wheel names

Browse files at this commit

a0c8c39b06e672c633e09f3751d46fa8fed4f3a4Ivan MolodetskikhParent: 977f148
niri-config/src/lib.rsmodified+41 -13
@@ -724,10 +724,19 @@ pub struct Bind {
724 724
725 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]725 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
726 pub struct Key {726 pub struct Key {
727- pub keysym: Keysym,727+ pub trigger: Trigger,
728 pub modifiers: Modifiers,728 pub modifiers: Modifiers,
729 }729 }
730 730
731+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
732+pub enum Trigger {
733+ Keysym(Keysym),
734+ WheelDown,
735+ WheelUp,
736+ WheelLeft,
737+ WheelRight,
738+}
739+
731 bitflags! {740 bitflags! {
732 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]741 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
733 pub struct Modifiers : u8 {742 pub struct Modifiers : u8 {
@@ -1499,12 +1508,23 @@ impl FromStr for Key {
1499 }1508 }
1500 }1509 }
1501 1510
1502- let keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE);1511+ let trigger = if key.eq_ignore_ascii_case("WheelDown") {
1503- if keysym.raw() == KEY_NoSymbol {1512+ Trigger::WheelDown
1504- return Err(miette!("invalid key: {key}"));1513+ } else if key.eq_ignore_ascii_case("WheelUp") {
1505- }1514+ Trigger::WheelUp
1515+ } else if key.eq_ignore_ascii_case("WheelLeft") {
1516+ Trigger::WheelLeft
1517+ } else if key.eq_ignore_ascii_case("WheelRight") {
1518+ Trigger::WheelRight
1519+ } else {
1520+ let keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE);
1521+ if keysym.raw() == KEY_NoSymbol {
1522+ return Err(miette!("invalid key: {key}"));
1523+ }
1524+ Trigger::Keysym(keysym)
1525+ };
1506 1526
1507- Ok(Key { keysym, modifiers })1527+ Ok(Key { trigger, modifiers })
1508 }1528 }
1509 }1529 }
1510 1530
@@ -1712,6 +1732,7 @@ mod tests {
1712 Mod+Comma { consume-window-into-column; }1732 Mod+Comma { consume-window-into-column; }
1713 Mod+1 { focus-workspace 1; }1733 Mod+1 { focus-workspace 1; }
1714 Mod+Shift+E { quit skip-confirmation=true; }1734 Mod+Shift+E { quit skip-confirmation=true; }
1735+ Mod+WheelDown { focus-workspace-down; }
1715 }1736 }
1716 1737
1717 debug {1738 debug {
@@ -1895,53 +1916,60 @@ mod tests {
1895 binds: Binds(vec![1916 binds: Binds(vec![
1896 Bind {1917 Bind {
1897 key: Key {1918 key: Key {
1898- keysym: Keysym::t,1919+ trigger: Trigger::Keysym(Keysym::t),
1899 modifiers: Modifiers::COMPOSITOR,1920 modifiers: Modifiers::COMPOSITOR,
1900 },1921 },
1901 action: Action::Spawn(vec!["alacritty".to_owned()]),1922 action: Action::Spawn(vec!["alacritty".to_owned()]),
1902 },1923 },
1903 Bind {1924 Bind {
1904 key: Key {1925 key: Key {
1905- keysym: Keysym::q,1926+ trigger: Trigger::Keysym(Keysym::q),
1906 modifiers: Modifiers::COMPOSITOR,1927 modifiers: Modifiers::COMPOSITOR,
1907 },1928 },
1908 action: Action::CloseWindow,1929 action: Action::CloseWindow,
1909 },1930 },
1910 Bind {1931 Bind {
1911 key: Key {1932 key: Key {
1912- keysym: Keysym::h,1933+ trigger: Trigger::Keysym(Keysym::h),
1913 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,1934 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
1914 },1935 },
1915 action: Action::FocusMonitorLeft,1936 action: Action::FocusMonitorLeft,
1916 },1937 },
1917 Bind {1938 Bind {
1918 key: Key {1939 key: Key {
1919- keysym: Keysym::l,1940+ trigger: Trigger::Keysym(Keysym::l),
1920 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL,1941 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL,
1921 },1942 },
1922 action: Action::MoveWindowToMonitorRight,1943 action: Action::MoveWindowToMonitorRight,
1923 },1944 },
1924 Bind {1945 Bind {
1925 key: Key {1946 key: Key {
1926- keysym: Keysym::comma,1947+ trigger: Trigger::Keysym(Keysym::comma),
1927 modifiers: Modifiers::COMPOSITOR,1948 modifiers: Modifiers::COMPOSITOR,
1928 },1949 },
1929 action: Action::ConsumeWindowIntoColumn,1950 action: Action::ConsumeWindowIntoColumn,
1930 },1951 },
1931 Bind {1952 Bind {
1932 key: Key {1953 key: Key {
1933- keysym: Keysym::_1,1954+ trigger: Trigger::Keysym(Keysym::_1),
1934 modifiers: Modifiers::COMPOSITOR,1955 modifiers: Modifiers::COMPOSITOR,
1935 },1956 },
1936 action: Action::FocusWorkspace(1),1957 action: Action::FocusWorkspace(1),
1937 },1958 },
1938 Bind {1959 Bind {
1939 key: Key {1960 key: Key {
1940- keysym: Keysym::e,1961+ trigger: Trigger::Keysym(Keysym::e),
1941 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,1962 modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
1942 },1963 },
1943 action: Action::Quit(true),1964 action: Action::Quit(true),
1944 },1965 },
1966+ Bind {
1967+ key: Key {
1968+ trigger: Trigger::WheelDown,
1969+ modifiers: Modifiers::COMPOSITOR,
1970+ },
1971+ action: Action::FocusWorkspaceDown,
1972+ },
1945 ]),1973 ]),
1946 debug: DebugConfig {1974 debug: DebugConfig {
1947 render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),1975 render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),
src/input.rsmodified+8 -8
@@ -3,7 +3,7 @@ use std::collections::HashSet;
3 use std::time::Duration;3 use std::time::Duration;
4 4
5 use input::event::gesture::GestureEventCoordinates as _;5 use input::event::gesture::GestureEventCoordinates as _;
6-use niri_config::{Action, Binds, Modifiers};6+use niri_config::{Action, Binds, Modifiers, Trigger};
7 use niri_ipc::LayoutSwitchTarget;7 use niri_ipc::LayoutSwitchTarget;
8 use smithay::backend::input::{8 use smithay::backend::input::{
9 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,9 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event,
@@ -1731,7 +1731,7 @@ fn bound_action(
1731 let raw = raw?;1731 let raw = raw?;
1732 1732
1733 for bind in &bindings.0 {1733 for bind in &bindings.0 {
1734- if bind.key.keysym != raw {1734+ if bind.key.trigger != Trigger::Keysym(raw) {
1735 continue;1735 continue;
1736 }1736 }
1737 1737
@@ -1911,7 +1911,7 @@ mod tests {
1911 let close_keysym = Keysym::q;1911 let close_keysym = Keysym::q;
1912 let bindings = Binds(vec![Bind {1912 let bindings = Binds(vec![Bind {
1913 key: Key {1913 key: Key {
1914- keysym: close_keysym,1914+ trigger: Trigger::Keysym(close_keysym),
1915 modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,1915 modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
1916 },1916 },
1917 action: Action::CloseWindow,1917 action: Action::CloseWindow,
@@ -2033,35 +2033,35 @@ mod tests {
2033 let bindings = Binds(vec![2033 let bindings = Binds(vec![
2034 Bind {2034 Bind {
2035 key: Key {2035 key: Key {
2036- keysym: Keysym::q,2036+ trigger: Trigger::Keysym(Keysym::q),
2037 modifiers: Modifiers::COMPOSITOR,2037 modifiers: Modifiers::COMPOSITOR,
2038 },2038 },
2039 action: Action::CloseWindow,2039 action: Action::CloseWindow,
2040 },2040 },
2041 Bind {2041 Bind {
2042 key: Key {2042 key: Key {
2043- keysym: Keysym::h,2043+ trigger: Trigger::Keysym(Keysym::h),
2044 modifiers: Modifiers::SUPER,2044 modifiers: Modifiers::SUPER,
2045 },2045 },
2046 action: Action::FocusColumnLeft,2046 action: Action::FocusColumnLeft,
2047 },2047 },
2048 Bind {2048 Bind {
2049 key: Key {2049 key: Key {
2050- keysym: Keysym::j,2050+ trigger: Trigger::Keysym(Keysym::j),
2051 modifiers: Modifiers::empty(),2051 modifiers: Modifiers::empty(),
2052 },2052 },
2053 action: Action::FocusWindowDown,2053 action: Action::FocusWindowDown,
2054 },2054 },
2055 Bind {2055 Bind {
2056 key: Key {2056 key: Key {
2057- keysym: Keysym::k,2057+ trigger: Trigger::Keysym(Keysym::k),
2058 modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,2058 modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
2059 },2059 },
2060 action: Action::FocusWindowUp,2060 action: Action::FocusWindowUp,
2061 },2061 },
2062 Bind {2062 Bind {
2063 key: Key {2063 key: Key {
2064- keysym: Keysym::l,2064+ trigger: Trigger::Keysym(Keysym::l),
2065 modifiers: Modifiers::SUPER | Modifiers::ALT,2065 modifiers: Modifiers::SUPER | Modifiers::ALT,
2066 },2066 },
2067 action: Action::FocusColumnRight,2067 action: Action::FocusColumnRight,
src/ui/hotkey_overlay.rsmodified+10 -2
@@ -4,7 +4,7 @@ use std::collections::HashMap;
4 use std::iter::zip;4 use std::iter::zip;
5 use std::rc::Rc;5 use std::rc::Rc;
6 6
7-use niri_config::{Action, Config, Key, Modifiers};7+use niri_config::{Action, Config, Key, Modifiers, Trigger};
8 use pangocairo::cairo::{self, ImageSurface};8 use pangocairo::cairo::{self, ImageSurface};
9 use pangocairo::pango::{AttrColor, AttrInt, AttrList, AttrString, FontDescription, Weight};9 use pangocairo::pango::{AttrColor, AttrInt, AttrList, AttrString, FontDescription, Weight};
10 use smithay::backend::renderer::element::memory::{10 use smithay::backend::renderer::element::memory::{
@@ -414,7 +414,15 @@ fn key_name(comp_mod: CompositorMod, key: &Key) -> String {
414 if key.modifiers.contains(Modifiers::CTRL) {414 if key.modifiers.contains(Modifiers::CTRL) {
415 name.push_str("Ctrl + ");415 name.push_str("Ctrl + ");
416 }416 }
417- name.push_str(&prettify_keysym_name(&keysym_get_name(key.keysym)));417+
418+ let pretty = match key.trigger {
419+ Trigger::Keysym(keysym) => prettify_keysym_name(&keysym_get_name(keysym)),
420+ Trigger::WheelDown => String::from("Wheel Down"),
421+ Trigger::WheelUp => String::from("Wheel Up"),
422+ Trigger::WheelLeft => String::from("Wheel Left"),
423+ Trigger::WheelRight => String::from("Wheel Right"),
424+ };
425+ name.push_str(&pretty);
418 426
419 name427 name
420 }428 }