input: Split bound_action() and add tests
Browse files at this commit577fba82e540d549ac2f2441a638e1d23d1f100dParent: b9116c51 changed file +164 -0
- src/input.rs +164 -0
src/input.rsmodified+164 -0
| @@ -1421,6 +1421,15 @@ fn action( | |||
| 1421 | _ => (), | 1421 | _ => (), |
| 1422 | } | 1422 | } |
| 1423 | 1423 | ||
| 1424 | + bound_action(bindings, comp_mod, raw, mods) | ||
| 1425 | +} | ||
| 1426 | + | ||
| 1427 | +fn bound_action( | ||
| 1428 | + bindings: &Binds, | ||
| 1429 | + comp_mod: CompositorMod, | ||
| 1430 | + raw: Option<Keysym>, | ||
| 1431 | + mods: ModifiersState, | ||
| 1432 | +) -> Option<Action> { | ||
| 1424 | // Handle configured binds. | 1433 | // Handle configured binds. |
| 1425 | let mut modifiers = Modifiers::empty(); | 1434 | let mut modifiers = Modifiers::empty(); |
| 1426 | if mods.ctrl { | 1435 | if mods.ctrl { |
| @@ -1720,4 +1729,159 @@ mod tests { | |||
| 1720 | // Ensure that no keys are being suppressed. | 1729 | // Ensure that no keys are being suppressed. |
| 1721 | assert!(suppressed_keys.is_empty()); | 1730 | assert!(suppressed_keys.is_empty()); |
| 1722 | } | 1731 | } |
| 1732 | + | ||
| 1733 | + #[test] | ||
| 1734 | + fn comp_mod_handling() { | ||
| 1735 | + let bindings = Binds(vec![ | ||
| 1736 | + Bind { | ||
| 1737 | + key: Key { | ||
| 1738 | + keysym: Keysym::q, | ||
| 1739 | + modifiers: Modifiers::COMPOSITOR, | ||
| 1740 | + }, | ||
| 1741 | + actions: vec![Action::CloseWindow], | ||
| 1742 | + }, | ||
| 1743 | + Bind { | ||
| 1744 | + key: Key { | ||
| 1745 | + keysym: Keysym::h, | ||
| 1746 | + modifiers: Modifiers::SUPER, | ||
| 1747 | + }, | ||
| 1748 | + actions: vec![Action::FocusColumnLeft], | ||
| 1749 | + }, | ||
| 1750 | + Bind { | ||
| 1751 | + key: Key { | ||
| 1752 | + keysym: Keysym::j, | ||
| 1753 | + modifiers: Modifiers::empty(), | ||
| 1754 | + }, | ||
| 1755 | + actions: vec![Action::FocusWindowDown], | ||
| 1756 | + }, | ||
| 1757 | + Bind { | ||
| 1758 | + key: Key { | ||
| 1759 | + keysym: Keysym::k, | ||
| 1760 | + modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER, | ||
| 1761 | + }, | ||
| 1762 | + actions: vec![Action::FocusWindowUp], | ||
| 1763 | + }, | ||
| 1764 | + Bind { | ||
| 1765 | + key: Key { | ||
| 1766 | + keysym: Keysym::l, | ||
| 1767 | + modifiers: Modifiers::SUPER | Modifiers::ALT, | ||
| 1768 | + }, | ||
| 1769 | + actions: vec![Action::FocusColumnRight], | ||
| 1770 | + }, | ||
| 1771 | + ]); | ||
| 1772 | + | ||
| 1773 | + assert_eq!( | ||
| 1774 | + bound_action( | ||
| 1775 | + &bindings, | ||
| 1776 | + CompositorMod::Super, | ||
| 1777 | + Some(Keysym::q), | ||
| 1778 | + ModifiersState { | ||
| 1779 | + logo: true, | ||
| 1780 | + ..Default::default() | ||
| 1781 | + } | ||
| 1782 | + ), | ||
| 1783 | + Some(Action::CloseWindow) | ||
| 1784 | + ); | ||
| 1785 | + assert_eq!( | ||
| 1786 | + bound_action( | ||
| 1787 | + &bindings, | ||
| 1788 | + CompositorMod::Super, | ||
| 1789 | + Some(Keysym::q), | ||
| 1790 | + ModifiersState::default(), | ||
| 1791 | + ), | ||
| 1792 | + None, | ||
| 1793 | + ); | ||
| 1794 | + | ||
| 1795 | + // assert_eq!( | ||
| 1796 | + // bound_action( | ||
| 1797 | + // &bindings, | ||
| 1798 | + // CompositorMod::Super, | ||
| 1799 | + // Some(Keysym::h), | ||
| 1800 | + // ModifiersState { | ||
| 1801 | + // logo: true, | ||
| 1802 | + // ..Default::default() | ||
| 1803 | + // } | ||
| 1804 | + // ), | ||
| 1805 | + // Some(Action::FocusColumnLeft) | ||
| 1806 | + // ); | ||
| 1807 | + assert_eq!( | ||
| 1808 | + bound_action( | ||
| 1809 | + &bindings, | ||
| 1810 | + CompositorMod::Super, | ||
| 1811 | + Some(Keysym::h), | ||
| 1812 | + ModifiersState::default(), | ||
| 1813 | + ), | ||
| 1814 | + None, | ||
| 1815 | + ); | ||
| 1816 | + | ||
| 1817 | + assert_eq!( | ||
| 1818 | + bound_action( | ||
| 1819 | + &bindings, | ||
| 1820 | + CompositorMod::Super, | ||
| 1821 | + Some(Keysym::j), | ||
| 1822 | + ModifiersState { | ||
| 1823 | + logo: true, | ||
| 1824 | + ..Default::default() | ||
| 1825 | + } | ||
| 1826 | + ), | ||
| 1827 | + None, | ||
| 1828 | + ); | ||
| 1829 | + assert_eq!( | ||
| 1830 | + bound_action( | ||
| 1831 | + &bindings, | ||
| 1832 | + CompositorMod::Super, | ||
| 1833 | + Some(Keysym::j), | ||
| 1834 | + ModifiersState::default(), | ||
| 1835 | + ), | ||
| 1836 | + Some(Action::FocusWindowDown) | ||
| 1837 | + ); | ||
| 1838 | + | ||
| 1839 | + assert_eq!( | ||
| 1840 | + bound_action( | ||
| 1841 | + &bindings, | ||
| 1842 | + CompositorMod::Super, | ||
| 1843 | + Some(Keysym::k), | ||
| 1844 | + ModifiersState { | ||
| 1845 | + logo: true, | ||
| 1846 | + ..Default::default() | ||
| 1847 | + } | ||
| 1848 | + ), | ||
| 1849 | + Some(Action::FocusWindowUp) | ||
| 1850 | + ); | ||
| 1851 | + assert_eq!( | ||
| 1852 | + bound_action( | ||
| 1853 | + &bindings, | ||
| 1854 | + CompositorMod::Super, | ||
| 1855 | + Some(Keysym::k), | ||
| 1856 | + ModifiersState::default(), | ||
| 1857 | + ), | ||
| 1858 | + None, | ||
| 1859 | + ); | ||
| 1860 | + | ||
| 1861 | + // assert_eq!( | ||
| 1862 | + // bound_action( | ||
| 1863 | + // &bindings, | ||
| 1864 | + // CompositorMod::Super, | ||
| 1865 | + // Some(Keysym::l), | ||
| 1866 | + // ModifiersState { | ||
| 1867 | + // logo: true, | ||
| 1868 | + // alt: true, | ||
| 1869 | + // ..Default::default() | ||
| 1870 | + // } | ||
| 1871 | + // ), | ||
| 1872 | + // Some(Action::FocusColumnRight) | ||
| 1873 | + // ); | ||
| 1874 | + assert_eq!( | ||
| 1875 | + bound_action( | ||
| 1876 | + &bindings, | ||
| 1877 | + CompositorMod::Super, | ||
| 1878 | + Some(Keysym::l), | ||
| 1879 | + ModifiersState { | ||
| 1880 | + logo: true, | ||
| 1881 | + ..Default::default() | ||
| 1882 | + }, | ||
| 1883 | + ), | ||
| 1884 | + None, | ||
| 1885 | + ); | ||
| 1886 | + } | ||
| 1723 | } | 1887 | } |