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
impl LibseatBackend
Sourcepub fn open() -> Result<Self, SessionError>
pub fn open() -> Result<Self, SessionError>
Connect to whatever seat is available, and wait for it to activate.
§Errors
SessionError::NoBackendwhen 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 withinDEFAULT_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}Sourcepub fn open_within(timeout: Option<Duration>) -> Result<Self, SessionError>
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.
Sourcepub fn name(&mut self) -> &str
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
impl Backend for LibseatBackend
Source§fn open_device(
&mut self,
path: &Path,
) -> Result<(DeviceId, RawFd), SessionError>
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>
fn close_device(&mut self, id: DeviceId) -> Result<(), SessionError>
Close one this session opened. Read more
Source§fn acknowledge_pause(&mut self) -> Result<(), SessionError>
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>
fn switch_session(&mut self, session: i32) -> Result<(), SessionError>
Ask to switch to another session, by VT number. Read more
Source§impl Debug for LibseatBackend
impl Debug for LibseatBackend
Source§impl Drop for LibseatBackend
impl Drop for LibseatBackend
Auto Trait Implementations§
impl !RefUnwindSafe for LibseatBackend
impl !Send for LibseatBackend
impl !Sync for LibseatBackend
impl !UnwindSafe for LibseatBackend
impl Freeze for LibseatBackend
impl Unpin for LibseatBackend
impl UnsafeUnpin for LibseatBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more