a11y/zoom: Drop last state
This commit is contained in:
parent
83a7926748
commit
babb96ddfa
4 changed files with 4 additions and 96 deletions
|
|
@ -68,7 +68,6 @@ pub struct Config {
|
|||
pub struct DynamicConfig {
|
||||
outputs: (Option<PathBuf>, OutputsConfig),
|
||||
numlock: (Option<PathBuf>, NumlockStateConfig),
|
||||
pub accessibility_zoom: (Option<PathBuf>, ZoomState),
|
||||
accessibility_filter: (Option<PathBuf>, ScreenFilter),
|
||||
}
|
||||
|
||||
|
|
@ -178,11 +177,6 @@ impl OutputConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
|
||||
pub struct ZoomState {
|
||||
pub last_level: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
|
||||
pub struct ScreenFilter {
|
||||
pub inverted: bool,
|
||||
|
|
@ -348,7 +342,7 @@ impl Config {
|
|||
});
|
||||
|
||||
Config {
|
||||
dynamic_conf: Self::load_dynamic(xdg.as_ref(), &cosmic_comp_config),
|
||||
dynamic_conf: Self::load_dynamic(xdg.as_ref()),
|
||||
cosmic_conf: cosmic_comp_config,
|
||||
cosmic_helper: config,
|
||||
settings_context,
|
||||
|
|
@ -358,10 +352,7 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_dynamic(
|
||||
xdg: Option<&xdg::BaseDirectories>,
|
||||
cosmic: &CosmicCompConfig,
|
||||
) -> DynamicConfig {
|
||||
fn load_dynamic(xdg: Option<&xdg::BaseDirectories>) -> DynamicConfig {
|
||||
let output_path =
|
||||
xdg.and_then(|base| base.place_state_file("cosmic-comp/outputs.ron").ok());
|
||||
let outputs = Self::load_outputs(&output_path);
|
||||
|
|
@ -369,10 +360,6 @@ impl Config {
|
|||
xdg.and_then(|base| base.place_state_file("cosmic-comp/numlock.ron").ok());
|
||||
let numlock = Self::load_numlock(&numlock_path);
|
||||
|
||||
let zoom_path =
|
||||
xdg.and_then(|base| base.place_state_file("cosmic-comp/a11y_zoom.ron").ok());
|
||||
let zoom = Self::load_zoom_state(&zoom_path, cosmic);
|
||||
|
||||
let filter_path = xdg.and_then(|base| {
|
||||
base.place_state_file("cosmic-comp/a11y_screen_filter.ron")
|
||||
.ok()
|
||||
|
|
@ -382,7 +369,6 @@ impl Config {
|
|||
DynamicConfig {
|
||||
outputs: (output_path, outputs),
|
||||
numlock: (numlock_path, numlock),
|
||||
accessibility_zoom: (zoom_path, zoom),
|
||||
accessibility_filter: (filter_path, filter),
|
||||
}
|
||||
}
|
||||
|
|
@ -449,35 +435,6 @@ impl Config {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn load_zoom_state(path: &Option<PathBuf>, cosmic: &CosmicCompConfig) -> ZoomState {
|
||||
if let Some(path) = path.as_ref() {
|
||||
if path.exists() {
|
||||
match ron::de::from_reader::<_, ZoomState>(
|
||||
OpenOptions::new().read(true).open(path).unwrap(),
|
||||
) {
|
||||
Ok(mut config) => {
|
||||
if config.last_level <= 1.0 {
|
||||
warn!("Invalid level, resetting");
|
||||
config.last_level =
|
||||
1.0 + cosmic.accessibility_zoom.increment as f64 / 100.0;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
Err(err) => {
|
||||
warn!(?err, "Failed to read zoom_state, resetting..");
|
||||
if let Err(err) = std::fs::remove_file(path) {
|
||||
error!(?err, "Failed to remove zoom_state.");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ZoomState {
|
||||
last_level: 1.0 + cosmic.accessibility_zoom.increment as f64 / 100.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_filter_state(path: &Option<PathBuf>) -> ScreenFilter {
|
||||
if let Some(path) = path.as_ref() {
|
||||
if path.exists() {
|
||||
|
|
@ -779,17 +736,6 @@ impl DynamicConfig {
|
|||
PersistenceGuard(self.numlock.0.clone(), &mut self.numlock.1)
|
||||
}
|
||||
|
||||
pub fn zoom_state(&self) -> &ZoomState {
|
||||
&self.accessibility_zoom.1
|
||||
}
|
||||
|
||||
pub fn zoom_state_mut(&mut self) -> PersistenceGuard<'_, ZoomState> {
|
||||
PersistenceGuard(
|
||||
self.accessibility_zoom.0.clone(),
|
||||
&mut self.accessibility_zoom.1,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn screen_filter(&self) -> &ScreenFilter {
|
||||
&self.accessibility_filter.1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
|
@ -24,7 +23,7 @@ use smithay::{
|
|||
use tracing::info;
|
||||
use tracing::{error, warn};
|
||||
|
||||
use std::{os::unix::process::CommandExt, thread, time::Duration};
|
||||
use std::{os::unix::process::CommandExt, thread};
|
||||
|
||||
use super::gestures;
|
||||
|
||||
|
|
@ -1033,11 +1032,6 @@ impl State {
|
|||
.zoom_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 - 1.0
|
||||
} else {
|
||||
change
|
||||
};
|
||||
|
||||
if current_level == 1. && change <= 0. {
|
||||
return;
|
||||
|
|
@ -1052,36 +1046,6 @@ impl State {
|
|||
animate,
|
||||
&self.common.event_loop_handle,
|
||||
);
|
||||
|
||||
if new_level > 1. {
|
||||
// bypass the persistence guard, so that `update_zoom` call pick up the latest value
|
||||
self.common
|
||||
.config
|
||||
.dynamic_conf
|
||||
.accessibility_zoom
|
||||
.1
|
||||
.last_level = new_level;
|
||||
|
||||
// and then debounce the config write, because of `Super+<Scroll Wheel>`
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ pub struct Common {
|
|||
|
||||
pub popups: PopupManager,
|
||||
pub shell: Arc<RwLock<Shell>>,
|
||||
pub zoom_config_debounce: Option<RegistrationToken>,
|
||||
|
||||
pub clock: Clock<Monotonic>,
|
||||
pub startup_done: Arc<AtomicBool>,
|
||||
|
|
@ -615,7 +614,6 @@ impl State {
|
|||
|
||||
popups: PopupManager::default(),
|
||||
shell,
|
||||
zoom_config_debounce: None,
|
||||
|
||||
local_offset,
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl A11yHandler for State {
|
|||
{
|
||||
let seat = shell.seats.last_active().clone();
|
||||
let level = if enabled {
|
||||
self.common.config.dynamic_conf.zoom_state().last_level
|
||||
1.0 + (self.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0)
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue