-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add client touch capability support #499
Changes from all commits
8ab4570
9a3d5a7
341a7bb
3d293fa
47bd529
e9000dc
e0d9b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ use std::{cell::RefCell, fmt, ops::Deref as _, rc::Rc}; | |
|
||
mod keyboard; | ||
mod pointer; | ||
mod touch; | ||
|
||
pub use self::{ | ||
keyboard::{ | ||
|
@@ -48,6 +49,7 @@ pub use self::{ | |
AxisFrame, CursorImageAttributes, CursorImageStatus, GrabStartData as PointerGrabStartData, | ||
PointerGrab, PointerHandle, PointerInnerHandle, | ||
}, | ||
touch::TouchHandle, | ||
}; | ||
|
||
use wayland_server::{ | ||
|
@@ -59,6 +61,7 @@ use wayland_server::{ | |
struct Inner { | ||
pointer: Option<PointerHandle>, | ||
keyboard: Option<KeyboardHandle>, | ||
touch: Option<TouchHandle>, | ||
known_seats: Vec<wl_seat::WlSeat>, | ||
} | ||
|
||
|
@@ -90,6 +93,9 @@ impl Inner { | |
if self.keyboard.is_some() { | ||
caps |= wl_seat::Capability::Keyboard; | ||
} | ||
if self.touch.is_some() { | ||
caps |= wl_seat::Capability::Touch; | ||
} | ||
caps | ||
} | ||
|
||
|
@@ -134,6 +140,7 @@ impl Seat { | |
inner: RefCell::new(Inner { | ||
pointer: None, | ||
keyboard: None, | ||
touch: None, | ||
known_seats: Vec::new(), | ||
}), | ||
log: log.new(slog::o!("smithay_module" => "seat_handler", "seat_name" => name.clone())), | ||
|
@@ -313,6 +320,59 @@ impl Seat { | |
} | ||
} | ||
|
||
/// Adds the touch capability to this seat | ||
/// | ||
/// You are provided a [`TouchHandle`], which allows you to send input events | ||
/// to this pointer. This handle can be cloned. | ||
/// | ||
/// Calling this method on a seat that already has a touch capability | ||
/// will overwrite it, and will be seen by the clients as if the | ||
/// touchscreen was unplugged and a new one was plugged in. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// # extern crate wayland_server; | ||
/// # | ||
/// # use smithay::wayland::seat::Seat; | ||
/// # | ||
/// # let mut display = wayland_server::Display::new(); | ||
/// # let (mut seat, seat_global) = Seat::new( | ||
/// # &mut display, | ||
/// # "seat-0".into(), | ||
/// # None | ||
/// # ); | ||
/// let touch_handle = seat.add_touch(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example doesn't really explain anything more than the function docs itself. If the seat creation are made visible it would be more jusitifed to have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, but I'd say the same applies for the existing code examples for keyboard/pointer?
What do you mean by this? Removing the |
||
/// ``` | ||
pub fn add_touch(&mut self) -> TouchHandle { | ||
let mut inner = self.arc.inner.borrow_mut(); | ||
let touch = TouchHandle::new(); | ||
if inner.touch.is_some() { | ||
// If there's already a tocuh device, remove it notify the clients about the change. | ||
inner.touch = None; | ||
inner.send_all_caps(); | ||
} | ||
inner.touch = Some(touch.clone()); | ||
inner.send_all_caps(); | ||
touch | ||
} | ||
|
||
/// Access the touch device of this seat, if any. | ||
pub fn get_touch(&self) -> Option<TouchHandle> { | ||
self.arc.inner.borrow_mut().touch.clone() | ||
} | ||
|
||
/// Remove the touch capability from this seat | ||
/// | ||
/// Clients will be appropriately notified. | ||
pub fn remove_touch(&mut self) { | ||
let mut inner = self.arc.inner.borrow_mut(); | ||
if inner.touch.is_some() { | ||
inner.touch = None; | ||
inner.send_all_caps(); | ||
} | ||
} | ||
|
||
/// Checks whether a given [`WlSeat`](wl_seat::WlSeat) is associated with this [`Seat`] | ||
pub fn owns(&self, seat: &wl_seat::WlSeat) -> bool { | ||
let inner = self.arc.inner.borrow_mut(); | ||
|
@@ -349,8 +409,13 @@ fn implement_seat(seat: Main<wl_seat::WlSeat>, arc: Rc<SeatRc>) -> wl_seat::WlSe | |
// same as pointer, should error but cannot | ||
} | ||
} | ||
wl_seat::Request::GetTouch { .. } => { | ||
// TODO | ||
wl_seat::Request::GetTouch { id } => { | ||
let touch = self::touch::implement_touch(id, inner.touch.as_ref()); | ||
if let Some(ref touch_handle) = inner.touch { | ||
touch_handle.new_touch(touch); | ||
} else { | ||
// same as pointer, should error but cannot | ||
} | ||
} | ||
wl_seat::Request::Release => { | ||
// Our destructors already handle it | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to change the
TouchSlot
here because it already was creating some friction inside my compositor when handling touch events and just created more problems when it came to converting theOption<TouchSlot>
back to ai32
to send it to the client.So since I'd assume nobody is using touch yet (since it doesn't work for clients), changing it now will prevent headaches in the future.