stabilize live speed indicator and normalize hi-res wheel handling
This commit is contained in:
@@ -8,8 +8,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
static INPUT_SPEED_BITS: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub fn read_input_speed() -> f64 {
|
||||
@@ -21,7 +19,16 @@ pub fn setup_input_speed_reader() -> JoinHandle<anyhow::Result<()>> {
|
||||
let path = stats_path();
|
||||
|
||||
loop {
|
||||
if let Ok(content) = std::fs::read_to_string(&path)
|
||||
let stale = std::fs::metadata(&path)
|
||||
.and_then(|m| m.modified())
|
||||
.ok()
|
||||
.and_then(|t| t.elapsed().ok())
|
||||
.map(|age| age > Duration::from_millis(300))
|
||||
.unwrap_or(true);
|
||||
|
||||
if stale {
|
||||
INPUT_SPEED_BITS.store(0.0f64.to_bits(), Ordering::Relaxed);
|
||||
} else if let Ok(content) = std::fs::read_to_string(&path)
|
||||
&& let Ok(parsed) = content.trim().parse::<f64>()
|
||||
{
|
||||
INPUT_SPEED_BITS.store(parsed.to_bits(), Ordering::Relaxed);
|
||||
@@ -37,18 +44,6 @@ fn stats_path() -> PathBuf {
|
||||
return PathBuf::from(path);
|
||||
}
|
||||
|
||||
if let Ok(runtime_dir) = std::env::var("XDG_RUNTIME_DIR") {
|
||||
return PathBuf::from(runtime_dir).join("gsf-speed.txt");
|
||||
}
|
||||
|
||||
let home = std::env::var("HOME").context("HOME missing").ok();
|
||||
if let Some(home) = home {
|
||||
return PathBuf::from(home)
|
||||
.join(".local")
|
||||
.join("state")
|
||||
.join("gsf")
|
||||
.join("speed.txt");
|
||||
}
|
||||
|
||||
// Keep default shared across sudo/non-sudo runs.
|
||||
PathBuf::from("/tmp/gsf-speed.txt")
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ impl Default for StoredConfig {
|
||||
yx_ratio: 1.0,
|
||||
input_dpi: 1000.0,
|
||||
angle_rotation: 0.0,
|
||||
accel: 0.0,
|
||||
offset_linear: 0.0,
|
||||
output_cap: 0.0,
|
||||
accel: 0.3,
|
||||
offset_linear: 2.0,
|
||||
output_cap: 2.0,
|
||||
decay_rate: 0.1,
|
||||
offset_natural: 0.0,
|
||||
limit: 1.5,
|
||||
@@ -164,6 +164,19 @@ fn config_path() -> anyhow::Result<PathBuf> {
|
||||
return Ok(PathBuf::from(p));
|
||||
}
|
||||
|
||||
// If daemon is launched with sudo, prefer caller's home so CLI/TUI and daemon share config.
|
||||
if let Ok(sudo_user) = std::env::var("SUDO_USER")
|
||||
&& !sudo_user.is_empty()
|
||||
&& sudo_user != "root"
|
||||
{
|
||||
let candidate = PathBuf::from("/home")
|
||||
.join(sudo_user)
|
||||
.join(".config")
|
||||
.join("gsf")
|
||||
.join("config.json");
|
||||
return Ok(candidate);
|
||||
}
|
||||
|
||||
let home = std::env::var("HOME").context("HOME is not set")?;
|
||||
Ok(PathBuf::from(home)
|
||||
.join(".config")
|
||||
|
||||
Reference in New Issue
Block a user