Skip to content

Commit

Permalink
#686 Add possibility to choose scroll axis, make persistence future-p…
Browse files Browse the repository at this point in the history
…roof
  • Loading branch information
helgoboss committed Sep 20, 2022
1 parent 6fced35 commit 7a447f9
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 105 deletions.
22 changes: 18 additions & 4 deletions api/src/persistence/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,22 @@ pub enum MouseAction {
///
/// - Canvas: Relative to all screens, current screen, REAPER window or focused window
/// - Pixel density: Take pixel density into account
Move { axis: Axis },
Move {
#[serde(skip_serializing_if = "Option::is_none")]
axis: Option<Axis>,
},
/// Like [`Self::Move`] but automatically presses a button while moving and releases it
/// when the move is finished.
///
/// Future extension possibilities:
///
/// - Timeout: Set time when to release button
Drag { axis: Axis, button: MouseButton },
Drag {
#[serde(skip_serializing_if = "Option::is_none")]
axis: Option<Axis>,
#[serde(skip_serializing_if = "Option::is_none")]
button: Option<MouseButton>,
},
/// Button state.
///
/// Control:
Expand All @@ -447,15 +455,21 @@ pub enum MouseAction {
///
/// - Click or double-click a mouse button (press and immediate release, this could be a generic
/// "Glue" option because it could be useful for other on/off targets as well).
Click { button: MouseButton },
Click {
#[serde(skip_serializing_if = "Option::is_none")]
button: Option<MouseButton>,
},
/// Scroll wheel.
///
/// Control:
///
/// - Invoke scroll wheel
///
/// Feedback: None
Scroll,
Scroll {
#[serde(skip_serializing_if = "Option::is_none")]
axis: Option<Axis>,
},
}

impl Default for MouseAction {
Expand Down
70 changes: 31 additions & 39 deletions main/src/application/target_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::domain::{
get_non_present_virtual_track_label, get_track_routes, ActionInvocationType, AnyOnParameter,
Compartment, CompoundMappingTarget, Exclusivity, ExpressionEvaluator, ExtendedProcessorContext,
FeedbackResolution, FxDescriptor, FxDisplayType, FxParameterDescriptor, GroupId,
MappingSnapshotId, OscDeviceId, ProcessorContext, RealearnTarget, ReaperTarget,
ReaperTargetType, SeekOptions, SendMidiDestination, SoloBehavior, Tag, TagScope,
MappingSnapshotId, MouseActionType, OscDeviceId, ProcessorContext, RealearnTarget,
ReaperTarget, ReaperTargetType, SeekOptions, SendMidiDestination, SoloBehavior, Tag, TagScope,
TouchedRouteParameterType, TouchedTrackParameterType, TrackDescriptor, TrackExclusivity,
TrackRouteDescriptor, TrackRouteSelector, TrackRouteType, TransportAction,
UnresolvedActionTarget, UnresolvedAllTrackFxEnableTarget, UnresolvedAnyOnTarget,
Expand Down Expand Up @@ -2097,7 +2097,9 @@ impl TargetModel {
use ReaperTargetType::*;
let target = match self.r#type {
Mouse => UnresolvedReaperTarget::Mouse(UnresolvedMouseTarget {
action: self.mouse_action(),
action_type: self.mouse_action_type,
axis: self.axis,
button: self.mouse_button,
}),
Action => UnresolvedReaperTarget::Action(UnresolvedActionTarget {
action: self.resolved_action()?,
Expand Down Expand Up @@ -2483,35 +2485,40 @@ impl TargetModel {

pub fn mouse_action(&self) -> MouseAction {
match self.mouse_action_type {
MouseActionType::Move => MouseAction::Move { axis: self.axis },
MouseActionType::Move => MouseAction::Move {
axis: Some(self.axis),
},
MouseActionType::Drag => MouseAction::Drag {
axis: self.axis,
button: self.mouse_button,
axis: Some(self.axis),
button: Some(self.mouse_button),
},
MouseActionType::Click => MouseAction::Click {
button: self.mouse_button,
button: Some(self.mouse_button),
},
MouseActionType::Scroll => MouseAction::Scroll {
axis: Some(self.axis),
},
MouseActionType::Scroll => MouseAction::Scroll,
}
}

pub fn set_mouse_action_without_notification(&mut self, mouse_action: MouseAction) {
match mouse_action {
MouseAction::Move { axis } => {
self.mouse_action_type = MouseActionType::Move;
self.axis = axis;
self.axis = axis.unwrap_or_default();
}
MouseAction::Drag { axis, button } => {
self.mouse_action_type = MouseActionType::Drag;
self.axis = axis;
self.mouse_button = button;
self.axis = axis.unwrap_or_default();
self.mouse_button = button.unwrap_or_default();
}
MouseAction::Click { button } => {
self.mouse_action_type = MouseActionType::Click;
self.mouse_button = button;
self.mouse_button = button.unwrap_or_default();
}
MouseAction::Scroll => {
MouseAction::Scroll { axis } => {
self.mouse_action_type = MouseActionType::Scroll;
self.axis = axis.unwrap_or_default();
}
}
}
Expand All @@ -2531,7 +2538,7 @@ impl TargetModel {
pub fn supports_mouse_axis(&self) -> bool {
matches!(
self.mouse_action_type,
MouseActionType::Move | MouseActionType::Drag
MouseActionType::Move | MouseActionType::Drag | MouseActionType::Scroll
)
}

Expand Down Expand Up @@ -3013,6 +3020,16 @@ impl<'a> Display for TargetModelFormatMultiLine<'a> {
GoToBookmark => {
write!(f, "{}\n{}", tt, self.bookmark_label())
}
Mouse => {
write!(f, "{}\n{}", tt, self.target.mouse_action_type)?;
if self.target.supports_mouse_axis() {
write!(f, "\n{}", self.target.axis)?;
}
if self.target.supports_mouse_button() {
write!(f, "\n{}", self.target.mouse_button)?;
}
Ok(())
}
_ => write!(f, "{}", tt),
}
}
Expand Down Expand Up @@ -4198,28 +4215,3 @@ fn convert_monitoring_mode_to_realearn(monitoring_mode: InputMonitoringMode) ->
InputMonitoringMode::Unknown(_) => MonitoringMode::Off,
}
}

#[derive(
Copy,
Clone,
Eq,
PartialEq,
Debug,
derive_more::Display,
enum_iterator::IntoEnumIterator,
num_enum::TryFromPrimitive,
num_enum::IntoPrimitive,
)]
#[repr(usize)]
pub enum MouseActionType {
Move,
Drag,
Click,
Scroll,
}

impl Default for MouseActionType {
fn default() -> Self {
Self::Move
}
}
2 changes: 1 addition & 1 deletion main/src/domain/mouse/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait Mouse {

fn adjust_cursor_position(&mut self, x_delta: i32, y_delta: i32) -> Result<(), &'static str>;

fn scroll(&mut self, delta: i32) -> Result<(), &'static str>;
fn scroll(&mut self, axis: Axis, delta: i32) -> Result<(), &'static str>;

fn press(&mut self, button: MouseButton) -> Result<(), &'static str>;

Expand Down
7 changes: 5 additions & 2 deletions main/src/domain/mouse/enigo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ impl Mouse for EnigoMouse {
Ok(())
}

fn scroll(&mut self, delta: i32) -> Result<(), &'static str> {
self.0.mouse_scroll_y(delta);
fn scroll(&mut self, axis: Axis, delta: i32) -> Result<(), &'static str> {
match axis {
Axis::X => self.0.mouse_scroll_x(delta),
Axis::Y => self.0.mouse_scroll_y(delta),
}
Ok(())
}

Expand Down
12 changes: 8 additions & 4 deletions main/src/domain/mouse/mouse_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ impl Mouse for RsMouse {
self.set_cursor_position(new_pos)
}

fn scroll(&mut self, delta: i32) -> Result<(), &'static str> {
self.0
.scroll(delta)
.map_err(|_| "couldn't scroll mouse wheel")
fn scroll(&mut self, axis: Axis, delta: i32) -> Result<(), &'static str> {
match axis {
Axis::X => Err("scrolling on X axis not supported"),
Axis::Y => self
.0
.scroll(delta)
.map_err(|_| "couldn't scroll mouse wheel"),
}
}

fn press(&mut self, button: MouseButton) -> Result<(), &'static str> {
Expand Down
9 changes: 4 additions & 5 deletions main/src/domain/reaper_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ use crate::domain::{
OscSendTarget, PlayrateTarget, RealTimeClipColumnTarget, RealTimeClipMatrixTarget,
RealTimeClipRowTarget, RealTimeClipTransportTarget, RealTimeControlContext,
RealTimeFxParameterTarget, RouteMuteTarget, RoutePanTarget, RouteTouchStateTarget,
RouteVolumeTarget, RsMouseTarget, SeekTarget, SelectedTrackTarget, TakeMappingSnapshotTarget,
TempoTarget, TrackArmTarget, TrackAutomationModeTarget, TrackMonitoringModeTarget,
TrackMuteTarget, TrackPanTarget, TrackParentSendTarget, TrackPeakTarget, TrackSelectionTarget,
TrackShowTarget, TrackSoloTarget, TrackTouchStateTarget, TrackVolumeTarget, TrackWidthTarget,
TransportTarget,
RouteVolumeTarget, SeekTarget, SelectedTrackTarget, TakeMappingSnapshotTarget, TempoTarget,
TrackArmTarget, TrackAutomationModeTarget, TrackMonitoringModeTarget, TrackMuteTarget,
TrackPanTarget, TrackParentSendTarget, TrackPeakTarget, TrackSelectionTarget, TrackShowTarget,
TrackSoloTarget, TrackTouchStateTarget, TrackVolumeTarget, TrackWidthTarget, TransportTarget,
};
use crate::domain::{
AnyOnTarget, CompoundChangeEvent, EnableInstancesTarget, EnableMappingsTarget, HitResponse,
Expand Down
Loading

0 comments on commit 7a447f9

Please sign in to comment.