From 3afd513c366b8cf70cc0ec717c4c47f28f2709b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Meki=C4=87?= Date: Fri, 30 Oct 2026 16:54:13 +0100 Subject: [PATCH] Compatibility with macOS --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/curve_editor.rs | 22 +++++++++++++++++++--- src/drum.rs | 43 +++++++++++++++++++++++++++++++++++++++---- src/waveform.rs | 20 +++++++++++++++++++- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 054c310..a977e25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2084,7 +2084,7 @@ dependencies = [ [[package]] name = "maolan-widgets" -version = "0.0.44" +version = "0.1.0" dependencies = [ "iced", "iced_aw", diff --git a/Cargo.toml b/Cargo.toml index 0e9da2c..cfffeea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "maolan-widgets" -version = "0.0.44" +version = "0.1.0" edition = "2024" description = "Widgets used for Maolan DAW" license = "BSD-2-Clause" diff --git a/src/curve_editor.rs b/src/curve_editor.rs index dd3c6e1..8c95f00 100644 --- a/src/curve_editor.rs +++ b/src/curve_editor.rs @@ -1,5 +1,5 @@ use iced::{ - Color, Event, Point, Rectangle, Renderer, Size, Theme, mouse, + Color, Event, Point, Rectangle, Renderer, Size, Theme, keyboard, mouse, widget::canvas::{Action as CanvasAction, Cache, Frame, Geometry, Path, Program, Stroke}, }; use std::cell::Cell; @@ -46,6 +46,7 @@ pub struct CurveEditor { pub struct CurveEditorState { mode: CurveEditorDragMode, + modifiers: keyboard::Modifiers, cache: Cache, last_hash: Cell, } @@ -67,6 +68,7 @@ impl Default for CurveEditorState { fn default() -> Self { Self { mode: CurveEditorDragMode::None, + modifiers: keyboard::Modifiers::default(), cache: Cache::new(), last_hash: Cell::new(0), } @@ -182,7 +184,16 @@ impl Program for CurveEditor { cursor: mouse::Cursor, ) -> Option> { match event { - Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right)) => { + Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => { + state.modifiers = *modifiers; + None + } + Event::Mouse(mouse::Event::ButtonPressed(button)) + if *button == mouse::Button::Right + || (cfg!(target_os = "macos") + && *button == mouse::Button::Left + && state.modifiers.control()) => + { let position = cursor.position_in(bounds)?; if let Some(idx) = self.point_index_at_position(position, bounds) { let sample = self.points[idx].sample; @@ -209,7 +220,12 @@ impl Program for CurveEditor { } None } - Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right)) => { + Event::Mouse(mouse::Event::ButtonReleased(button)) + if *button == mouse::Button::Right + || (cfg!(target_os = "macos") + && *button == mouse::Button::Left + && matches!(&state.mode, CurveEditorDragMode::Drawing { .. })) => + { if let CurveEditorDragMode::Drawing { start, current } = state.mode { state.mode = CurveEditorDragMode::None; let points = self.build_drawn_points(start, current, bounds); diff --git a/src/drum.rs b/src/drum.rs index 196a28c..6d68172 100644 --- a/src/drum.rs +++ b/src/drum.rs @@ -1,6 +1,6 @@ use crate::midi::PianoNote; use iced::{ - Color, Event, Point, Rectangle, Renderer, Size, Theme, mouse, + Color, Event, Point, Rectangle, Renderer, Size, Theme, keyboard, mouse, widget::canvas::{Action as CanvasAction, Frame, Geometry, Path, Program}, }; use std::collections::HashSet; @@ -65,6 +65,8 @@ pub struct DrumRollInteractionState { pub creating_dragged: bool, pub creating_start_sample: Option, pub creating_pitch: Option, + emulated_middle_click: bool, + modifiers: keyboard::Modifiers, } impl DrumRollInteraction { @@ -136,9 +138,17 @@ impl Program for DrumRollInteraction { let notes = &self.notes; match event { - Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { + Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => { + state.modifiers = *modifiers; + return None; + } + Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) + if !(cfg!(target_os = "macos") && state.modifiers.control()) => + { if let Some(position) = cursor.position_in(bounds) { if let Some(note_idx) = self.note_at_position(position, pps, notes) { + state.emulated_middle_click = + cfg!(target_os = "macos") && state.modifiers.alt(); state.drag_start = Some(position); state.drag_current = Some(position); state.drag_note_index = Some(note_idx); @@ -159,7 +169,12 @@ impl Program for DrumRollInteraction { } } } - Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right)) => { + Event::Mouse(mouse::Event::ButtonPressed(button)) + if *button == mouse::Button::Right + || (cfg!(target_os = "macos") + && *button == mouse::Button::Left + && state.modifiers.control()) => + { if let Some(position) = cursor.position_in(bounds) { state.drag_start = Some(position); state.drag_current = Some(position); @@ -211,6 +226,21 @@ impl Program for DrumRollInteraction { } Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) => { let mode = state.dragging_mode; + if state.emulated_middle_click + && mode == DraggingMode::DraggingNote + && state + .drag_start + .zip(state.drag_current) + .is_some_and(|(start, current)| start.distance(current) < 3.0) + && let Some(note_idx) = state.drag_note_index.take() + { + state.drag_start = None; + state.drag_current = None; + state.dragging_mode = DraggingMode::None; + return Some( + CanvasAction::publish(DrumMessage::NoteDelete(note_idx)).and_capture(), + ); + } match mode { DraggingMode::SelectingRect => { @@ -251,7 +281,12 @@ impl Program for DrumRollInteraction { DraggingMode::None => {} } } - Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right)) => { + Event::Mouse(mouse::Event::ButtonReleased(button)) + if *button == mouse::Button::Right + || (cfg!(target_os = "macos") + && *button == mouse::Button::Left + && state.dragging_mode == DraggingMode::CreatingNote) => + { if state.dragging_mode == DraggingMode::CreatingNote { let start = state.drag_start.take(); let current = state.drag_current.take(); diff --git a/src/waveform.rs b/src/waveform.rs index e0cf741..fccc19a 100644 --- a/src/waveform.rs +++ b/src/waveform.rs @@ -251,6 +251,24 @@ impl Program for SampleWaveform<'_, Message> { state.modifiers = *modifiers; None } + Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) + if cfg!(target_os = "macos") && state.modifiers.alt() => + { + state.drag_start = None; + state.selecting = false; + state.xfade_edge = None; + state.last_click_at = None; + let ratio = cursor_ratio(cursor, bounds)?; + if self.near_marker(ratio, bounds.width) { + self.on_middle_click + .as_ref() + .map(|message| CanvasAction::publish(message(ratio)).and_capture()) + } else { + self.on_middle_click_away + .as_ref() + .map(|message| CanvasAction::publish(message(ratio)).and_capture()) + } + } Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { let ratio = cursor_ratio(cursor, bounds)?; let position = cursor.position_in(bounds)?; @@ -270,7 +288,7 @@ impl Program for SampleWaveform<'_, Message> { .map(|message| CanvasAction::publish(message(ratio)).and_capture()); } - if state.modifiers.control() + if state.modifiers.command() && let Some(edge) = self.selection_edge_at(ratio, bounds.width) { state.drag_start = None;