Skip to main content

LibseatBackend

Struct LibseatBackend 

Source
pub struct LibseatBackend { /* private fields */ }
Available on crate feature libseat only.
Expand description

A session backed by libseat.

Whichever backend libseat finds: logind, seatd, or the builtin fallback for a process running as root on a TTY. LIBSEAT_BACKEND picks one explicitly.

Implementations§

Source§

impl LibseatBackend

Source

pub fn open() -> Result<Self, SessionError>

Connect to whatever seat is available, and wait for it to activate.

§Errors
  • SessionError::NoBackend when there is no seat. That is the ordinary case outside a login session – over SSH, in a container, on a CI runner – and a caller that only wants to look at a display can open devices directly instead. What it gives up is surviving a VT switch. The same when the backend connects but does not activate the seat within DEFAULT_ENABLE_TIMEOUT – seatd over SSH, with no VT to take – so the caller falls back the same way. And the same when a dispatch fails before the seat activates, as the reference falls back on it.
Examples found in repository?
examples/seat.rs (line 20)
17fn main() {
18    let paths: Vec<String> = std::env::args().skip(1).collect();
19
20    let mut backend = match drmkit_session::LibseatBackend::open() {
21        Ok(backend) => backend,
22        Err(SessionError::NoBackend) => {
23            println!("no seat here: not a login session, no seatd, no root TTY");
24            return;
25        }
26        Err(error) => {
27            eprintln!("seat: {error}");
28            std::process::exit(1);
29        }
30    };
31
32    println!("seat: {}", backend.name());
33    let mut session = Session::new(backend);
34
35    for path in &paths {
36        match session.take_device(path) {
37            Ok(device) => println!("  {path}: fd {}", device.fd),
38            Err(error) => println!("  {path}: {error}"),
39        }
40    }
41
42    if paths.is_empty() {
43        println!("pass device paths to open some");
44    }
45}
Source

pub fn open_within(timeout: Option<Duration>) -> Result<Self, SessionError>

As open, waiting up to timeout for the seat to activate; None waits indefinitely.

Without a bound, a backend that connects but never activates the seat blocked forever, and SIGINT could not break the wait, so the process kept DRM master (drm-cxx 60c6f10). On timeout the seat is closed.

§Errors

As open.

Source

pub fn name(&mut self) -> &str

The seat’s name, for logging.

Examples found in repository?
examples/seat.rs (line 32)
17fn main() {
18    let paths: Vec<String> = std::env::args().skip(1).collect();
19
20    let mut backend = match drmkit_session::LibseatBackend::open() {
21        Ok(backend) => backend,
22        Err(SessionError::NoBackend) => {
23            println!("no seat here: not a login session, no seatd, no root TTY");
24            return;
25        }
26        Err(error) => {
27            eprintln!("seat: {error}");
28            std::process::exit(1);
29        }
30    };
31
32    println!("seat: {}", backend.name());
33    let mut session = Session::new(backend);
34
35    for path in &paths {
36        match session.take_device(path) {
37            Ok(device) => println!("  {path}: fd {}", device.fd),
38            Err(error) => println!("  {path}: {error}"),
39        }
40    }
41
42    if paths.is_empty() {
43        println!("pass device paths to open some");
44    }
45}

Trait Implementations§

Source§

impl Backend for LibseatBackend

Source§

fn open_device( &mut self, path: &Path, ) -> Result<(DeviceId, RawFd), SessionError>

Open a device the seat controls. Read more
Source§

fn close_device(&mut self, id: DeviceId) -> Result<(), SessionError>

Close one this session opened. Read more
Source§

fn acknowledge_pause(&mut self) -> Result<(), SessionError>

Tell the seat the pause has been acted on. Read more
Source§

fn switch_session(&mut self, session: i32) -> Result<(), SessionError>

Ask to switch to another session, by VT number. Read more
Source§

fn poll_fd(&self) -> Option<RawFd>

A descriptor that becomes readable when the seat has something to say.
Source§

fn dispatch( &mut self, timeout_ms: i32, events: &mut Vec<RawEvent>, ) -> Result<(), SessionError>

Let the seat deliver whatever it has, appending to events. Read more
Source§

impl Debug for LibseatBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LibseatBackend

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.