ref: 76f746d0617e324141268cbbec646414e95ef398
parent: bb752a9da7a19f43f90bde90d20d97ba07d513aa
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Mar 11 11:45:42 EDT 2024
Fixed some fullscreen mode issues
--- a/src/ft2_events.c
+++ b/src/ft2_events.c
@@ -508,6 +508,9 @@
{
mouseButtonDownHandler(event.button.button);
}
+#if defined __APPLE__ && defined __aarch64__
+ armMacGhostMouseCursorFix(&event);
+#endif
if (editor.throwExit)
editor.programRunning = false;
--- a/src/ft2_main.c
+++ b/src/ft2_main.c
@@ -135,6 +135,11 @@
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.
--- a/src/ft2_mouse.c
+++ b/src/ft2_mouse.c
@@ -31,6 +31,21 @@
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,8 +853,15 @@
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);
mouse.absX = mx;
@@ -850,14 +872,6 @@
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;
--- a/src/ft2_mouse.h
+++ b/src/ft2_mouse.h
@@ -33,6 +33,10 @@
#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);
--- a/src/ft2_sysreqs.c
+++ b/src/ft2_sysreqs.c
@@ -334,7 +334,9 @@
if (testCheckBoxMouseDown()) continue;
}
}
-
+#if defined __APPLE__ && defined __aarch64__
+ armMacGhostMouseCursorFix(&inputEvent);
+#endif
if (!ui.sysReqShown)
break;
}
@@ -572,7 +574,9 @@
if (testPushButtonMouseDown()) continue;
}
}
-
+#if defined __APPLE__ && defined __aarch64__
+ armMacGhostMouseCursorFix(&inputEvent);
+#endif
if (!ui.sysReqShown)
break;
}
--- a/src/ft2_video.c
+++ b/src/ft2_video.c
@@ -266,33 +266,26 @@
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 @@
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 @@
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 @@
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 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
@@ -1015,12 +1015,6 @@
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();
--- a/src/ft2_video.h
+++ b/src/ft2_video.h
@@ -19,7 +19,7 @@
typedef struct video_t
{
- bool fullscreen, showFPSCounter, useDesktopMouseCoords;
+ bool fullscreen, showFPSCounter;
uint32_t xScale, yScale;
uint32_t *frameBuffer, palette[PAL_NUM];
#ifdef _WIN32