Skip to content

Commit 695dac6

Browse files
flowerysongJustinSpedding
authored andcommitted
Add special release binds that always trigger
The main use case (apart from modifier-only binds) the community has presented for release binds is push-to-talk, which is less viable when you can trigger the unmute but then accidentally not trigger the mute because of other input you performed.
1 parent 70a0572 commit 695dac6

File tree

6 files changed

+157
-4
lines changed

6 files changed

+157
-4
lines changed

docs/wiki/Configuration:-Key-Bindings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ binds {
9393
}
9494
```
9595

96-
These will only trigger if no other keys were released and no keys or mouse buttons were pressed after the bound key was pressed.
96+
These will normally only trigger if no other keys were released and no keys or mouse buttons were pressed after the bound key was pressed. If you want one to always trigger you should also set `allow-invalidation=false`.
9797

9898
Note that the modifier state is updated before binds are evaluated, so if you want to configure a modifier key as both a normal bind and a release bind the entries are slightly different.
9999

100100
```kdl
101101
binds {
102102
Alt+Ctrl+Control_L repeat=false { spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SOURCE@" "0"; }
103-
Alt+Control_L release=true { spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SOURCE@" "1"; }
103+
Alt+Control_L release=true allow-invalidation=false { spawn "wpctl" "set-mute" "@DEFAULT_AUDIO_SOURCE@" "1"; }
104104
}
105105
```
106106

niri-config/src/binds.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct Bind {
2727
pub cooldown: Option<Duration>,
2828
pub allow_when_locked: bool,
2929
pub allow_inhibiting: bool,
30+
pub allow_invalidation: bool,
3031
pub hotkey_overlay_title: Option<Option<String>>,
3132
}
3233

@@ -869,6 +870,7 @@ where
869870
let mut allow_when_locked = false;
870871
let mut allow_when_locked_node = None;
871872
let mut allow_inhibiting = true;
873+
let mut allow_invalidation = true;
872874
let mut hotkey_overlay_title = None;
873875
for (name, val) in &node.properties {
874876
match &***name {
@@ -890,6 +892,9 @@ where
890892
"allow-inhibiting" => {
891893
allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?;
892894
}
895+
"allow-invalidation" => {
896+
allow_invalidation = knuffel::traits::DecodeScalar::decode(val, ctx)?;
897+
}
893898
"hotkey-overlay-title" => {
894899
hotkey_overlay_title = Some(knuffel::traits::DecodeScalar::decode(val, ctx)?);
895900
}
@@ -916,6 +921,7 @@ where
916921
cooldown: None,
917922
allow_when_locked: false,
918923
allow_inhibiting: true,
924+
allow_invalidation: true,
919925
hotkey_overlay_title: None,
920926
};
921927

@@ -953,6 +959,7 @@ where
953959
cooldown,
954960
allow_when_locked,
955961
allow_inhibiting,
962+
allow_invalidation,
956963
hotkey_overlay_title,
957964
})
958965
}

niri-config/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ mod tests {
908908
Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
909909
Super+Alt+S allow-when-locked=true { spawn-sh "pkill orca || exec orca"; }
910910
Mod release=true { toggle-overview; }
911+
Shift+Mod release=true allow-invalidation=false { toggle-window-floating; }
911912
}
912913
913914
switch-events {
@@ -1899,6 +1900,7 @@ mod tests {
18991900
cooldown: None,
19001901
allow_when_locked: false,
19011902
allow_inhibiting: false,
1903+
allow_invalidation: true,
19021904
hotkey_overlay_title: Some(
19031905
Some(
19041906
"Inhibit",
@@ -1920,6 +1922,7 @@ mod tests {
19201922
cooldown: None,
19211923
allow_when_locked: false,
19221924
allow_inhibiting: false,
1925+
allow_invalidation: true,
19231926
hotkey_overlay_title: None,
19241927
},
19251928
Bind {
@@ -1941,6 +1944,7 @@ mod tests {
19411944
cooldown: None,
19421945
allow_when_locked: true,
19431946
allow_inhibiting: true,
1947+
allow_invalidation: true,
19441948
hotkey_overlay_title: None,
19451949
},
19461950
Bind {
@@ -1958,6 +1962,7 @@ mod tests {
19581962
cooldown: None,
19591963
allow_when_locked: false,
19601964
allow_inhibiting: true,
1965+
allow_invalidation: true,
19611966
hotkey_overlay_title: Some(
19621967
None,
19631968
),
@@ -1977,6 +1982,7 @@ mod tests {
19771982
cooldown: None,
19781983
allow_when_locked: false,
19791984
allow_inhibiting: true,
1985+
allow_invalidation: true,
19801986
hotkey_overlay_title: None,
19811987
},
19821988
Bind {
@@ -1996,6 +2002,7 @@ mod tests {
19962002
cooldown: None,
19972003
allow_when_locked: false,
19982004
allow_inhibiting: true,
2005+
allow_invalidation: true,
19992006
hotkey_overlay_title: None,
20002007
},
20012008
Bind {
@@ -2013,6 +2020,7 @@ mod tests {
20132020
cooldown: None,
20142021
allow_when_locked: false,
20152022
allow_inhibiting: true,
2023+
allow_invalidation: true,
20162024
hotkey_overlay_title: None,
20172025
},
20182026
Bind {
@@ -2032,6 +2040,7 @@ mod tests {
20322040
cooldown: None,
20332041
allow_when_locked: false,
20342042
allow_inhibiting: true,
2043+
allow_invalidation: true,
20352044
hotkey_overlay_title: None,
20362045
},
20372046
Bind {
@@ -2051,6 +2060,7 @@ mod tests {
20512060
cooldown: None,
20522061
allow_when_locked: false,
20532062
allow_inhibiting: true,
2063+
allow_invalidation: true,
20542064
hotkey_overlay_title: None,
20552065
},
20562066
Bind {
@@ -2068,6 +2078,7 @@ mod tests {
20682078
cooldown: None,
20692079
allow_when_locked: false,
20702080
allow_inhibiting: true,
2081+
allow_invalidation: true,
20712082
hotkey_overlay_title: None,
20722083
},
20732084
Bind {
@@ -2089,6 +2100,7 @@ mod tests {
20892100
cooldown: None,
20902101
allow_when_locked: false,
20912102
allow_inhibiting: true,
2103+
allow_invalidation: true,
20922104
hotkey_overlay_title: None,
20932105
},
20942106
Bind {
@@ -2110,6 +2122,7 @@ mod tests {
21102122
cooldown: None,
21112123
allow_when_locked: false,
21122124
allow_inhibiting: true,
2125+
allow_invalidation: true,
21132126
hotkey_overlay_title: None,
21142127
},
21152128
Bind {
@@ -2129,6 +2142,7 @@ mod tests {
21292142
cooldown: None,
21302143
allow_when_locked: false,
21312144
allow_inhibiting: false,
2145+
allow_invalidation: true,
21322146
hotkey_overlay_title: None,
21332147
},
21342148
Bind {
@@ -2146,6 +2160,7 @@ mod tests {
21462160
),
21472161
allow_when_locked: false,
21482162
allow_inhibiting: true,
2163+
allow_invalidation: true,
21492164
hotkey_overlay_title: None,
21502165
},
21512166
Bind {
@@ -2165,6 +2180,7 @@ mod tests {
21652180
cooldown: None,
21662181
allow_when_locked: true,
21672182
allow_inhibiting: true,
2183+
allow_invalidation: true,
21682184
hotkey_overlay_title: None,
21692185
},
21702186
Bind {
@@ -2180,6 +2196,23 @@ mod tests {
21802196
cooldown: None,
21812197
allow_when_locked: false,
21822198
allow_inhibiting: true,
2199+
allow_invalidation: true,
2200+
hotkey_overlay_title: None,
2201+
},
2202+
Bind {
2203+
key: Key {
2204+
trigger: KeyCompositor,
2205+
modifiers: Modifiers(
2206+
SHIFT,
2207+
),
2208+
},
2209+
action: ToggleWindowFloating,
2210+
repeat: true,
2211+
release: true,
2212+
cooldown: None,
2213+
allow_when_locked: false,
2214+
allow_inhibiting: true,
2215+
allow_invalidation: false,
21832216
hotkey_overlay_title: None,
21842217
},
21852218
],
@@ -2305,6 +2338,7 @@ mod tests {
23052338
cooldown: None,
23062339
allow_when_locked: false,
23072340
allow_inhibiting: true,
2341+
allow_invalidation: true,
23082342
hotkey_overlay_title: None,
23092343
},
23102344
Bind {
@@ -2328,6 +2362,7 @@ mod tests {
23282362
cooldown: None,
23292363
allow_when_locked: false,
23302364
allow_inhibiting: true,
2365+
allow_invalidation: true,
23312366
hotkey_overlay_title: None,
23322367
},
23332368
Bind {
@@ -2353,6 +2388,7 @@ mod tests {
23532388
cooldown: None,
23542389
allow_when_locked: false,
23552390
allow_inhibiting: true,
2391+
allow_invalidation: true,
23562392
hotkey_overlay_title: None,
23572393
},
23582394
],

niri-config/src/recent_windows.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl From<MruBind> for Bind {
154154
cooldown: None,
155155
allow_when_locked: false,
156156
allow_inhibiting: x.allow_inhibiting,
157+
allow_invalidation: true,
157158
hotkey_overlay_title: x.hotkey_overlay_title,
158159
}
159160
}

0 commit comments

Comments
 (0)