Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using touch state instead of most recent event #97

Merged
merged 2 commits into from
Apr 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/input/wacom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct WacomState {
last_ytilt: AtomicU16,
last_dist: AtomicU16,
last_pressure: AtomicU16,
last_tool: Atomic<Option<WacomPen>>,
last_touch_state: Atomic<bool>,
}

impl ::std::default::Default for WacomState {
Expand All @@ -34,7 +34,7 @@ impl ::std::default::Default for WacomState {
last_ytilt: AtomicU16::new(0),
last_dist: AtomicU16::new(0),
last_pressure: AtomicU16::new(0),
last_tool: Atomic::new(None),
last_touch_state: Atomic::new(false),
}
}
}
Expand Down Expand Up @@ -88,8 +88,8 @@ pub fn decode(ev: &EvInputEvent, outer_state: &InputDeviceState) -> Option<Input
_ => unreachable!(),
};
match ev.event_type().0 {
ecodes::EV_SYN => match state.last_tool.load(Ordering::Relaxed) {
Some(WacomPen::ToolPen) => Some(InputEvent::WacomEvent {
ecodes::EV_SYN => match state.last_touch_state.load(Ordering::Relaxed) {
false => Some(InputEvent::WacomEvent {
event: WacomEvent::Hover {
position: cgmath::Point2 {
x: (f32::from(state.last_x.load(Ordering::Relaxed)) * *WACOM_HSCALAR),
Expand All @@ -102,7 +102,7 @@ pub fn decode(ev: &EvInputEvent, outer_state: &InputDeviceState) -> Option<Input
},
},
}),
Some(WacomPen::Touch) => Some(InputEvent::WacomEvent {
true => Some(InputEvent::WacomEvent {
event: WacomEvent::Draw {
position: cgmath::Point2 {
x: (f32::from(state.last_x.load(Ordering::Relaxed)) * *WACOM_HSCALAR),
Expand All @@ -115,7 +115,6 @@ pub fn decode(ev: &EvInputEvent, outer_state: &InputDeviceState) -> Option<Input
},
},
}),
_ => None,
},
ecodes::EV_KEY => {
/* key (device detected - device out of range etc.) */
Expand All @@ -124,12 +123,16 @@ pub fn decode(ev: &EvInputEvent, outer_state: &InputDeviceState) -> Option<Input
}

let pen: WacomPen = unsafe { std::mem::transmute_copy(&ev.code()) };
state.last_tool.store(Some(pen), Ordering::Relaxed);
let pen_state = ev.value() != 0;

if pen == WacomPen::Touch {
state.last_touch_state.store(pen_state, Ordering::Relaxed);
}

Some(InputEvent::WacomEvent {
event: WacomEvent::InstrumentChange {
pen,
state: ev.value() != 0,
state: pen_state,
},
})
}
Expand All @@ -143,16 +146,12 @@ pub fn decode(ev: &EvInputEvent, outer_state: &InputDeviceState) -> Option<Input
// the last_dist supplants to that current max.
if state.last_pressure.load(Ordering::Relaxed) == 0 {
state.last_dist.store(ev.value() as u16, Ordering::Relaxed);
state
.last_tool
.store(Some(WacomPen::ToolPen), Ordering::Relaxed);
state.last_touch_state.store(false, Ordering::Relaxed);
} else {
state
.last_pressure
.fetch_add(ev.value() as u16, Ordering::Relaxed);
state
.last_tool
.store(Some(WacomPen::Touch), Ordering::Relaxed);
state.last_touch_state.store(true, Ordering::Relaxed);
}
}
ecodes::ABS_TILT_X => {
Expand Down