-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(TargetDevice): add target device traits
- Loading branch information
1 parent
de268e5
commit b1dea06
Showing
4 changed files
with
449 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use zbus::Connection; | ||
|
||
use super::{TargetInputDevice, TargetOutputDevice}; | ||
|
||
/// The threshold for axis inputs to be considered "pressed" | ||
const AXIS_THRESHOLD: f64 = 0.35; | ||
|
||
/// The internal emulated device state for tracking analog input | ||
#[derive(Debug, Clone, Default)] | ||
struct State { | ||
pressed_left: bool, | ||
pressed_right: bool, | ||
pressed_up: bool, | ||
pressed_down: bool, | ||
} | ||
|
||
/// The [DBusDevice] is a virtual input device that can emit input events. It | ||
/// is primarily used when a [CompositeDevice] is using input interception to | ||
/// divert inputs to an overlay over DBus. | ||
pub struct DBusDevice { | ||
state: State, | ||
conn: Connection, | ||
} | ||
|
||
impl DBusDevice { | ||
// Create a new [DBusDevice] instance. | ||
pub fn new(conn: Connection) -> Self { | ||
Self { | ||
state: State::default(), | ||
conn, | ||
} | ||
} | ||
} | ||
|
||
impl TargetInputDevice for DBusDevice { | ||
fn write_event( | ||
&mut self, | ||
event: crate::input::event::native::NativeEvent, | ||
) -> Result<(), super::InputError> { | ||
log::trace!("Discarding event: {event:?}"); | ||
Ok(()) | ||
} | ||
|
||
fn get_capabilities( | ||
&self, | ||
) -> Result<Vec<crate::input::capability::Capability>, super::InputError> { | ||
Ok(vec![]) | ||
} | ||
|
||
fn stop(&self) -> Result<(), super::InputError> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl TargetOutputDevice for DBusDevice {} |
Oops, something went wrong.