Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/desktop/backends/glfw2.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ bool platformHandleEvents(void) {
}

void platformSleepUntil(uint64_t time) {
double remaining = ((int64_t)time - nowNanos()) / 1000000000.0;
double remaining = ((int64_t)time - (int64_t)nowNanos()) / 1000000000.0;
if (remaining > 0.002) // glfwSleep takes seconds as a double
glfwSleep(remaining - 0.001);

Expand Down
4 changes: 4 additions & 0 deletions src/desktop/backends/sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ bool platformHandleEvents(void) {
}
break;
case SDL_KEYDOWN:
// SDL1.2 needs to manually intercept Alt+F4 to exit properly
if (e.key.keysym.sym == SDLK_F4 && (e.key.keysym.mod & KMOD_ALT)) {
return true;
}
// During playback, suppress real keyboard input
if (InputRecording_isPlaybackActive(globalInputRecording)) break;
RunnerKeyboard_onKeyDown(g_runner->keyboard, SDLKeyToGml(e.key.keysym.sym));
Expand Down
17 changes: 7 additions & 10 deletions src/desktop/backends/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,20 @@ bool platformGetScaledWindowSize(int32_t* outW, int32_t* outH) {
return true;
}

static void platformGetWindowScale(float *scale_x, float *scale_y) {
static float platformGetWindowScale(void) {
if (!scale_x || !scale_y) return;
int32_t draw_w, draw_h;
int logical_w, logical_h;
platformGetWindowSize(&draw_w, &draw_h);
SDL_GetWindowSize(window, &logical_w, &logical_h);
*scale_x = (logical_w > 0) ? (float)draw_w / logical_w : 1.0f;
*scale_y = (logical_h > 0) ? (float)draw_h / logical_h : 1.0f;
return (logical_h > 0) ? (float)draw_h / logical_h : 1.0f;
}

void platformSetWindowSize(int32_t width, int32_t height) {
if (width <= 0 || height <= 0) return;

float scale_x, scale_y;
platformGetWindowScale(&scale_x, &scale_y);
SDL_SetWindowSize(window, (int)(width / scale_x), (int)(height / scale_y));
float scale = platformGetWindowScale();
SDL_SetWindowSize(window, (int)(width / scale), (int)(height / scale));

if (gfx == SOFTWARE)
scr = SDL_GetWindowSurface(window);
Expand All @@ -154,10 +152,9 @@ void platformGetMousePos(double *xPos, double *yPos) {
if (!xPos || !yPos) return;
int mx = 0, my = 0;
SDL_GetMouseState(&mx, &my);
float scale_x, scale_y;
platformGetWindowScale(&scale_x, &scale_y);
*xPos = (double)mx * scale_x;
*yPos = (double)my * scale_y;
float scale = platformGetWindowScale();
*xPos = (double)mx * scale;
*yPos = (double)my * scale;
}

static bool platformGetWindowFocus(void) {
Expand Down
Loading