Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GetDisplayBounds returning stale data after a hotplug event? #9738

Closed
icculus opened this issue May 9, 2024 · 7 comments
Closed

SDL_GetDisplayBounds returning stale data after a hotplug event? #9738

icculus opened this issue May 9, 2024 · 7 comments
Assignees
Milestone

Comments

@icculus
Copy link
Collaborator

icculus commented May 9, 2024

As described in a PR for sdlwiki:

libsdl-org/sdlwiki#441

Can someone verify if this is happening, and if so, if it's incorrect behavior?

(This is SDL2, but verifying for SDL3 would help, too.)

@slouken slouken self-assigned this May 22, 2024
@slouken slouken added this to the 3.2.0 milestone May 22, 2024
@slouken slouken removed their assignment Oct 6, 2024
@icculus icculus self-assigned this Oct 6, 2024
@icculus icculus added the icculus-priority Things @icculus is looking at within a larger milestone. label Jan 8, 2025
@icculus
Copy link
Collaborator Author

icculus commented Jan 16, 2025

This might still be a problem in SDL2, but what he's describing seems to be that a) the primary display changed and b) Asking for information about display 0 didn't get him new primary display.

But this doesn't work this way in SDL3 any more, since you need a display ID instead of an index. SDL_GetPrimaryDisplay() tells you the display in question, not the array placement (although it happens to be first in the results of SDL_GetDisplays(), I don't believe this is documented to be officially true in SDL3).

However...I don't see anywhere where we can set a new monitor as primary in SDL3...

@icculus icculus removed the icculus-priority Things @icculus is looking at within a larger milestone. label Jan 16, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 16, 2025

However...I don't see anywhere where we can set a new monitor as primary in SDL3...

It.. um... is the first one in the list.

_this->displays[0]->id

@slouken slouken assigned slouken and unassigned icculus Jan 17, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 17, 2025

I've confirmed this bug. It's easiest to reproduce by putting the secondary monitor to the left of the primary, so when you turn the secondary monitor on and off the location of the primary monitor shifts around.

I'm working on it now.

@slouken
Copy link
Collaborator

slouken commented Jan 17, 2025

Here's the patch to testsprite that I'm using to verify this:

diff --git a/test/testsprite.c b/test/testsprite.c
index e8d8a7dcb..c49db59bc 100644
--- a/test/testsprite.c
+++ b/test/testsprite.c
@@ -556,9 +556,35 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
 
 SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
 {
+    static bool show = true;
     if (event->type == SDL_EVENT_RENDER_DEVICE_RESET) {
         LoadSprite(icon);
     }
+    switch (event->type) {
+    case SDL_EVENT_DISPLAY_ADDED:
+        SDL_Log("SDL_EVENT_DISPLAY_ADDED %d\n", event->display.displayID);
+        show = true;
+        break;
+    case SDL_EVENT_DISPLAY_REMOVED:
+        SDL_Log("SDL_EVENT_DISPLAY_REMOVED %d\n", event->display.displayID);
+        show = true;
+        break;
+    case SDL_EVENT_DISPLAY_MOVED:
+        SDL_Log("SDL_EVENT_DISPLAY_MOVED %d\n", event->display.displayID);
+        show = true;
+        break;
+    }
+    if (show) {
+        SDL_DisplayID *displays = SDL_GetDisplays(NULL);
+        int i;
+        for (i = 0; displays[i]; ++i) {
+            SDL_DisplayID d = displays[i];
+            SDL_Rect rect;
+            SDL_GetDisplayBounds(d, &rect);
+            SDL_Log("Display %d '%s': %dx%d at %d,%d\n", d, SDL_GetDisplayName(d), rect.w, rect.h, rect.x, rect.y);
+        }
+        show = false;
+    }
     return SDLTest_CommonEventMainCallbacks(state, event);
 }
 

@slouken
Copy link
Collaborator

slouken commented Jan 17, 2025

Fixed!

@slouken
Copy link
Collaborator

slouken commented Jan 17, 2025

Reopening to verify on macOS

@slouken slouken reopened this Jan 17, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 18, 2025

Confirmed working on macOS

@slouken slouken closed this as completed Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants