microsoft / vscode

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

Native wayland support with newest electron #109176

Closed toger5 closed 2 years ago

toger5 commented 4 years ago

Native wayland support would be great to run vs code without XWayland as described in https://github.com/microsoft/vscode/issues/77752.

Recently electron merged the chrome version with the ozone backend needed: https://github.com/electron/electron/pull/26022

This would allow for:

khimaros commented 3 years ago

great progress so far! launches fine in Debian Bullseye (Gnome 3.38.4). a few issues:

1) there is no window chrome (title bar) 2) navigating to File => Preferences submenu causes a crash

edit: after selecting a theme, $2 is no longer reproducible.

frandieguez commented 3 years ago

I'll edit this comment adding bugs that I found in this integration.

(Cypress:84586): Gtk-WARNING **: 12:04:18.737: cannot open display: :0


no problems whatsoever while not using the ozone flags

- [ ] No shadows under the window when using the ozone flags
![image](https://user-images.githubusercontent.com/4584/116055203-c0754b00-a67c-11eb-8ccf-7dc2d623e3ee.png)
paulcarroty commented 3 years ago

When opening a graphical app from the terminal

Wayland or X11 app?

frandieguez commented 3 years ago

When opening a graphical app from the terminal

Wayland or X11 app?

Seems to happen only when launching cypress as I've tested successfully with nautilus, chrome, firefox, spotify,...

rajveermalviya commented 3 years ago
* When opening a graphical app from the terminal it shows the follow output while using the ozone flags:

does this work?

GDK_BACKEND=x11 cypress open --browser chrome -C config/pre.json

probably vscode under wayland sets GDK_BACKEND=wayland in it's env, so any gtk apps that doesn't support wayland will fail when running from integrated terminal.

frandieguez commented 3 years ago
* When opening a graphical app from the terminal it shows the follow output while using the ozone flags:

does this work?

GDK_BACKEND=x11 cypress open --browser chrome -C config/pre.json

yes!

vially commented 3 years ago

probably vscode under wayland sets GDK_BACKEND=wayland in it's env, so any gtk apps that doesn't support wayland will fail when running from integrated terminal

This is due to a Chromium/Electron issue: https://github.com/electron/electron/issues/28436 (also https://github.com/electron/electron/issues/28793).

oscarkey commented 3 years ago

It seems like the Snap package might need to be modified to allow Wayland support? Alternatively there might be something wrong with my Snap installation, but other Snap packages work fine on Wayland.

If I install code insiders from the Snap Store I get the following error when enabling Wayland support:

~ code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland --verbose
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.
(code-insiders:840372): Gdk-WARNING **: 16:18:08.095: Wayland compositor does not support xdg_shell interface, not using Wayland display
[840372:0429/161808.095463:ERROR:browser_main_loop.cc(271)] GLib: g_hash_table_destroy: assertion 'hash_table != NULL' failed
(code-insiders:840372): Gtk-WARNING **: 16:18:08.095: cannot open display: :0

~ code-insiders -v
1.56.0-insider
0123d26aaa393bccf99f31f1eac07df6c9e218ce
x64

If I use the version from the AUR then it works fine.

a-chris commented 3 years ago

It seems like the Snap package might need to be modified to allow Wayland support? Alternatively there might be something wrong with my Snap installation, but other Snap packages work fine on Wayland.

If I install code insiders from the Snap Store I get the following error when enabling Wayland support:

~ code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland --verbose
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.

~ code-insiders -v
1.56.0-insider
0123d26aaa393bccf99f31f1eac07df6c9e218ce
x64

If I use the version from the AUR then it works fine.

EDIT: I have the same warning with the insiders version installed with .deb but the application runs successfully

davidcaste commented 3 years ago

@oscarkey, @a-chris, are you using Wayland? You can check it with the following command:

$ loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p Type | awk -F= '{print $2}'
wayland

At least in my case, it works has intended on Ubuntu 21.04:

$ lsb_release -d
Description:    Ubuntu 21.04

Using the latest code-insiders deb package:

$ dpkg -l | grep code-insiders
ii  code-insiders                              1.56.0-1619673725                                                    amd64        Code editing. Redefined.

Finally I execute it with the following parameters:

$ code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland           
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.
(...)
a-chris commented 3 years ago

@oscarkey, @a-chris, are you using Wayland? You can check it with the following command:

$ loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p Type | awk -F= '{print $2}'
wayland

At least in my case, it works has intended on Ubuntu 21.04:

$ lsb_release -d
Description:  Ubuntu 21.04

Using the latest code-insiders deb package:

$ dpkg -l | grep code-insiders
ii  code-insiders                              1.56.0-1619673725                                                    amd64        Code editing. Redefined.

Finally I execute it with the following parameters:

$ code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland           
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.
(...)

Sorry, I meant I only have the same warnings: 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.

but the application runs successfully, is this supposed to be okey?

I have the same setup as yours: Ubuntu 21.04, Wayland, VSCode Insiders

oscarkey commented 3 years ago

Hi @davidcaste I am using Sway 1.6 on Arch:

~ loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p Type | awk -F= '{print $2}'
wayland

I am using the official code-insiders Snap (version a348d103). For me the app does not launch. It just prints the error I gave in https://github.com/microsoft/vscode/issues/109176#issuecomment-829332998 and exits. Other Snaps (e.g. Firefox) work, and I have confirmed they are using Wayland by using xeyes.

paulcarroty commented 3 years ago

So this is snap-only issue, maybe worth enough to create another report.

@a-chris, parsing loginctl with double awk is kinda mad 😜, next time just use XDG_SESSION_TYPE or WAYLAND_DISPLAY.

darkbasic commented 3 years ago

Does it affect flatpak as well?

oscarkey commented 3 years ago

Does it affect flatpak as well?

Flatpak works, but only if you pass the --socket=wayland flag:

~ flatpak run com.visualstudio.code.insiders --enable-features=UseOzonePlatform --ozone-platform=wayland --verbose
...
[18:0430/235229.138987:ERROR:wayland_connection.cc(103)] Failed to connect to Wayland display
[18:0430/235229.139031:FATAL:ozone_platform_wayland.cc(170)] Failed to initialize Wayland platform

~ flatpak --socket=wayland run com.visualstudio.code.insiders --enable-features=UseOzonePlatform --ozone-platform=wayland --verbose 
[launches and works fine]

I installed this Flatpak: https://github.com/flathub/com.visualstudio.code.insiders

ghost commented 3 years ago

In Fedora 43, both code and code-insiders did not show any error but invisible with Gnome 40.

~ code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland
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.
oscarkey commented 3 years ago

@konan8205 could you try again with the --verbose flag?

rajveermalviya commented 3 years ago

In Fedora 43,

@konan8205 you mean Fedora 34 right?

anyways, both works fine for me on Fedora 34, are you using wayland?

ghost commented 3 years ago

@oscarkey log.txt

ghost commented 3 years ago

@rajveermalviya yes, Fedora 34 with NVIDIA proprietary driver and wayland session. vscode with wayland flag and nvidia proprietary driver worked on Ubuntu 21.04.

rajveermalviya commented 3 years ago

okay, it maybe a NVIDIA issue, is it any different when running chrome/chromium with ozone flags?

ghost commented 3 years ago

@rajveermalviya same

~ rpm -qa | grep nvidia
xorg-x11-drv-nvidia-kmodsrc-465.27-1.fc34.x86_64
xorg-x11-drv-nvidia-libs-465.27-1.fc34.x86_64
nvidia-settings-465.27-1.fc34.x86_64
xorg-x11-drv-nvidia-465.27-1.fc34.x86_64
akmod-nvidia-465.27-1.fc34.x86_64
kmod-nvidia-5.11.17-300.fc34.x86_64-465.27-1.fc34.x86_64
rajveermalviya commented 3 years ago

i found this at crbug, seems like nvidia is not supported with chromium+ozone+wayland.

ghost commented 3 years ago

I removed nvidia driver and now I can see the window, but it has no title bar.

lnicola commented 3 years ago

Use "window.titleBarStyle": "custom" for the title bar.

polarathene commented 3 years ago

Regarding nvidia, upcoming drivers (470 iirc) are meant to improve wayland support. As wayland is becoming a default for popular distros, nvidia is making more effort lately to address the problems on wayland their drivers have, give it some more time :)

