From d66b8b071010dc22ace561e129435044404af9c7 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Mon, 17 Jun 2024 19:19:55 +0200 Subject: [PATCH] bugfix: Fix KMSDRM problems when switching between GUI -> emulation (fixes #1351) The emulation screen would not get the focus always, when resuming from the GUI, if running under KMSDRM. Removed the code that checked if the window had focus, and instead trying to grab it right away now. It still sometimes doesn't get it (not sure why), but at least you can click on it once and resume properly now. --- src/osdep/amiberry.cpp | 23 --------------------- src/osdep/amiberry_gfx.cpp | 38 +++++++++++++++-------------------- src/osdep/gui/main_window.cpp | 38 +++++++++++++++-------------------- 3 files changed, 32 insertions(+), 67 deletions(-) diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index 4000ad2a2..4c31494bf 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -677,29 +677,6 @@ static void setmouseactive2(struct AmigaMonitor* mon, int active, bool allowpaus } } - bool gotfocus = false; - for (int i = 0; i < MAX_AMIGAMONITORS; i++) { - SDL_Window* window = SDL_GetMouseFocus(); - if (window && (window == AMonitors[i].amiga_window)) { - mon = &AMonitors[i]; - break; - } - } - for (int i = 0; i < MAX_AMIGAMONITORS; i++) { - if (iswindowfocus(&AMonitors[i])) { - gotfocus = true; - break; - } - } - if (!gotfocus) { - write_log("Tried to capture mouse but window didn't have focus! F=%d A=%d\n", focus, mouseactive); - focus = 0; - mouseactive = 0; - active = 0; - releasecapture(mon); - recapture = 0; - } - if (mouseactive > 0) focus = mon->monitor_id + 1; diff --git a/src/osdep/amiberry_gfx.cpp b/src/osdep/amiberry_gfx.cpp index bce6e3fa4..2d88e48f4 100644 --- a/src/osdep/amiberry_gfx.cpp +++ b/src/osdep/amiberry_gfx.cpp @@ -229,45 +229,39 @@ static void SDL2_init() mon->currentmode.freq = sdl_mode.refresh_rate; } - // If KMSDRM is detected, force Full-Window mode - if (kmsdrm_detected) - { - currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen = changed_prefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen = GFX_FULLWINDOW; - currprefs.gfx_apmode[APMODE_RTG].gfx_fullscreen = changed_prefs.gfx_apmode[APMODE_RTG].gfx_fullscreen = GFX_FULLWINDOW; - } - if (!mon->amiga_window) { write_log("Creating Amiberry window...\n"); Uint32 mode; - if (sdl_mode.w >= 800 && sdl_mode.h >= 600) + if (!kmsdrm_detected) { - // Only enable Windowed mode if we're running under x11 and the resolution is at least 800x600 + // Only enable Windowed mode if we're running under x11 if (currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen == GFX_FULLWINDOW) mode = SDL_WINDOW_FULLSCREEN_DESKTOP; else if (currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen == GFX_FULLSCREEN) mode = SDL_WINDOW_FULLSCREEN; else mode = SDL_WINDOW_RESIZABLE; - if (currprefs.borderless) - mode |= SDL_WINDOW_BORDERLESS; - if (currprefs.main_alwaysontop) - mode |= SDL_WINDOW_ALWAYS_ON_TOP; - if (currprefs.start_minimized) - mode |= SDL_WINDOW_HIDDEN; - else - mode |= SDL_WINDOW_SHOWN; - // Set Window allow high DPI by default - mode |= SDL_WINDOW_ALLOW_HIGHDPI; -#ifdef USE_OPENGL - mode |= SDL_WINDOW_OPENGL; -#endif } else { // otherwise go for Full-window mode = SDL_WINDOW_FULLSCREEN_DESKTOP; } + + if (currprefs.borderless) + mode |= SDL_WINDOW_BORDERLESS; + if (currprefs.main_alwaysontop) + mode |= SDL_WINDOW_ALWAYS_ON_TOP; + if (currprefs.start_minimized) + mode |= SDL_WINDOW_HIDDEN; + else + mode |= SDL_WINDOW_SHOWN; + // Set Window allow high DPI by default + mode |= SDL_WINDOW_ALLOW_HIGHDPI; +#ifdef USE_OPENGL + mode |= SDL_WINDOW_OPENGL; +#endif if (amiberry_options.rotation_angle == 0 || amiberry_options.rotation_angle == 180) { diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index a4f8687f5..371def2db 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -285,35 +285,29 @@ void amiberry_gui_init() check_error_sdl(gui_screen == nullptr, "Unable to create GUI surface:"); } - // If KMSDRM is detected, force Full-Window mode - if (kmsdrm_detected) - { - currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen = changed_prefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen = GFX_FULLWINDOW; - currprefs.gfx_apmode[APMODE_RTG].gfx_fullscreen = changed_prefs.gfx_apmode[APMODE_RTG].gfx_fullscreen = GFX_FULLWINDOW; - } - if (!mon->gui_window) { write_log("Creating Amiberry GUI window...\n"); Uint32 mode; - if (sdl_mode.w >= 800 && sdl_mode.h >= 600 && !kmsdrm_detected) + if (!kmsdrm_detected) { - // Only enable Windowed mode if we're running under x11 and the resolution is at least 800x600 + // Only enable Windowed mode if we're running under x11 mode = SDL_WINDOW_RESIZABLE; - if (currprefs.gui_alwaysontop) - mode |= SDL_WINDOW_ALWAYS_ON_TOP; - if (currprefs.start_minimized) - mode |= SDL_WINDOW_HIDDEN; - else - mode |= SDL_WINDOW_SHOWN; - // Set Window allow high DPI by default - mode |= SDL_WINDOW_ALLOW_HIGHDPI; - } + } + else + { + // otherwise go for Full-window + mode = SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_ALWAYS_ON_TOP; + } + + if (currprefs.gui_alwaysontop) + mode |= SDL_WINDOW_ALWAYS_ON_TOP; + if (currprefs.start_minimized) + mode |= SDL_WINDOW_HIDDEN; else - { - // otherwise go for Full-window - mode = SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_ALWAYS_ON_TOP; - } + mode |= SDL_WINDOW_SHOWN; + // Set Window allow high DPI by default + mode |= SDL_WINDOW_ALLOW_HIGHDPI; if (amiberry_options.rotation_angle == 0 || amiberry_options.rotation_angle == 180) {