-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Comments
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... |
It.. um... is the first one in the list. _this->displays[0]->id |
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. |
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);
}
|
Fixed! |
Reopening to verify on macOS |
Confirmed working on macOS |
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.)
The text was updated successfully, but these errors were encountered: