Merge pull request #70 from Smithay/feature/seat_name
Add names to backend seats
This commit is contained in:
commit
7df2cf4cd1
|
@ -1,6 +1,7 @@
|
||||||
//! Common traits for input backends to receive input from.
|
//! Common traits for input backends to receive input from.
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::string::ToString;
|
||||||
use wayland_server::EventLoopHandle;
|
use wayland_server::EventLoopHandle;
|
||||||
|
|
||||||
/// A seat describes a group of input devices and at least one
|
/// 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.
|
/// 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
|
/// 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.
|
/// use this to calculate the differences since the last callback.
|
||||||
#[derive(Debug, Clone, Copy, Eq)]
|
#[derive(Debug, Clone, Eq)]
|
||||||
pub struct Seat {
|
pub struct Seat {
|
||||||
id: u64,
|
id: u64,
|
||||||
|
name: String,
|
||||||
capabilities: SeatCapabilities,
|
capabilities: SeatCapabilities,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Seat {
|
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 {
|
Seat {
|
||||||
id: id,
|
id: id,
|
||||||
|
name: name.to_string(),
|
||||||
capabilities: capabilities,
|
capabilities: capabilities,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +39,11 @@ impl Seat {
|
||||||
pub fn capabilities(&self) -> &SeatCapabilities {
|
pub fn capabilities(&self) -> &SeatCapabilities {
|
||||||
&self.capabilities
|
&self.capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the name of this `Seat`
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&*self.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::cmp::PartialEq for Seat {
|
impl ::std::cmp::PartialEq for Seat {
|
||||||
|
|
|
@ -318,7 +318,7 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
let device_seat = added.seat();
|
let device_seat = added.seat();
|
||||||
self.devices.push(added);
|
self.devices.push(added);
|
||||||
|
|
||||||
match self.seats.entry(device_seat) {
|
match self.seats.entry(device_seat.clone()) {
|
||||||
Entry::Occupied(mut seat_entry) => {
|
Entry::Occupied(mut seat_entry) => {
|
||||||
let old_seat = seat_entry.get_mut();
|
let old_seat = seat_entry.get_mut();
|
||||||
{
|
{
|
||||||
|
@ -335,8 +335,15 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
Entry::Vacant(seat_entry) => {
|
Entry::Vacant(seat_entry) => {
|
||||||
let mut hasher = DefaultHasher::default();
|
let mut hasher = DefaultHasher::default();
|
||||||
seat_entry.key().hash(&mut hasher);
|
seat_entry.key().hash(&mut hasher);
|
||||||
let seat =
|
let seat = seat_entry.insert(backend::Seat::new(
|
||||||
seat_entry.insert(backend::Seat::new(hasher.finish(), new_caps));
|
hasher.finish(),
|
||||||
|
format!(
|
||||||
|
"{}:{}",
|
||||||
|
device_seat.physical_name(),
|
||||||
|
device_seat.logical_name()
|
||||||
|
),
|
||||||
|
new_caps,
|
||||||
|
));
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
trace!(self.logger, "Calling on_seat_created with {:?}", seat);
|
||||||
handler.on_seat_created(evlh, seat);
|
handler.on_seat_created(evlh, seat);
|
||||||
|
@ -384,9 +391,9 @@ impl backend::InputBackend for LibinputInputBackend {
|
||||||
}
|
}
|
||||||
// it has, notify about updates
|
// it has, notify about updates
|
||||||
} else if let Some(ref mut handler) = self.handler {
|
} 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);
|
trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
|
||||||
handler.on_seat_changed(evlh, &seat);
|
handler.on_seat_changed(evlh, seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,7 @@ where
|
||||||
key_counter: 0,
|
key_counter: 0,
|
||||||
seat: Seat::new(
|
seat: Seat::new(
|
||||||
0,
|
0,
|
||||||
|
"winit",
|
||||||
SeatCapabilities {
|
SeatCapabilities {
|
||||||
pointer: true,
|
pointer: true,
|
||||||
keyboard: true,
|
keyboard: true,
|
||||||
|
|
Loading…
Reference in New Issue