microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.75k stars 29.1k forks source link

VS Code should default to Wayland when possible #207033

Open justin13888 opened 7 months ago

justin13888 commented 7 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

Run code from terminal or open VS Code using code.desktop packaged with VS Code for Fedora repositories.

Problem:

It appears VS Code always defaults to XWayland on running on Linux Wayland desktops (at least when I tried on Fedora Workstation 39 and Ubuntu 22.04 LTS). Wayland has been the default display server on most GNU/Linux distros for the past few years, even for NVIDIA drivers. While forcing VS Code to start with Wayland with command-line arguments for example is possible, it is an extra step and the most convenient method to always start VS Code with Wayland is to append --enable-features=UseOzonePlatform --ozone-platform=wayland to your .desktop files or alias code with those arguments.

However, updating VS Code for example on Fedora may overwrite any changes to the .desktop file. There should be a way for VS Code to default to Wayland without manual user invention when Wayland is detected. Open to thoughts and comments on this suggestion and its feasibility!

Note: There may be similar issues or duplicate but I cannot find them

ryanabx commented 7 months ago

Should be noted: --enable-features=UseOzonePlatform --ozone-platform=auto would cover people who use X11 -- because it will use wayland, and if wayland isn't detected fall back to X11

justin13888 commented 7 months ago

In terms of steps needed to address this improvement, I think the most direct approach would be for VS Code to default to Ozone on Linux? Users should be able to just run code from the terminal and VS code would start in Wayland when used.

RafalSkolasinski commented 7 months ago

that would be highly appreciated, the warning is quite annoying

Warning: 'enable-features' is not in the list of known options, but still passed to Electron/Chromium.
Warning: 'ozone-platform' is not in the list of known options, but still passed to Electron/Chromium.
real-felix commented 6 months ago

Yes please, I hate the current state. There is no way to ask vscode to run with wayland by default, I have tried all of the X-flags.conf I have found online without success. Without wayland, the scaling is awful.

SethMacKayChandler commented 5 months ago

For those who use gnome shell, there is a method to update the application shortcut for code in a way that doesn't get overwritten by updates.

Since implementing this behavior as default would still allow for x11 fallback support when needed I think it is a fantastic idea to make this the default behavior.

MartyBeGood commented 5 months ago

--ozone-platform=auto wouldn't open a window for me, but the other options for it seem to be wayland and x11. code --enable-features=UseOzonePlatform --ozone-platform=$XDG_SESSION_TYPE works well over here for now.

septatrix commented 5 months ago

You may also create the following file on distros using systemd (or in ~/.profile or similar file otherwise):

# ~/.config/environment.d/30-electron-ozone-wayland.conf
ELECTRON_OZONE_PLATFORM_HINT=auto

Though for me running under wayland breaks shortcuts like Ctrl+Shift+´ (which I assume is the same issue as #127932) so that should be fixed before defaulting to wayland as I assume many people using non-US layouts will be affected by this.

Flimm commented 4 months ago

Thank you @septatrix . Setting the environment variable ELECTRON_OZONE_PLATFORM_HINT to auto worked for me. To test it out quickly, I ran:

ELECTRON_OZONE_PLATFORM_HINT=auto code
Flimm commented 4 months ago

Thank you @septatrix . Setting the environment variable ELECTRON_OZONE_PLATFORM_HINT to auto worked for me. To test it out quickly, I ran:

ELECTRON_OZONE_PLATFORM_HINT=auto code

For changes to ~/.config/environment.d/*.conf to take effect, I had to restart my computer.

po1o commented 4 months ago

I tried everything listed here, but vscode still starts under XWayland for me. Any idea what's going on? I am on Fedora 40.

opiateblush commented 4 months ago

You may also create the following file on distros using systemd (or in ~/.profile or similar file otherwise):

# ~/.config/environment.d/30-electron-ozone-wayland.conf
ELECTRON_OZONE_PLATFORM_HINT=auto

Though for me running under wayland breaks shortcuts like Ctrl+Shift+´ (which I assume is the same issue as #127932) so that should be fixed before defaulting to wayland as I assume many people using non-US layouts will be affected by this.

That works on Ubuntu 22.04, as well, thanks! Unfortunately, it also moved the close, minimize and maximize buttons to the other side of the window bar (from right to left). Is there a way to reverse this?

ptr727 commented 2 months ago

Just installed insiders on ubuntu, same issue, 4K monitor, 150% scaling (also had to fix chrome with chrome://flags/#ozone-platform-hint). What is the best method to fix this when installing using snap, or am I better off installing from DEB so I can edit startup?

justin13888 commented 2 months ago

Just installed insiders on ubuntu, same issue, 4K monitor, 150% scaling (also had to fix chrome with chrome://flags/#ozone-platform-hint). What is the best method to fix this when installing using snap, or am I better off installing from DEB so I can edit startup?

Just from personal experience, for something that you use as frequently as your code editor that runs various things on your system for dev, I prefer the actual binary (i.e. code distributed through the deb repo).

ptr727 commented 2 months ago

Just from personal experience, for something that you use as frequently as your code editor that runs various things on your system for dev, I prefer the actual binary (i.e. code distributed through the deb repo).

That's what I ended up doing, uninstall snap, install from repo, set env, only downside as others mentioned is the min/max/close buttons are now reversed to the OS.

It is a pita to have to fix wayland scaling for chrome and vscode and warp, each in a different way, for the same issue.

justin13888 commented 2 months ago

your

wait so what happened to the window decoration (the thing around the actual application window with the buttons? Are you on ubuntu desktop (since you mentioned Snaps)?

To be fair, fractional scaling on Wayland is a (basically) solved problem in Electron. But it's really something that's a problem with app devs and because desktop Linux users still make up such a small fraction in general. Also Gnome on wayland only has client-side decorations so that's another part app devs have to handle (although I don't think it's right)

ptr727 commented 2 months ago

wait so what happened to the window decoration (the thing around the actual application window with the buttons? Are you on ubuntu desktop (since you mentioned Snaps)?

When setting the env variable code changes its location of window control buttons (decorations?) to the other side compared to normal apps, this is on ubuntu desktop 24.04.

justin13888 commented 2 months ago

wait so what happened to the window decoration (the thing around the actual application window with the buttons? Are you on ubuntu desktop (since you mentioned Snaps)?

When setting the env variable code changes its location of window control buttons (decorations?) to the other side compared to normal apps, this is on ubuntu desktop 24.04.

I reread everything you wrote a few times but it isn't entirely clear what you did and what happened. But the screenshot in the issue you referenced seems to show a standard GTK decoration.

The blurriness from rendering through xwayland out of the box should be fixed as a priority though. Wondering if there's a timeline for this?

hermidalc commented 2 months ago

ELECTRON_OZONE_PLATFORM_HINT=auto code works for me on Fedora 38. Thanks for the tip

adsick commented 1 month ago

Hello, for some reason my VS Code is always using XWayland instead of native Wayland. I believe it is after some nvidia driver update/other update. I have

--enable-features=UseOzonePlatform
--ozone-platform=wayland

in /home/user/.config/code-flags.conf, but when resizing VS Code window it's not smooth and I see distinctive black strips around the edge of the window - signs of XWayland running.

justin13888 commented 1 month ago

Hello, for some reason my VS Code is always using XWayland instead of native Wayland. I believe it is after some nvidia driver update/other update. I have

--enable-features=UseOzonePlatform
--ozone-platform=wayland

in /home/user/.config/code-flags.conf, but when resizing VS Code window it's not smooth and I see distinctive black strips around the edge of the window - signs of XWayland running.

Have you confirmed the flags are actually fed into vs code on startup? I'm assuming you're on Arch with the conf path

adsick commented 1 month ago

Have you confirmed the flags are actually fed into vs code on startup? I'm assuming you're on Arch with the conf path

I'm on Fedora 40. You are right, I've tested manually passing flags to the code command and I see that it's running on Wayland now. (confirmed with xeyes test)

although I see this log:

Warning: 'enable-features' is not in the list of known options, but still passed to Electron/Chromium.

What I did is I modified the desktop file and created an alias in my .baschrc: /usr/share/applications/code.desktop

...
Exec=code --enable-features=UseOzonePlatform --ozone-platform=wayland %F
...

/home/user/.bashrc

...
alias code="code --enable-features=UseOzonePlatform --ozone-platform=wayland"
...

It really works, but does not seem totally ideal to me. Do you know any better way of configuring VSC with these flags enabled on every start?

hermidalc commented 1 month ago

Have you confirmed the flags are actually fed into vs code on startup? I'm assuming you're on Arch with the conf path

I'm on Fedora 40. You are right, I've tested manually passing flags to the code command and I see that it's running on Wayland now. (confirmed with xeyes test)

although I see this log:

Warning: 'enable-features' is not in the list of known options, but still passed to Electron/Chromium.

What I did is I modified the desktop file and created an alias in my .baschrc: /usr/share/applications/code.desktop

...
Exec=code --enable-features=UseOzonePlatform --ozone-platform=wayland %F
...

/home/user/.bashrc

...
alias code="code --enable-features=UseOzonePlatform --ozone-platform=wayland"
...

It really works, but does not seem totally ideal to me. Do you know any better way of configuring VSC with these flags enabled on every start?

No need for command line options just set the env var discussed above

Yikai-Liao commented 1 month ago

Hi, I have try all the above commands to open a vscode under wayland. But after testing using xeyes, all the opened windows are running in xwayland. I don't know what's wrong.

I am using KDE 6.1.5 (wayland) in openSUSE.

                                     ......             lyk@192
     .,cdxxxoc,.               .:kKMMMNWMMMNk:.         -------
    cKMMN0OOOKWMMXo. A        ;0MWk:'      ':OMMk.      OS: openSUSE Tumbleweed 20240920 x86_64
  ;WMK;'       'lKMMNM,     :NMK'             'OMW;     Host: 21LG (ThinkBook 16 G6+ AHP)
 cMW;             WMMMN   ,XMK'                 oMM.    Kernel: Linux 6.10.11-1-default
.MMc             ''^*~l. xMN:                    KM0    Uptime: 2 hours, 2 mins
'MM.                   .NMO                      oMM    Packages: 3566 (rpm), 3 (flatpak)
.MM,                 .kMMl                       xMN    Shell: zsh 5.9
 KM0               .kMM0' .dl>~,.               .WMd    Display (LG ULTRAFINE): 3840x2160 @ 60 Hz (as 1920x1080) in 32″ [External] *
 'XM0.           ,OMMK'    OMMM7'              .XMK     Display (BOE0AC1): 2560x1600 @ 120 Hz (as 1462x914) in 16″ [Built-in]
   *WMO:.    .;xNMMk'       NNNMKl.          .xWMx      DE: KDE Plasma 6.1.5
     ^ONMMNXMMMKx;          V  'xNMWKkxllox0NMWk'       WM: KWin (Wayland)
         '''''                    ':dOOXXKOxl'          WM Theme: Breeze
                                                        Theme: Breeze (Dark) [Qt], Breeze-Dark [GTK2], Breeze [GTK3/4]
                                                        Icons: breeze-dark [Qt], breeze-dark [GTK2/3/4]
                                                        Font: 霞鹜文楷NF (10pt) [Qt], 霞鹜文楷NF (10pt) [GTK2/3/4]
                                                        Cursor: breeze (24px)
                                                        Terminal: yakuake 24.08.1
                                                        CPU: AMD Ryzen 7 8845H w/ Radeon 780M Graphics (16) @ 3.80 GHz
                                                        GPU: AMD Phoenix3 [Integrated]
                                                        Memory: 11.90 GiB / 27.21 GiB (44%)
                                                        Swap: 25.50 MiB / 32.00 GiB (0%)
                                                        Disk (/): 142.25 GiB / 479.00 GiB (30%) - btrfs
                                                        Disk (/run/media/lyk/系统): 539.18 GiB / 1.36 TiB (39%) - fuseblk
                                                        Local IP (wlp4s0): 192.168.1.12/24
                                                        Battery (L23N4PG1): 98% [AC Connected]
                                                        Locale: zh_CN.UTF-8
$ code --version                                                  
1.93.1
38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
x64
hermidalc commented 1 month ago

Hi, I have try all the above commands to open a vscode under wayland. But after testing using xeyes, all the opened windows are running in xwayland. I don't know what's wrong.

I am using KDE 6.1.5 (wayland) in openSUSE.

                                     ......             lyk@192
     .,cdxxxoc,.               .:kKMMMNWMMMNk:.         -------
    cKMMN0OOOKWMMXo. A        ;0MWk:'      ':OMMk.      OS: openSUSE Tumbleweed 20240920 x86_64
  ;WMK;'       'lKMMNM,     :NMK'             'OMW;     Host: 21LG (ThinkBook 16 G6+ AHP)
 cMW;             WMMMN   ,XMK'                 oMM.    Kernel: Linux 6.10.11-1-default
.MMc             ''^*~l. xMN:                    KM0    Uptime: 2 hours, 2 mins
'MM.                   .NMO                      oMM    Packages: 3566 (rpm), 3 (flatpak)
.MM,                 .kMMl                       xMN    Shell: zsh 5.9
 KM0               .kMM0' .dl>~,.               .WMd    Display (LG ULTRAFINE): 3840x2160 @ 60 Hz (as 1920x1080) in 32″ [External] *
 'XM0.           ,OMMK'    OMMM7'              .XMK     Display (BOE0AC1): 2560x1600 @ 120 Hz (as 1462x914) in 16″ [Built-in]
   *WMO:.    .;xNMMk'       NNNMKl.          .xWMx      DE: KDE Plasma 6.1.5
     ^ONMMNXMMMKx;          V  'xNMWKkxllox0NMWk'       WM: KWin (Wayland)
         '''''                    ':dOOXXKOxl'          WM Theme: Breeze
                                                        Theme: Breeze (Dark) [Qt], Breeze-Dark [GTK2], Breeze [GTK3/4]
                                                        Icons: breeze-dark [Qt], breeze-dark [GTK2/3/4]
                                                        Font: 霞鹜文楷NF (10pt) [Qt], 霞鹜文楷NF (10pt) [GTK2/3/4]
                                                        Cursor: breeze (24px)
                                                        Terminal: yakuake 24.08.1
                                                        CPU: AMD Ryzen 7 8845H w/ Radeon 780M Graphics (16) @ 3.80 GHz
                                                        GPU: AMD Phoenix3 [Integrated]
                                                        Memory: 11.90 GiB / 27.21 GiB (44%)
                                                        Swap: 25.50 MiB / 32.00 GiB (0%)
                                                        Disk (/): 142.25 GiB / 479.00 GiB (30%) - btrfs
                                                        Disk (/run/media/lyk/系统): 539.18 GiB / 1.36 TiB (39%) - fuseblk
                                                        Local IP (wlp4s0): 192.168.1.12/24
                                                        Battery (L23N4PG1): 98% [AC Connected]
                                                        Locale: zh_CN.UTF-8
$ code --version                                                  
1.93.1
38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
x64

openSUSE + KDE users? Any idea? Many of us are using Fedora + GNOME and it works.

Merrit commented 1 month ago

But after testing using xeyes

FYI, on KDE you can use the KWin Debug Console to check if a window is running on Wayland native or not. Search in KRunner for KWin Debug Console

image

FWIW I am on Fedora + KDE + Wayland, and it is working here.

Yikai-Liao commented 1 month ago

FYI, on KDE you can use the KWin Debug Console to check if a window is running on Wayland native or not. Search in KRunner for KWin Debug Console

Thanks,and the following command works today. xeye also tells me that it is a wayland window. I don't quite understand the difference. But at least, I could use a native vscode now.

ELECTRON_OZONE_PLATFORM_HINT=auto code

pcf26536 commented 3 weeks ago

For those experiencing delayed start with the flag --ozone-platform=wayland on hybrid GPU, try adding --disable-gpu. I don't know what are the repercussions.

hermidalc commented 3 weeks ago

For those experiencing delayed start with the flag --ozone-platform=wayland on hybrid GPU, try adding --disable-gpu. I don't know what are the repercussions.

That means you are turning off hardware acceleration

oriolarcas commented 3 weeks ago

I am a Debian user with Wayland fractional scaling. I manually patch the code.desktop launcher with the Wayland options for Electron, but every time there is an update it is overwritten.

I got fed up, so I created this Debian package: it will monitor changes to the launcher file through a DPKG trigger, and update it automatically.

https://github.com/oriolarcas/code-wayland

Any feedback is welcome.

septatrix commented 3 weeks ago

I am a Debian user with Wayland fractional scaling. I manually patch the code.desktop launcher with the Wayland options for Electron, but every time there is an update it is overwritten.

I got fed up, so I created this Debian package: it will monitor changes to the launcher file through a DPKG trigger, and update it automatically.

Any feedback is welcome.

You could just set the environment variable as I noted above: https://github.com/microsoft/vscode/issues/207033#issuecomment-2104720712. Only difference is that the environment variable would also be applied to other electron apps. I see this as an advantage though in some cases this might be undesirable.

Otherwise, as the desktop file from vscode rarely changes, you could copy it to ~/.local/share/applications and modify it there. That copy will not be overwritten by updates to the APT package. You can use desktop-file-install --dir=$HOME/.local/share/applications /usr/share/applications/code.desktop for that (or simply copy it using cp - should be the same)

If you want to stick to your dpkg trigger and script, it would be cleaner to replace grep/sed with desktop-file-edit as that properly parses the file and validates that the result is well formed.

oriolarcas commented 3 weeks ago

Thanks for the feedback @septatrix, will have a look desktop-file-edit.

Update: Looking at desktop-file-edit, I don't think it can handle other groups than [Desktop], and code.desktop has [Desktop Action new-empty-window], so I think sed is fine.

mvavassori commented 2 weeks ago

Gnome 47 is out and vscode is still blurry, without any options in the settings to set wayland as preferred platform. If you try to hack it with the cli options it always breaks the default desktop app icon. (it adds a URL Handler and sees it as another application). Is there a fix for it?

It's just unacceptable that i am using the most popular text editor on the most popular Linux distribution (Ubuntu), that comes with the most popular desktop environment, and there's still this problem after all those years. It's not like i'm running it on some obscure system with deprecated stuff; it's the most standard software choice i could possible choose as a developer. You are a 3 trillion dollars corporation, it's not like you don't have the resources to fix basic stuff, ADD A GODDAMN OPTION TO RUN ON NATIVE WAYLAND IN THE SETTINGS. It's already there on some chromium apps like Google Chrome.

hermidalc commented 2 weeks ago

Gnome 47 is out and vscode is still blurry, without any options in the settings to set wayland as preferred platform. If you try to hack it with the cli options it always breaks the default desktop app icon. (it adds a URL Handler and sees it as another application). Is there a fix for it?

It's just unacceptable that i am using the most popular text editor on the most popular Linux distribution (Ubuntu), that comes with the most popular desktop environment, and there's still this problem after all those years. It's not like i'm running it on some obscure system with deprecated stuff; it's the most standard software choice i could possible choose as a developer. You are a 3 trillion dollars corporation, it's not like you don't have the resources to fix basic stuff, ADD A GODDAMN OPTION TO RUN ON NATIVE WAYLAND IN THE SETTINGS. It's already there on some chromium apps like Google Chrome.

I’m on (old) Fedora 38 GNOME 44 and VSCode has never been blurry in either X-Wayland or Wayland modes even since before Fedora 38. Are you using display fractional scaling could this be the cause?

mvavassori commented 2 weeks ago

@hermidalc of course i am using fractional scaling. I thought everybody here was having the problem with fractional scaling enabled.

justin13888 commented 2 weeks ago

@hermidalc of course i am using fractional scaling. I thought everybody here was having the problem with fractional scaling enabled.

Same lol. But blurry text doesn't necessarily only come from fractional scaling (e.g. 150%, 225%) while on Wayland

hermidalc commented 2 weeks ago

@hermidalc of course i am using fractional scaling. I thought everybody here was having the problem with fractional scaling enabled.

I know this isn't an all-around solution to your desktop, but at least with VSCode you don't need fractional scaling of the desktop turned on to get the IDE to size properly, using a combination of window.zoomLevel and the various fontSize settings will make it configurable to your liking.

adsick commented 2 weeks ago

No need for command line options just set the env var discussed above

The problem with that env var is that it breaks Slack for me

PlatinumLucario commented 4 days ago

The suggested edit to the .desktop file doesn't work for me (at least in the snap version). It crashes immediately upon running it with the following error that I found when I tested it with a terminal:

administrator@MS-7984:~$ /snap/bin/code --force-user-env --enable-ozone --ozone-platform=wayland %F
Warning: 'enable-ozone' is not in the list of known options, but still passed to Electron/Chromium.
administrator@MS-7984:~$ 

I've tried and tried and tried, even with just /snap/bin/code --enable-ozone --ozone-platform=wayland %F and even removing the %F, it still doesn't work... Is there a better solution? Or has Wayland support been completely disabled in VS Code?

artemudovyk commented 4 days ago

The suggested edit to the .desktop file doesn't work for me (at least in the snap version). It crashes immediately upon running it with the following error that I found when I tested it with a terminal:

administrator@MS-7984:~$ /snap/bin/code --force-user-env --enable-ozone --ozone-platform=wayland %F
Warning: 'enable-ozone' is not in the list of known options, but still passed to Electron/Chromium.
administrator@MS-7984:~$ 

I've tried and tried and tried, even with just /snap/bin/code --enable-ozone --ozone-platform=wayland %F and even removing the %F, it still doesn't work... Is there a better solution? Or has Wayland support been completely disabled in VS Code?

Did you try --enable-features=UseOzonePlatform instead of --enable-ozone?

code --enable-features=UseOzonePlatform --ozone-platform=wayland

PlatinumLucario commented 4 days ago

Did you try --enable-features=UseOzonePlatform instead of --enable-ozone?

code --enable-features=UseOzonePlatform --ozone-platform=wayland

Tried it, doesn't work...

administrator@MS-7984:~$ /snap/bin/code --enable-features=UseOzonePlatform --ozone-platform=wayland
Warning: 'enable-features' is not in the list of known options, but still passed to Electron/Chromium.
administrator@MS-7984:~$
PlatinumLucario commented 4 days ago

Also, I should note that I'm using Ubuntu 24.04 LTS as well, which uses GNOME 46 as the DE.

PlatinumLucario commented 2 days ago

I've also created a separate issue regarding VS Code no longer supporting Native Wayland, as seen here: https://github.com/microsoft/vscode/issues/231955