From 2a26a5d8b0e40a08c33ca29caf91d2c35173ef05 Mon Sep 17 00:00:00 2001 From: gambas Date: Tue, 22 Dec 2020 01:36:13 +0100 Subject: [PATCH 1/2] The 'GB_GUI_PLATFORM' environment variable allows to override the default platform. [GB.GTK3] * NEW: The 'GB_GUI_PLATFORM' environment variable allows to override the default platform. [GB.QT5] * NEW: The 'GB_GUI_PLATFORM' environment variable allows to override the default platform. --- gb.gtk3/src/main.cpp | 13 +++++++++++++ gb.qt5/src/main.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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"; From 5c3903441865db48c5b3fa8df9fb61b2bc0e3b6d Mon Sep 17 00:00:00 2001 From: gambas Date: Tue, 22 Dec 2020 01:52:01 +0100 Subject: [PATCH 2/2] Support for Wayland. [GB.SDL2] * NEW: The 'GB_GUI_PLATFORM' environement variable allows to select the platform between 'x11' or 'wayland'. * NEW: By default, the SDL2 'wayland' video driver is used if the 'WAYLAND_DISPLAY' environment variable exists. --- gb.sdl2/src/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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");