From 354c365a0345787f6b98ee2d77d4516150a61254 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sun, 3 Nov 2024 14:50:02 +0100 Subject: xdg: cleanup activation tokens valid tokens will stay around until explicitly cleaned-up. remove the token after it has been successfully used or we consider it timed out to prevent leaking the memory used by the activation tokens --- src/handlers/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/handlers') diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index f3f5cb82..6de1e09e 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -7,6 +7,7 @@ use std::io::Write; use std::os::fd::OwnedFd; use std::sync::Arc; use std::thread; +use std::time::Duration; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::drm::DrmNode; @@ -80,6 +81,8 @@ use crate::{ delegate_output_management, delegate_screencopy, }; +pub const XDG_ACTIVATION_TOKEN_TIMEOUT: Duration = Duration::from_secs(10); + impl SeatHandler for State { type KeyboardFocus = WlSurface; type PointerFocus = WlSurface; @@ -624,16 +627,18 @@ impl XdgActivationHandler for State { fn request_activation( &mut self, - _token: XdgActivationToken, + token: XdgActivationToken, token_data: XdgActivationTokenData, surface: WlSurface, ) { - if token_data.timestamp.elapsed().as_secs() < 10 { + if token_data.timestamp.elapsed() < XDG_ACTIVATION_TOKEN_TIMEOUT { if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&surface) { let window = mapped.window.clone(); self.niri.layout.activate_window(&window); self.niri.layer_shell_on_demand_focus = None; self.niri.queue_redraw_all(); + + self.niri.activation_state.remove_token(&token); } } } -- cgit