Skip to content

Conversation

@mg-dev25
Copy link
Contributor

Fix: Improve Paste Reliability with Overlay Timing Callback

This PR fixes paste failures on Linux (especially Wayland) by ensuring the overlay is fully hidden and focus is restored to the target application before attempting to paste.

Problem

On Linux/Wayland, the current implementation attempts to paste text immediately after hiding the overlay. However, Wayland window managers handle focus changes asynchronously, meaning the previous application may not have regained focus by the time the paste operation is executed. This results in:

  • Text not appearing in the target application
  • Text being pasted into the overlay itself
  • Users needing to manually click the target window before paste works

Solution

Introduces hide_recording_overlay_with_callback() which:

  1. Triggers the fade-out animation (300ms)
  2. Hides the overlay window
  3. Waits an additional 150ms for the window manager to restore focus
  4. Only then executes the paste operation via callback

This ensures reliable paste behavior across all Linux desktop environments, particularly on Wayland compositors.

Technical Changes

src-tauri/src/overlay.rs:

  • Added hide_recording_overlay_with_callback<F>() function with callback support
  • Comprehensive documentation explaining Wayland focus behavior

src-tauri/src/actions.rs:

  • Updated TranscribeAction::stop() to use callback-based overlay hiding
  • Paste now executes only after overlay is fully hidden and focus restored

Testing

Tested on:

  • Linux Mint (Cinnamon/X11)
  • Fedora (Wayland/GNOME)

Related Issues

Add hide_recording_overlay_with_callback() that waits for the overlay
fade-out animation to complete and the window manager to restore focus
before executing the paste operation.

This fixes paste failures on Wayland/Linux where focus changes are
asynchronous and the previous application may not have regained focus
by the time the paste is attempted.

Changes:
- Add hide_recording_overlay_with_callback() in overlay.rs with:
  - 300ms delay for fade-out animation
  - 150ms delay for window manager focus restoration
  - Immediate callback execution if no overlay exists
- Update actions.rs to use callback-based approach for pasting
- Remove run_on_main_thread wrapper (callback runs in spawned thread)

Relates to cjpais#390
@cjpais
Copy link
Owner

cjpais commented Nov 30, 2025

So I've reviewed this briefly and also with the help of some large language models and I'm a bit skeptical to pull this in as is due to cross-platform concerns. Generally needing to review the history of the code, specifically in regards to the change away from running on the main thread. Quite frankly I'm not quite versed enough in the specifics of each platform to know if that was required anyhow, but the LLM's are concerned for what it's worth. Also there is some code duplication between hide_recording_overlay and hide_recording_overlay_with_callback. There's probably a much cleaner way to move forward. Maybe an optional callback.

Also, I'm not very happy with the delay that this introduces on MacOS. In testing, I find it quite awkward. It's fine for Linux because it fixes a real issue on many distros of Linux. But I don't think the delay is acceptable to have on Windows and MacOS and should be feature flagged off for just Linux.

I believe your fork prevents me from making any changes on this branch. I'm happy to both review and change files as necessary, if you're up to allow that.

@mg-dev25
Copy link
Contributor Author

@cjpais Because of this issues with github https://github.com/orgs/community/discussions/5634
I don't have the option to allow edit of the Pr. So I give you access to write the fork create by my org.
Tell me if this did not work.

@cjpais
Copy link
Owner

cjpais commented Dec 1, 2025

Thanks, that worked, I will take a look when I can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Typing fails due to target window not focused at correct time

2 participants