FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(ui): open the context menu on macOS Ctrl+Click
gyrof21434cf9fbc
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 9a6393b87..76257f5f6 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -302,6 +302,12 @@ pub struct FilmcraftApp {deferred: Vec<(ControlRequest, f64)>,last_ui_time: f64,pub(crate) synthetic: Vec<egui::Event>,+ /// macOS: a Control+Click already translated to a secondary (context) click, so its release is+ /// translated too even if Control is let go mid-click. AppKit delivers Control+Click to the+ /// view as a *primary* press with the Control modifier (`rightMouseDown:` only fires for a+ /// right button or two-finger click), so the app does the platform's translation itself.+ #[cfg_attr(not(target_os = "macos"), allow(dead_code))]+ mac_ctrl_click_armed: bool,/// The mouse press in progress (its start time) and the undo history when it began, for Escape/// to take back what the press changed (#580).value_press: Option<(f64, filmcraft_engine::UndoMark)>,@@ -555,6 +561,7 @@ impl FilmcraftApp {deferred: Vec::new(),last_ui_time: 0.0,synthetic: Vec::new(),+ mac_ctrl_click_armed: false,value_press: None,loudness: None,status_seen: (String::new(), 0.0),@@ -1937,9 +1944,44 @@ impl FilmcraftApp {}}+/// On macOS a Control+Click means "right click": AppKit delivers it to the view as a *primary*+/// press carrying the Control modifier (`rightMouseDown:` only fires for a real right button or+/// two-finger click), so the app translates it to a secondary click before egui computes pointer+/// state. `armed` pairs the press with its release, so the release is still a context click when+/// Control is let go mid-click. Called from [`eframe::App::raw_input_hook`], which runs before+/// egui's pass; only wired in on macOS, where Ctrl+Click is not a selection modifier.+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+fn synthesize_mac_ctrl_click(armed: &mut bool, raw_input: &mut egui::RawInput) {+ for event in &mut raw_input.events {+ match event {+ egui::Event::PointerButton { button, pressed, modifiers, .. } if *button == egui::PointerButton::Primary => {+ if *pressed {+ if modifiers.ctrl {+ *button = egui::PointerButton::Secondary;+ *armed = true;+ } else {+ // A plain primary press ends any pairing left open (eg. the pointer left+ // the window mid-click, which egui also forgets).+ *armed = false;+ }+ } else if *armed {+ *button = egui::PointerButton::Secondary;+ *armed = false;+ }+ }+ egui::Event::PointerGone => *armed = false,+ _ => {}+ }+ }+}+impl eframe::App for FilmcraftApp {fn raw_input_hook(&mut self, _ctx: &egui::Context, raw_input: &mut egui::RawInput) {self.native_window_focused = Some(raw_input.focused);+ #[cfg(target_os = "macos")]+ if !self.control_input_only {+ synthesize_mac_ctrl_click(&mut self.mac_ctrl_click_armed, raw_input);+ }if self.control_input_only {// Preserve screenshot responses and all viewport lifecycle/geometry metadata.raw_input.events.retain(|event| matches!(event, egui::Event::Screenshot { .. }));@@ -2210,6 +2252,96 @@ mod clipboard_key_tests {}}+#[cfg(test)]+mod mac_ctrl_click_tests {+ use egui::{Event, Modifiers, PointerButton, RawInput};++ fn click(button: PointerButton, pressed: bool, ctrl: bool) -> Event {+ Event::PointerButton { pos: egui::pos2(40.0, 12.0), button, pressed, modifiers: if ctrl { Modifiers::CTRL } else { Modifiers::NONE } }+ }++ fn buttons(raw: &mut RawInput) -> Vec<(PointerButton, bool)> {+ raw.events+ .iter()+ .filter_map(|e| match e {+ Event::PointerButton { button, pressed, .. } => Some((*button, *pressed)),+ _ => None,+ })+ .collect()+ }++ /// AppKit delivers Control+Click as a primary press with the Control modifier; it must reach+ /// egui as a secondary click so `secondary_clicked()` (the context menus) fires on macOS.+ #[test]+ fn ctrl_click_is_a_secondary_click() {+ let mut raw = RawInput { events: vec![click(PointerButton::Primary, true, true), click(PointerButton::Primary, false, true)], ..Default::default() };+ let mut armed = false;+ super::synthesize_mac_ctrl_click(&mut armed, &mut raw);+ assert!(!armed);+ assert_eq!(buttons(&mut raw), vec![(PointerButton::Secondary, true), (PointerButton::Secondary, false)]);+ }++ /// End to end: the rewritten events are what egui's pointer state sees, so the context+ /// menus (`secondary_clicked()`) fire on a Control+Click exactly like on a real right click.+ #[test]+ fn synthesized_click_fires_secondary_clicked() {+ let ctx = egui::Context::default();+ let mut raw = RawInput { events: vec![click(PointerButton::Primary, true, true), click(PointerButton::Primary, false, true)], ..Default::default() };+ let mut armed = false;+ super::synthesize_mac_ctrl_click(&mut armed, &mut raw);+ let mut secondary = false;+ // No renderer here: drop the pass output, clearing its texture deltas so epaint's drop+ // guard does not panic on the font texture.+ let mut out = ctx.run_ui(raw, |ctx| secondary = ctx.input(|i| i.pointer.secondary_clicked()));+ out.textures_delta.clear();+ assert!(secondary);+ }++ /// Releasing Control before the mouse button still closes the click as a context click; the+ /// mouse release alone must not become a stray primary click.+ #[test]+ fn release_is_paired_to_the_ctrl_press() {+ let mut raw = RawInput {+ events: vec![+ click(PointerButton::Primary, true, true),+ click(PointerButton::Primary, false, false), // Control already released+ ],+ ..Default::default()+ };+ let mut armed = false;+ super::synthesize_mac_ctrl_click(&mut armed, &mut raw);+ assert!(!armed);+ assert_eq!(buttons(&mut raw), vec![(PointerButton::Secondary, true), (PointerButton::Secondary, false)]);+ }++ /// A plain click keeps its meaning (on macOS Cmd is the selection modifier, not Control).+ #[test]+ fn plain_click_is_untouched() {+ let mut raw = RawInput { events: vec![click(PointerButton::Primary, true, false), click(PointerButton::Primary, false, false)], ..Default::default() };+ super::synthesize_mac_ctrl_click(&mut false, &mut raw);+ assert_eq!(buttons(&mut raw), vec![(PointerButton::Primary, true), (PointerButton::Primary, false)]);+ }++ /// A half-open pairing (pointer left the window mid-click) must not turn the next plain click+ /// into a context click.+ #[test]+ fn new_plain_press_clears_a_stale_pairing() {+ let mut raw = RawInput {+ events: vec![+ click(PointerButton::Primary, true, true),+ Event::PointerGone,+ click(PointerButton::Primary, true, false),+ click(PointerButton::Primary, false, false),+ ],+ ..Default::default()+ };+ let mut armed = false;+ super::synthesize_mac_ctrl_click(&mut armed, &mut raw);+ assert!(!armed);+ assert_eq!(buttons(&mut raw), vec![(PointerButton::Secondary, true), (PointerButton::Primary, true), (PointerButton::Primary, false),]);+ }+}+#[cfg(test)]mod gpu_fallback_tests {use filmcraft_render::plan::{FramePlan, PlanLayer};