Skip to main content

Session

Struct Session 

Source
pub struct Session<B: Backend> { /* private fields */ }
Expand description

Devices held across VT switches.

Implementations§

Source§

impl<B: Backend> Session<B>

Source

pub fn new(backend: B) -> Self

Wrap a seat that is currently active.

Examples found in repository?
examples/seat.rs (line 33)
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 const fn is_active(&self) -> bool

Whether the session currently owns the display.

Source

pub fn devices(&self) -> &[TakenDevice]

The devices being held.

Source

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

A descriptor to poll for seat activity.

Source

pub fn take_device( &mut self, path: impl AsRef<Path>, ) -> Result<TakenDevice, SessionError>

Open a device through the seat and hold it.

Opening the same path twice returns what is already held rather than a second descriptor: the seat would give one, and then a resume would have two to reopen and the caller two to keep straight.

§Errors
Examples found in repository?
examples/seat.rs (line 36)
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 release_device( &mut self, path: impl AsRef<Path>, ) -> Result<(), SessionError>

Give a device back to the seat.

§Errors
Source

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

Ask to switch to another session, by VT number.

Asynchronous: the seat pauses this session when it honors the request, and resumes it when the user comes back. Useful where the process owns the TTY in graphics mode and the kernel is no longer handling Ctrl+Alt+F<n> itself.

§Errors

SessionError::Seat if the seat refuses.

Source

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

Let the seat deliver what it has, turning it into events to act on.

A negative timeout blocks. Call Session::next_event afterwards.

The reference runs the caller’s callbacks synchronously from inside this call, which means the caller is re-entering the seat from inside the seat’s own dispatch. Queuing instead keeps that from being possible.

A device that cannot be reopened on resume is not an error here: it is reported as a SessionEvent::DeviceLost, and the rest come back.

§Errors

SessionError::Seat if the seat refuses to dispatch or to acknowledge a pause.

Source

pub fn next_event(&mut self) -> Option<SessionEvent>

The next thing the caller has to act on.

Trait Implementations§

Source§

impl<B: Debug + Backend> Debug for Session<B>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Session<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Session<B>
where B: RefUnwindSafe,

§

impl<B> Send for Session<B>
where B: Send,

§

impl<B> Sync for Session<B>
where B: Sync,

§

impl<B> Unpin for Session<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Session<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for Session<B>
where B: UnwindSafe,

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.