microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
9.9k stars 296 forks source link

Ubuntu 24.04 Wayland falling back to X11 #1244

Open avlec opened 1 month ago

avlec commented 1 month ago

Windows build number:

10.0.22621.0

Your Distribution version:

24.04

Your WSL 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.22621.3296

Steps to reproduce:

  1. wsl --install Ubuntu-24.04
  2. setup account
  3. sudo apt update
  4. sudo apt install emacs-pgtk (or other GTK app)
  5. emacs

WSL logs:

stderr.log weston.log pulseaudio.log

WSL dumps:

No response

Expected behavior:

Emacs or whatever GUI application to launch using Wayland and not Xwayland

Actual behavior:

Outputs the following and falls back to xorg display frames.

MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen

image

avlec commented 1 month ago

Some more context if I try to explicitly set the GDK_BACKEND as follows I just get the following console output, no window is opened, and the program terminates.

> GDK_BACKEND=wayland emacs

(emacs:1152): Gtk-WARNING **: 09:26:41.236: cannot open display: :0
avlec commented 1 month ago

On 22.04 I do not need to use weston. I can also just use emacs without pgtk but this should be something that works

viruscamp commented 1 month ago

Due to a bug of systemd fixed in 24.04, you must do :

ln -sf  /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/

Or use an autostart conf : https://github.com/viruscamp/wslg-links

BTW, It's real that wayland working in 22.04@WSL depends a bug of systemd.

avlec commented 1 month ago

Yeah I'm not having any luck with the symlink.

This is still happening https://github.com/microsoft/wslg/issues/1244#issuecomment-2110655655

A weird quirk is that creating this symlink under your user account doesn't work (symlink is red in ls) but creating it when su'd into ubuntu the symlink creation works (symlink is blue in ls) but it still can't open the app.

zcobol commented 1 month ago

The fix provided by @viruscamp makes emacs work on wayland instead of Xwayland:

emacs-pgtk_wsl_wayland

Your ls -la $XDG_RUNTIME_DIR output should be like above.

Thanks @viruscamp!

avlec commented 1 month ago

So yeah no dice still. My XDG_RUNTIME_DIR seems to be missing things when compared to your screenshot.

In the screenshot creating those links under my user account doesn't work. Creating the links under the ubuntu user works but it still can't open the display.

image

avlec commented 1 month ago

Perhaps I'm running into this issue https://github.com/ubuntu/WSL/issues/468 because I would have just used the ubuntu username but it complains that user already exists?

How are you installing 24.04? Are you updating from an existing 22.04?

viruscamp commented 1 month ago

Perhaps I'm running into this issue ubuntu/WSL#468 because I would have just used the ubuntu username but it complains that user already exists?

How are you installing 24.04? Are you updating from an existing 22.04?

I think you met the bug.

id avlec
id ubuntu

You can see that uid=1000 is ubuntu . WSLg works only for uid=1000. That another bug of WSLg.

Ubuntu's fix only applies to new install of 24.04.

Maybe there is only unstable and insecure method:

avlec commented 1 month ago

Yes all of my attempts to use 24.04 on WSL have been fresh installs.

The fixes @viruscamp linked are working on the ubuntu user.

I'm just running into the user bug still with installing 24.04 fresh. (I removed the 24.04 app and reinstalled from winget) Is there some Windows or WSL update I have not gotten?

viruscamp commented 1 month ago

I guess the fixed wsl-setup package has not been put into the install image of ubuntu 24.04 for WSL.

We'd better wait them to publish a new image.

elsaco commented 1 month ago

@avlec you're correct, wslg already starts a compositor:

Command line: /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayland-0 --shell=rdpr
ail-shell.so --log=/mnt/wslg/weston.log --logger-scopes=log,rdp-backend,rdprail-shell

Looks like the Ubuntu-24.04 switches to cloud-init and has user id=1000 defined in the cloud.cfg:

# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
  # This will affect which distro class gets used
  distro: ubuntu
  # Default user name + that default users groups (if added/used)
  default_user:
    name: ubuntu
    lock_passwd: True
    gecos: Ubuntu
    groups: [adm, cdrom, dip, lxd, sudo]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash

and the installer is creating a user with id=1002 messing up wslg which is hardcoded to user id=1000.

If you want to fix it and use emacs-pgtk with wayland backend just edit /etc/group and /etc/passwd and switch IDs. You also have to edit the regkey and change DefaultUid from 0x3ea (1002) to 0x3e8 (1000). Look for the corresponding distro keys in \HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\. Or, wait for the store package to be fixed.

emacs-pgtk works, after applying @viruscamp fix:

emacs_pgtk_ubuntu

avlec commented 1 month ago

Yes @elsaco that's where we've gotten to. Just don't know what @zcobol did to have it working without hacking the user/groups.

Note: an easier hack is to create a 24.04 and use a throw away username and then just do the registry edit trick to change the DefaultUid then you can login as ubuntu and apply viruscamp's fix

@viruscamp is there any issue anywhere tracking the problem you fixed?

mwoodpatrick commented 1 month ago

I just did a clean install of Ubuntu 24.04 and applied viruscamp's fix and

lrwxrwxrwx 1 ubuntu ubuntu  31 May 19 06:54 wayland-0 -> /mnt/wslg/runtime-dir/wayland-0
lrwxrwxrwx 1 ubuntu ubuntu  36 May 19 06:54 wayland-0.lock -> /mnt/wslg/runtime-dir/wayland-0.lock

Linls are valid

But when I run google-chrome as the ubuntu user (id: 1000) I get:

MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen

Does anyone know why or have any suggestions on the best way to debug?

wsl --version shows:

WSL version: 2.2.2.0
Kernel version: 5.15.150.1-2
WSLg version: 1.0.61
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.22635.3640
andrekenji commented 3 weeks ago

I had a issue " Error: Can't open display: " when I tried to run applications. PS: I had already installed package x11-apps .

Resolved:

step 1: Windows 11, open Powershell with Run as Administrator, Command line: wsl --update After updated, I opened WSL ubuntu 24.04 LTS and executed command line: xeyes And GUI open in Windows.

I don't know if this will help you.