darkbasic commented 3 years ago

give it some more time

If you don't need compute support it would probably be better to simply switch to AMD.

sbogomolov commented 3 years ago

EDIT: This bug is present when running with XWayland. When running with ozone - everything is fine.

Works mostly well on Fedora 34. The only issue I have is non-functioning drag&drop. When I try to reorder tabs or drag files/folders weird stuff happens. Like, tab stays where it was and also appears in a different windows of VS Code. When dragging files, they are not moved, but sometimes are copied to a project opened in a different VS Code window.

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 34 (Thirty Four)
Release:        34
Codename:       ThirtyFour

$ sway --version
sway version 1.6

$ code --version
1.56.0
cfa2e218100323074ac1948c885448fdf4de2a7f
x64

From code.desktop:

...
Name=Visual Studio Code
Exec=/usr/share/code/code --no-sandbox --unity-launch --enable-features=UseOzonePlatform --ozone-platform=wayland %F
...
Name=New Empty Window
Exec=/usr/share/code/code --no-sandbox --new-window --enable-features=UseOzonePlatform --ozone-platform=wayland %F
...
darkbasic commented 3 years ago

@sbogomolov did you file a bug report about the broken drag and drop support? Can you please link it? Thanks

sbogomolov commented 3 years ago

@darkbasic this is a good point. Here it is: https://github.com/microsoft/vscode/issues/123779

