Skip to content

Commit

Permalink
bugfix: Fix KMSDRM problems when switching between GUI -> emulation (f…
Browse files Browse the repository at this point in the history
…ixes #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.
  • Loading branch information
midwan committed Jun 17, 2024
1 parent 96dd8d0 commit d66b8b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 67 deletions.
23 changes: 0 additions & 23 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 16 additions & 22 deletions src/osdep/amiberry_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
38 changes: 16 additions & 22 deletions src/osdep/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit d66b8b0

Please sign in to comment.