Repository: vscode
Issue: Warning when running in vscode terminal 'xdg-open "https://..."'
Labels: bug,linux,good first issue,terminal,snap,wayland

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
Similar issue was closed at: https://github.com/microsoft/vscode/issues/213004 with no resolution.

In my case, firefox is open indirectly by `xdg-open "https://www.google.es"` (for instance). And I got the message `Error: Failed to open Wayland display, fallback to X11. WAYLAND_DISPLAY='wayland-0' DISPLAY=':0'`
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: (Yes/No) IDK

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.91.1
- OS Version: Linux x64 6.9.9-200.fc40.x86_64

- Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
- Date: 2024-07-09T22:08:12.169Z
- Electron: 29.4.0
- ElectronBuildId: 9728852
- Chromium: 122.0.6261.156
- Node.js: 20.9.0
- V8: 12.2.281.27-electron.0

Steps to Reproduce:

1. Use a wayland session.
2. Start vscode.
3. Open the terminal window inside vscode.
4. Run `xdg-open https://www.google.es`

---

I have observed the situation does not happen when I run:

```
export GDK_BACKEND=wayland
xdg-open "https://www.google.es"
```

the previous value was `GDK_BACKEND=x11`.

Maybe the environment variable `XDG_SESSION_TYPE` can be used to decide the value of `GDK_BACKEND` and set it according to the type of session.

---

I have observed from https://github.com/microsoft/vscode/blob/64b7b6d9797b4f9a2f33d1f237b16542a45536b1/resources/linux/snap/electron-launch#L139 that the value for wayland_enabled is false, after run that block (I am using vscode installed from RPM).

I got the below isolating the execution (running from a vscode terminal):

```raw
$ bash -xv test.wayland.sh 
#!/bin/bash
# From: https://github.com/microsoft/vscode/blob/64b7b6d9797b4f9a2f33d1f237b16542a45536b1/resources/linux/snap/electron-launch#L139
wayland_available=false
+ wayland_available=false
if [[ -n "$XDG_RUNTIME_DIR" && -z "$DISABLE_WAYLAND" ]]; then
    wdisplay="wayland-0"
    if [ -n "$WAYLAND_DISPLAY" ]; then
        wdisplay="$WAYLAND_DISPLAY"
    fi
    wayland_sockpath="$XDG_RUNTIME_DIR/../$wdisplay"
    wayland_snappath="$XDG_RUNTIME_DIR/$wdisplay"
    if [ -S "$wayland_sockpath" ]; then
        # if running under wayland, use it
        #export WAYLAND_DEBUG=1
        # shellcheck disable=SC2034
        wayland_available=true
        # create the compat symlink for now
        if [ ! -e "$wayland_snappath" ]; then
            ln -s "$wayland_sockpath" "$wayland_snappath"
        fi
    fi
fi
+ [[ -n /run/user/1001 ]]
+ [[ -z '' ]]
+ wdisplay=wayland-0
+ '[' -n wayland-0 ']'
+ wdisplay=wayland-0
+ wayland_sockpath=/run/user/1001/../wayland-0
+ wayland_snappath=/run/user/1001/wayland-0
+ '[' -S /run/user/1001/../wayland-0 ']'

echo "wayland_available='$wayland_available'"
+ echo 'wayland_available='\''false'\'''
wayland_available='false'
```

The path checked for `wayland_sockpath` does not exist, but it exists `wayland_snappath`.

HTH