Merge pull request #70 from Smithay/feature/seat_name

Add names to backend seats
This commit is contained in:
Victor Brekenfeld 2018-02-19 19:41:37 +01:00 committed by GitHub
commit 7df2cf4cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 7 deletions

View File

@ -1,6 +1,7 @@
//! Common traits for input backends to receive input from.
use std::error::Error;
use std::string::ToString;
use wayland_server::EventLoopHandle;
/// A seat describes a group of input devices and at least one
@ -14,16 +15,18 @@ use wayland_server::EventLoopHandle;
/// hash, but capabilities of cloned and copied `Seat`s will not be updated by smithay.
/// Always referr to the `Seat` given by a callback for up-to-date information. You may
/// use this to calculate the differences since the last callback.
#[derive(Debug, Clone, Copy, Eq)]
#[derive(Debug, Clone, Eq)]
pub struct Seat {
id: u64,
name: String,
capabilities: SeatCapabilities,
}
impl Seat {
pub(crate) fn new(id: u64, capabilities: SeatCapabilities) -> Seat {
pub(crate) fn new<S: ToString>(id: u64, name: S, capabilities: SeatCapabilities) -> Seat {
Seat {
id: id,
name: name.to_string(),
capabilities: capabilities,
}
}
@ -36,6 +39,11 @@ impl Seat {
pub fn capabilities(&self) -> &SeatCapabilities {
&self.capabilities
}
/// Get the name of this `Seat`
pub fn name(&self) -> &str {
&*self.name
}
}
impl ::std::cmp::PartialEq for Seat {

View File

@ -318,7 +318,7 @@ impl backend::InputBackend for LibinputInputBackend {
let device_seat = added.seat();
self.devices.push(added);
match self.seats.entry(device_seat) {
match self.seats.entry(device_seat.clone()) {
Entry::Occupied(mut seat_entry) => {
let old_seat = seat_entry.get_mut();
{
@ -335,8 +335,15 @@ impl backend::InputBackend for LibinputInputBackend {
Entry::Vacant(seat_entry) => {
let mut hasher = DefaultHasher::default();
seat_entry.key().hash(&mut hasher);
let seat =
seat_entry.insert(backend::Seat::new(hasher.finish(), new_caps));
let seat = seat_entry.insert(backend::Seat::new(
hasher.finish(),
format!(
"{}:{}",
device_seat.physical_name(),
device_seat.logical_name()
),
new_caps,
));
if let Some(ref mut handler) = self.handler {
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
handler.on_seat_created(evlh, seat);
@ -384,9 +391,9 @@ impl backend::InputBackend for LibinputInputBackend {
}
// it has, notify about updates
} else if let Some(ref mut handler) = self.handler {
let seat = self.seats[&device_seat];
let seat = &self.seats[&device_seat];
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
handler.on_seat_changed(evlh, &seat);
handler.on_seat_changed(evlh, seat);
}
}
}

View File

@ -167,6 +167,7 @@ where
key_counter: 0,
seat: Seat::new(
0,
"winit",
SeatCapabilities {
pointer: true,
keyboard: true,