Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

fix(linux): clear stale modifier latch after xdotool type (#1817) (#1892)

Mike Evdokimov99052eefa6c1
diff --git a/src-tauri/src/clipboard.rs b/src-tauri/src/clipboard.rs
index f3ee8bea..c1964481 100644
--- a/src-tauri/src/clipboard.rs
+++ b/src-tauri/src/clipboard.rs
@@ -421,6 +421,47 @@ fn type_text_via_xdotool(text: &str) -> Result<(), String> {
.output()
.map_err(|e| format!("Failed to execute xdotool: {}", e))?;
+ // `--clearmodifiers` restores the modifiers that were held when xdotool
+ // started. If the user releases one while xdotool is typing, that synthetic
+ // restore can leave the modifier latched on the XTEST keyboard (#1817).
+ // Release both sides of Handy's supported push-style modifiers to clear any
+ // stale restore. Lock keys are intentionally excluded because key events
+ // toggle them.
+ //
+ // The release is unconditional, so it can make a modifier that is still
+ // physically held appear released until the next physical event. This is
+ // preferable to leaving a synthetic modifier latched system-wide.
+ //
+ // Clean up before checking the typing status because xdotool may have
+ // changed modifier state before returning an error. Cleanup remains
+ // best-effort because the text may already have been partially or fully
+ // typed, but failures are logged so they can be diagnosed.
+ match Command::new("xdotool")
+ .arg("keyup")
+ .args([
+ "Control_L",
+ "Control_R",
+ "Shift_L",
+ "Shift_R",
+ "Alt_L",
+ "Alt_R",
+ "Super_L",
+ "Super_R",
+ ])
+ .output()
+ {
+ Ok(cleanup_output) if !cleanup_output.status.success() => {
+ let stderr = String::from_utf8_lossy(&cleanup_output.stderr);
+ log::warn!(
+ "xdotool modifier cleanup failed with status {:?}: {}",
+ cleanup_output.status.code(),
+ stderr.trim()
+ );
+ }
+ Err(error) => log::warn!("Failed to execute xdotool modifier cleanup: {}", error),
+ _ => {}
+ }
+
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(format!("xdotool failed: {}", stderr));