diff --git a/exegol/config/EnvInfo.py b/exegol/config/EnvInfo.py index d0eb1a17..1522e519 100644 --- a/exegol/config/EnvInfo.py +++ b/exegol/config/EnvInfo.py @@ -1,4 +1,5 @@ import json +import os import platform from enum import Enum from typing import Optional, Any, List @@ -16,6 +17,11 @@ class HostOs(Enum): WINDOWS = "Windows" LINUX = "Linux" MAC = "Mac" + + class DisplayServer(Enum): + """Dictionary class for static Display Server""" + WAYLAND = "Wayland" + X11 = "X11" class DockerEngine(Enum): """Dictionary class for static Docker engine name""" @@ -107,6 +113,18 @@ def getHostOs(cls) -> HostOs: assert cls.__docker_host_os is not None return cls.__docker_host_os + @classmethod + def getDisplayServer(cls) -> DisplayServer: + """Returns the display server + Can be 'X11' or 'Wayland'""" + if "wayland" in os.getenv("XDG_SESSION_TYPE"): + return cls.DisplayServer.WAYLAND + elif "x11" in os.getenv("XDG_SESSION_TYPE"): + return cls.DisplayServer.X11 + else: + # Should return an error + return os.getenv("XDG_SESSION_TYPE") + @classmethod def getWindowsRelease(cls) -> str: # Cache check @@ -128,6 +146,16 @@ def isMacHost(cls) -> bool: """Return true if macOS is detected on the host""" return cls.getHostOs() == cls.HostOs.MAC + @classmethod + def isX11(cls) -> bool: + """Return true if x11 is detected on the host""" + return cls.getDisplayServer() == cls.DisplayServer.X11 + + @classmethod + def isWayland(cls) -> bool: + """Return true if wayland is detected on the host""" + return cls.getDisplayServer() == cls.DisplayServer.WAYLAND + @classmethod def isDockerDesktop(cls) -> bool: """Return true if docker desktop is used on the host""" diff --git a/exegol/model/ContainerConfig.py b/exegol/model/ContainerConfig.py index 34fa1131..dfb515ec 100644 --- a/exegol/model/ContainerConfig.py +++ b/exegol/model/ContainerConfig.py @@ -1080,9 +1080,17 @@ def getShellEnvs(self) -> List[str]: result = [] # Select default shell to use result.append(f"{self.ExegolEnv.user_shell.value}={ParametersManager().shell}") - # Share X11 (GUI Display) config + # Manage the GUI if self.__enable_gui: current_display = GuiUtils.getDisplayEnv() + + # Wayland + if EnvInfo.isWayland(): + result.append(f"WAYLAND_DISPLAY={current_display}") + result.append(f"XDG_RUNTIME_DIR=/tmp") + + # Share X11 (GUI Display) config + # If the default DISPLAY environment in the container is not the same as the DISPLAY of the user's session, # the environment variable will be updated in the exegol shell. if current_display and self.__envs.get('DISPLAY', '') != current_display: diff --git a/exegol/utils/GuiUtils.py b/exegol/utils/GuiUtils.py index 62ee1f95..d3d0229f 100644 --- a/exegol/utils/GuiUtils.py +++ b/exegol/utils/GuiUtils.py @@ -61,9 +61,17 @@ def getX11SocketPath(cls) -> Optional[str]: @classmethod def getDisplayEnv(cls) -> str: """ - Get the current DISPLAY env to access X11 socket + Get the current DISPLAY environment to access the display server :return: """ + if EnvInfo.isWayland(): + # Wayland + return os.getenv('WAYLAND_DISPLAY', 'wayland-1') + + if EnvInfo.isX11(): + # X11 + return os.getenv('DISPLAY', ":0") + if EnvInfo.isMacHost(): # xquartz Mac mode return "host.docker.internal:0"