Prevent locking while another lock client is already active
Browse files at this commit62892d636112230dc16778b91331fbe97576b005Parent: 31c13b61 changed file +22 -3
- src/niri.rs +22 -3
src/niri.rsmodified+22 -3
| @@ -44,6 +44,7 @@ use smithay::reexports::calloop::{ | |||
| 44 | self, Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction, RegistrationToken, | 44 | self, Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction, RegistrationToken, |
| 45 | }; | 45 | }; |
| 46 | use smithay::reexports::input; | 46 | use smithay::reexports::input; |
| 47 | +use smithay::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1; | ||
| 47 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities; | 48 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities; |
| 48 | use smithay::reexports::wayland_protocols_misc::server_decoration as _server_decoration; | 49 | use smithay::reexports::wayland_protocols_misc::server_decoration as _server_decoration; |
| 49 | use smithay::reexports::wayland_server::backend::{ | 50 | use smithay::reexports::wayland_server::backend::{ |
| @@ -263,7 +264,7 @@ pub enum LockState { | |||
| 263 | #[default] | 264 | #[default] |
| 264 | Unlocked, | 265 | Unlocked, |
| 265 | Locking(SessionLocker), | 266 | Locking(SessionLocker), |
| 266 | - Locked, | 267 | + Locked(ExtSessionLockV1), |
| 267 | } | 268 | } |
| 268 | 269 | ||
| 269 | #[derive(PartialEq, Eq)] | 270 | #[derive(PartialEq, Eq)] |
| @@ -1300,8 +1301,9 @@ impl Niri { | |||
| 1300 | .all(|state| state.lock_render_state == LockRenderState::Locked); | 1301 | .all(|state| state.lock_render_state == LockRenderState::Locked); |
| 1301 | 1302 | ||
| 1302 | if all_locked { | 1303 | if all_locked { |
| 1304 | + let lock = confirmation.ext_session_lock().clone(); | ||
| 1303 | confirmation.lock(); | 1305 | confirmation.lock(); |
| 1304 | - self.lock_state = LockState::Locked; | 1306 | + self.lock_state = LockState::Locked(lock); |
| 1305 | } else { | 1307 | } else { |
| 1306 | // Still waiting. | 1308 | // Still waiting. |
| 1307 | self.lock_state = LockState::Locking(confirmation); | 1309 | self.lock_state = LockState::Locking(confirmation); |
| @@ -2108,8 +2110,9 @@ impl Niri { | |||
| 2108 | .all(|state| state.lock_render_state == LockRenderState::Locked); | 2110 | .all(|state| state.lock_render_state == LockRenderState::Locked); |
| 2109 | 2111 | ||
| 2110 | if all_locked { | 2112 | if all_locked { |
| 2113 | + let lock = confirmation.ext_session_lock().clone(); | ||
| 2111 | confirmation.lock(); | 2114 | confirmation.lock(); |
| 2112 | - self.lock_state = LockState::Locked; | 2115 | + self.lock_state = LockState::Locked(lock); |
| 2113 | } else { | 2116 | } else { |
| 2114 | // Still waiting. | 2117 | // Still waiting. |
| 2115 | self.lock_state = LockState::Locking(confirmation); | 2118 | self.lock_state = LockState::Locking(confirmation); |
| @@ -2833,6 +2836,22 @@ impl Niri { | |||
| 2833 | } | 2836 | } |
| 2834 | 2837 | ||
| 2835 | pub fn lock(&mut self, confirmation: SessionLocker) { | 2838 | pub fn lock(&mut self, confirmation: SessionLocker) { |
| 2839 | + // Check if another client is in the process of locking. | ||
| 2840 | + if matches!(self.lock_state, LockState::Locking(_)) { | ||
| 2841 | + info!("refusing lock as another client is currently locking"); | ||
| 2842 | + return; | ||
| 2843 | + } | ||
| 2844 | + | ||
| 2845 | + // Check if we're already locked with an active client. | ||
| 2846 | + if let LockState::Locked(lock) = &self.lock_state { | ||
| 2847 | + if lock.is_alive() { | ||
| 2848 | + info!("refusing lock as already locked with an active client"); | ||
| 2849 | + return; | ||
| 2850 | + } | ||
| 2851 | + | ||
| 2852 | + // If the client had died, continue with the new lock. | ||
| 2853 | + } | ||
| 2854 | + | ||
| 2836 | info!("locking session"); | 2855 | info!("locking session"); |
| 2837 | 2856 | ||
| 2838 | self.screenshot_ui.close(); | 2857 | self.screenshot_ui.close(); |