diff --git a/src/controller/controls/media.rs b/src/controller/controls/media.rs index 44a2f13..5207ad5 100644 --- a/src/controller/controls/media.rs +++ b/src/controller/controls/media.rs @@ -26,7 +26,7 @@ impl ControlMode for Media { } fn on_start(&mut self, haptics: &DialHaptics) -> DynResult<()> { - haptics.set_mode(false, Some(36))?; + haptics.set_mode(true, Some(36))?; Ok(()) } diff --git a/src/controller/controls/mod.rs b/src/controller/controls/mod.rs index 7561e10..b516171 100644 --- a/src/controller/controls/mod.rs +++ b/src/controller/controls/mod.rs @@ -1,11 +1,13 @@ mod media; mod null; mod paddle; -mod scroll_zoom; +mod scroll; mod volume; +mod zoom; pub use self::media::*; pub use self::null::*; pub use self::paddle::*; -pub use self::scroll_zoom::*; +pub use self::scroll::*; pub use self::volume::*; +pub use self::zoom::*; diff --git a/src/controller/controls/scroll.rs b/src/controller/controls/scroll.rs new file mode 100644 index 0000000..6adb2e9 --- /dev/null +++ b/src/controller/controls/scroll.rs @@ -0,0 +1,50 @@ +use crate::controller::{ControlMode, ControlModeMeta}; +use crate::dial_device::DialHaptics; +use crate::fake_input::{FakeInput, ScrollStep}; +use crate::DynResult; + +pub struct Scroll { + fake_input: FakeInput, +} + +impl Scroll { + pub fn new() -> Scroll { + Scroll { + fake_input: FakeInput::new(), + } + } +} + +impl ControlMode for Scroll { + fn meta(&self) -> ControlModeMeta { + ControlModeMeta { + name: "Scroll", + icon: "input-mouse", + } + } + + fn on_start(&mut self, haptics: &DialHaptics) -> DynResult<()> { + haptics.set_mode(false, Some(90))?; + Ok(()) + } + + fn on_btn_press(&mut self, _: &DialHaptics) -> DynResult<()> { + Ok(()) + } + + fn on_btn_release(&mut self, _haptics: &DialHaptics) -> DynResult<()> { + Ok(()) + } + + fn on_dial(&mut self, _: &DialHaptics, delta: i32) -> DynResult<()> { + if delta > 0 { + eprintln!("scroll down"); + self.fake_input.scroll_step(ScrollStep::Down)?; + } else { + eprintln!("scroll up"); + self.fake_input.scroll_step(ScrollStep::Up)?; + } + + Ok(()) + } +} diff --git a/src/controller/controls/scroll_zoom.rs b/src/controller/controls/scroll_zoom.rs deleted file mode 100644 index 72e2642..0000000 --- a/src/controller/controls/scroll_zoom.rs +++ /dev/null @@ -1,83 +0,0 @@ -use crate::common::action_notification; -use crate::controller::{ControlMode, ControlModeMeta}; -use crate::dial_device::DialHaptics; -use crate::fake_input::{FakeInput, ScrollStep}; -use crate::DynResult; - -use evdev_rs::enums::EV_KEY; - -pub struct ScrollZoom { - zoom: bool, - - fake_input: FakeInput, -} - -impl ScrollZoom { - pub fn new() -> ScrollZoom { - ScrollZoom { - zoom: false, - - fake_input: FakeInput::new(), - } - } -} - -const ZOOM_SENSITIVITY: u16 = 36; -const SCROLL_SENSITIVITY: u16 = 90; - -impl ControlMode for ScrollZoom { - fn meta(&self) -> ControlModeMeta { - ControlModeMeta { - name: "Scroll/Zoom", - icon: "input-mouse", - } - } - - fn on_start(&mut self, haptics: &DialHaptics) -> DynResult<()> { - haptics.set_mode(false, Some(SCROLL_SENSITIVITY))?; - Ok(()) - } - - fn on_btn_press(&mut self, _: &DialHaptics) -> DynResult<()> { - Ok(()) - } - - fn on_btn_release(&mut self, haptics: &DialHaptics) -> DynResult<()> { - self.zoom = !self.zoom; - haptics.buzz(1)?; - - if self.zoom { - action_notification("Zoom Mode", "zoom-in")?; - haptics.set_mode(false, Some(ZOOM_SENSITIVITY))?; - } else { - action_notification("Scroll Mode", "input-mouse")?; - haptics.set_mode(false, Some(SCROLL_SENSITIVITY))?; - } - - Ok(()) - } - - fn on_dial(&mut self, _: &DialHaptics, delta: i32) -> DynResult<()> { - if delta > 0 { - if self.zoom { - eprintln!("zoom in"); - self.fake_input - .key_click(&[EV_KEY::KEY_LEFTCTRL, EV_KEY::KEY_EQUAL])?; - } else { - eprintln!("scroll down"); - self.fake_input.scroll_step(ScrollStep::Down)?; - } - } else { - if self.zoom { - eprintln!("zoom out"); - self.fake_input - .key_click(&[EV_KEY::KEY_LEFTCTRL, EV_KEY::KEY_MINUS])?; - } else { - eprintln!("scroll up"); - self.fake_input.scroll_step(ScrollStep::Up)?; - } - } - - Ok(()) - } -} diff --git a/src/controller/controls/volume.rs b/src/controller/controls/volume.rs index 2fb6168..d926a4d 100644 --- a/src/controller/controls/volume.rs +++ b/src/controller/controls/volume.rs @@ -31,7 +31,7 @@ impl ControlMode for Volume { } fn on_btn_press(&mut self, _: &DialHaptics) -> DynResult<()> { - // TODO: support double-click to mute + // TODO: support double-click to play/pause Ok(()) } diff --git a/src/controller/controls/zoom.rs b/src/controller/controls/zoom.rs new file mode 100644 index 0000000..5729334 --- /dev/null +++ b/src/controller/controls/zoom.rs @@ -0,0 +1,54 @@ +use crate::controller::{ControlMode, ControlModeMeta}; +use crate::dial_device::DialHaptics; +use crate::fake_input::FakeInput; +use crate::DynResult; + +use evdev_rs::enums::EV_KEY; + +pub struct Zoom { + fake_input: FakeInput, +} + +impl Zoom { + pub fn new() -> Zoom { + Zoom { + fake_input: FakeInput::new(), + } + } +} + +impl ControlMode for Zoom { + fn meta(&self) -> ControlModeMeta { + ControlModeMeta { + name: "Zoom", + icon: "zoom-in", + } + } + + fn on_start(&mut self, haptics: &DialHaptics) -> DynResult<()> { + haptics.set_mode(true, Some(36))?; + Ok(()) + } + + fn on_btn_press(&mut self, _: &DialHaptics) -> DynResult<()> { + Ok(()) + } + + fn on_btn_release(&mut self, _haptics: &DialHaptics) -> DynResult<()> { + Ok(()) + } + + fn on_dial(&mut self, _: &DialHaptics, delta: i32) -> DynResult<()> { + if delta > 0 { + eprintln!("zoom in"); + self.fake_input + .key_click(&[EV_KEY::KEY_LEFTCTRL, EV_KEY::KEY_EQUAL])?; + } else { + eprintln!("zoom out"); + self.fake_input + .key_click(&[EV_KEY::KEY_LEFTCTRL, EV_KEY::KEY_MINUS])?; + } + + Ok(()) + } +} diff --git a/src/main.rs b/src/main.rs index 1b6335b..1358ab2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![allow(clippy::collapsible_if, clippy::new_without_default)] -mod common; +pub mod common; mod config; pub mod controller; mod dial_device; @@ -88,7 +88,8 @@ fn true_main(kill_notif_tx: mpsc::Sender>) -> Dyn dial, cfg.last_mode, vec![ - Box::new(controller::controls::ScrollZoom::new()), + Box::new(controller::controls::Scroll::new()), + Box::new(controller::controls::Zoom::new()), Box::new(controller::controls::Volume::new()), Box::new(controller::controls::Media::new()), Box::new(controller::controls::Paddle::new()),