input/
seat.rs

1use crate::{ffi, AsRaw, FromRaw, Libinput};
2use std::{borrow::Cow, 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) -> Cow<'_, str> {
30        unsafe {
31            CStr::from_ptr(ffi::libinput_seat_get_physical_name(self.as_raw_mut()))
32                .to_string_lossy()
33        }
34    }
35
36    /// Return the logical name of the seat.
37    ///
38    /// This is an identifier to group sets of devices within the
39    /// compositor.
40    pub fn logical_name(&self) -> Cow<'_, str> {
41        unsafe {
42            CStr::from_ptr(ffi::libinput_seat_get_logical_name(self.as_raw_mut())).to_string_lossy()
43        }
44    }
45}