1
0
Fork 0
forked from wry/wry

wayland: implement wl_touch

Co-authored-by: Julian Orth <ju.orth@gmail.com>
This commit is contained in:
Amine Hassane 2024-04-21 14:48:26 +01:00 committed by Julian Orth
parent 905e2dd7ba
commit 681c1ad033
35 changed files with 1071 additions and 52 deletions

View file

@ -131,6 +131,8 @@ pub enum DeviceCommand {
MapToOutput(MapToOutputArgs),
/// Removes the mapping from this device to an output.
RemoveMapping,
/// Set the calibration matrix.
SetCalibrationMatrix(SetCalibrationMatrixArgs),
}
#[derive(ValueEnum, Debug, Clone)]
@ -200,6 +202,16 @@ pub struct SetTransformMatrixArgs {
pub m22: f64,
}
#[derive(Args, Debug, Clone)]
pub struct SetCalibrationMatrixArgs {
pub m00: f32,
pub m01: f32,
pub m02: f32,
pub m10: f32,
pub m11: f32,
pub m12: f32,
}
#[derive(Args, Debug, Clone)]
pub struct MapToOutputArgs {
/// The output to map to.
@ -272,6 +284,7 @@ struct InputDevice {
pub px_per_wheel_scroll: Option<f64>,
pub transform_matrix: Option<[[f64; 2]; 2]>,
pub output: Option<String>,
pub calibration_matrix: Option<[[f32; 3]; 2]>,
}
#[derive(Clone, Debug, Default)]
@ -595,6 +608,21 @@ impl Input {
output: None,
});
}
DeviceCommand::SetCalibrationMatrix(a) => {
self.handle_error(input, |e| {
eprintln!("Could not modify the calibration matrix: {}", e);
});
tc.send(jay_input::SetCalibrationMatrix {
self_id: input,
id: args.device,
m00: a.m00,
m01: a.m01,
m02: a.m02,
m10: a.m10,
m11: a.m11,
m12: a.m12,
});
}
}
tc.round_trip().await;
}
@ -728,6 +756,9 @@ impl Input {
if let Some(v) = &device.output {
println!("{prefix} mapped to output: {}", v);
}
if let Some(v) = &device.calibration_matrix {
println!("{prefix} calibration matrix: {:?}", v);
}
}
async fn get(self: &Rc<Self>, input: JayInputId) -> Data {
@ -792,6 +823,7 @@ impl Input {
px_per_wheel_scroll: is_pointer.then_some(msg.px_per_wheel_scroll),
transform_matrix: uapi::pod_read(msg.transform_matrix).ok(),
output: None,
calibration_matrix: None,
});
});
jay_input::InputDeviceOutput::handle(tc, input, data.clone(), |data, msg| {
@ -800,6 +832,13 @@ impl Input {
last.output = Some(msg.output.to_string());
}
});
jay_input::CalibrationMatrix::handle(tc, input, data.clone(), |data, msg| {
let mut data = data.borrow_mut();
if let Some(last) = data.input_device.last_mut() {
last.calibration_matrix =
Some([[msg.m00, msg.m01, msg.m02], [msg.m10, msg.m11, msg.m12]]);
}
});
tc.round_trip().await;
let x = data.borrow_mut().clone();
x

View file

@ -15,7 +15,8 @@ use {
TabletPadStripSource, TabletPadStripStop, TabletToolButton, TabletToolDistance,
TabletToolDown, TabletToolFrame, TabletToolMotion, TabletToolPressure,
TabletToolProximityIn, TabletToolProximityOut, TabletToolRotation,
TabletToolSlider, TabletToolTilt, TabletToolUp, TabletToolWheel,
TabletToolSlider, TabletToolTilt, TabletToolUp, TabletToolWheel, TouchCancel,
TouchDown, TouchMotion, TouchUp,
},
},
},
@ -583,6 +584,54 @@ async fn run(seat_test: Rc<SeatTest>) {
}
println!();
});
let st = seat_test.clone();
TouchDown::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Touch: {}, Down: {}x{}",
time(ev.time_usec),
ev.id,
ev.x,
ev.y
);
}
});
let st = seat_test.clone();
TouchUp::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!("Time: {:.4}, Touch: {}, Up", time(ev.time_usec), ev.id);
}
});
let st = seat_test.clone();
TouchMotion::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Touch: {} Motion: {}x{}",
time(ev.time_usec),
ev.id,
ev.x,
ev.y
);
}
});
let st = seat_test.clone();
TouchCancel::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!("Time: {:.4}, Touch: {}, Cancel", time(ev.time_usec), ev.id);
}
});
pending::<()>().await;
}