From 57033ef758a89120fdc61453469a2dbfa049aa33 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Thu, 15 Oct 2026 13:30:40 -0700 Subject: [PATCH] =?UTF-8?q?Keyboard=20Shortcuts:=20a=20conflict=20goes=20s?= =?UTF-8?q?tale=20when=20the=20bindings=20change=20after=20it=20(Reset=20A?= =?UTF-8?q?ll,=20Use=20Default,=20Delete,=20=C3=97,=20Escape,=20a=20set=20?= =?UTF-8?q?switch);=20Accept=20takes=20the=20key=20from=20every=20holder;?= =?UTF-8?q?=20Linux=20reserves=20its=20own=20keys;=20doc=20comment=20back?= =?UTF-8?q?=20on=20shortcut=5Ftext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ui-egui/src/prefs_ui.rs | 64 +++++++++++++++++--- crates/ui-egui/src/shortcut_capture_tests.rs | 55 +++++++++++++++++ 2 files changed, 109 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rs index c62e75815b..99750ae7f1 100644 --- a/crates/ui-egui/src/prefs_ui.rs +++ b/crates/ui-egui/src/prefs_ui.rs @@ -804,7 +804,14 @@ pub fn shortcut_items(app: &PhotocraftApp) -> Vec<(String, String, Vec, out } -/// Text of a key press for the shortcut editor (`Cmd+Shift+K`), `None` for bare modifiers. +/// A fingerprint of the bindings a shortcut conflict describes. +fn conflict_state(overrides: &BTreeMap, alternates: &BTreeMap>, selected: &str, set: Option<&Value>) -> u64 { + use std::hash::{Hash, Hasher}; + let mut h = std::collections::hash_map::DefaultHasher::new(); + (overrides, alternates, selected, set.map(Value::to_string)).hash(&mut h); + h.finish() +} + /// Keys the system takes before the app sees them (switching apps, closing the window, force /// quit): Edit › Keyboard Shortcuts won't assign them, as Photoshop won't. `sc` is in our /// notation, where `Cmd` is Ctrl off the Mac. @@ -812,12 +819,33 @@ pub fn reserved_shortcut(sc: &str) -> bool { let Some(n) = prefs::normalize_shortcut(sc) else { return false }; let reserved: &[&str] = if cfg!(target_os = "macos") { &["Cmd+Tab", "Cmd+Shift+Tab", "Cmd+Alt+Escape", "Cmd+`"] - } else { + } else if cfg!(target_os = "windows") { &["Alt+Tab", "Alt+Shift+Tab", "Alt+F4", "Cmd+Alt+Delete", "Cmd+Escape", "Cmd+Shift+Escape"] + } else { + // Linux and the BSDs: window switching and closing, and the virtual consoles. + &[ + "Alt+Tab", + "Alt+Shift+Tab", + "Alt+F4", + "Cmd+Alt+Delete", + "Cmd+Alt+F1", + "Cmd+Alt+F2", + "Cmd+Alt+F3", + "Cmd+Alt+F4", + "Cmd+Alt+F5", + "Cmd+Alt+F6", + "Cmd+Alt+F7", + "Cmd+Alt+F8", + "Cmd+Alt+F9", + "Cmd+Alt+F10", + "Cmd+Alt+F11", + "Cmd+Alt+F12", + ] }; reserved.iter().filter_map(|r| prefs::normalize_shortcut(r)).any(|r| r == n) } +/// Text of a key press for the shortcut editor (`Cmd+Shift+K`), `None` for bare modifiers. pub fn shortcut_text(key: egui::Key, m: egui::Modifiers) -> Option { if is_modifier_key(key) { return None; @@ -1755,6 +1783,7 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map = serde_json::from_value(c["holders"].clone()).unwrap_or_else(|_| vec![with.to_string()]); + for holder in &holders { + let def = items.iter().find(|i| i.0 == *holder).and_then(|i| i.3.clone()); + let cur = eff(&overrides, holder, &def); + if cur.as_deref().and_then(prefs::normalize_shortcut).as_deref() == Some(key) { + overrides.insert(holder.clone(), String::new()); + } + let keys = eff_alts(&alt_overrides, holder, eff(&overrides, holder, &def).as_deref()); + if keys.iter().any(|k| k == key) { + alt_overrides.insert(holder.clone(), keys.into_iter().filter(|k| k != key).collect()); + } } selected = with.to_string(); filter.clear(); @@ -2007,6 +2047,10 @@ fn shortcuts_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map