shortcuts: physical-key bindings for AZERTY layouts; Go to Work Area Start/End
Shortcut presets accept Physical+<key> (egui US-position names) so layouts that report the same logical key for two physical keys (AZERTY's - and )) can bind them separately; physical bindings win for that press, and a focused panel's binding wins over an application command on the same chord. ui.key accepts the same notation. Adds time.workAreaStart / time.workAreaEnd. (cherry picked from commit 209543e9e0ba32f809f9ff333abb8b8ec4125cea) (cherry picked from commit f8301a9e3e0b60e200e8a233455398741658481e) (cherry picked from commit 4d002fabf992934e1bb73a0c32bc9f3fd3ae5447) (cherry picked from commit 5d466c5955ee934d5347c194ec7d15fb5f58bba4)
This commit is contained in:
@@ -382,8 +382,9 @@ pub fn handle(app: &mut EffectcraftApp, ctx: &egui::Context, req: &ControlReques
|
||||
let Some((mut m, key)) = crate::menus::parse_shortcut(name) else { return err(format!("unknown key `{name}`")) };
|
||||
let extra = modifiers(p);
|
||||
m |= extra;
|
||||
app.synthetic.push(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: m });
|
||||
app.synthetic.push(egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: m });
|
||||
let physical_key = name.starts_with("Physical+").then_some(key);
|
||||
app.synthetic.push(egui::Event::Key { key, physical_key, pressed: true, repeat: false, modifiers: m });
|
||||
app.synthetic.push(egui::Event::Key { key, physical_key, pressed: false, repeat: false, modifiers: m });
|
||||
Outcome::AfterInput
|
||||
}
|
||||
"ui.type" => {
|
||||
|
||||
+33
-11
@@ -1539,6 +1539,7 @@ pub fn parse_shortcut(s: &str) -> Option<(egui::Modifiers, egui::Key)> {
|
||||
m.ctrl = true;
|
||||
}
|
||||
}
|
||||
"Physical" => {}
|
||||
"Shift" => m.shift = true,
|
||||
"Alt" => m.alt = true,
|
||||
"Ctrl" => m.ctrl = true,
|
||||
@@ -1586,6 +1587,9 @@ pub type Binding = (egui::Modifiers, egui::Key, String, Value);
|
||||
pub fn bindings(session: &effectcraft_engine::Session) -> Vec<Binding> {
|
||||
let mut v: Vec<Binding> = Vec::new();
|
||||
for (sc, b) in session.shortcuts().bindings() {
|
||||
if sc.starts_with("Physical+") {
|
||||
continue;
|
||||
}
|
||||
// Off macOS `Cmd` is Ctrl, so a custom Ctrl+Cmd shortcut would
|
||||
// steal the plain Cmd one: such macOS-only shortcuts aren't bound there.
|
||||
if !cfg!(target_os = "macos") && sc.split('+').any(|p| p == "Ctrl") && sc.split('+').any(|p| p == "Cmd") {
|
||||
@@ -1699,7 +1703,7 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
// The paste event's text: Edit ▸ Paste pastes SVG markup as a shape layer.
|
||||
let pasted =
|
||||
if clipboard { ctx.input(|i| i.events.iter().rev().find_map(|e| if let egui::Event::Paste(t) = e { Some(t.clone()) } else { None })) } else { None };
|
||||
let mut events: Vec<(egui::Key, egui::Modifiers, bool)> = ctx.input(|i| {
|
||||
let mut events: Vec<(egui::Key, egui::Modifiers, bool, Option<egui::Key>)> = ctx.input(|i| {
|
||||
// The windowing layer turns Ctrl+C / Ctrl+X / Ctrl+V into clipboard events instead of
|
||||
// key presses: map them back to the keys (with the modifiers held) so Edit ▸ Copy, Cut,
|
||||
// Paste and their variants (Ctrl+Alt+C…) run. Clipboard events carry no modifiers and
|
||||
@@ -1715,31 +1719,31 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
egui::Event::ModifiersChanged(m) => at = Some(*m),
|
||||
// egui forgets the modifiers held when the window loses focus.
|
||||
egui::Event::WindowFocused(false) => at = Some(egui::Modifiers::NONE),
|
||||
egui::Event::Key { key, pressed: true, modifiers, repeat, .. }
|
||||
egui::Event::Key { key, physical_key, pressed: true, modifiers, repeat, .. }
|
||||
if !*repeat
|
||||
|| matches!(
|
||||
key,
|
||||
egui::Key::PageUp | egui::Key::PageDown | egui::Key::ArrowLeft | egui::Key::ArrowRight | egui::Key::ArrowUp | egui::Key::ArrowDown
|
||||
) =>
|
||||
{
|
||||
out.push((*key, *modifiers, true));
|
||||
out.push((*key, *modifiers, true, *physical_key));
|
||||
}
|
||||
egui::Event::Key { key: egui::Key::Space, pressed: false, .. } => out.push((egui::Key::Space, egui::Modifiers::NONE, false)),
|
||||
egui::Event::Copy if clipboard => out.push((egui::Key::C, held(at), true)),
|
||||
egui::Event::Key { key: egui::Key::Space, pressed: false, .. } => out.push((egui::Key::Space, egui::Modifiers::NONE, false, None)),
|
||||
egui::Event::Copy if clipboard => out.push((egui::Key::C, held(at), true, None)),
|
||||
// On Windows, Shift+Delete is the old Cut key and arrives as Cut too. The Project
|
||||
// panel has no clipboard: there a Cut with only Shift held is Shift+Delete (Delete
|
||||
// Project Items Without Confirmation). Never when the modifiers aren't known.
|
||||
egui::Event::Cut if clipboard && project && at.is_some_and(only_shift) => {
|
||||
out.push((egui::Key::Delete, egui::Modifiers::SHIFT, true));
|
||||
out.push((egui::Key::Delete, egui::Modifiers::SHIFT, true, None));
|
||||
}
|
||||
egui::Event::Cut if clipboard => out.push((egui::Key::X, held(at), true)),
|
||||
egui::Event::Paste(_) if clipboard => out.push((egui::Key::V, held(at), true)),
|
||||
egui::Event::Cut if clipboard => out.push((egui::Key::X, held(at), true, None)),
|
||||
egui::Event::Paste(_) if clipboard => out.push((egui::Key::V, held(at), true, None)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
out
|
||||
});
|
||||
events.retain(|(key, _, _)| (*key == egui::Key::Tab) == tab_only);
|
||||
events.retain(|(key, _, _, _)| (*key == egui::Key::Tab) == tab_only);
|
||||
// Numpad * (or `*` typed with Shift+8): Add Marker (#275). egui has no key for it, so it
|
||||
// comes as text.
|
||||
if !tab_only && clipboard && app.dialog.is_none() && ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Text(t) if t == "*"))) {
|
||||
@@ -1754,7 +1758,7 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
return;
|
||||
}
|
||||
let binds = bindings(&app.session);
|
||||
for (key, mods, pressed) in events {
|
||||
for (key, mods, pressed, physical_key) in events {
|
||||
// Plain Spacebar runs its shortcut (Play Current Preview) on the release: held, it is
|
||||
// the Hand tool (After Effects), and a drag with it must not start or stop playback.
|
||||
if key == egui::Key::Space && (!pressed || !mods.any()) {
|
||||
@@ -1812,7 +1816,25 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
let _ = invoke(app, ctx, "edit.clear", json!({}));
|
||||
continue;
|
||||
}
|
||||
if let Some((_, _, id, params)) = binds.iter().find(|(m, k, ..)| *k == key && mods_match(*m, mods)) {
|
||||
// Explicit physical bindings distinguish keys that a layout reports with the same
|
||||
// logical name (for example AZERTY's minus and right parenthesis).
|
||||
let physical = physical_key.and_then(|key| {
|
||||
app.session.shortcuts().bindings().into_iter().find_map(|(sc, b)| {
|
||||
let (m, k) = parse_shortcut(sc.strip_prefix("Physical+")?)?;
|
||||
(k == key && mods_match(m, mods)).then(|| (b.command.clone(), b.params.clone()))
|
||||
})
|
||||
});
|
||||
if let Some((id, params)) = physical {
|
||||
if let Err(e) = invoke(app, ctx, &id, if params.is_null() { json!({}) } else { params }) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some((_, _, id, params)) = binds.iter().filter(|(m, k, ..)| *k == key && mods_match(*m, mods)).min_by_key(|(_, _, id, params)| {
|
||||
// The focused panel wins over an application command sharing its chord.
|
||||
let key = effectcraft_engine::shortcuts::binding_key(id, params);
|
||||
app.session.shortcuts().find(&key).is_none_or(|b| b.scope != app.ui.focused.id())
|
||||
}) {
|
||||
let (id, params) = (id.clone(), if params.is_null() { json!({}) } else { params.clone() });
|
||||
if id == "edit.paste"
|
||||
&& let Some(t) = &pasted
|
||||
|
||||
Reference in New Issue
Block a user