Added SDL_HINT_MOUSE_DPI_SCALE_CURSORS

We only want to change cursor display scale if the application or the user opts in by setting a hint. Otherwise cursors could change size unexpectedly when upgrading to SDL 3.4.0.
This commit is contained in:
Sam Lantinga
2025-12-09 16:38:43 -08:00
parent 5b572638b8
commit 466ca58b04
5 changed files with 39 additions and 8 deletions

View File

@@ -1025,6 +1025,21 @@ typedef struct Wayland_PointerObject
bool is_pointer;
} Wayland_PointerObject;
static float Wayland_GetCursorScale(SDL_WindowData *focus)
{
SDL_VideoData *viddata = SDL_GetVideoDevice()->internal;
if (!SDL_GetHintBoolean(SDL_HINT_MOUSE_DPI_SCALE_CURSORS, false)) {
return 1.0f;
}
// If viewports aren't available, the scale is always 1.0.
if (viddata->viewporter && focus) {
return (float)focus->scale_factor;
}
return 1.0f;
}
static void Wayland_CursorStateSetCursor(SDL_WaylandCursorState *state, const Wayland_PointerObject *obj, SDL_WindowData *focus, Uint32 serial, SDL_Cursor *cursor)
{
SDL_VideoData *viddata = SDL_GetVideoDevice()->internal;
@@ -1079,16 +1094,14 @@ static void Wayland_CursorStateSetCursor(SDL_WaylandCursorState *state, const Wa
return;
}
// If viewports aren't available, the scale is always 1.0.
state->scale = viddata->viewporter && focus ? focus->scale_factor : 1.0;
state->scale = Wayland_GetCursorScale(focus);
if (!Wayland_GetSystemCursor(cursor_data, state, &dst_width, &hot_x, &hot_y)) {
return;
}
dst_height = dst_width;
} else {
// If viewports aren't available, the scale is always 1.0.
state->scale = viddata->viewporter && focus ? focus->scale_factor : 1.0;
state->scale = Wayland_GetCursorScale(focus);
dst_width = cursor_data->cursor_data.custom.width;
dst_height = cursor_data->cursor_data.custom.height;
hot_x = cursor_data->cursor_data.custom.hot_x;

View File

@@ -566,9 +566,12 @@ static HCURSOR GetCachedCursor(SDL_Cursor *cursor)
{
SDL_CursorData *data = cursor->internal;
float scale = SDL_GetDisplayContentScale(SDL_GetDisplayForWindow(SDL_GetMouseFocus()));
if (scale == 0.0f) {
scale = 1.0f;
float scale = 1.0f;
if (SDL_GetHintBoolean(SDL_HINT_MOUSE_DPI_SCALE_CURSORS, false)) {
scale = SDL_GetDisplayContentScale(SDL_GetDisplayForWindow(SDL_GetMouseFocus()));
if (scale == 0.0f) {
scale = 1.0f;
}
}
for (CachedCursor *entry = data->cache; entry; entry = entry->next) {
if (scale == entry->scale) {