From 9abeeea5dfff5a82f53c4d8ea4261ce8252713c9 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 27 Oct 2023 13:33:18 -0700 Subject: [PATCH] Allow session lock if existing session lock is no longer valid This makes it possible to handle a crash in the session lock client by restarting it, for instance. This is similar to how Sway behaves. --- src/state.rs | 2 ++ src/wayland/handlers/session_lock.rs | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/state.rs b/src/state.rs index cc763e67..d41ed452 100644 --- a/src/state.rs +++ b/src/state.rs @@ -50,6 +50,7 @@ use smithay::{ output::{Mode as OutputMode, Output, Scale}, reexports::{ calloop::{LoopHandle, LoopSignal}, + wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1, wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::Mode, wayland_server::{ backend::{ClientData, ClientId, DisconnectReason}, @@ -189,6 +190,7 @@ pub struct SurfaceDmabufFeedback { #[derive(Debug)] pub struct SessionLock { + pub ext_session_lock: ExtSessionLockV1, pub surfaces: HashMap, } diff --git a/src/wayland/handlers/session_lock.rs b/src/wayland/handlers/session_lock.rs index f390b4bb..a93b1e72 100644 --- a/src/wayland/handlers/session_lock.rs +++ b/src/wayland/handlers/session_lock.rs @@ -7,7 +7,7 @@ use crate::{ use smithay::{ delegate_session_lock, output::Output, - reexports::wayland_server::protocol::wl_output::WlOutput, + reexports::wayland_server::{protocol::wl_output::WlOutput, Resource}, utils::Size, wayland::session_lock::{ LockSurface, SessionLockHandler, SessionLockManagerState, SessionLocker, @@ -21,12 +21,24 @@ impl SessionLockHandler for State { } fn lock(&mut self, locker: SessionLocker) { - if self.common.session_lock.is_none() { - locker.lock(); - self.common.session_lock = Some(SessionLock { - surfaces: HashMap::new(), - }); + // Reject lock if sesion lock exists and is still valid + if let Some(session_lock) = self.common.session_lock.as_ref() { + if self + .common + .display_handle + .get_client(session_lock.ext_session_lock.id()) + .is_ok() + { + return; + } } + + let ext_session_lock = locker.ext_session_lock().clone(); + locker.lock(); + self.common.session_lock = Some(SessionLock { + ext_session_lock, + surfaces: HashMap::new(), + }); } fn unlock(&mut self) {