From b92879e60b60a05c0490816a32e276703f4ee4f4 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 14 Feb 2025 19:14:43 +0100 Subject: [PATCH] zoom: Fix config/state changes --- src/backend/mod.rs | 12 +++++++++++- src/config/mod.rs | 2 +- src/input/actions.rs | 45 ++++++++++++++++++++++++++++++-------------- src/state.rs | 3 +++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 465a2c46..714bfbe1 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -72,7 +72,17 @@ pub fn init_backend_auto( .write() .unwrap() .seats - .add_seat(initial_seat); + .add_seat(initial_seat.clone()); + + if state + .common + .config + .cosmic_conf + .accessibility_zoom + .start_on_login + { + state.update_zoom(&initial_seat, 1.0, true); + } let desired_numlock = state .common diff --git a/src/config/mod.rs b/src/config/mod.rs index 64103b3a..652d7d4d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -68,7 +68,7 @@ pub struct Config { pub struct DynamicConfig { outputs: (Option, OutputsConfig), numlock: (Option, NumlockStateConfig), - accessibility_zoom: (Option, ZoomState), + pub accessibility_zoom: (Option, ZoomState), } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/input/actions.rs b/src/input/actions.rs index 8b709e6c..a1c0820e 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -11,6 +11,7 @@ use crate::{ handlers::xdg_activation::ActivationContext, protocols::workspace::WorkspaceUpdateGuard, }, }; +use calloop::timer::{TimeoutAction, Timer}; use cosmic_comp_config::{workspace::WorkspaceLayout, TileBehavior}; use cosmic_config::ConfigSet; use cosmic_settings_config::shortcuts; @@ -19,11 +20,11 @@ use smithay::{ input::{pointer::MotionEvent, Seat}, utils::{Point, Serial}, }; -use tracing::error; #[cfg(not(feature = "debug"))] use tracing::info; +use tracing::{error, warn}; -use std::{os::unix::process::CommandExt, thread}; +use std::{os::unix::process::CommandExt, thread, time::Duration}; use super::gestures; @@ -1045,7 +1046,7 @@ impl State { } } - fn spawn_command(&mut self, command: String) { + pub fn spawn_command(&mut self, command: String) { let mut shell = self.common.shell.write().unwrap(); let (token, data) = self.common.xdg_activation_state.create_external_token(None); @@ -1095,7 +1096,7 @@ impl State { .map(|state| (state.current_seat(), state.current_level())) .unwrap_or_else(|| (seat.clone(), 1.0)); let change = if current_level == 1.0 && animate { - self.common.config.dynamic_conf.zoom_state().last_level + self.common.config.dynamic_conf.zoom_state().last_level - 1.0 } else { change }; @@ -1114,19 +1115,35 @@ impl State { &self.common.event_loop_handle, ); - /* TODO: debounce - if new_level > 1. - && self - .common + if new_level > 1. { + // bypass the persistence guard, so that `update_zoom` call pick up the latest value + self.common .config - .cosmic_conf + .dynamic_conf .accessibility_zoom - .start_on_login - { - self.common.config.dynamic_conf.zoom_state_mut().last_level = - new_level; + .1 + .last_level = new_level; + + // and then debounce the config write, because of `Super+` + if let Some(token) = self.common.zoom_config_debounce.take() { + self.common.event_loop_handle.remove(token); + } + match self.common.event_loop_handle.insert_source( + Timer::from_duration(Duration::from_secs(5)), + move |_, _, state| { + state.common.config.dynamic_conf.zoom_state_mut().last_level = new_level; + let _ = state.common.zoom_config_debounce.take(); + TimeoutAction::Drop + }, + ) { + Ok(token) => { + self.common.zoom_config_debounce = Some(token); + } + Err(err) => { + warn!("Failed to schedule debounced configuration write: {}", err); + } + } } - */ } } } diff --git a/src/state.rs b/src/state.rs index c64ce05f..5cb519de 100644 --- a/src/state.rs +++ b/src/state.rs @@ -27,6 +27,7 @@ use crate::{ xwayland::XWaylandState, }; use anyhow::Context; +use calloop::RegistrationToken; use i18n_embed::{ fluent::{fluent_language_loader, FluentLanguageLoader}, DesktopLanguageRequester, @@ -185,6 +186,7 @@ pub struct Common { pub popups: PopupManager, pub shell: Arc>, + pub zoom_config_debounce: Option, pub clock: Clock, pub startup_done: Arc, @@ -592,6 +594,7 @@ impl State { popups: PopupManager::default(), shell, + zoom_config_debounce: None, local_offset,