Skip to content

Commit bf928a0

Browse files
committed
per-hotkey overrides for hotkey overlap check
1 parent f98402d commit bf928a0

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/BizHawk.Client.Common/config/Binding.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ static HotkeyInfo()
1919
var dict = new Dictionary<string, HotkeyInfo>();
2020
var i = 0;
2121
#if true
22-
void Bind(string tabGroup, string displayName, string defaultBinding = "", string toolTip = "")
23-
=> dict.Add(displayName, new(tabGroup: tabGroup, i++, displayName: displayName, toolTip: toolTip, defaultBinding: defaultBinding));
22+
// Note (2025-10-23): Having bindings init with an intended scope would be better than merely marking overlaps with defaultBindingOverlaps
23+
// e.g., for Ctrl+C overlaps (like MainForm vs. TAStudio), there's other code that checks which UI is focused, but consolidating such scope here on init would be better. --RetroEdit
24+
void Bind(string tabGroup, string displayName, string defaultBinding = "", string toolTip = "", bool defaultBindingOverlaps = false)
25+
=> dict.Add(displayName, new(tabGroup: tabGroup, i++, displayName: displayName, toolTip: toolTip, defaultBinding: defaultBinding, defaultBindingOverlaps: defaultBindingOverlaps));
2426
#else //TODO switch to a sort key more resilient than the DisplayName, like with this example (need to update `Config.HotkeyBindings["A Hotkey"]` usages across codebase; please switch it to a `Config.GetHotkeyBindings` method so it can return "<not bound>")
2527
void Bind(string tabGroup, string displayName, string defaultBinding = "", string toolTip = "")
26-
=> dict.Add($"{tabGroup}__{displayName}".Replace(" ", ""), new(tabGroup: tabGroup, i++, displayName: displayName, toolTip: toolTip, defaultBinding: defaultBinding));
28+
=> dict.Add($"{tabGroup}__{displayName}".Replace(" ", ""), new(tabGroup: tabGroup, i++, displayName: displayName, toolTip: toolTip, defaultBinding: defaultBinding, defaultBindingOverlaps: defaultBindingOverlaps));
2729
#endif
2830

2931
Bind("General", "Frame Advance", "F");
@@ -61,7 +63,7 @@ void Bind(string tabGroup, string displayName, string defaultBinding = "", strin
6163
Bind("General", "Reboot Core", "Ctrl+R");
6264
Bind("General", "Toggle Sound");
6365
Bind("General", "Exit Program");
64-
Bind("General", "Screen Raw to Clipboard", "Ctrl+C");
66+
Bind("General", "Screen Raw to Clipboard", "Ctrl+C", defaultBindingOverlaps: true);
6567
Bind("General", "Screen Client to Clipboard", "Ctrl+Shift+C");
6668
Bind("General", "Toggle Skip Lag Frame");
6769
Bind("General", "Toggle Key Priority");
@@ -151,7 +153,7 @@ void Bind(string tabGroup, string displayName, string defaultBinding = "", strin
151153
Bind("TAStudio", "Sel. bet. Markers", "Ctrl+A");
152154
Bind("TAStudio", "Select All", "Ctrl+Shift+A");
153155
Bind("TAStudio", "Reselect Clip.", "Ctrl+B");
154-
Bind("TAStudio", "Copy Frames", "Ctrl+C");
156+
Bind("TAStudio", "Copy Frames", "Ctrl+C", defaultBindingOverlaps: true);
155157
Bind("TAStudio", "Paste Frames", "Ctrl+V");
156158
Bind("TAStudio", "Paste Insert Frames", "Ctrl+Shift+V");
157159
Bind("TAStudio", "Cut Frames", "Ctrl+X");
@@ -200,20 +202,20 @@ void Bind(string tabGroup, string displayName, string defaultBinding = "", strin
200202
Bind("NDS", "Swap Screens");
201203

202204
Bind("RAIntegration", "Open RA Overlay", "Escape");
203-
Bind("RAIntegration", "RA Up", "Up");
204-
Bind("RAIntegration", "RA Down", "Down");
205-
Bind("RAIntegration", "RA Left", "Left");
206-
Bind("RAIntegration", "RA Right", "Right");
207-
Bind("RAIntegration", "RA Confirm", "X");
208-
Bind("RAIntegration", "RA Cancel", "Z");
209-
Bind("RAIntegration", "RA Quit", "Backspace");
205+
Bind("RAIntegration", "RA Up", "Up", defaultBindingOverlaps: true);
206+
Bind("RAIntegration", "RA Down", "Down", defaultBindingOverlaps: true);
207+
Bind("RAIntegration", "RA Left", "Left", defaultBindingOverlaps: true);
208+
Bind("RAIntegration", "RA Right", "Right", defaultBindingOverlaps: true);
209+
Bind("RAIntegration", "RA Confirm", "X", defaultBindingOverlaps: true);
210+
Bind("RAIntegration", "RA Cancel", "Z", defaultBindingOverlaps: true);
211+
Bind("RAIntegration", "RA Quit", "Backspace", defaultBindingOverlaps: true);
210212

211213
AllHotkeys = dict;
212214
Groupings = dict.Values.Select(static info => info.TabGroup).Distinct().ToList();
213215

214216
#if DEBUG
215217
var bindings = dict.Values
216-
.Where(static info => !info.DisplayName.StartsWith("RA ") && !string.IsNullOrEmpty(info.DefaultBinding))
218+
.Where(static info => !info.DefaultBindingOverlapCheckOverride && !string.IsNullOrEmpty(info.DefaultBinding))
217219
.Select(static info => info.DefaultBinding)
218220
.ToArray();
219221
Debug.Assert(bindings.Distinct().CountIsExactly(bindings.Length), "Do not default bind multiple hotkeys to the same button combination.");
@@ -228,6 +230,8 @@ public static void ResolveWithDefaults(IDictionary<string, string> dict)
228230

229231
public readonly string DefaultBinding;
230232

233+
public readonly bool DefaultBindingOverlapCheckOverride;
234+
231235
public readonly string DisplayName;
232236

233237
public readonly int Ordinal;
@@ -236,13 +240,14 @@ public static void ResolveWithDefaults(IDictionary<string, string> dict)
236240

237241
public readonly string ToolTip;
238242

239-
private HotkeyInfo(string tabGroup, int ordinal, string displayName, string toolTip, string defaultBinding)
243+
private HotkeyInfo(string tabGroup, int ordinal, string displayName, string toolTip, string defaultBinding, bool defaultBindingOverlaps)
240244
{
241245
DefaultBinding = defaultBinding;
242246
DisplayName = displayName;
243247
Ordinal = ordinal;
244248
TabGroup = tabGroup;
245249
ToolTip = toolTip;
250+
DefaultBindingOverlapCheckOverride = defaultBindingOverlaps;
246251
}
247252
}
248253
}

0 commit comments

Comments
 (0)