Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct DeviceProfile {
pub pen_y_max: i32,
pub pen_pressure_max: i32,
pub pen_distance_max: i32,
// Whether ABS_DISTANCE grows as the pen approaches (opposite of the evdev convention)
pub pen_distance_inverted: bool,
pub pen_tilt_range: i32,

// Touch screen dimensions
Expand Down
1 change: 1 addition & 0 deletions src/device/rm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const RM2: DeviceProfile = DeviceProfile {
pen_y_max: 15725,
pen_pressure_max: 4095,
pen_distance_max: 255,
pen_distance_inverted: false,
pen_tilt_range: 6400,

// Touch screen: 1872×1404 display, ~210×158 mm → ~9 units/mm
Expand Down
2 changes: 2 additions & 0 deletions src/device/rmpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub const RMPP: DeviceProfile = DeviceProfile {
pen_y_max: 15340,
pen_pressure_max: 4096,
pen_distance_max: 65535,
// Elan digitizer reports ~0 on proximity-in, rising to ~19000 near contact
pen_distance_inverted: true,
pen_tilt_range: 9000,

touch_x_max: 2064,
Expand Down
23 changes: 19 additions & 4 deletions src/input/pen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use crate::orientation::Orientation;
use crate::palm::SharedPalmState;
use crate::ssh;

use super::event::{key_event, parse_input_event, ABS_PRESSURE, EV_ABS, EV_SYN, SYN_REPORT};
use super::event::{key_event, parse_input_event, ABS_PRESSURE, EV_ABS, EV_KEY, EV_SYN, SYN_REPORT};

const ABS_X: u16 = 0x00;
const ABS_Y: u16 = 0x01;
const ABS_DISTANCE: u16 = 0x19;
const ABS_TILT_X: u16 = 0x1a;
const ABS_TILT_Y: u16 = 0x1b;

Expand Down Expand Up @@ -61,6 +62,8 @@ pub fn run_pen(
let mut buf = vec![0u8; device_profile.input_event_size];
let mut batch: Vec<InputEvent> = Vec::with_capacity(32);
let mut touch_down = false;
// evdev only reports changed values, so pressure persists across frames
let mut pressure: i32 = 0;
let mut frame_count: u64 = 0;

// For collecting X/Y/tilt values within a frame
Expand All @@ -81,6 +84,17 @@ pub fn run_pen(
let code = ev.raw_code();
let value = ev.raw_value();

// BTN_TOUCH is derived from pressure below; drop the device's own
if ty == EV_KEY && code == btn_touch_code {
continue;
}

if ty == EV_ABS && code == ABS_DISTANCE && device_profile.pen_distance_inverted {
let distance = device_profile.pen_distance_max - value.clamp(0, device_profile.pen_distance_max);
batch.push(InputEvent::new(ev.event_type(), code, distance));
continue;
}

// Collect position and tilt values, defer transformation until SYN_REPORT
if ty == EV_ABS {
match code {
Expand Down Expand Up @@ -128,11 +142,12 @@ pub fn run_pen(
batch.insert(1, InputEvent::new(evdevil::event::EventType::from_raw(EV_ABS), Abs::TILT_Y.raw(), out_ty));
}

let pressure = batch
if let Some(p) = batch
.iter()
.rfind(|e| e.event_type().raw() == EV_ABS && e.raw_code() == ABS_PRESSURE)
.map(|e| e.raw_value())
.unwrap_or(0);
{
pressure = p.raw_value();
}

let now_touching = pressure > 0;
update_palm_state(&palm, now_touching);
Expand Down