diff --git a/gb.gtk3/src/main.cpp b/gb.gtk3/src/main.cpp index 81831bce4..30848feca 100644 --- a/gb.gtk3/src/main.cpp +++ b/gb.gtk3/src/main.cpp @@ -450,10 +450,23 @@ static bool global_key_event_handler(int type) static void hook_main(int *argc, char ***argv) { static bool init = false; + + char *env; if (init) return; + env = getenv("GB_GUI_PLATFORM"); + if (env && *env) + { + if (!strcasecmp(env, "X11")) + putenv((char *)"GDK_BACKEND=x11"); + else if (!strcasecmp(env, "WAYLAND")) + putenv((char *)"GDK_BACKEND=wayland"); + else + fprintf(stderr, "gb.gtk3: warning: unknown platform: %s\n", env); + } + gApplication::init(argc, argv); load_platform(); diff --git a/gb.qt5/src/main.cpp b/gb.qt5/src/main.cpp index d8e02d902..c74e35831 100644 --- a/gb.qt5/src/main.cpp +++ b/gb.qt5/src/main.cpp @@ -718,11 +718,23 @@ static void hook_main(int *argc, char ***argv) { QString platform; const char *comp; + char *env; + env = getenv("GB_GUI_PLATFORM"); + if (env && *env) + { + if (!strcasecmp(env, "X11")) + putenv((char *)"QT_QPA_PLATFORM=xcb"); + else if (!strcasecmp(env, "WAYLAND")) + putenv((char *)"QT_QPA_PLATFORM=wayland"); + else + fprintf(stderr, QT_NAME ": warning: unknown platform: %s\n", env); + } + new MyApplication(*argc, *argv); platform = qApp->platformName(); - fprintf(stderr, "platform = %s\n", TO_UTF8(platform)); + if (platform == "wayland") { comp = "gb.qt5.wayland"; diff --git a/gb.sdl2/src/main.c b/gb.sdl2/src/main.c index 70296e0ae..f22186517 100644 --- a/gb.sdl2/src/main.c +++ b/gb.sdl2/src/main.c @@ -131,6 +131,28 @@ static bool event_loop() static void my_main(int *argc, char **argv) { + char *env; + const char *driver = NULL; + + env = getenv("GB_GUI_PLATFORM"); + if (env && *env) + { + if (!strcasecmp(env, "wayland")) + driver = "SDL_VIDEODRIVER=wayland"; + else if (!strcasecmp(env, "x11")) + driver = "SDL_VIDEODRIVER=x11"; + else + fprintf(stderr, "gb.sdl2: warning: unsupported platform: %s\n", env); + } + + if (!driver) + { + if (getenv("WAYLAND_DISPLAY")) + putenv("SDL_VIDEODRIVER=wayland"); + } + else + putenv((char *)driver); + init_sdl(); CLASS_Window = GB.FindClass("Window");