Setting up CopyQ for use in Sway
guides
Some assembly required.
Introduction
CopyQ is a great choice of clipboard manager, however it requires some manual configuration to get working on Sway. I’d like to show you this installation process.
This post alone is enough to get CopyQ working on Sway; refer to the footnotes for further references and additional information1 that might help you to debug issues.
By the end you will be able to copy and paste as before, but with a shortcut allowing you to paste items from your clipboard history.
Prerequisites
You will need a working installation of Sway2, and I am assuming you are comfortable with modifying its configuration.
You will also need systemd and I am assuming some familiarity with it.
I am using Fedora3, but these steps should be applicable to other distros.
Setup
Install the packages copyq
4 and ydotool
5.6
ydotool
Enable the ydotool service unit by running sudo systemctl enable ydotool
. Start (activate) it by running sudo systemctl start ydotool
.7
Now we need to give unprivileged users access to the ydotool socket.
Run sudo systemctl cat ydotool
to display the unit file ydotool.service
8 and look for the line that starts the ydotool daemon ydotoold
. For me, that line is ExecStart=/usr/bin/ydotoold
and it is in the [Service]
section.
Run sudo systemctl edit ydotool
to create an override9 which invokes ydotoold
with the arguments --socket-path="/run/.ydotool_socket" --socket-own="YOUR-USER-ID:YOUR-GROUP-ID"
10, replacing YOUR-USER-ID
and YOUR-GROUP-ID
accordingly (use id --user
and id --group
to check what these are).
If you are not the only user of your system, I trust that you know what you’re doing. If your service unit file does not look like mine (perhaps due to a future ydotool update), do not make this change blindly; instead, investigate how ydotoold
is invoked and make an analogous change based on the contents of your service unit file.
For me, this override file looks like this:
[Service]
ExecStart=
ExecStart=/usr/bin/ydotoold --socket-path="/run/.ydotool_socket" --socket-own="1000:1000"
Restart the service unit with sudo systemctl restart ydotool
.11
Add export YDOTOOL_SOCKET="/run/.ydotool_socket"
to ~/.bash_profile
.
Now re-login.12
Sway
Paste the following into your Sway config file, with your preferred keyboard shortcut.
# ensure CopyQ is always floating instead of tiled
for_window [app_id="com.github.hluk.copyq"] floating enable
# start CopyQ on startup
exec copyq --start-server
# open CopyQ with the shortcut Super+C
bindsym Mod4+c exec copyq show
Now re-login.13
CopyQ
Open CopyQ (using either your keyboard shortcut or the new tray icon) and follow these steps to add this command to CopyQ.
Finishing touches
At this point, your installation of CopyQ should be working!14
Copy and paste text as before, and use the shortcut you configured above to select an item from the clipboard history. Read on if you’d like to know of a few useful options in the CopyQ preferences menu (all these are in the ‘General’ section).
I always untick ‘Close When Unfocused’ since I do not want any accidental movement across the window boundary to result in CopyQ disappearing.
I also find that ticking ‘(2) Store text selected using mouse’, ‘(3) Paste clipboard with mouse’ and ‘(4) Paste mouse selection with keyboard’15 (all under ‘Clipboard Manipulation’) is necessary to have a more or less consistent experience, such that the selection buffer (PRIMARY selection) and the clipboard are kept in sync. This allows me to use different shortcuts to copy/paste, depending on the application I’m using (which may have conflicting keybinds) or whether I am using the mouse.
Different ways to copy/paste include:
Ctrl+C
/Ctrl+V
Ctrl+Shift+C
/Ctrl+Shift+V
Ctrl+Insert
/Shift+Insert
- Copying text by selecting it with the mouse/pasting it with mouse middle click may be supported in some applications.
-
https://copyq.readthedocs.io/en/latest/faq.html#why-does-pasting-from-copyq-not-work
https://copyq.readthedocs.io/en/latest/known-issues.html#on-linux-global-shortcuts-pasting-or-clipboard-monitoring-does-not-work
https://github.com/hluk/CopyQ/issues/27
https://old.reddit.com/r/swaywm/comments/16ifbaa/i_finally_got_copyq_to_work_on_sway_with/ ↩︎ -
I am using Sway 1.9 . ↩︎
-
I am using Fedora 40. ↩︎
-
I am using CopyQ 9.0.0 . ↩︎
-
I am using ydotool 1.0.4 . ↩︎
-
Ensure we are on the same page by running
sudo systemctl status ydotool
. You should see that this service unit exists, but is inactive and disabled. ↩︎ -
Ensure we are on the same page by running
sudo systemctl status ydotool
. You should see that this service unit is both active and enabled.
Now you should be able to usesudo ydotool type hello
to make ydotool type “hello” in your terminal. However, runningydotool type hello
(withoutsudo
) should fail with an error message similar to:failed to connect socket `/run/user/1000/.ydotool_socket': No such file or directory Please check if ydotoold is running.
↩︎ -
My
ydotool.service
file looks like this:[Unit] Description=Starts ydotoold service [Service] Type=simple Restart=always ExecStart=/usr/bin/ydotoold ExecReload=/usr/bin/kill -HUP $MAINPID KillMode=process TimeoutSec=180 [Install] WantedBy=default.target
↩︎ -
https://docs.fedoraproject.org/en-US/quick-docs/systemd-understanding-and-administering/#_modifying_existing_systemd_services ↩︎
-
https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s15.html ↩︎
-
Ensure we are on the same page by running
ls -l /run/.ydotool_socket
to confirm that this file exists and is owned by your user/group. ↩︎ -
Ensure we are on the same page by running
ydotool type hello
(withoutsudo
) to confirm that this makes ydotool type “hello” in your terminal. ↩︎ -
At this point, the CopyQ icon should be in your tray. ↩︎
-
https://github.com/hluk/CopyQ/issues/1780#issuecomment-950270956 ↩︎