Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use GUI apps/tools as Wayland socket doesn't exist in XDG_RUNTIME_DIR #11261

Open
1 of 2 tasks
mangkoran opened this issue Mar 7, 2024 · 15 comments
Open
1 of 2 tasks

Comments

@mangkoran
Copy link

mangkoran commented Mar 7, 2024

Windows Version

10.0.19044.4046

WSL Version

2.0.14.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-1

Distro Version

Arch

Other Software

  • wl-clipboard 2.2.1 (shouldn't be the root cause)
  • systemd 255.4-2

Repro Steps

  1. Install wl-clipboard -> sudo pacman -S wl-clipboard
  2. Run echo "foobar" | wl-copy

Expected Behavior

foobar is copied to Windows clipboard through Wayland

Actual Behavior

❯ echo "foobar" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.

Diagnostic Logs

Not applicable

Additional Note

I couldn't open any GUI apps and any Wayland-related tools such as wl-copy.

❯ echo "foobar" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.

The following are the content of /run/user/1000/

❯ ls -la /run/user/1000/
total 0
drwx------ 7 mangkoran mangkoran 220 Mar  7 08:38 ./
drwxr-xr-x 3 root      root       60 Mar  7 08:34 ../
srw-rw-rw- 1 mangkoran mangkoran   0 Mar  7 08:34 bus=
prw------- 1 mangkoran mangkoran   0 Mar  7 08:34 fish_universal_variables.notifier|
drwx------ 2 mangkoran mangkoran  60 Mar  7 08:34 gcr/
drwx------ 2 mangkoran mangkoran 160 Mar  7 08:34 gnupg/
drwxr-xr-x 2 mangkoran mangkoran  60 Mar  7 08:34 p11-kit/
srw-rw-rw- 1 mangkoran mangkoran   0 Mar  7 08:34 pipewire-0=
srw-rw-rw- 1 mangkoran mangkoran   0 Mar  7 08:34 pipewire-0-manager=
drwxr-xr-x 2 mangkoran mangkoran  60 Mar  7 08:34 pulse/
drwxr-xr-x 6 mangkoran mangkoran 160 Mar  7 08:34 systemd/

Based on that it seems wayland-0 socket is missing in XDG_RUNTIME_DIR. Hmm pretty weird I think as I don't disable guiApplications in .wslconfig.

Then I found microsoft/wslg#1187. I proceed to check /mnt/wslg/runtime-dir/.

❯ ls -la /mnt/wslg/runtime-dir/
total 0
drwx------ 4 mangkoran mangkoran 120 Mar  7 09:24 ./
drwxrwxrwt 8 root      root      320 Mar  7 08:34 ../
drwx------ 3 mangkoran mangkoran  60 Mar  7 08:34 dbus-1/
drwx------ 2 mangkoran mangkoran  80 Mar  7 08:34 pulse/
srwxrwxrwx 1 mangkoran mangkoran   0 Mar  7 08:34 wayland-0=
-rw-rw---- 1 mangkoran mangkoran   0 Mar  7 08:34 wayland-0.lock

And yep there it is. So Wayland socket is currently not in XDG_RUNTIME_DIR. It seems the Wayland socket was previously symlinked in XDG_RUNTIME_DIR as in #10205. Then I tried to link the Wayland socket.

~
❯ ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1000/

~
❯ echo "foobar" | wl-copy

~
❯ echo $status
0

Although it works as intended, I think this isn't the default behavior/a regression.

Workaround

As a workaround, I created a simple systemd user oneshot service/unit.

❯ cat ~/.config/systemd/user/symlink-wayland-socket.service
[Unit]
Description=Symlink Wayland socket to XDG_RUNTIME_DIR

[Service]
Type=oneshot
ExecStart=/usr/bin/ln -s /mnt/wslg/runtime-dir/wayland-0      $XDG_RUNTIME_DIR
ExecStart=/usr/bin/ln -s /mnt/wslg/runtime-dir/wayland-0.lock $XDG_RUNTIME_DIR

[Install]
WantedBy=default.target

Enable it using the following command.

systemctl --user enable symlink-wayland-socket.service
@mangkoran mangkoran changed the title Cannot use GUI apps/tools as Wayland socket is in /mnt/wslg/runtime-dir instead of XDG_RUNTIME_DIR Cannot use GUI apps/tools as Wayland socket not exist in XDG_RUNTIME_DIR Mar 7, 2024
@mangkoran mangkoran changed the title Cannot use GUI apps/tools as Wayland socket not exist in XDG_RUNTIME_DIR Cannot use GUI apps/tools as Wayland socket doesn't exist in XDG_RUNTIME_DIR Mar 7, 2024
@dixonwille
Copy link

Can confirm with:

Versions

WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3155
NAME="Fedora Linux"
VERSION="39 (Container Image)"
ID=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"

Workaround

Exactly what @mangkoran mentioned by creating a oneshot systemd service.

@stefan-oskamp
Copy link

Many thanks, @mangkoran, for the details and the service script. Had the same issue with WSL 2.1.5 and Fedora 39 and the workaround fixed it.

@xuangeyouneihan
Copy link

xuangeyouneihan commented Mar 21, 2024

Here is another workaround according to this post. Create /etc/systemd/system/user-runtime-dir@.service.d/override.conf and add:

[Service]
ExecStart = sh -c "ln -fs /mnt/wslg/runtime-dir/* /run/user/"%i

This will link everything in /mnt/wslg/runtime-dir to /run/user/$UID. The reason why I don't mount /mnt/wslg/runtime-dir at /run/user/$UID like what the original post does is that it will cause user@UID.service's failure due to /run/user/$UID's incorrect owner

@king-11
Copy link

king-11 commented Apr 6, 2024

sorry for asking this novice question but @mangkoran how do we enable this service. Thanks for the help

@mangkoran
Copy link
Author

mangkoran commented Apr 6, 2024

@king-11 It should be the following.

systemctl --user enable symlink-wayland-socket.service

I will add this to my top post.

PS: A quick Google search should help you faster 😉

@gergelypolonkai
Copy link

Although this issue is about Wayland, for anyone who found this becaus X apps don’t work either (like me), if you want to use X11 apps, too, you will also have to symlink /mnt/wslg/.X11-unix/X0 to /tmp/.X11-unix/X0.

naveenkumarg-oss pushed a commit to naveenkumarg-oss/dotfiles that referenced this issue May 22, 2024
naveenkumarg-oss pushed a commit to naveenkumarg-oss/dotfiles that referenced this issue May 22, 2024
@arf1372
Copy link

arf1372 commented Jun 8, 2024

For me, X11 apps work but Wayland doesn't.

WSL info:

> wsl --version
WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3593

Ubuntu info:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04 LTS
Release:        24.04
Codename:       noble
$ uname -a
Linux *** 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

and systemd is enabled.

tried:

$ echo "hello" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.

As I fear the provided workaround may break my system(?) I didn't test it.

@mangkoran
Copy link
Author

@arf1372 You could try the symlink command first (not the systemd service) and see if solves the issue on your machine.

ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1000/

This command is harmless as it just symlinks and not removing any files. If anything goes wrong, you could restart WSL and everything will be reverted.

@Kunal-Singh-Dadhwal
Copy link

Kunal-Singh-Dadhwal commented Jul 3, 2024

For me, X11 apps work but Wayland doesn't.

WSL info:

> wsl --version
WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3593

Ubuntu info:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04 LTS
Release:        24.04
Codename:       noble
$ uname -a
Linux *** 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

and systemd is enabled.

tried:

$ echo "hello" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.

As I fear the provided workaround may break my system(?) I didn't test it.

Hey @arf1372 , could you tell how you configured X11?

@tusharsnx
Copy link

Ubuntu-24.04 set these files differently than Ubuntu-22.04:

image
image

I don't think I ever faced this issue on Ubuntu 22.04. On 24.04, I can't even run ls on /mnt/wslg/runtime-dir/ without sudo, whereas 22.04 doesn't require it all.

@noopole
Copy link

noopole commented Jul 17, 2024

I don't think I ever faced this issue on Ubuntu 22.04. On 24.04, I can't even run ls on /mnt/wslg/runtime-dir/ without sudo, whereas 22.04 doesn't require it all.

To make it work under Ubuntu 24.04 I had to set rx permissions or change owner on runtime-dir, then I could create the simlink.

sudo chmod +rx /mnt/wslg/runtime-dir (or) chown 1002:1002 /mnt/wslg/runtime-dir
ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1002/

(where 1002 is the current user.)

@alonbl
Copy link

alonbl commented Aug 23, 2024

WSLg bug: microsoft/wslg#1244

@feoh
Copy link

feoh commented Sep 6, 2024

So, this may not be a satisfying work-around for everyone, but this poblem was bowing up my Neovim session, because WAYLAND_DISPLAY was set, causing Neovim to assume that wl-copy was in play and working properly.

I added this awful bodge to my .zshrc that may help someone so I am including it here. If WSL is detected, we unset WAYLAND_DISPLAY but also add a 'wway' alias to put it back if we actually WANT to run a GUI app :)

# Under WSL, we KINDA have Wayland, but not really, and that blows up Neovim. Ungh. :)
# Add an alias so if we actually WANT the pseudo wayland, we can haz.

if [[ $(uname -r | grep "microsoft") ]] then
        unset WAYLAND_DISPLAY
        alias wway='export WAYLAND_DISPLAY=wayland-0'
fi

Yay! My neovim works again :)

@vanderzielj
Copy link

Thank you @mangkoran

This is an issue for me on Ubuntu 24.04.1 LTS running on WSL2

WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.4037

@shpankau
Copy link

shpankau commented Sep 30, 2024

So, this was also blowing up my copying while using Neovim (nvim) after my X410 trial ended:

$ echo abc | /usr/bin/wl-copy.orig
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.

My issue was not pasting into WSL, but copying from WSL and pasting into Windows, especially from nvim.

Unless you have disabled it, you should be able to run Windows binaries from within WSL 2. The workaround for clipboard access I have implemented is to wrapper Microsoft's bundled c:\Windows\system32\clip.exe binary in a script to copy:

#!/bin/bash
# the pbcopy script

tee <&0 | clip.exe
exit 0

For pasting, I opted to wrapper PowerShell and strip the extraneous appended carriage return or null:

#!/bin/bash
# the pbpaste script

powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'
exit 0

Put these scripts in /usr/bin as /usr/bin/pbcopy and /usr/bin/pbpaste. Then rename wl-copy and wl-paste and symlink the pb scripts:

$ sudo mv /usr/bin/wl-copy{,.orig}
$ sudo mv /usr/bin/wl-paste{,.orig}
$ sudo ln -s /usr/bin/pbcopy /usr/bin/wl-copy
$ sudo ln -s /usr/bin/pbpaste /usr/bin/wl-paste

If you want to test this in nvim, go into visual mode, select some text, and press <Ctrl-R>"+y to yank the selection to the system clipboard. Then try pasting it in a Windows app.

Yes, you could just name the scripts wl-copy and wl-paste, but I use symlinks to avoid confusing myself six months from now.

The other benefit of symlinking is being able to use the pbcopy and pbpaste commands like I would in macOS. 😄

NOTE: This approach assumes you only want to copy/paste text. Unlike wl-copy/paste the MIME type is stripped/ignored.

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

No branches or pull requests