fix: remove clipboard save/restore — leaked content into text

- xclip -o read triggered unwanted paste in some apps
- Clipboard save/restore was over-engineering the Ctrl+C/V fix
- Simple clipboard write+paste is sufficient
This commit is contained in:
Khoa Vo 2026-06-26 17:18:04 +07:00
parent a4c83e06b9
commit 0770cc59cc

View file

@ -361,18 +361,13 @@ impl UinputInjector {
return InjectResult::Success; return InjectResult::Success;
} }
// Unicode: clipboard paste. Save user clipboard first, restore after. // Unicode: clipboard paste. Backspaces FIRST, then paste.
let saved = self.read_clipboard();
if backspaces > 0 { if backspaces > 0 {
for _ in 0..backspaces { let _ = self.send_backspace(); } for _ in 0..backspaces { let _ = self.send_backspace(); }
} }
if self.copy_to_clipboard(text) { if self.copy_to_clipboard(text) {
self.send_ctrl_v_x11(); self.send_ctrl_v_x11();
} }
// Restore user's clipboard
if let Some(prev) = saved {
self.copy_to_clipboard(&prev);
}
InjectResult::Success InjectResult::Success
} }
@ -453,19 +448,6 @@ impl UinputInjector {
} }
/// Copy text to clipboard using wl-copy (Wayland) or xclip (X11). /// Copy text to clipboard using wl-copy (Wayland) or xclip (X11).
fn read_clipboard(&self) -> Option<String> {
// Read clipboard via xclip to restore after injection
let output = std::process::Command::new("xclip")
.args(["-selection", "clipboard", "-o"])
.output()
.ok()?;
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
}
fn copy_to_clipboard(&self, s: &str) -> bool { fn copy_to_clipboard(&self, s: &str) -> bool {
// Try wl-copy (Wayland) via user_cmd // Try wl-copy (Wayland) via user_cmd
{ {