Restore clipboard after paste failure
This commit is contained in:
@@ -50,7 +50,10 @@ Each bounded iteration must:
|
||||
- [x] Add unit coverage for configured shortcut parsing and lock-state grab variants (17 tests and Docker GTK/X11 build, 2026-09-10).
|
||||
- [ ] Verify global shortcut registration, cleanup, conflicts, and configured shortcuts.
|
||||
- [ ] Verify previous-focus capture and paste behavior against real X11 applications.
|
||||
- [ ] Preserve clipboard contents and show an actionable error when paste fails.
|
||||
- [x] Preserve readable textual clipboard contents after paste injection fails;
|
||||
retain the selected entry only when the original clipboard cannot be read or
|
||||
restored, and show the existing actionable failure status (27 X11-feature
|
||||
tests and Docker GTK/X11/package build, 2026-09-12).
|
||||
- [x] Keep the popup hidden after a successful paste so focus remains in the target application; reopen only on failure (Docker GTK/X11 build, 2026-09-10).
|
||||
- [x] Keep the popup visible for explicit Paste actions while restoring target focus before XTest injection (Docker GTK/X11 build, 2026-09-12).
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ pub fn run(
|
||||
}
|
||||
};
|
||||
let clipboard_reader = X11ClipboardReader::start(config.max_entry_bytes)?;
|
||||
let clipboard_worker = X11ClipboardWorker::start()?;
|
||||
let clipboard_worker = X11ClipboardWorker::start(config.max_entry_bytes)?;
|
||||
let shared = Rc::new(RefCell::new(UiState {
|
||||
entries: database.load_entries()?,
|
||||
database,
|
||||
|
||||
@@ -50,7 +50,7 @@ pub struct X11ClipboardWorker {
|
||||
}
|
||||
|
||||
impl X11ClipboardWorker {
|
||||
pub fn start() -> Result<Self> {
|
||||
pub fn start(max_entry_bytes: usize) -> Result<Self> {
|
||||
let (requests, request_receiver) = mpsc::sync_channel::<ClipboardAction>(1);
|
||||
let (result_sender, results) = mpsc::sync_channel::<ClipboardWorkerResult>(1);
|
||||
thread::Builder::new()
|
||||
@@ -85,24 +85,39 @@ impl X11ClipboardWorker {
|
||||
ClipboardAction::Write {
|
||||
content,
|
||||
paste_target,
|
||||
} => match clipboard.write_text(&content) {
|
||||
} => {
|
||||
let previous_clipboard = read_clipboard_text(&clipboard.clipboard, max_entry_bytes)
|
||||
.ok()
|
||||
.flatten();
|
||||
match clipboard.write_text(&content) {
|
||||
Err(error) => ClipboardWorkerResult::Action {
|
||||
result: Err(error),
|
||||
clipboard_written: false,
|
||||
},
|
||||
Ok(()) => {
|
||||
let mut clipboard_written = true;
|
||||
let result = if let Some(target) = paste_target {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
clipboard.paste_into_active_window(target)
|
||||
let paste_result = clipboard.paste_into_active_window(target);
|
||||
if paste_result.is_err() {
|
||||
if let Some(previous) = previous_clipboard {
|
||||
match clipboard.write_text(&previous) {
|
||||
Ok(()) => clipboard_written = false,
|
||||
Err(error) => tracing::error!(%error, "failed to restore clipboard after paste failure"),
|
||||
}
|
||||
}
|
||||
}
|
||||
paste_result
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
ClipboardWorkerResult::Action {
|
||||
result,
|
||||
clipboard_written: true,
|
||||
clipboard_written,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
if result_sender.send(result).is_err() {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user