mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Prevent locking while another lock client is already active
Fixes double swaylock from manual + swayidle.
This commit is contained in:
+22
-3
@@ -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::{
|
||||
@@ -263,7 +264,7 @@ pub enum LockState {
|
||||
#[default]
|
||||
Unlocked,
|
||||
Locking(SessionLocker),
|
||||
Locked,
|
||||
Locked(ExtSessionLockV1),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user