I am building a small emoji picker desktop app with tauri and svelte. Thanks a lot for tauri and its documentation, it was quick and pleasant to get the project up and running!
I am facing 2 issues when writing to the clipboard though, they occur in different context but seem to be related
When the user clicks on an emoji it is added to the clipboard using clipboard.writeText(emoji) in javascript, the window is hidden, then we invoke() a rust command which aims to automatically paste the copied emoji. In the rust invocation we have 2 scenarios:
On x11 we use xdotool key ctrl+v, the emoji is properly pasted, but the clipboard is emptied, and we get the same behavior when using xdotool type 😅
If we try to write again the emoji to the clipboard with app_handle.clipboard_manager().write_text(emoji).unwrap(); we actually end up with what was in the clipboard previously (which is a nice feature, but not what we expected)
On an other hand triggering xdotool directly from the terminal does not empty the clipboard, which makes me think something could be happening on the tauri side
On wayland we use ydotool key, the emoji is properly pasted, and it stays in the clipboard. But if I try to add back the item that was in the clipboard before copying the emoji, this time the emoji stays...
I also tried to write back the previous clipboard item through the javascript, after having await the invoke, but the emoji stays in the clipboard. I also tried to do all the write_text and hide window from the rust command, but still the same issues
This happens when I just hide the window, and when I completely close the app, no changes
Reproduction
Feel free to check the code, it is quite straight to the point and has comments:
If you are using linux x11 you will need to install an additional dependency for xdotool, on fedora it goes like sudo dnf install libX11-devel libxdo-devel
Then install and run the app:
git clone https://github.com/vemonet/EmojiMart -b clipboard-issue
cd EmojiMart
make install
make dev
When the picker pops up click on an emoji:
If you are on x11: the emoji will be pasted to the currently focused window, but will not be in the clipboard anymore. Which is not normal because we do not overwrite the text.
If we just remove the xdotool key command, then the emoji stays in the clipboard, indicating xdotool might play a role, at least in the x11 case
If we try to add clipboard.writeText(emoji) the previous item is copied!!! even if the previous item was not even read in the first place! (that was a funny surprise, got data I never asked for)
If we try to add clipboard.writeText(previous) after running xdotool all of sudden at the same time we have xdotool automatically copying the previous text to the focused window, and magically this time the clipboard is not cleared! (what a funny coincidence)
If you are on wayland: the emoji will be added to the clipboard, which is not normal because we run clipboard.writeText(previous) after copying the emoji
Sorry if it is a bit complex but those 2 errors are so connected it did not feel right to create 2 different issues yet
You can change a bit where the clipboard.writeText() are called to see how weird the whole clipboard behavior is
Expected behavior
When we call clipboard.writeText("😅") (or its rust counterpart) it should add 😅 to the keyboard, instead of adding the previous clipboard item or clearing the clipboard
I also tried to run the clipboard_manager().write_text in a separate thread (using thread::spawn), but the results were the same
Any idea what could cause these issues? Are they caused by the same underlying problem? Or are they 2 completely separate problems dependent on the windowing system?
Anyone ever faced this weird cleaning of the clipboard by xdotool only when called from tauri?
I must admit it's quite puzzling, so any tips on how to better handle the clipboard are welcomed! Maybe there are things I am not aware of (different types of clipboard exists?)
I don't think tauri has any effect since you're using Command which is from rust std lib, but maybe try using arboard crate which will be used under the hood for tauri-plugin-clipboard for v2
Describe the bug
I am building a small emoji picker desktop app with tauri and svelte. Thanks a lot for tauri and its documentation, it was quick and pleasant to get the project up and running!
I am facing 2 issues when writing to the clipboard though, they occur in different context but seem to be related
When the user clicks on an emoji it is added to the clipboard using
clipboard.writeText(emoji)
in javascript, the window is hidden, then weinvoke()
a rust command which aims to automatically paste the copied emoji. In the rust invocation we have 2 scenarios:xdotool key ctrl+v
, the emoji is properly pasted, but the clipboard is emptied, and we get the same behavior when usingxdotool type 😅
If we try to write again the emoji to the clipboard with
app_handle.clipboard_manager().write_text(emoji).unwrap();
we actually end up with what was in the clipboard previously (which is a nice feature, but not what we expected)On an other hand triggering
xdotool
directly from the terminal does not empty the clipboard, which makes me think something could be happening on the tauri sideydotool key
, the emoji is properly pasted, and it stays in the clipboard. But if I try to add back the item that was in the clipboard before copying the emoji, this time the emoji stays...I also tried to write back the previous clipboard item through the javascript, after having
await
the invoke, but the emoji stays in the clipboard. I also tried to do all thewrite_text
andhide
window from the rust command, but still the same issuesThis happens when I just hide the window, and when I completely close the app, no changes
Reproduction
Feel free to check the code, it is quite straight to the point and has comments:
To reproduce:
If you are using linux x11 you will need to install an additional dependency for xdotool, on fedora it goes like
sudo dnf install libX11-devel libxdo-devel
Then install and run the app:
When the picker pops up click on an emoji:
xdotool key
command, then the emoji stays in the clipboard, indicatingxdotool
might play a role, at least in the x11 caseclipboard.writeText(emoji)
the previous item is copied!!! even if the previous item was not even read in the first place! (that was a funny surprise, got data I never asked for)clipboard.writeText(previous)
after runningxdotool
all of sudden at the same time we havexdotool
automatically copying the previous text to the focused window, and magically this time the clipboard is not cleared! (what a funny coincidence)clipboard.writeText(previous)
after copying the emojiSorry if it is a bit complex but those 2 errors are so connected it did not feel right to create 2 different issues yet
You can change a bit where the
clipboard.writeText()
are called to see how weird the whole clipboard behavior isExpected behavior
When we call
clipboard.writeText("😅")
(or its rust counterpart) it should add 😅 to the keyboard, instead of adding the previous clipboard item or clearing the clipboardPlatform and versions
Stack trace
No response
Additional context
I found an issue that could be related here: https://github.com/tauri-apps/tauri/issues/3666
I also tried to run the
clipboard_manager().write_text
in a separate thread (usingthread::spawn
), but the results were the sameAny idea what could cause these issues? Are they caused by the same underlying problem? Or are they 2 completely separate problems dependent on the windowing system?
Anyone ever faced this weird cleaning of the clipboard by
xdotool
only when called from tauri?I must admit it's quite puzzling, so any tips on how to better handle the clipboard are welcomed! Maybe there are things I am not aware of (different types of clipboard exists?)