WPS Office uses XWayland for operation, which causes issues with copying text from applications running via Wayland (such as Chromium, Firefox, and others).
This happens due to the incompatibility of the clipboard between Wayland and XWayland.
As a result, the WPS Office application cannot access the clipboard content, leading to errors when attempting to paste text.
- Install dependencies:
- Arch Linux: sudo pacman -S xclip wl-clipboard
- Ubuntu/Debian: sudo apt-get install xclip wl-clipboard
- Create a Bash script (e.g., clipboard.sh):
#!/bin/bash
# Credits
# DiabloSat - https://github.com/progzone122
# Andrés Alberto - https://gist.github.com/andriandreo
while true; do
# Capture the current clipboard content
clipboard_content=$(wl-paste)
# Remove trailing newlines using sed
cleaned_content=$(echo "$clipboard_content" | sed ':a; /^$/{$d; N;}; /\n$/ba')
# Place the cleaned content back into the clipboard
echo -n "$cleaned_content" | xclip -selection clipboard
# Use xclip to set the clipboard content to itself (optional redundancy)
xclip -selection clipboard -o | wl-copy
# Wait for 0.5 seconds before the next iteration
sleep 0.5
done
- Make the Bash script executable:
chmod +x clipboard.sh
-
Configure the Bash script to run at system startup using any convenient method:
- For hyprland:
Edit the file hyprland.conf:
# fix buffer copy&paste between wayland and xwayland exec-once = sleep 2 && $HOME/.config/hypr/clipboard.sh # Enter your path to the script
- For i3wm:
Edit the file config:
# fix buffer copy&paste between Wayland and XWayland exec --no-startup-id $HOME/.config/i3/clipboard.sh & # Enter your path to the script
- For bspwm:
Edit the file ~/.config/bspwm/bspwmrc:
nohup $HOME/.config/bspwm/clipboard.sh & # Enter your path to the script
- For KDE:
Create file ~/.config/autostart/clipboard.desktop
[Desktop Entry] Type=Application Name=my-script GenericName=my-script Comment=My Script Exec='absolute_path_to_your_script' Terminal=false
- For Gnome:
Create file ~/.config/autostart/clipboard.desktop
[Desktop Entry] Name=my-script GenericName=my-script Comment=My Script Exec='absolute_path_to_your_script' Terminal=false Type=Application X-GNOME-Autostart-enabled=true
Also fixes VirtualBox Shared Clipboard on Wayland because it is supposed to work with the X11 clipboard only.