KDE Connect is a fantastic tool to integrate your cellphone with your desktop. But while it generally works well, it has a few issues in Sway.
Here's a quick overview of how to make it work correctly.
First of all, you need to start the KDE Connect daemon when the session opens. No biggie, it's just a regular config line:
exec QT_QPA_PLATFORM=xcb kdeconnectd
The KDE Connect runs silently in the background. You can tell if it's working properly by trying to list devices it sees around on the network:
$ kdeconnect-cli -l
- Fairphone4: (paired and reachable)
- lloyd@november: _24be2fd9_7c47_47de_a454_618bb6e0e016_ (reachable)
- rosco@alfa: _508af911_1c83_4b3b_af01_7e2ca78c776a_ (reachable)
3 devices found
Then you want to run the KDE Connect indicator in the system tray. You can try to run the KDE Connect-supplied indicator program from the Sway config file by adding this line after starting the daemon:
exec kdeconnect-indicator
If it works for you, great! You're done with that.
Unfortunately, I find that it doesn't play so nicely with Waybar. It works 75% of the time, but it regularly fails to show up in my system tray - as in, it runs okay, but the icon is missing, which kind of defeats the purpose.
If this happens to you too, you're in luck: a kind soul has written a simple Python replacement that works great. You can download it here:
https://github.com/juanramoncastan/xfconnect-indicator/tree/main
No need to clone the repo, you just need the Python script here and the two icons here and here.
- Copy
xfconnect-indicator.py
in/usr/local/bin
- Copy
xfconnect-icon.svg
andxfconnect-icon-disconnected.svg
in/usr/share/icons
Then replace the kdeconnect-indicator
startup line above in your Sway config file with:
exec --no-startup-id (sleep 1 && xfconnect-indicator.py) || (sleep 1 && xfconnect-indicator.py) || (sleep 1 && xfconnect-indicator.py) || (sleep 1 && xfconnect-indicator.py) || (sleep 1 && xfconnect-indicator.py)
Why this convoluted line you ask?
Because xfconnect-indicator.py
fails with an exception if the KDE Connect daemon isn't running instead of retrying to connect. This ensures Sway tries to start it 5 times with a 1 second delay when it starts, giving the KDE Connect daemon time to start on its own.
The xfconnect-indicator icon should appear in the system tray reliably, and the functionalities are identical to kdeconnect-indicator.
Finally, arguably the most useful bit of KDE Connect won't necessarily work quite right for you: the sftp plugin, aka the "Browse remote" option in the indicator, that lets you browse your cellphone's files with the file manager.
In KDE, Gnome or Cinnamon, this is usually well integrated (particularly in KDE naturally): when you click on "Browse remote", Dolphin, Nautilus or Nemo appears and you can browse your cellphone's storage.
In Sway, not so much.
Most likely, if you hit "Browse remote", your default browser will open with a funky-looking kdeconnect://<uuid>
URI that it won't know what to do with.
To fix this problem, create this shell script somewhere in your home directoy. I usually put all my scripts in ~/scripts
and I called this one nautilus_kdeconnect_browse_remote.sh
. It opens Nautilus but any file manager should work. Feel free to do your own thing instead 😃
#!/bin/bash
DIR=/run/user/$(id -u)/$(echo $1 | sed -e "s/kdeconnect:\/\///")/storage/emulated/0
nautilus --new-window $DIR
This script extracts the UUID from the kdeconnect://
URI and uses it to work out the mountpoint / sub-directory corresponding to your cellphone's internal storage, where KDEConnect has mounted the SSHFS filesystem - usually /run/user/<your userid>/<uuid>/
.
You can test it by calling it with the funky URI in your browser as argument: Nautilus should open at the right directory and you should see your cellphone's files.
Then you need to make a .desktop file for the shell script, so xdg knows what to do with it. To do this, create the file ~/.local/share/applications/nautilus_kdeconnect_browse_remote.desktop
with the following content:
[Desktop Entry]
Name=nautilus_kdeconnect_browse_remote.sh
Comment=Open Nautilus at the right location when passed a kdeconnect://<uuid> URI
Exec=/home/ppc/scripts/nautilus_kdeconnect_browse_remote.sh
Type=Application
MimeType=x-scheme-handler/kdeconnect
You can validate that the .desktop file is correct by doing:
desktop-file-validate ~/.local/share/applications/nautilus_kdeconnect_browse_remote.desktop
Finally, register your .desktop file as the default handler for the kdeconnect://
scheme by adding this to your ~/.config/mimeapps.list
(create the file if it doesn't exist):
[Default Applications]
x-scheme-handler/kdeconnect=nautilus_kdeconnect_browse_remote.desktop;
Check that it all works by trying to open the funky URI with xdg-open - which is really what KDE Connect does:
$ xdg-open kdeconnect://02bb6f9f_5907_4b00_ee73_8d439a9e6451
Nautilus should open at the correct directory now, instead of the browser:
And of course, the same should happen when you hit "Browse remote" too.