Detect wayland sessions and report a clear error prompting users to switch to X11 or choose a different graphics mode

PiperOrigin-RevId: 904460146
Change-Id: I9324f403cb09787833c06f863ac157059eea60e7
This commit is contained in:
Matija Kecman
2026-04-23 08:02:05 -07:00
committed by Copybara-Service
parent 8a87a1efbf
commit 2b211e1ce6
2 changed files with 16 additions and 1 deletions
+1
View File
@@ -16,6 +16,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <span>
#include <string>
#include <string_view>
+15 -1
View File
@@ -75,7 +75,7 @@ class FileResource {
int main(int argc, char** argv, char** envp) {
absl::ParseCommandLine(argc, argv);
const char* home = getenv("HOME");
const char* home = std::getenv("HOME");
const std::string ini_path = std::string(home ? home : ".") + "/.mujoco.ini";
mjpResourceProvider resource_provider;
@@ -103,6 +103,20 @@ int main(int argc, char** argv, char** envp) {
std::string gfx = absl::GetFlag(FLAGS_gfx);
const char* session_type = std::getenv("XDG_SESSION_TYPE");
const char* wayland_display = std::getenv("WAYLAND_DISPLAY");
if ((session_type && std::string_view(session_type) == "wayland") ||
wayland_display) {
if (gfx.empty()) {
gfx = "opengl_headless";
} else if (gfx == "classic" || gfx == "opengl") {
mju_error(
"Wayland does not support '%s' graphics mode. "
"Restart with a different graphics mode, or login using X11.",
gfx.c_str());
}
}
mujoco::platform::GraphicsMode gfx_mode =
mujoco::platform::GraphicsModeFromString(
gfx, mujoco::platform::GraphicsMode::FilamentOpenGl);