Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland support #200

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading