Skip to content

Commit

Permalink
feat(Touch): add basic touch input translation support
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Jul 11, 2024
1 parent 33381d3 commit 04544f6
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 2 deletions.
79 changes: 77 additions & 2 deletions rootfs/usr/share/inputplumber/schema/device_profile_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
"keyboard",
"gamepad",
"xb360",
"xbox-elite",
"xbox-series",
"deck",
"ds5",
"ds5-usb",
"ds5-bt",
"ds5-edge",
"ds5-edge-usb",
"ds5-edge-bt"
"ds5-edge-bt",
"touchscreen-fts3528"
]
}
},
Expand Down Expand Up @@ -254,6 +257,12 @@
"mouse": {
"$ref": "#/definitions/MouseEvent"
},
"touchpad": {
"$ref": "#/definitions/TouchpadEvent"
},
"touchscreen": {
"$ref": "#/definitions/TouchEvent"
},
"dbus": {
"type": "string",
"enum": [
Expand All @@ -276,7 +285,11 @@
"ui_r2",
"ui_r3",
"ui_volume_up",
"ui_volume_down"
"ui_volume_down",
"ui_volume_mute",
"ui_osk",
"ui_screenshot",
"ui_touch"
]
},
"gamepad": {
Expand Down Expand Up @@ -333,6 +346,68 @@
}
}
},
"TouchpadEvent": {
"title": "TouchpadEvent",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"enum": [
"LeftPad",
"RightPad",
"CenterPad"
]
},
"touch": {
"$ref": "#/definitions/TouchEvent"
}
}
},
"TouchEvent": {
"title": "TouchEvent",
"type": "object",
"additionalProperties": false,
"properties": {
"motion": {
"$ref": "#/definitions/TouchMotionEvent"
},
"button": {
"type": "string",
"enum": [
"Touch",
"Press"
]
}
},
"required": []
},
"TouchMotionEvent": {
"title": "TouchMotionEvent",
"type": "object",
"additionalProperties": false,
"properties": {
"region": {
"type": "string",
"description": "Map from a specific region of the touch device",
"enum": [
"left",
"right",
"top",
"bottom",
"top-left",
"top-right",
"bottom-left",
"bottom-right"
]
},
"speed_pps": {
"type": "number",
"description": "Speed of the target motion event in pixels per second",
"default": 800
}
}
},
"GamepadEvent": {
"title": "GamepadEvent",
"type": "object",
Expand Down
39 changes: 39 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ impl ProfileMapping {
}
}

// Touchpad event
// TODO: implement touchpad specific matching

// Touchscreen event
if let Some(touch) = self.source_event.touchscreen.as_ref() {
// Touch motion
if let Some(motion) = touch.motion.as_ref() {
// Touch motion was defined for source event!
if let Some(_direction) = motion.region.as_ref() {
// TODO: Implement ability to map certain parts of the touch
// screen.
return true;
}
}
}

// If no other input types were defined in the config, then it counts as
// a match.
true
Expand Down Expand Up @@ -182,6 +198,8 @@ pub struct CapabilityConfig {
pub keyboard: Option<String>,
pub mouse: Option<MouseCapability>,
pub dbus: Option<String>,
pub touchpad: Option<TouchpadCapability>,
pub touchscreen: Option<TouchCapability>,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -231,6 +249,27 @@ pub struct MouseMotionCapability {
pub speed_pps: Option<u64>,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct TouchpadCapability {
pub name: String,
pub touch: TouchCapability,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct TouchCapability {
pub button: Option<String>,
pub motion: Option<TouchMotionCapability>,
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct TouchMotionCapability {
pub region: Option<String>,
pub speed_pps: Option<u64>,
}

/// Defines a platform match for loading a [CompositeDevice]
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
Expand Down
55 changes: 55 additions & 0 deletions src/input/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ impl FromStr for Capability {
"DBus" => Ok(Capability::DBus(Action::from_str(
parts.join(":").as_str(),
)?)),
"Touchpad" => Ok(Capability::Touchpad(Touchpad::from_str(
parts.join(":").as_str(),
)?)),
"Touchscreen" => Ok(Capability::Touchscreen(Touch::from_str(
parts.join(":").as_str(),
)?)),
_ => Err(()),
}
}
Expand Down Expand Up @@ -158,6 +164,54 @@ impl From<CapabilityConfig> for Capability {
return Capability::DBus(action);
}

// Touchpad
if let Some(touchpad) = value.touchpad.as_ref() {
let touch = {
if touchpad.touch.motion.is_some() {
Touch::Motion
} else if touchpad.touch.button.is_some() {
let button_string = touchpad.touch.button.as_ref().unwrap();
let button = TouchButton::from_str(button_string.as_str());
if button.is_err() {
log::error!("Invalid or unimplemented button: {button_string}");
return Capability::NotImplemented;
}
let button = button.unwrap();
Touch::Button(button)
} else {
log::error!("Invalid or unimplemented touchpad config");
return Capability::NotImplemented;
}
};

// TODO: Is there a better way to do this?
match touchpad.name.as_str() {
"LeftPad" => return Capability::Touchpad(Touchpad::LeftPad(touch)),
"RightPad" => return Capability::Touchpad(Touchpad::RightPad(touch)),
"CenterPad" => return Capability::Touchpad(Touchpad::CenterPad(touch)),
_ => return Capability::NotImplemented,
}
}

// Touchscreen
if let Some(touch) = value.touchscreen.as_ref() {
// Motion
if touch.motion.is_some() {
return Capability::Touchscreen(Touch::Motion);
}

// Button
if let Some(button_string) = touch.button.as_ref() {
let button = TouchButton::from_str(button_string);
if button.is_err() {
log::error!("Invalid or unimplemented button: {button_string}");
return Capability::NotImplemented;
}
let button = button.unwrap();
return Capability::Touchscreen(Touch::Button(button));
}
}

Capability::NotImplemented
}
}
Expand Down Expand Up @@ -1040,6 +1094,7 @@ impl FromStr for Keyboard {
}
}

#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Touchpad {
LeftPad(Touch),
Expand Down

0 comments on commit 04544f6

Please sign in to comment.