pub struct Session<B: Backend> { /* private fields */ }Expand description
Devices held across VT switches.
Implementations§
Source§impl<B: Backend> Session<B>
impl<B: Backend> Session<B>
Sourcepub fn new(backend: B) -> Self
pub fn new(backend: B) -> Self
Wrap a seat that is currently active.
Examples found in repository?
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 devices(&self) -> &[TakenDevice]
pub fn devices(&self) -> &[TakenDevice]
The devices being held.
Sourcepub fn take_device(
&mut self,
path: impl AsRef<Path>,
) -> Result<TakenDevice, SessionError>
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
SessionError::Inactivewhile the session does not own the display. The seat would refuse anyway; failing here says why.SessionError::Seatif the seat refuses.
Examples found in repository?
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 release_device(
&mut self,
path: impl AsRef<Path>,
) -> Result<(), SessionError>
pub fn release_device( &mut self, path: impl AsRef<Path>, ) -> Result<(), SessionError>
Give a device back to the seat.
§Errors
SessionError::UnknownDeviceif this session did not open it.SessionError::Seatif the seat refuses.
Sourcepub fn switch_session(&mut self, session: i32) -> Result<(), SessionError>
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.
Sourcepub fn dispatch(&mut self, timeout_ms: i32) -> Result<(), SessionError>
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.
Sourcepub fn next_event(&mut self) -> Option<SessionEvent>
pub fn next_event(&mut self) -> Option<SessionEvent>
The next thing the caller has to act on.