Skip to content

Commit

Permalink
Prevent locking while another lock client is already active
Browse files Browse the repository at this point in the history
Fixes double swaylock from manual + swayidle.
  • Loading branch information
YaLTeR committed Feb 17, 2024
1 parent 31c13b6 commit 62892d6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use smithay::reexports::calloop::{
self, Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction, RegistrationToken,
};
use smithay::reexports::input;
use smithay::reexports::wayland_protocols::ext::session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities;
use smithay::reexports::wayland_protocols_misc::server_decoration as _server_decoration;
use smithay::reexports::wayland_server::backend::{
Expand Down Expand Up @@ -263,7 +264,7 @@ pub enum LockState {
#[default]
Unlocked,
Locking(SessionLocker),
Locked,
Locked(ExtSessionLockV1),
}

#[derive(PartialEq, Eq)]
Expand Down Expand Up @@ -1300,8 +1301,9 @@ impl Niri {
.all(|state| state.lock_render_state == LockRenderState::Locked);

if all_locked {
let lock = confirmation.ext_session_lock().clone();
confirmation.lock();
self.lock_state = LockState::Locked;
self.lock_state = LockState::Locked(lock);
} else {
// Still waiting.
self.lock_state = LockState::Locking(confirmation);
Expand Down Expand Up @@ -2108,8 +2110,9 @@ impl Niri {
.all(|state| state.lock_render_state == LockRenderState::Locked);

if all_locked {
let lock = confirmation.ext_session_lock().clone();
confirmation.lock();
self.lock_state = LockState::Locked;
self.lock_state = LockState::Locked(lock);
} else {
// Still waiting.
self.lock_state = LockState::Locking(confirmation);
Expand Down Expand Up @@ -2833,6 +2836,22 @@ impl Niri {
}

pub fn lock(&mut self, confirmation: SessionLocker) {
// Check if another client is in the process of locking.
if matches!(self.lock_state, LockState::Locking(_)) {
info!("refusing lock as another client is currently locking");
return;
}

// Check if we're already locked with an active client.
if let LockState::Locked(lock) = &self.lock_state {
if lock.is_alive() {
info!("refusing lock as already locked with an active client");
return;
}

// If the client had died, continue with the new lock.
}

info!("locking session");

self.screenshot_ui.close();
Expand Down

0 comments on commit 62892d6

Please sign in to comment.