Skip to content

Commit

Permalink
WIP wl-touch
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Nov 7, 2023
1 parent 18067de commit 5a13aa0
Showing 1 changed file with 90 additions and 3 deletions.
93 changes: 90 additions & 3 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::Inp
#[allow(deprecated)]
use smithay::{
backend::input::{
Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent, GestureEndEvent,
GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, InputBackend, InputEvent,
KeyState, PointerAxisEvent,
AbsolutePositionEvent, Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent,
GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, InputBackend,
InputEvent, KeyState, PointerAxisEvent, TouchEvent,
},
desktop::{layer_map_for_output, space::SpaceElement, WindowSurfaceType},
input::{
Expand Down Expand Up @@ -205,6 +205,7 @@ pub fn add_seat(
.expect("Failed to load xkb configuration files");
}
seat.add_pointer();
seat.add_touch();

seat
}
Expand Down Expand Up @@ -1139,6 +1140,92 @@ impl State {
);
}
}
InputEvent::TouchDown { event, .. } => {
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
let current_output = seat.active_output();
let geometry = current_output.geometry();

// XXX
let position = geometry.loc.to_f64()
+ event
.position_transformed(geometry.size.as_logical())
.as_global();

let overview = self.common.shell.overview_mode();
let workspace = self.common.shell.workspaces.active_mut(&current_output);
let under = State::surface_under(
position,
&current_output,
&self.common.shell.override_redirect_windows,
overview.0.clone(),
workspace,
self.common.session_lock.as_ref(),
)
.map(|(target, pos)| (target, pos.as_logical()));

if let Some((target, pos)) = under {
if let Some(wl_surface) = target.wl_surface() {
let serial = SERIAL_COUNTER.next_serial();
let mut touch = seat.get_touch().unwrap();
touch.down(
serial,
event.time() as u32,
&wl_surface,
position.as_logical() - pos.to_f64(),
event.slot(),
);
}
}
}
}
InputEvent::TouchMotion { event, .. } => {
if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() {
let current_output = seat.active_output();
let geometry = current_output.geometry();

// XXX
let position = geometry.loc.to_f64()
+ event
.position_transformed(geometry.size.as_logical())
.as_global();

let overview = self.common.shell.overview_mode();
let workspace = self.common.shell.workspaces.active_mut(&current_output);
let under = State::surface_under(
position,
&current_output,
&self.common.shell.override_redirect_windows,
overview.0.clone(),
workspace,
self.common.session_lock.as_ref(),
)
.map(|(target, pos)| (target, pos.as_logical()));

if let Some((target, pos)) = under {
// XX surface changed?
let mut touch = seat.get_touch().unwrap();
touch.motion(
event.time() as u32,
event.slot(),
position.as_logical() - pos.to_f64(),
);
}
}
}
InputEvent::TouchUp { event, .. } => {
if let Some(seat) = self.common.seat_with_device(&event.device()) {
let serial = SERIAL_COUNTER.next_serial();
let touch = seat.get_touch().unwrap();
touch.up(serial, event.time() as u32, event.slot());
}
}
InputEvent::TouchCancel { event, .. } => {
if let Some(seat) = self.common.seat_with_device(&event.device()) {
let touch = seat.get_touch().unwrap();
touch.cancel();
}
}
InputEvent::TouchFrame { event, .. } => {}
_ => { /* TODO e.g. tablet or touch events */ }
}
}
Expand Down

0 comments on commit 5a13aa0

Please sign in to comment.