Skip to content

Commit

Permalink
Merge pull request #200 from QU35T-code/wayland
Browse files Browse the repository at this point in the history
Wayland support
  • Loading branch information
Dramelac authored Jan 28, 2024
2 parents 4141901 + fc8b82b commit 6c72231
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
28 changes: 28 additions & 0 deletions exegol/config/EnvInfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import platform
from enum import Enum
from typing import Optional, Any, List
Expand All @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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"""
Expand Down
10 changes: 9 additions & 1 deletion exegol/model/ContainerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion exegol/utils/GuiUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6c72231

Please sign in to comment.