Add map_to_output input option for touch devices
This commit is contained in:
parent
70bb9b9a2e
commit
45946fc75d
4 changed files with 54 additions and 5 deletions
|
|
@ -27,6 +27,8 @@ pub struct InputConfig {
|
||||||
pub scroll_config: Option<ScrollConfig>,
|
pub scroll_config: Option<ScrollConfig>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
pub tap_config: Option<TapConfig>,
|
pub tap_config: Option<TapConfig>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub map_to_output: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ pub fn for_device(device: &InputDevice) -> InputConfig {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
map_to_output: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -426,6 +426,16 @@ impl Config {
|
||||||
.map_or(1.0, |x| x.0)
|
.map_or(1.0, |x| x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn map_to_output(&self, device: &InputDevice) -> Option<&str> {
|
||||||
|
let (device_config, default_config) = self.get_device_config(device);
|
||||||
|
Some(
|
||||||
|
input_config::get_config(device_config, default_config, |x| {
|
||||||
|
x.map_to_output.as_deref()
|
||||||
|
})?
|
||||||
|
.0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_device_config(&self, device: &InputDevice) -> (Option<&InputConfig>, &InputConfig) {
|
fn get_device_config(&self, device: &InputDevice) -> (Option<&InputConfig>, &InputConfig) {
|
||||||
let default_config = if device.config_tap_finger_count() > 0 {
|
let default_config = if device.config_tap_finger_count() > 0 {
|
||||||
&self.input_touchpad
|
&self.input_touchpad
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,12 @@ use smithay::{
|
||||||
Seat, SeatState,
|
Seat, SeatState,
|
||||||
},
|
},
|
||||||
output::Output,
|
output::Output,
|
||||||
reexports::wayland_server::DisplayHandle,
|
reexports::{
|
||||||
|
input::event::touch::{
|
||||||
|
TouchDownEvent as LibinputTouchDownEvent, TouchMotionEvent as LibinputTouchMotionEvent,
|
||||||
|
},
|
||||||
|
wayland_server::DisplayHandle,
|
||||||
|
},
|
||||||
utils::{Point, Serial, SERIAL_COUNTER},
|
utils::{Point, Serial, SERIAL_COUNTER},
|
||||||
wayland::{
|
wayland::{
|
||||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat,
|
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat,
|
||||||
|
|
@ -217,6 +222,8 @@ impl State {
|
||||||
needs_key_repetition: bool,
|
needs_key_repetition: bool,
|
||||||
) where
|
) where
|
||||||
<B as InputBackend>::PointerAxisEvent: 'static,
|
<B as InputBackend>::PointerAxisEvent: 'static,
|
||||||
|
<B as InputBackend>::TouchDownEvent: 'static,
|
||||||
|
<B as InputBackend>::TouchMotionEvent: 'static,
|
||||||
{
|
{
|
||||||
use smithay::backend::input::Event;
|
use smithay::backend::input::Event;
|
||||||
match event {
|
match event {
|
||||||
|
|
@ -1167,9 +1174,23 @@ impl State {
|
||||||
}
|
}
|
||||||
InputEvent::TouchDown { event, .. } => {
|
InputEvent::TouchDown { event, .. } => {
|
||||||
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
|
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
|
||||||
// TODO: Configuration option for mapping touch device to output
|
// TODO Is it possible to determine mapping for external touchscreen?
|
||||||
// Is it possible to determine mapping for external touchscreen?
|
let map_to_output = if let Some(event) =
|
||||||
let Some(output) = self.common.shell.builtin_output().cloned() else {
|
<dyn Any>::downcast_ref::<LibinputTouchDownEvent>(&event)
|
||||||
|
{
|
||||||
|
self.common
|
||||||
|
.config
|
||||||
|
.map_to_output(&event.device())
|
||||||
|
.and_then(|name| {
|
||||||
|
self.common
|
||||||
|
.shell
|
||||||
|
.outputs()
|
||||||
|
.find(|output| output.name() == name)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let Some(output) = map_to_output.or_else(|| self.common.shell.builtin_output()).cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1209,7 +1230,22 @@ impl State {
|
||||||
}
|
}
|
||||||
InputEvent::TouchMotion { event, .. } => {
|
InputEvent::TouchMotion { event, .. } => {
|
||||||
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
|
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
|
||||||
let Some(output) = self.common.shell.builtin_output().cloned() else {
|
let map_to_output = if let Some(event) =
|
||||||
|
<dyn Any>::downcast_ref::<LibinputTouchMotionEvent>(&event)
|
||||||
|
{
|
||||||
|
self.common
|
||||||
|
.config
|
||||||
|
.map_to_output(&event.device())
|
||||||
|
.and_then(|name| {
|
||||||
|
self.common
|
||||||
|
.shell
|
||||||
|
.outputs()
|
||||||
|
.find(|output| output.name() == name)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let Some(output) = map_to_output.or_else(|| self.common.shell.builtin_output()).cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue