forge
Explore
Log in

Don't you dare go Hollow

Add allow-when-locked=true spawn bind property

Browse files at this commit

914237fa1149a022d8e012ce5a0aa1107c4906fcIvan MolodetskikhParent: 0b93c46
niri-config/src/lib.rsmodified+36 -7
@@ -739,6 +739,7 @@ pub struct Bind {
739 pub key: Key,739 pub key: Key,
740 pub action: Action,740 pub action: Action,
741 pub cooldown: Option<Duration>,741 pub cooldown: Option<Duration>,
742+ pub allow_when_locked: bool,
742 }743 }
743 744
744 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]745 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
@@ -1564,7 +1565,7 @@ where
1564 &val.literal,1565 &val.literal,
1565 "argument",1566 "argument",
1566 "no arguments expected for this node",1567 "no arguments expected for this node",
1567- ))1568+ ));
1568 }1569 }
1569 1570
1570 let key = node1571 let key = node
@@ -1573,6 +1574,8 @@ where
1573 .map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?;1574 .map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?;
1574 1575
1575 let mut cooldown = None;1576 let mut cooldown = None;
1577+ let mut allow_when_locked = false;
1578+ let mut allow_when_locked_node = None;
1576 for (name, val) in &node.properties {1579 for (name, val) in &node.properties {
1577 match &***name {1580 match &***name {
1578 "cooldown-ms" => {1581 "cooldown-ms" => {
@@ -1580,6 +1583,10 @@ where
1580 knuffel::traits::DecodeScalar::decode(val, ctx)?,1583 knuffel::traits::DecodeScalar::decode(val, ctx)?,
1581 ));1584 ));
1582 }1585 }
1586+ "allow-when-locked" => {
1587+ allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?;
1588+ allow_when_locked_node = Some(name);
1589+ }
1583 name_str => {1590 name_str => {
1584 ctx.emit_error(DecodeError::unexpected(1591 ctx.emit_error(DecodeError::unexpected(
1585 name,1592 name,
@@ -1599,6 +1606,7 @@ where
1599 key,1606 key,
1600 action: Action::Spawn(vec![]),1607 action: Action::Spawn(vec![]),
1601 cooldown: None,1608 cooldown: None,
1609+ allow_when_locked: false,
1602 };1610 };
1603 1611
1604 if let Some(child) = children.next() {1612 if let Some(child) = children.next() {
@@ -1610,11 +1618,24 @@ where
1610 ));1618 ));
1611 }1619 }
1612 match Action::decode_node(child, ctx) {1620 match Action::decode_node(child, ctx) {
1613- Ok(action) => Ok(Self {1621+ Ok(action) => {
1614- key,1622+ if !matches!(action, Action::Spawn(_)) {
1615- action,1623+ if let Some(node) = allow_when_locked_node {
1616- cooldown,1624+ ctx.emit_error(DecodeError::unexpected(
1617- }),1625+ node,
1626+ "property",
1627+ "allow-when-locked can only be set on spawn binds",
1628+ ));
1629+ }
1630+ }
1631+
1632+ Ok(Self {
1633+ key,
1634+ action,
1635+ cooldown,
1636+ allow_when_locked,
1637+ })
1638+ }
1618 Err(e) => {1639 Err(e) => {
1619 ctx.emit_error(e);1640 ctx.emit_error(e);
1620 Ok(dummy)1641 Ok(dummy)
@@ -1922,7 +1943,7 @@ mod tests {
1922 }1943 }
1923 1944
1924 binds {1945 binds {
1925- Mod+T { spawn "alacritty"; }1946+ Mod+T allow-when-locked=true { spawn "alacritty"; }
1926 Mod+Q { close-window; }1947 Mod+Q { close-window; }
1927 Mod+Shift+H { focus-monitor-left; }1948 Mod+Shift+H { focus-monitor-left; }
1928 Mod+Ctrl+Shift+L { move-window-to-monitor-right; }1949 Mod+Ctrl+Shift+L { move-window-to-monitor-right; }
@@ -2131,6 +2152,7 @@ mod tests {
2131 },2152 },
2132 action: Action::Spawn(vec!["alacritty".to_owned()]),2153 action: Action::Spawn(vec!["alacritty".to_owned()]),
2133 cooldown: None,2154 cooldown: None,
2155+ allow_when_locked: true,
2134 },2156 },
2135 Bind {2157 Bind {
2136 key: Key {2158 key: Key {
@@ -2139,6 +2161,7 @@ mod tests {
2139 },2161 },
2140 action: Action::CloseWindow,2162 action: Action::CloseWindow,
2141 cooldown: None,2163 cooldown: None,
2164+ allow_when_locked: false,
2142 },2165 },
2143 Bind {2166 Bind {
2144 key: Key {2167 key: Key {
@@ -2147,6 +2170,7 @@ mod tests {
2147 },2170 },
2148 action: Action::FocusMonitorLeft,2171 action: Action::FocusMonitorLeft,
2149 cooldown: None,2172 cooldown: None,
2173+ allow_when_locked: false,
2150 },2174 },
2151 Bind {2175 Bind {
2152 key: Key {2176 key: Key {
@@ -2155,6 +2179,7 @@ mod tests {
2155 },2179 },
2156 action: Action::MoveWindowToMonitorRight,2180 action: Action::MoveWindowToMonitorRight,
2157 cooldown: None,2181 cooldown: None,
2182+ allow_when_locked: false,
2158 },2183 },
2159 Bind {2184 Bind {
2160 key: Key {2185 key: Key {
@@ -2163,6 +2188,7 @@ mod tests {
2163 },2188 },
2164 action: Action::ConsumeWindowIntoColumn,2189 action: Action::ConsumeWindowIntoColumn,
2165 cooldown: None,2190 cooldown: None,
2191+ allow_when_locked: false,
2166 },2192 },
2167 Bind {2193 Bind {
2168 key: Key {2194 key: Key {
@@ -2171,6 +2197,7 @@ mod tests {
2171 },2197 },
2172 action: Action::FocusWorkspace(1),2198 action: Action::FocusWorkspace(1),
2173 cooldown: None,2199 cooldown: None,
2200+ allow_when_locked: false,
2174 },2201 },
2175 Bind {2202 Bind {
2176 key: Key {2203 key: Key {
@@ -2179,6 +2206,7 @@ mod tests {
2179 },2206 },
2180 action: Action::Quit(true),2207 action: Action::Quit(true),
2181 cooldown: None,2208 cooldown: None,
2209+ allow_when_locked: false,
2182 },2210 },
2183 Bind {2211 Bind {
2184 key: Key {2212 key: Key {
@@ -2187,6 +2215,7 @@ mod tests {
2187 },2215 },
2188 action: Action::FocusWorkspaceDown,2216 action: Action::FocusWorkspaceDown,
2189 cooldown: Some(Duration::from_millis(150)),2217 cooldown: Some(Duration::from_millis(150)),
2218+ allow_when_locked: false,
2190 },2219 },
2191 ]),2220 ]),
2192 debug: DebugConfig {2221 debug: DebugConfig {
resources/default-config.kdlmodified+4 -2
@@ -263,8 +263,10 @@ binds {
263 // Mod+T { spawn "bash" "-c" "notify-send hello && exec alacritty"; }263 // Mod+T { spawn "bash" "-c" "notify-send hello && exec alacritty"; }
264 264
265 // Example volume keys mappings for PipeWire & WirePlumber.265 // Example volume keys mappings for PipeWire & WirePlumber.
266- XF86AudioRaiseVolume { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1+"; }266+ // The allow-when-locked=true property makes them work even when the session is locked.
267- XF86AudioLowerVolume { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1-"; }267+ XF86AudioRaiseVolume allow-when-locked=true { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1+"; }
268+ XF86AudioLowerVolume allow-when-locked=true { spawn "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.1-"; }
269+ XF86AudioMute allow-when-locked=true { spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SINK@" "toggle"; }
268 270
269 Mod+Q { close-window; }271 Mod+Q { close-window; }
270 272
src/input.rsmodified+13 -5
@@ -297,12 +297,12 @@ impl State {
297 297
298 pub fn handle_bind(&mut self, bind: Bind) {298 pub fn handle_bind(&mut self, bind: Bind) {
299 let Some(cooldown) = bind.cooldown else {299 let Some(cooldown) = bind.cooldown else {
300- self.do_action(bind.action);300+ self.do_action(bind.action, bind.allow_when_locked);
301 return;301 return;
302 };302 };
303 303
304 // Check this first so that it doesn't trigger the cooldown.304 // Check this first so that it doesn't trigger the cooldown.
305- if self.niri.is_locked() && !allowed_when_locked(&bind.action) {305+ if self.niri.is_locked() && !(bind.allow_when_locked || allowed_when_locked(&bind.action)) {
306 return;306 return;
307 }307 }
308 308
@@ -323,13 +323,13 @@ impl State {
323 .unwrap();323 .unwrap();
324 entry.insert(token);324 entry.insert(token);
325 325
326- self.do_action(bind.action);326+ self.do_action(bind.action, bind.allow_when_locked);
327 }327 }
328 }328 }
329 }329 }
330 330
331- pub fn do_action(&mut self, action: Action) {331+ pub fn do_action(&mut self, action: Action, allow_when_locked: bool) {
332- if self.niri.is_locked() && !allowed_when_locked(&action) {332+ if self.niri.is_locked() && !(allow_when_locked || allowed_when_locked(&action)) {
333 return;333 return;
334 }334 }
335 335
@@ -1844,6 +1844,7 @@ fn should_intercept_key(
1844 },1844 },
1845 action,1845 action,
1846 cooldown: None,1846 cooldown: None,
1847+ allow_when_locked: false,
1847 });1848 });
1848 }1849 }
1849 }1850 }
@@ -1892,6 +1893,7 @@ fn find_bind(
1892 },1893 },
1893 action,1894 action,
1894 cooldown: None,1895 cooldown: None,
1896+ allow_when_locked: false,
1895 });1897 });
1896 }1898 }
1897 1899
@@ -2174,6 +2176,7 @@ mod tests {
2174 },2176 },
2175 action: Action::CloseWindow,2177 action: Action::CloseWindow,
2176 cooldown: None,2178 cooldown: None,
2179+ allow_when_locked: false,
2177 }]);2180 }]);
2178 2181
2179 let comp_mod = CompositorMod::Super;2182 let comp_mod = CompositorMod::Super;
@@ -2306,6 +2309,7 @@ mod tests {
2306 },2309 },
2307 action: Action::CloseWindow,2310 action: Action::CloseWindow,
2308 cooldown: None,2311 cooldown: None,
2312+ allow_when_locked: false,
2309 },2313 },
2310 Bind {2314 Bind {
2311 key: Key {2315 key: Key {
@@ -2314,6 +2318,7 @@ mod tests {
2314 },2318 },
2315 action: Action::FocusColumnLeft,2319 action: Action::FocusColumnLeft,
2316 cooldown: None,2320 cooldown: None,
2321+ allow_when_locked: false,
2317 },2322 },
2318 Bind {2323 Bind {
2319 key: Key {2324 key: Key {
@@ -2322,6 +2327,7 @@ mod tests {
2322 },2327 },
2323 action: Action::FocusWindowDown,2328 action: Action::FocusWindowDown,
2324 cooldown: None,2329 cooldown: None,
2330+ allow_when_locked: false,
2325 },2331 },
2326 Bind {2332 Bind {
2327 key: Key {2333 key: Key {
@@ -2330,6 +2336,7 @@ mod tests {
2330 },2336 },
2331 action: Action::FocusWindowUp,2337 action: Action::FocusWindowUp,
2332 cooldown: None,2338 cooldown: None,
2339+ allow_when_locked: false,
2333 },2340 },
2334 Bind {2341 Bind {
2335 key: Key {2342 key: Key {
@@ -2338,6 +2345,7 @@ mod tests {
2338 },2345 },
2339 action: Action::FocusColumnRight,2346 action: Action::FocusColumnRight,
2340 cooldown: None,2347 cooldown: None,
2348+ allow_when_locked: false,
2341 },2349 },
2342 ]);2350 ]);
2343 2351
src/ipc/server.rsmodified+1 -1
@@ -156,7 +156,7 @@ fn process(ctx: &ClientCtx, buf: &str) -> anyhow::Result<Response> {
156 Request::Action(action) => {156 Request::Action(action) => {
157 let action = niri_config::Action::from(action);157 let action = niri_config::Action::from(action);
158 ctx.event_loop.insert_idle(move |state| {158 ctx.event_loop.insert_idle(move |state| {
159- state.do_action(action);159+ state.do_action(action, false);
160 });160 });
161 Response::Handled161 Response::Handled
162 }162 }
wiki/Configuration:-Key-Bindings.mdmodified+9 -0
@@ -113,6 +113,15 @@ binds {
113 }113 }
114 ```114 ```
115 115
116+Spawn bindings have a special `allow-when-locked=true` property that makes them work even while the session is locked:
117+
118+```
119+binds {
120+ // This mute bind will work even when the session is locked.
121+ XF86AudioMute allow-when-locked=true { spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SINK@" "toggle"; }
122+}
123+```
124+
116 Currently, niri *does not* use a shell to run commands, which means that you need to manually separate arguments.125 Currently, niri *does not* use a shell to run commands, which means that you need to manually separate arguments.
117 126
118 ```127 ```