input/
seat.rs

1use crate::{ffi, AsRaw, FromRaw, Libinput};
2use std::ffi::CStr;
3
4ffi_ref_struct!(
5/// A seat has two identifiers, the physical name and the logical name.
6///
7/// A device is always assigned to exactly one seat. It may change to a
8/// different logical seat but it cannot change physical seats. See
9/// [Seats](https://wayland.freedesktop.org/libinput/doc/latest/seats.html)
10/// for details.
11struct Seat, ffi::libinput_seat, ffi::libinput_seat_ref, ffi::libinput_seat_unref);
12
13impl Seat {
14    /// Get the libinput context from the seat.
15    pub fn context(&self) -> Libinput {
16        self.context.clone()
17    }
18
19    /// Return the physical name of the seat.
20    ///
21    /// For libinput contexts created from udev, this is always the
22    /// same value as passed into `udev_assign_seat` and all
23    /// seats from that context will have the same physical name.
24    ///
25    /// The physical name of the seat is one that is usually set by the
26    /// system or lower levels of the stack. In most cases, this is the
27    /// base filter for devices - devices assigned to seats outside the
28    /// current seat will not be available to the caller.
29    pub fn physical_name(&self) -> &str {
30        unsafe {
31            CStr::from_ptr(ffi::libinput_seat_get_physical_name(self.as_raw_mut()))
32                .to_str()
33                .expect("Seat physical_name is no valid utf-8")
34        }
35    }
36
37    /// Return the logical name of the seat.
38    ///
39    /// This is an identifier to group sets of devices within the
40    /// compositor.
41    pub fn logical_name(&self) -> &str {
42        unsafe {
43            CStr::from_ptr(ffi::libinput_seat_get_logical_name(self.as_raw_mut()))
44                .to_str()
45                .expect("Seat logical_name is no valid utf-8")
46        }
47    }
48}