EDIT: This bug is present when running with XWayland. When running with ozone - everything is fine.

sbogomolov commented 3 years ago

@darkbasic Actually I have just realized that I was starting code from the terminal and did not use Walyand-native mode. So this bug is present when running with XWayland. With Wayland-native I do not see it :) I'll update that bug report.

skewty commented 3 years ago

Anyone else seeing a huge mouse pointer while inside VScode when launched in wayland / ozone mode? Looks like my mouse cursor is being scaled up. It goes back to regular size when it leaves the boundary of VScode.

Edited: added strikethrough as my problem went away

paulcarroty commented 3 years ago

@skewty provide more info about environment. Can't reproduce it on GNOME 40.

gaetanlegac commented 3 years ago

My mouse cursor is also slightly scaled up on vscode 1.57.0 Insider + ozone. I'm using Gnome 3.38.5 (wayland) on Ubuntu 21.04 with 1.5x fractional scaling on a 4k monitor.

I forgot to mention that some cursors are not affected, probably because electron/vscode do not use system theme to display theses. That's the case with the hand cursor, which is white (while my cursor theme is the default Adwaita) and smaller that others (1.5x smaller ?).

kamrandotpk commented 3 years ago

On Fedora Linux 34, with Gnome 40, at 125% scaling, when I run:

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

I no longer get the blurry screen but now the window panes are gone missing - so no window decoration around the UI. Any ideas? Thanks!

skewty commented 3 years ago

I no longer get the blurry screen but now the window panes are gone missing - so no window decoration around the UI. Any ideas? Thanks!

As Inicola mentions above.:

Use "window.titleBarStyle": "custom" for the title bar.

Just go into VScode settings and set titlebar to custom.

kamrandotpk commented 3 years ago

Thanks @skewty - it works! :)

mystiquewolf commented 3 years ago

On the other hand - in KDE with VS Code custom titlebar you get two titlebars, so you have to use the System one, no matter whether you prefer to use the custom one.

mufeedali commented 3 years ago

On the other hand - in KDE with VS Code custom titlebar you get two titlebars, so you have to use the System one, no matter whether you prefer to use the custom one.

Might be a vscode or electron bug because kwin shouldn't be drawing decorations if it was not asked for.

rohmishra commented 3 years ago

On the other hand - in KDE with VS Code custom titlebar you get two titlebars, so you have to use the System one, no matter whether you prefer to use the custom one.

Might be a vscode or electron bug because kwin shouldn't be drawing decorations if it was not asked for.

Could be Kwin. I don't get system bars with vscodd

rohmishra commented 3 years ago

@skewty would be nice if vscode followed system convention with custom styling. It would need vscode to read the config and handle it correctly though

mystiquewolf commented 3 years ago

I know it's KWin. The difference is that Kwin draws decorations. Actually i've heard Gnome is the only one that doesn't draw decorations and leaves that to the clients. I have no idea why VS Code doesn't disable the decorations from KDE when it implements client-side decorations as its "custom" titlebar.

ZanderBrown commented 3 years ago

I know it's KWin. The difference is that Kwin draws decorations. Actually i've heard Gnome is the only one that doesn't draw decorations and leaves that to the clients.

Wayland compositors shouldn't draw any borders/decorations, however it is true some (such as KWin) allow clients to opt-in to having decorations (which KDE apps do of course)

So either KWin is doing something funky or electron is (incorrectly) deciding to ask KWin to draw - either way the problem lies outside vscode

khimaros commented 3 years ago

some exciting progress on CSD in electron here https://github.com/electron/electron/pull/29618

francoism90 commented 3 years ago

Does anyone know how to fix Plasma not showing the VSCode icon but a generic Wayland-icon instead?

mystiquewolf commented 3 years ago

Does anyone know how to fix Plasma not showing the VSCode icon but a generic Wayland-icon instead?

@francoism90 https://github.com/microsoft/vscode/issues/129953

francoism90 commented 3 years ago

@mystiquewolf Thanks for linking to the bug. :)

Hope this can be fixed, it really looks out-of-place, however I can understand this may be more an Electon issue.

stalkerg commented 3 years ago

Wayland compositors shouldn't draw any borders/decorations,

just for information: Wayland supports server-side decoration by official extension. It's a valid option and most Wayland not mobile DE use it, except Gnome.

suhr commented 2 years ago

XCompose does not work in VS Code under Wayland.

Related issue for Electron: https://giters.com/electron/electron/issues/29345

MaxIhlenfeldt commented 2 years ago

(Reposting my comment from the linked issue) A fix for this has recently been merged upstream (https://crrev.com/c/3207928) and will be included in Chromium 98 (release scheduled for Feb 1, 2022).