ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit 76f746d0617e324141268cbbec646414e95ef398
parent bb752a9da7a19f43f90bde90d20d97ba07d513aa
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Mon, 11 Mar 2024 15:45:15 +0100

Fixed some fullscreen mode issues

Diffstat:
Msrc/ft2_events.c | 3+++
Msrc/ft2_main.c | 5+++++
Msrc/ft2_mouse.c | 32+++++++++++++++++++++++---------
Msrc/ft2_mouse.h | 4++++
Msrc/ft2_sysreqs.c | 8++++++--
Msrc/ft2_video.c | 70++++++++++++++++++++++++++++++++--------------------------------------
Msrc/ft2_video.h | 2+-
7 files changed, 74 insertions(+), 50 deletions(-)

diff --git a/src/ft2_events.c b/src/ft2_events.c @@ -508,6 +508,9 @@ static void handleSDLEvents(void) { mouseButtonDownHandler(event.button.button); } +#if defined __APPLE__ && defined __aarch64__ + armMacGhostMouseCursorFix(&event); +#endif if (editor.throwExit) editor.programRunning = false; diff --git a/src/ft2_main.c b/src/ft2_main.c @@ -135,6 +135,11 @@ int main(int argc, char *argv[]) showErrorMsgBox("Couldn't initialize SDL:\n%s", SDL_GetError()); return 1; } + + // unfinished Linux kludge for fullscreen issues, can't test this right now, so uncommenting + // if (strcmp("xwayland", SDL_GetCurrentVideoDriver()) == 0) + // SDL_VideoInit("wayland"); + SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* Text input is started by default in SDL2, turn it off to remove ~2ms spikes per key press. diff --git a/src/ft2_mouse.c b/src/ft2_mouse.c @@ -31,6 +31,21 @@ static int16_t mouseShape; static int32_t mouseModeGfxOffs, mouseBusyGfxFrame; static SDL_Cursor *cursors[NUM_CURSORS]; +#if defined __APPLE__ && defined __aarch64__ +void armMacGhostMouseCursorFix(SDL_Event *event) +{ + /* M E G A K L U D G E: + ** The mouse cursor can sometimes change back to OS stock + ** (or show both stock and custom mouse) on Macs with a notch + ** (ARM based) in fullscreen mode. Weird, right?! + ** + ** XXX: Can this cause stuttering or performance issues? + */ + if (video.fullscreen && event->type == SDL_MOUSEMOTION) + SDL_SetCursor(NULL); // forces redraw +} +#endif + static bool setSystemCursor(SDL_Cursor *cur) { if (config.specialFlags2 & USE_OS_MOUSE_POINTER) @@ -838,7 +853,14 @@ void readMouseXY(void) return; } - if (video.useDesktopMouseCoords) + if (video.fullscreen) + { + mouse.buttonState = SDL_GetMouseState(&mx, &my); + + mouse.absX = mx; + mouse.absY = my; + } + else { mouse.buttonState = SDL_GetGlobalMouseState(&mx, &my); @@ -851,14 +873,6 @@ void readMouseXY(void) mx -= windowX; my -= windowY; } - else - { - // special mode for KMSDRM (XXX: Confirm that this still works...) - mouse.buttonState = SDL_GetMouseState(&mx, &my); - - mouse.absX = mx; - mouse.absY = my; - } mouse.rawX = mx; mouse.rawY = my; diff --git a/src/ft2_mouse.h b/src/ft2_mouse.h @@ -33,6 +33,10 @@ extern mouse_t mouse; // ft2_mouse.c #define MOUSE_GLASS_ANI_FRAMES 22 #define MOUSE_CLOCK_ANI_FRAMES 5 +#if defined __APPLE__ && defined __aarch64__ +void armMacGhostMouseCursorFix(SDL_Event *event); +#endif + void freeMouseCursors(void); bool createMouseCursors(void); void setMousePosToCenter(void); diff --git a/src/ft2_sysreqs.c b/src/ft2_sysreqs.c @@ -334,7 +334,9 @@ int16_t okBox(int16_t type, const char *headline, const char *text, void (*check if (testCheckBoxMouseDown()) continue; } } - +#if defined __APPLE__ && defined __aarch64__ + armMacGhostMouseCursorFix(&inputEvent); +#endif if (!ui.sysReqShown) break; } @@ -572,7 +574,9 @@ int16_t inputBox(int16_t type, const char *headline, char *edText, uint16_t maxS if (testPushButtonMouseDown()) continue; } } - +#if defined __APPLE__ && defined __aarch64__ + armMacGhostMouseCursorFix(&inputEvent); +#endif if (!ui.sysReqShown) break; } diff --git a/src/ft2_video.c b/src/ft2_video.c @@ -266,33 +266,26 @@ void showErrorMsgBox(const char *fmt, ...) static void updateRenderSizeVars(void) { float fXScale, fYScale; + SDL_DisplayMode dm; - if (video.useDesktopMouseCoords) - { - SDL_DisplayMode dm; - int32_t di = SDL_GetWindowDisplayIndex(video.window); - if (di < 0) - di = 0; // return display index 0 (default) on error + int32_t di = SDL_GetWindowDisplayIndex(video.window); + if (di < 0) + di = 0; // return display index 0 (default) on error - SDL_GetDesktopDisplayMode(di, &dm); - video.displayW = dm.w; - video.displayH = dm.h; - } - else - { - SDL_GetWindowSize(video.window, &video.displayW, &video.displayH); - } + SDL_GetDesktopDisplayMode(di, &dm); + video.displayW = dm.w; + video.displayH = dm.h; SDL_GetWindowSize(video.window, &video.windowW, &video.windowH); + video.renderX = 0; + video.renderY = 0; if (video.fullscreen) { if (config.specialFlags2 & STRETCH_IMAGE) { - video.renderW = video.displayW; - video.renderH = video.displayH; - video.renderX = 0; - video.renderY = 0; + video.renderW = video.windowW; + video.renderH = video.windowH; } else { @@ -311,28 +304,25 @@ static void updateRenderSizeVars(void) int32_t actualScreenW, actualScreenH; SDL_GetRendererOutputSize(video.renderer, &actualScreenW, &actualScreenH); - const double dXUpscale = (const double)actualScreenW / video.displayW; - const double dYUpscale = (const double)actualScreenH / video.displayH; + const double dXUpscale = (const double)actualScreenW / video.windowW; + const double dYUpscale = (const double)actualScreenH / video.windowH; // downscale back to correct sizes if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale); if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale); - video.renderX = (video.displayW - video.renderW) / 2; - video.renderY = (video.displayH - video.renderH) / 2; + video.renderX = (video.windowW - video.renderW) / 2; + video.renderY = (video.windowH - video.renderH) / 2; } } else { SDL_GetWindowSize(video.window, &video.renderW, &video.renderH); - - video.renderX = 0; - video.renderY = 0; } // for mouse cursor creation - video.xScale = (uint32_t)round(video.renderW / (double)SCREEN_W); - video.yScale = (uint32_t)round(video.renderH / (double)SCREEN_H); + video.xScale = (uint32_t)floor(video.renderW / (double)SCREEN_W); + video.yScale = (uint32_t)floor(video.renderH / (double)SCREEN_H); createMouseCursors(); } @@ -340,6 +330,7 @@ static void updateRenderSizeVars(void) void enterFullscreen(void) { SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP); + SDL_Delay(15); // fixes possible issues if (config.specialFlags2 & STRETCH_IMAGE) { @@ -351,16 +342,22 @@ void enterFullscreen(void) SDL_GetDesktopDisplayMode(di, &dm); + SDL_RenderSetIntegerScale(video.renderer, SDL_FALSE); +#ifdef __APPLE__ + SDL_RenderSetLogicalSize(video.renderer, 640, SCREEN_H); // 640=kludge :) +#else SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h); +#endif + SDL_SetWindowSize(video.window, dm.w, dm.h); } else { + SDL_RenderSetIntegerScale(video.renderer, SDL_TRUE); SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H); + SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H); } - SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H); - -#ifndef __unix__ // can be severely buggy on Linux... (at least when used like this) +#ifndef __unix__ // Linux kludge... SDL_SetWindowGrab(video.window, SDL_TRUE); #endif @@ -372,13 +369,16 @@ void enterFullscreen(void) void leaveFullscreen(void) { SDL_SetWindowFullscreen(video.window, 0); + SDL_Delay(15); // fixes possible issues + + SDL_RenderSetIntegerScale(video.renderer, SDL_TRUE); SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H); - setWindowSizeFromConfig(false); + setWindowSizeFromConfig(false); // false = do not change actual window size, only update variables SDL_SetWindowSize(video.window, SCREEN_W * video.upscaleFactor, SCREEN_H * video.upscaleFactor); -#ifndef __unix__ +#ifndef __unix__ // revert Linux kludge... SDL_SetWindowGrab(video.window, SDL_FALSE); #endif @@ -1016,12 +1016,6 @@ bool setupRenderer(void) if (!setupSprites()) return false; - // Workaround: SDL_GetGlobalMouseState() doesn't work with KMSDRM/Wayland - video.useDesktopMouseCoords = true; - const char *videoDriver = SDL_GetCurrentVideoDriver(); - if (videoDriver != NULL && (strcmp("KMSDRM", videoDriver) == 0 || strcmp("wayland", videoDriver) == 0)) - video.useDesktopMouseCoords = false; - updateRenderSizeVars(); updateMouseScaling(); diff --git a/src/ft2_video.h b/src/ft2_video.h @@ -19,7 +19,7 @@ enum typedef struct video_t { - bool fullscreen, showFPSCounter, useDesktopMouseCoords; + bool fullscreen, showFPSCounter; uint32_t xScale, yScale; uint32_t *frameBuffer, palette[PAL_NUM]; #ifdef _WIN32