Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix session lock example and add more explanations #463

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions examples/session_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ fn main() {
app_data.session_lock =
Some(app_data.session_lock_state.lock(&qh).expect("ext-session-lock not supported"));

// After locking the session, we're expected to create a lock surface for each output.
// As soon as all lock surfaces are created, `SessionLockHandler::locked` will be called
// and the every surface receives a `SessionLockHandler::configure` call.
let qh: QueueHandle<AppData> = event_queue.handle();
for output in app_data.output_state().outputs() {
let session_lock = app_data.session_lock.as_ref().unwrap();
let surface = app_data.compositor_state.create_surface(&qh);

// It's important to keep the `SessionLockSurface` returned here around, as the
// surface will be destroyed when the `SessionLockSurface` is dropped.
let lock_surface = session_lock.create_lock_surface(surface, &output, &qh);
app_data.lock_surfaces.push(lock_surface);
}

WaylandSource::new(conn.clone(), event_queue).insert(event_loop.handle()).unwrap();

loop {
Expand All @@ -74,15 +88,9 @@ fn main() {
}

impl SessionLockHandler for AppData {
fn locked(&mut self, _conn: &Connection, qh: &QueueHandle<Self>, session_lock: SessionLock) {
fn locked(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _session_lock: SessionLock) {
println!("Locked");

for output in self.output_state.outputs() {
let surface = self.compositor_state.create_surface(&qh);
let lock_surface = session_lock.create_lock_surface(surface, &output, qh);
self.lock_surfaces.push(lock_surface);
}

// After 5 seconds, destroy lock
self.loop_handle
.insert_source(Timer::from_duration(Duration::from_secs(5)), |_, _, app_data| {
Expand All @@ -103,7 +111,7 @@ impl SessionLockHandler for AppData {
_qh: &QueueHandle<Self>,
_session_lock: SessionLock,
) {
println!("Finished");
println!("Session could not be locked");
self.exit = true;
}

Expand Down
Loading