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

macOS: hotplugging a monitor marks it as removed #12016

Closed
slouken opened this issue Jan 18, 2025 · 28 comments
Closed

macOS: hotplugging a monitor marks it as removed #12016

slouken opened this issue Jan 18, 2025 · 28 comments
Milestone

Comments

@slouken
Copy link
Collaborator

slouken commented Jan 18, 2025

When I plug a second monitor into my Mac Mini M1 running macOS 15.1.1, I get an event that the display was added, then immediately removed.

The debug output shows:

2025-01-18 08:58:31.192 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:31.192 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:31.192 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:31.194 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:31.221 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:31.221 testsprite[71613:27427842]  - kCGDisplayMovedFlag
2025-01-18 08:58:31.221 testsprite[71613:27427842]  - kCGDisplaySetModeFlag
2025-01-18 08:58:31.221 testsprite[71613:27427842]  - kCGDisplayAddFlag
2025-01-18 08:58:31.221 testsprite[71613:27427842]  - kCGDisplayEnabledFlag
2025-01-18 08:58:31.221 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 08:58:31.222 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:31.222 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 08:58:31.226 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:31.226 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:31.226 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:31.226 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:31.227 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:31.227 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:31.246 testsprite[71613:27427842] SDL_EVENT_DISPLAY_ADDED 8
2025-01-18 08:58:31.246 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
2025-01-18 08:58:31.246 testsprite[71613:27427842] Display 8 '8': 1920x1080 at -1920,84
2025-01-18 08:58:31.246 testsprite[71613:27427842] SDL_EVENT_DISPLAY_MOVED 8
2025-01-18 08:58:31.246 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
2025-01-18 08:58:31.246 testsprite[71613:27427842] Display 8 '8': 1920x1080 at -1920,84
2025-01-18 08:58:33.000 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.000 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.000 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.000 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayMovedFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplaySetModeFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayAddFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayRemoveFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayEnabledFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayDisabledFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
add and remove
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.006 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.006 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 08:58:33.006 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.006 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 08:58:33.006 testsprite[71613:27427842] SDL_EVENT_DISPLAY_REMOVED 8
2025-01-18 08:58:33.006 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
2025-01-18 08:58:33.048 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.048 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.048 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:33.048 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 08:58:33.065 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 08:58:33.065 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 08:58:34.565 testsprite[71613:27427842] 1147.00 frames per second

For reference, when the display is removed, the sequence is:

2025-01-18 09:03:53.828 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 09:03:53.828 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:03:53.828 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:03:53.828 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:03:53.845 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 09:03:53.845 testsprite[71613:27427842]  - kCGDisplayRemoveFlag
2025-01-18 09:03:53.845 testsprite[71613:27427842]  - kCGDisplayDisabledFlag
2025-01-18 09:03:53.845 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:03:53.845 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:03:53.845 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:03:53.846 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:03:53.846 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:03:53.846 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1

When I connect an iPad as a second display, the sequence is:

2025-01-18 09:05:17.922 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:05:17.922 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:05:17.922 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=5
2025-01-18 09:05:17.922 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:05:17.976 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=5
2025-01-18 09:05:17.976 testsprite[71613:27427842]  - kCGDisplayMovedFlag
2025-01-18 09:05:17.976 testsprite[71613:27427842]  - kCGDisplaySetModeFlag
2025-01-18 09:05:17.976 testsprite[71613:27427842]  - kCGDisplayAddFlag
2025-01-18 09:05:17.976 testsprite[71613:27427842]  - kCGDisplayEnabledFlag
2025-01-18 09:05:17.976 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:05:17.984 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:05:17.984 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:05:18.104 testsprite[71613:27427842] SDL_EVENT_DISPLAY_ADDED 9
2025-01-18 09:05:18.105 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
2025-01-18 09:05:18.105 testsprite[71613:27427842] Display 9 '9': 1288x946 at -1288,0
2025-01-18 09:05:18.105 testsprite[71613:27427842] SDL_EVENT_DISPLAY_MOVED 9
2025-01-18 09:05:18.105 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
2025-01-18 09:05:18.105 testsprite[71613:27427842] Display 9 '9': 1288x946 at -1288,0

and when I remove it, the sequence is:

2025-01-18 09:05:59.777 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=5
2025-01-18 09:05:59.777 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:05:59.777 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:05:59.777 testsprite[71613:27427842]  - kCGDisplayBeginConfigurationFlag
2025-01-18 09:05:59.831 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=5
2025-01-18 09:05:59.831 testsprite[71613:27427842]  - kCGDisplayRemoveFlag
2025-01-18 09:05:59.831 testsprite[71613:27427842]  - kCGDisplayDisabledFlag
2025-01-18 09:05:59.831 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:05:59.831 testsprite[71613:27427842] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 09:05:59.831 testsprite[71613:27427842]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 09:05:59.834 testsprite[71613:27427842] SDL_EVENT_DISPLAY_REMOVED 9
2025-01-18 09:05:59.834 testsprite[71613:27427842] Display 1 '1': 2560x1440 at 0,0
@slouken slouken added this to the 3.2.0 milestone Jan 18, 2025
@maia-s
Copy link
Contributor

maia-s commented Jan 18, 2025

I tried it here with an usb-c connected monitor, and I got (with testsprite --info all --log all):

...
2025-01-18 18:19:28.123 testsprite[19978:19708253] SDL EVENT: Window 2 shown
2025-01-18 18:19:28.146 testsprite[19978:19708253] SDL EVENT: Window 2 exposed
2025-01-18 18:19:32.818 testsprite[19978:19708253] 75.40 frames per second
2025-01-18 18:19:37.715 testsprite[19978:19708253] SDL EVENT: Display 3 attached
2025-01-18 18:19:37.715 testsprite[19978:19708253] SDL EVENT: Display 3 removed
2025-01-18 18:19:37.822 testsprite[19978:19708253] 68.15 frames per second
2025-01-18 18:19:39.299 testsprite[19978:19708253] SDL EVENT: Window 2 moved to 463,257
2025-01-18 18:19:39.299 testsprite[19978:19708253] SDL EVENT: Display 4 attached
2025-01-18 18:19:39.299 testsprite[19978:19708253] SDL EVENT: Window 2 display changed to 4
2025-01-18 18:19:39.299 testsprite[19978:19708253] SDL EVENT: Display 4 changed position
2025-01-18 18:19:39.299 testsprite[19978:19708253] SDL EVENT: Display 1 changed position
2025-01-18 18:19:42.827 testsprite[19978:19708253] 55.56 frames per second
2025-01-18 18:19:43.413 testsprite[19978:19708253] SDL EVENT: Mouse entered window 2
2025-01-18 18:19:43.743 testsprite[19978:19708253] SDL EVENT: Window 2 gained keyboard focus
2025-01-18 18:19:43.743 testsprite[19978:19708253] SDL EVENT: Clipboard updated
2025-01-18 18:19:43.999 testsprite[19978:19708253] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-18 18:19:44.000 testsprite[19978:19708253] +[IMKInputSession subclass]: chose IMKInputSession_Modern
2025-01-18 18:19:44.625 testsprite[19978:19708253] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

ie display 3 is attached and immediately removed, then display 4 is attached after. (i only attached the monitor once)

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

@maia-s, can you enable the debug printing code in Cocoa_DisplayReconfigurationCallback() and run that again?

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

I also added this patch to testsprite, to help with debugging:

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);
 }
 

@maia-s
Copy link
Contributor

maia-s commented Jan 18, 2025

Sure thing:

2025-01-18 18:47:55.471 testsprite[21017:19734897] SDL EVENT: Window 2 shown
2025-01-18 18:47:55.582 testsprite[21017:19734897] SDL EVENT: Window 2 exposed
2025-01-18 18:48:00.171 testsprite[21017:19734897] 73.98 frames per second
2025-01-18 18:48:02.855 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:02.855 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:02.855 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:02.855 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplayMovedFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplaySetMainFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplaySetModeFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplayAddFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplayEnabledFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:02.861 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:02.862 testsprite[21017:19734897]  - kCGDisplayMovedFlag
2025-01-18 18:48:02.864 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL EVENT: Window 2 moved to 463,257
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL_EVENT_DISPLAY_ADDED 3
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL EVENT: Display 3 attached
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL EVENT: Window 2 display changed to 3
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL_EVENT_DISPLAY_MOVED 3
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL EVENT: Display 3 changed position
2025-01-18 18:48:02.868 testsprite[21017:19734897] SDL_EVENT_DISPLAY_MOVED 1
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:48:02.868 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:02.879 testsprite[21017:19734897] SDL EVENT: Display 1 changed position
2025-01-18 18:48:05.219 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:05.219 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:05.219 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:05.219 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplayRemoveFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplayDisabledFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplayMovedFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplaySetMainFlag
2025-01-18 18:48:05.279 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL EVENT: Window 2 moved to 463,270
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL EVENT: Window 2 display changed to 1
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL_EVENT_DISPLAY_REMOVED 3
2025-01-18 18:48:05.285 testsprite[21017:19734897] Display 1 '1': 1512x982 at 0,0
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL EVENT: Display 3 removed
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL_EVENT_DISPLAY_MOVED 1
2025-01-18 18:48:05.285 testsprite[21017:19734897] Display 1 '1': 1512x982 at 0,0
2025-01-18 18:48:05.285 testsprite[21017:19734897] SDL EVENT: Display 1 changed position
2025-01-18 18:48:05.286 testsprite[21017:19734897] 54.35 frames per second
2025-01-18 18:48:09.198 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:09.198 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:09.198 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:09.198 testsprite[21017:19734897]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplayMovedFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplaySetMainFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplaySetModeFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplayAddFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplayEnabledFlag
2025-01-18 18:48:09.210 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:09.211 testsprite[21017:19734897] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:48:09.211 testsprite[21017:19734897]  - kCGDisplayMovedFlag
2025-01-18 18:48:09.211 testsprite[21017:19734897]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL EVENT: Window 2 moved to 463,257
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL_EVENT_DISPLAY_ADDED 4
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL EVENT: Display 4 attached
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL EVENT: Window 2 display changed to 4
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL_EVENT_DISPLAY_MOVED 4
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL EVENT: Display 4 changed position
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL_EVENT_DISPLAY_MOVED 1
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:48:09.215 testsprite[21017:19734897] SDL EVENT: Display 1 changed position
2025-01-18 18:48:10.301 testsprite[21017:19734897] 67.00 frames per second
2025-01-18 18:48:13.068 testsprite[21017:19734897] SDL EVENT: Mouse entered window 2
2025-01-18 18:48:13.805 testsprite[21017:19734897] SDL EVENT: Window 2 gained keyboard focus
2025-01-18 18:48:13.805 testsprite[21017:19734897] SDL EVENT: Clipboard updated
2025-01-18 18:48:14.055 testsprite[21017:19734897] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-18 18:48:14.055 testsprite[21017:19734897] +[IMKInputSession subclass]: chose IMKInputSession_Modern
^[2025-01-18 18:48:15.301 testsprite[21017:19734897] 59.99 frames per second
2025-01-18 18:48:15.341 testsprite[21017:19734897] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

Before this, after I added the patches, I also had a run where everything seemed to work alright with only one attach:

...
2025-01-18 18:45:54.598 testsprite[20981:19732749] SDL EVENT: Window 2 shown
2025-01-18 18:45:54.756 testsprite[20981:19732749] SDL EVENT: Window 2 exposed
2025-01-18 18:45:59.278 testsprite[20981:19732749] 73.40 frames per second
2025-01-18 18:46:01.280 testsprite[20981:19732749] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:46:01.280 testsprite[20981:19732749]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:46:01.280 testsprite[20981:19732749] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:46:01.280 testsprite[20981:19732749]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplayMovedFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplaySetMainFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplaySetModeFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplayAddFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplayEnabledFlag
2025-01-18 18:46:01.293 testsprite[20981:19732749]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:46:01.295 testsprite[20981:19732749] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:46:01.295 testsprite[20981:19732749]  - kCGDisplayMovedFlag
2025-01-18 18:46:01.295 testsprite[20981:19732749]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL EVENT: Window 2 moved to 463,257
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL_EVENT_DISPLAY_ADDED 3
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL EVENT: Display 3 attached
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL EVENT: Window 2 display changed to 3
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL_EVENT_DISPLAY_MOVED 3
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL EVENT: Display 3 changed position
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL_EVENT_DISPLAY_MOVED 1
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 3 '3': 1920x1080 at 0,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:46:01.306 testsprite[20981:19732749] SDL EVENT: Display 1 changed position
2025-01-18 18:46:04.291 testsprite[20981:19732749] 58.46 frames per second
2025-01-18 18:46:04.492 testsprite[20981:19732749] SDL EVENT: Mouse entered window 2
2025-01-18 18:46:05.145 testsprite[20981:19732749] SDL EVENT: Mouse left window 2
2025-01-18 18:46:05.958 testsprite[20981:19732749] SDL EVENT: Mouse entered window 2
2025-01-18 18:46:06.212 testsprite[20981:19732749] SDL EVENT: Window 2 gained keyboard focus
2025-01-18 18:46:06.212 testsprite[20981:19732749] SDL EVENT: Clipboard updated
^[2025-01-18 18:46:06.462 testsprite[20981:19732749] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-18 18:46:06.463 testsprite[20981:19732749] +[IMKInputSession subclass]: chose IMKInputSession_Modern
2025-01-18 18:46:08.048 testsprite[20981:19732749] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

@maia-s
Copy link
Contributor

maia-s commented Jan 18, 2025

This one is more similar to the run in my first post with the detach happening instantly after the first attach

2025-01-18 18:54:09.104 testsprite[21066:19739082] SDL EVENT: Window 2 shown
2025-01-18 18:54:09.230 testsprite[21066:19739082] SDL EVENT: Window 2 exposed
2025-01-18 18:54:13.795 testsprite[21066:19739082] 73.93 frames per second
2025-01-18 18:54:18.803 testsprite[21066:19739082] 80.09 frames per second
2025-01-18 18:54:20.373 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:20.373 testsprite[21066:19739082]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:54:20.374 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:54:20.375 testsprite[21066:19739082]  - kCGDisplayAddFlag
2025-01-18 18:54:20.375 testsprite[21066:19739082]  - kCGDisplayEnabledFlag
2025-01-18 18:54:20.375 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:20.379 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:20.379 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:20.380 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:20.380 testsprite[21066:19739082]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:54:20.382 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:54:20.382 testsprite[21066:19739082]  - kCGDisplayRemoveFlag
2025-01-18 18:54:20.382 testsprite[21066:19739082]  - kCGDisplayDisabledFlag
2025-01-18 18:54:20.382 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:20.382 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:20.382 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:20.385 testsprite[21066:19739082] SDL_EVENT_DISPLAY_ADDED 3
2025-01-18 18:54:20.385 testsprite[21066:19739082] Display 1 '1': 1512x982 at 0,0
2025-01-18 18:54:20.385 testsprite[21066:19739082] SDL EVENT: Display 3 attached
2025-01-18 18:54:20.385 testsprite[21066:19739082] SDL_EVENT_DISPLAY_REMOVED 3
2025-01-18 18:54:20.385 testsprite[21066:19739082] Display 1 '1': 1512x982 at 0,0
2025-01-18 18:54:20.385 testsprite[21066:19739082] SDL EVENT: Display 3 removed
2025-01-18 18:54:23.808 testsprite[21066:19739082] 67.73 frames per second
2025-01-18 18:54:24.621 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:54:24.621 testsprite[21066:19739082]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:54:24.621 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:24.621 testsprite[21066:19739082]  - kCGDisplayBeginConfigurationFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplayMovedFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplaySetMainFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplaySetModeFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplayAddFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplayEnabledFlag
2025-01-18 18:54:24.640 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:24.641 testsprite[21066:19739082] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 18:54:24.641 testsprite[21066:19739082]  - kCGDisplayMovedFlag
2025-01-18 18:54:24.641 testsprite[21066:19739082]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL EVENT: Window 2 moved to 463,257
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL_EVENT_DISPLAY_ADDED 4
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL EVENT: Display 4 attached
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL EVENT: Window 2 display changed to 4
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL_EVENT_DISPLAY_MOVED 4
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL EVENT: Display 4 changed position
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL_EVENT_DISPLAY_MOVED 1
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 4 '4': 1920x1080 at 0,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] Display 1 '1': 1512x982 at -1512,0
2025-01-18 18:54:24.652 testsprite[21066:19739082] SDL EVENT: Display 1 changed position
2025-01-18 18:54:27.960 testsprite[21066:19739082] SDL EVENT: Mouse entered window 2
2025-01-18 18:54:28.384 testsprite[21066:19739082] SDL EVENT: Window 2 gained keyboard focus
2025-01-18 18:54:28.384 testsprite[21066:19739082] SDL EVENT: Clipboard updated
2025-01-18 18:54:28.630 testsprite[21066:19739082] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-18 18:54:28.630 testsprite[21066:19739082] +[IMKInputSession subclass]: chose IMKInputSession_Modern
^[2025-01-18 18:54:28.809 testsprite[21066:19739082] 53.19 frames per second
2025-01-18 18:54:29.200 testsprite[21066:19739082] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Connecting to a Roku Ultra over the network with AirPlay. First COCOA DISPLAY RECONFIG block is me clicking "disconnect" on the Roku in System Preferences. Second block is me reconnecting to it.

macbuildbot:buildbot icculus$ ./test/testsprite
2025-01-18 15:48:16.006 testsprite[4147:12544798] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 15:48:16.006 testsprite[4147:12544798] Display 2 'Roku Ultra (AirPlay)': 1920x1080 at 1920,0
2025-01-18 15:48:20.638 testsprite[4147:12544798] 117.61 frames per second
2025-01-18 15:48:25.637 testsprite[4147:12544798] 120.00 frames per second
2025-01-18 15:48:28.272 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=52
2025-01-18 15:48:28.272 testsprite[4147:12544798]  - kCGDisplayBeginConfigurationFlag
2025-01-18 15:48:28.272 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 15:48:28.272 testsprite[4147:12544798]  - kCGDisplayBeginConfigurationFlag
2025-01-18 15:48:28.286 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=52
2025-01-18 15:48:28.286 testsprite[4147:12544798]  - kCGDisplayRemoveFlag
2025-01-18 15:48:28.286 testsprite[4147:12544798]  - kCGDisplayDisabledFlag
2025-01-18 15:48:28.286 testsprite[4147:12544798]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 15:48:28.286 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 15:48:28.286 testsprite[4147:12544798]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 15:48:28.292 testsprite[4147:12544798] SDL_EVENT_DISPLAY_REMOVED 2
2025-01-18 15:48:28.292 testsprite[4147:12544798] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 15:48:30.649 testsprite[4147:12544798] 541.70 frames per second
2025-01-18 15:48:35.650 testsprite[4147:12544798] 1103.78 frames per second
2025-01-18 15:48:36.626 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 15:48:36.626 testsprite[4147:12544798]  - kCGDisplayBeginConfigurationFlag
2025-01-18 15:48:36.626 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=53
2025-01-18 15:48:36.626 testsprite[4147:12544798]  - kCGDisplayBeginConfigurationFlag
2025-01-18 15:48:36.667 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=53
2025-01-18 15:48:36.667 testsprite[4147:12544798]  - kCGDisplayMovedFlag
2025-01-18 15:48:36.667 testsprite[4147:12544798]  - kCGDisplaySetModeFlag
2025-01-18 15:48:36.667 testsprite[4147:12544798]  - kCGDisplayAddFlag
2025-01-18 15:48:36.667 testsprite[4147:12544798]  - kCGDisplayEnabledFlag
2025-01-18 15:48:36.667 testsprite[4147:12544798]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 15:48:36.674 testsprite[4147:12544798] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 15:48:36.674 testsprite[4147:12544798]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 15:48:36.729 testsprite[4147:12544798] SDL_EVENT_DISPLAY_ADDED 4
2025-01-18 15:48:36.730 testsprite[4147:12544798] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 15:48:36.730 testsprite[4147:12544798] Display 4 'Roku Ultra (AirPlay)': 1920x1080 at 1920,0
2025-01-18 15:48:36.730 testsprite[4147:12544798] SDL_EVENT_DISPLAY_MOVED 4
2025-01-18 15:48:36.730 testsprite[4147:12544798] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 15:48:36.730 testsprite[4147:12544798] Display 4 'Roku Ultra (AirPlay)': 1920x1080 at 1920,0
2025-01-18 15:48:40.653 testsprite[4147:12544798] 248.25 frames per second
2025-01-18 15:48:45.662 testsprite[4147:12544798] 133.76 frames per second

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayAddFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayRemoveFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayEnabledFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayDisabledFlag

wtf, it set all of these in one callback?

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayAddFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayRemoveFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayEnabledFlag
2025-01-18 08:58:33.004 testsprite[71613:27427842]  - kCGDisplayDisabledFlag

wtf, it set all of these in one callback?

Yep!

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

So it looks like in your case it doesn't set both, so in theory if both are set we can assume it's connected?

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Seems like the quickest fix to do that.

CGDisplayIsOnline() reports true during this callback for disconnecting devices, infuriatingly.

But, add this real fast to the callback:

    SDL_Log("DISPLAY IS ONLINE: %s", CGDisplayIsOnline(displayid) ? "true" : "false");
    SDL_Log("DISPLAY IS %dx%d", (int) CGDisplayPixelsWide(displayid), (int) CGDisplayPixelsHigh(displayid));

When I disconnect the Roku, it's still reported as online (probably changes right after this callback), but the display size becomes 0x0. It has a correct size when adding.

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

Okay, adding:

2025-01-18 13:27:54.031 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:54.031 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:54.031 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.031 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:54.031 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:54.031 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:54.031 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.031 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:54.034 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:54.034 testsprite[85899:27827661]  - kCGDisplayMovedFlag
2025-01-18 13:27:54.034 testsprite[85899:27827661]  - kCGDisplaySetModeFlag
2025-01-18 13:27:54.034 testsprite[85899:27827661]  - kCGDisplayAddFlag
2025-01-18 13:27:54.034 testsprite[85899:27827661]  - kCGDisplayEnabledFlag
2025-01-18 13:27:54.034 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:54.034 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.034 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:54.035 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:54.035 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:54.035 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:54.035 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:54.035 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:54.035 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.035 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:54.035 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:54.038 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.038 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:54.038 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:54.038 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:54.038 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:54.041 testsprite[85899:27827661] SDL_EVENT_DISPLAY_ADDED 6
2025-01-18 13:27:54.041 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0
2025-01-18 13:27:54.041 testsprite[85899:27827661] Display 6 'SMB2330HD': 1920x1080 at -1920,84
2025-01-18 13:27:54.041 testsprite[85899:27827661] SDL_EVENT_DISPLAY_MOVED 6
2025-01-18 13:27:54.041 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0
2025-01-18 13:27:54.041 testsprite[85899:27827661] Display 6 'SMB2330HD': 1920x1080 at -1920,84
2025-01-18 13:27:56.118 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.118 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.118 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.118 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.118 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.118 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.118 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.118 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.138 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayMovedFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplaySetModeFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayAddFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayRemoveFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayEnabledFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayDisabledFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.138 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.138 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.138 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:56.138 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.175 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.175 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.175 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.175 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.175 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.175 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.176 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.177 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.177 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.177 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.177 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.177 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.180 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.180 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.180 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.180 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.180 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.180 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.180 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.180 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.189 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.189 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS 1920x1080
2025-01-18 13:27:56.189 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:27:56.189 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:27:56.190 testsprite[85899:27827661] SDL_EVENT_DISPLAY_REMOVED 6
2025-01-18 13:27:56.190 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0

and then removing:

2025-01-18 13:29:07.561 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:29:07.561 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:29:07.561 testsprite[85899:27827661] DISPLAY IS ONLINE: false
2025-01-18 13:29:07.561 testsprite[85899:27827661] DISPLAY IS 1x1
2025-01-18 13:29:07.561 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:29:07.561 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:29:07.561 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:29:07.561 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:29:07.565 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=2
2025-01-18 13:29:07.565 testsprite[85899:27827661]  - kCGDisplayRemoveFlag
2025-01-18 13:29:07.565 testsprite[85899:27827661]  - kCGDisplayDisabledFlag
2025-01-18 13:29:07.565 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:29:07.565 testsprite[85899:27827661] DISPLAY IS ONLINE: false
2025-01-18 13:29:07.565 testsprite[85899:27827661] DISPLAY IS 1x1
2025-01-18 13:29:07.565 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:29:07.565 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:29:07.565 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:29:07.565 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:29:07.565 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:29:07.565 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:29:07.565 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:29:07.569 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:29:07.569 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:29:07.569 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:29:07.569 testsprite[85899:27827661] DISPLAY IS 2560x1440

Connecting my iPad:

2025-01-18 13:19:03.404 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:19:03.404 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:19:03.404 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:03.404 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:19:03.404 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=7
2025-01-18 13:19:03.404 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:19:03.404 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:03.404 testsprite[85899:27827661] DISPLAY IS 1288x946
2025-01-18 13:19:03.459 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=7
2025-01-18 13:19:03.459 testsprite[85899:27827661]  - kCGDisplayMovedFlag
2025-01-18 13:19:03.459 testsprite[85899:27827661]  - kCGDisplaySetModeFlag
2025-01-18 13:19:03.459 testsprite[85899:27827661]  - kCGDisplayAddFlag
2025-01-18 13:19:03.459 testsprite[85899:27827661]  - kCGDisplayEnabledFlag
2025-01-18 13:19:03.474 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:19:03.474 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:03.474 testsprite[85899:27827661] DISPLAY IS 1288x946
2025-01-18 13:19:03.476 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:19:03.476 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:19:03.477 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:03.477 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:19:03.484 testsprite[85899:27827661] SDL_EVENT_DISPLAY_ADDED 3
2025-01-18 13:19:03.484 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0
2025-01-18 13:19:03.484 testsprite[85899:27827661] Display 3 'Sidecar Display (AirPlay)': 1288x946 at -1288,0
2025-01-18 13:19:03.484 testsprite[85899:27827661] SDL_EVENT_DISPLAY_MOVED 3
2025-01-18 13:19:03.484 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0
2025-01-18 13:19:03.504 testsprite[85899:27827661] Display 3 'Sidecar Display (AirPlay)': 1288x946 at -1288,0

Disconnecting my iPad:

2025-01-18 13:19:41.260 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=7
2025-01-18 13:19:41.260 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:19:41.260 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:41.260 testsprite[85899:27827661] DISPLAY IS 0x0
2025-01-18 13:19:41.260 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:19:41.260 testsprite[85899:27827661]  - kCGDisplayBeginConfigurationFlag
2025-01-18 13:19:41.260 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:41.260 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:19:41.268 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=7
2025-01-18 13:19:41.268 testsprite[85899:27827661]  - kCGDisplayRemoveFlag
2025-01-18 13:19:41.268 testsprite[85899:27827661]  - kCGDisplayDisabledFlag
2025-01-18 13:19:41.268 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:19:41.268 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:41.285 testsprite[85899:27827661] DISPLAY IS 0x0
2025-01-18 13:19:41.285 testsprite[85899:27827661] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-18 13:19:41.285 testsprite[85899:27827661]  - kCGDisplayDesktopShapeChangedFlag
2025-01-18 13:19:41.285 testsprite[85899:27827661] DISPLAY IS ONLINE: true
2025-01-18 13:19:41.285 testsprite[85899:27827661] DISPLAY IS 2560x1440
2025-01-18 13:19:41.297 testsprite[85899:27827661] SDL_EVENT_DISPLAY_REMOVED 3
2025-01-18 13:19:41.298 testsprite[85899:27827661] Display 1 'DELL U3219Q': 2560x1440 at 0,0

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Screw it, let's go with the other plan and see what happens. I'm pushing a fix.

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

Potential fix:

diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index 7de75729c..9a63e779d 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -405,8 +405,13 @@ static void Cocoa_DisplayReconfigurationCallback(CGDirectDisplayID displayid, CG
     }
 
     if ((flags & kCGDisplayAddFlag) && (flags & kCGDisplayRemoveFlag)) {
-        // both adding _and_ removing? Treat it as a remove exclusively. This can happen if a display is unmirroring because it's being disabled, etc.
-        flags &= ~kCGDisplayAddFlag;
+        if (CGDisplayPixelsWide(displayid) > 1) {
+            // Final state is connected
+            flags &= ~kCGDisplayRemoveFlag;
+        } else {
+            // Final state is disconnected
+            flags &= ~kCGDisplayAddFlag;
+        }
     }
 
     if (flags & kCGDisplayAddFlag) {

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Oh, connecting a Roku when it defaults to mirrored got this, which is probably where the comment came from:

2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplayMovedFlag
2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplaySetModeFlag
2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplayAddFlag
2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplayEnabledFlag
2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplayMirrorFlag
2025-01-18 16:38:54.395 testsprite[5163:12614333]  - kCGDisplayDesktopShapeChangedFlag

AddFlag (added) and MirrorFlag (removed, because it's not a separate display anymore).

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Okay, push the patch in #12016 (comment), but please add a comment that explains why > 1 is there.

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

Actually, that would be a bug in this case. The Roku would be added as a second display since the size would be valid, right?

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Ah shoot, yes, it comes up with a real value.

-        // both adding _and_ removing? Treat it as a remove exclusively. This can happen if a display is unmirroring because it's being disabled, etc.
-        flags &= ~kCGDisplayAddFlag;
+        if (((flags & kCGDisplayMirrorFlag) == 0) && (CGDisplayPixelsWide(displayid) > 1)) {
+            // Final state is connected
+            flags &= ~kCGDisplayRemoveFlag;
+        } else {
+            // Final state is disconnected
+            flags &= ~kCGDisplayAddFlag;
+        }
     }

Hopefully this isn't going to be a massive pile of hacks by the time we're done.

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

That seems reasonable to me... push it?

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

Here was my more complicated rewrite:

diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index 7de75729c..146b08a29 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -387,29 +387,31 @@ static void Cocoa_DisplayReconfigurationCallback(CGDirectDisplayID displayid, CG
 
     SDL_VideoDevice *_this = (SDL_VideoDevice *) userInfo;
     SDL_VideoDisplay *display = Cocoa_FindSDLDisplayByCGDirectDisplayID(_this, displayid);  // will be NULL for newly-added (or newly-unmirrored) displays!
+    bool added = false;
+    bool removed = false;
 
-    if (flags & kCGDisplayDisabledFlag) {
-        flags |= kCGDisplayRemoveFlag;  // treat this like a display leaving, even though it's still plugged in.
+    if (flags & (kCGDisplayRemoveFlag | kCGDisplayDisabledFlag)) {
+        removed = true;
     }
 
-    if (flags & kCGDisplayEnabledFlag) {
-        flags |= kCGDisplayAddFlag;  // treat this like a display leaving, even though it's still plugged in.
+    if (flags & (kCGDisplayAddFlag | kCGDisplayEnabledFlag)) {
+        added = true;
     }
 
     if (flags & kCGDisplayMirrorFlag) {
-        flags |= kCGDisplayRemoveFlag;  // treat this like a display leaving, even though it's still actually here.
+        removed = true; // treat this like a display leaving, even though it's still actually here.
     }
 
     if (flags & kCGDisplayUnMirrorFlag) {
-        flags |= kCGDisplayAddFlag;  // treat this like a new display arriving, even though it was here all along.
+        added = true;  // treat this like a new display arriving, even though it was here all along.
     }
 
-    if ((flags & kCGDisplayAddFlag) && (flags & kCGDisplayRemoveFlag)) {
-        // both adding _and_ removing? Treat it as a remove exclusively. This can happen if a display is unmirroring because it's being disabled, etc.
-        flags &= ~kCGDisplayAddFlag;
+    if (added && removed) {
+        // Do we need to see if the display is valid?
+        removed = false;
     }
 
-    if (flags & kCGDisplayAddFlag) {
+    if (added) {
         if (!display) {
             if (!Cocoa_AddDisplay(displayid, true)) {
                 return;  // oh well.
@@ -419,7 +421,7 @@ static void Cocoa_DisplayReconfigurationCallback(CGDirectDisplayID displayid, CG
         }
     }
 
-    if (flags & kCGDisplayRemoveFlag) {
+    if (removed) {
         if (display) {
             SDL_DelVideoDisplay(display->id, true);
             display = NULL;

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

This doesn't work here. Every time I disconnect the Roku when mirrored and reconnect it, I get a new display with a number for a name and the dead one remains:

2025-01-18 16:56:38.788 testsprite[6021:12649233] SDL_EVENT_DISPLAY_ADDED 6
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 5 '5': 0x0 at 0,0
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 6 '6': 1920x1080 at 0,0

Let's go with the smaller patch for now.

@slouken
Copy link
Collaborator Author

slouken commented Jan 18, 2025

This doesn't work here. Every time I disconnect the Roku when mirrored and reconnect it, I get a new display with a number for a name and the dead one remains:

2025-01-18 16:56:38.788 testsprite[6021:12649233] SDL_EVENT_DISPLAY_ADDED 6
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 1 'PHL 276E8V': 1920x1080 at 0,0
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 5 '5': 0x0 at 0,0
2025-01-18 16:56:38.788 testsprite[6021:12649233] Display 6 '6': 1920x1080 at 0,0

Let's go with the smaller patch for now.

Sounds good!

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

Okay, it's in. Everyone try the latest in revision control and make sure it still works with your configuration, please!

@icculus
Copy link
Collaborator

icculus commented Jan 18, 2025

(Also, with testsprite, you don't need the patch, you can just run it with --info event on the command line.)

@maia-s
Copy link
Contributor

maia-s commented Jan 19, 2025

I still get the display removed event with the latest git

2025-01-19 01:26:00.456 testsprite[24943:19969778] SDL EVENT: Window 2 exposed
2025-01-19 01:26:00.456 testsprite[24943:19969778] SDL EVENT: Window 2 gained keyboard focus
2025-01-19 01:26:00.703 testsprite[24943:19969778] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-19 01:26:00.703 testsprite[24943:19969778] +[IMKInputSession subclass]: chose IMKInputSession_Modern
2025-01-19 01:26:05.047 testsprite[24943:19969778] 89.53 frames per second
2025-01-19 01:26:10.055 testsprite[24943:19969778] 79.87 frames per second
2025-01-19 01:26:10.892 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:10.892 testsprite[24943:19969778]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:26:10.892 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:10.892 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:10.901 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:26:10.901 testsprite[24943:19969778]  - kCGDisplayAddFlag
2025-01-19 01:26:10.901 testsprite[24943:19969778]  - kCGDisplayEnabledFlag
2025-01-19 01:26:10.901 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:10.901 testsprite[24943:19969778] DISPLAY IS ONLINE: false
2025-01-19 01:26:10.901 testsprite[24943:19969778] DISPLAY IS 1x1
2025-01-19 01:26:10.907 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:10.907 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:10.907 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:10.907 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:10.907 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:10.907 testsprite[24943:19969778]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:26:10.907 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:10.908 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:10.911 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:26:10.911 testsprite[24943:19969778]  - kCGDisplayRemoveFlag
2025-01-19 01:26:10.911 testsprite[24943:19969778]  - kCGDisplayDisabledFlag
2025-01-19 01:26:10.911 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:10.911 testsprite[24943:19969778] DISPLAY IS ONLINE: false
2025-01-19 01:26:10.911 testsprite[24943:19969778] DISPLAY IS 1x1
2025-01-19 01:26:10.912 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:10.912 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:10.912 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:10.913 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:10.914 testsprite[24943:19969778] SDL_EVENT_DISPLAY_ADDED 3
2025-01-19 01:26:10.914 testsprite[24943:19969778] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:26:10.914 testsprite[24943:19969778] SDL EVENT: Display 3 attached
2025-01-19 01:26:10.914 testsprite[24943:19969778] SDL_EVENT_DISPLAY_REMOVED 3
2025-01-19 01:26:10.914 testsprite[24943:19969778] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:26:10.914 testsprite[24943:19969778] SDL EVENT: Display 3 removed
2025-01-19 01:26:12.351 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:26:12.351 testsprite[24943:19969778]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:26:12.351 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:12.351 testsprite[24943:19969778] DISPLAY IS 1920x1080
2025-01-19 01:26:12.351 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:12.351 testsprite[24943:19969778]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:26:12.351 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:12.351 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:12.373 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayMovedFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplaySetMainFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplaySetModeFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayAddFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayEnabledFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:12.373 testsprite[24943:19969778] DISPLAY IS 1920x1080
2025-01-19 01:26:12.373 testsprite[24943:19969778] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayMovedFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:26:12.373 testsprite[24943:19969778] DISPLAY IS ONLINE: true
2025-01-19 01:26:12.375 testsprite[24943:19969778] DISPLAY IS 1512x982
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL EVENT: Window 2 moved to 466,257
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL_EVENT_DISPLAY_ADDED 4
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL EVENT: Display 4 attached
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL EVENT: Window 2 display changed to 4
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL_EVENT_DISPLAY_MOVED 4
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL EVENT: Display 4 changed position
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:26:12.393 testsprite[24943:19969778] SDL EVENT: Display 1 changed position
2025-01-19 01:26:15.057 testsprite[24943:19969778] 47.38 frames per second
2025-01-19 01:26:16.328 testsprite[24943:19969778] SDL EVENT: Mouse entered window 2
2025-01-19 01:26:16.641 testsprite[24943:19969778] SDL EVENT: Mouse: button 1 pressed at 68.2695,276.145 with click count 1 in window 2
2025-01-19 01:26:16.757 testsprite[24943:19969778] SDL EVENT: Mouse: button 1 released at 68.2695,276.402 with click count 1 in window 2
2025-01-19 01:26:16.965 testsprite[24943:19969778] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

@maia-s
Copy link
Contributor

maia-s commented Jan 19, 2025

but not always (this is with just --info event)

2025-01-19 01:31:08.314 testsprite[24979:19974490] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:31:08.314 testsprite[24979:19974490] SDL EVENT: Window 2 changed pixel size to 640x480
2025-01-19 01:31:08.314 testsprite[24979:19974490] SDL EVENT: Window 2 shown
2025-01-19 01:31:08.448 testsprite[24979:19974490] SDL EVENT: Window 2 exposed
2025-01-19 01:31:12.991 testsprite[24979:19974490] 90.95 frames per second
2025-01-19 01:31:16.901 testsprite[24979:19974490] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:31:16.901 testsprite[24979:19974490]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:31:16.901 testsprite[24979:19974490] DISPLAY IS ONLINE: true
2025-01-19 01:31:16.901 testsprite[24979:19974490] DISPLAY IS 1920x1080
2025-01-19 01:31:16.901 testsprite[24979:19974490] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:31:16.901 testsprite[24979:19974490]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:31:16.901 testsprite[24979:19974490] DISPLAY IS ONLINE: true
2025-01-19 01:31:16.901 testsprite[24979:19974490] DISPLAY IS 1512x982
2025-01-19 01:31:16.910 testsprite[24979:19974490] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayMovedFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplaySetMainFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplaySetModeFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayAddFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayEnabledFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490] DISPLAY IS ONLINE: true
2025-01-19 01:31:16.910 testsprite[24979:19974490] DISPLAY IS 1920x1080
2025-01-19 01:31:16.910 testsprite[24979:19974490] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayMovedFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:31:16.910 testsprite[24979:19974490] DISPLAY IS ONLINE: true
2025-01-19 01:31:16.912 testsprite[24979:19974490] DISPLAY IS 1512x982
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL EVENT: Window 2 moved to 466,257
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL_EVENT_DISPLAY_ADDED 3
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 3 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL EVENT: Display 3 attached
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL EVENT: Window 2 display changed to 3
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL_EVENT_DISPLAY_MOVED 3
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 3 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL EVENT: Display 3 changed position
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 3 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:31:16.917 testsprite[24979:19974490] SDL EVENT: Display 1 changed position
2025-01-19 01:31:17.994 testsprite[24979:19974490] 65.96 frames per second
2025-01-19 01:31:21.329 testsprite[24979:19974490] SDL EVENT: Mouse entered window 2
2025-01-19 01:31:21.663 testsprite[24979:19974490] SDL EVENT: Window 2 gained keyboard focus
2025-01-19 01:31:21.663 testsprite[24979:19974490] SDL EVENT: Clipboard updated
2025-01-19 01:31:21.915 testsprite[24979:19974490] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-19 01:31:21.915 testsprite[24979:19974490] +[IMKInputSession subclass]: chose IMKInputSession_Modern
^[2025-01-19 01:31:22.750 testsprite[24979:19974490] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

@maia-s
Copy link
Contributor

maia-s commented Jan 19, 2025

It does seem a lot more rare now. I've run it 10 times in a row (detach monitor and wait for that to finish, run testsprite, attach monitor, exit testsprite), and it only got the detach event the first time

@maia-s
Copy link
Contributor

maia-s commented Jan 19, 2025

It happened again after I attached and detached the monitor while testsprite was running. I let it rest a few seconds after each detach seemed complete so I don't think it's a delayed event. It did work a few times before it happened again

Final detach before bug:

2025-01-19 01:41:01.895 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:01.895 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:01.895 testsprite[25124:19986960] DISPLAY IS ONLINE: false
2025-01-19 01:41:01.895 testsprite[25124:19986960] DISPLAY IS 1x1
2025-01-19 01:41:01.895 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:01.895 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:01.895 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:01.895 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:01.984 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplayRemoveFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplayDisabledFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960] DISPLAY IS ONLINE: false
2025-01-19 01:41:01.984 testsprite[25124:19986960] DISPLAY IS 1x1
2025-01-19 01:41:01.984 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplaySetMainFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:01.984 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:01.984 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL EVENT: Window 2 moved to 466,270
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL EVENT: Window 2 display changed to 1
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL_EVENT_DISPLAY_REMOVED 3
2025-01-19 01:41:01.989 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL EVENT: Display 3 removed
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:41:01.989 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:41:01.989 testsprite[25124:19986960] SDL EVENT: Display 1 changed position
2025-01-19 01:41:04.646 testsprite[25124:19986960] 94.39 frames per second
2025-01-19 01:41:09.647 testsprite[25124:19986960] 80.38 frames per second

Attach after the above:

2025-01-19 01:41:14.656 testsprite[25124:19986960] 80.47 frames per second
2025-01-19 01:41:17.707 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:17.707 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:17.707 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:17.707 testsprite[25124:19986960] DISPLAY IS 1920x1080
2025-01-19 01:41:17.707 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:17.707 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:17.707 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:17.707 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:17.720 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplaySetMainFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplaySetModeFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplayAddFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplayEnabledFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:17.720 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:17.720 testsprite[25124:19986960] DISPLAY IS 1920x1080
2025-01-19 01:41:17.727 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:17.727 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:17.727 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:17.727 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:17.727 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL EVENT: Window 2 moved to 466,257
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL_EVENT_DISPLAY_ADDED 4
2025-01-19 01:41:17.731 testsprite[25124:19986960] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:17.731 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL EVENT: Display 4 attached
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL EVENT: Window 2 display changed to 4
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 4
2025-01-19 01:41:17.731 testsprite[25124:19986960] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:17.731 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL EVENT: Display 4 changed position
2025-01-19 01:41:17.731 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:41:17.731 testsprite[25124:19986960] Display 4 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:17.732 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:17.732 testsprite[25124:19986960] SDL EVENT: Display 1 changed position
2025-01-19 01:41:19.671 testsprite[25124:19986960] 62.60 frames per second
2025-01-19 01:41:20.544 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:20.544 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:20.544 testsprite[25124:19986960] DISPLAY IS ONLINE: false
2025-01-19 01:41:20.544 testsprite[25124:19986960] DISPLAY IS 1x1
2025-01-19 01:41:20.544 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:20.544 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:20.544 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:20.544 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:20.584 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplayRemoveFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplayDisabledFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960] DISPLAY IS ONLINE: false
2025-01-19 01:41:20.584 testsprite[25124:19986960] DISPLAY IS 1x1
2025-01-19 01:41:20.584 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplaySetMainFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:20.584 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:20.584 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL EVENT: Window 2 moved to 466,270
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL EVENT: Window 2 display changed to 1
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL_EVENT_DISPLAY_REMOVED 4
2025-01-19 01:41:20.601 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL EVENT: Display 4 removed
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:41:20.601 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at 0,0
2025-01-19 01:41:20.601 testsprite[25124:19986960] SDL EVENT: Display 1 changed position
2025-01-19 01:41:24.750 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:24.750 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:24.750 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:24.750 testsprite[25124:19986960] DISPLAY IS 1920x1080
2025-01-19 01:41:24.750 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:24.750 testsprite[25124:19986960]  - kCGDisplayBeginConfigurationFlag
2025-01-19 01:41:24.750 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:24.750 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:24.779 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=3
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplaySetMainFlag
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplaySetModeFlag
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplayAddFlag
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplayEnabledFlag
2025-01-19 01:41:24.779 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:24.780 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:24.780 testsprite[25124:19986960] DISPLAY IS 1920x1080
2025-01-19 01:41:24.780 testsprite[25124:19986960] COCOA DISPLAY RECONFIG CALLBACK! display=1
2025-01-19 01:41:24.780 testsprite[25124:19986960]  - kCGDisplayMovedFlag
2025-01-19 01:41:24.780 testsprite[25124:19986960]  - kCGDisplayDesktopShapeChangedFlag
2025-01-19 01:41:24.780 testsprite[25124:19986960] DISPLAY IS ONLINE: true
2025-01-19 01:41:24.780 testsprite[25124:19986960] DISPLAY IS 1512x982
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL EVENT: Window 2 moved to 466,257
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL_EVENT_DISPLAY_ADDED 5
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 5 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL EVENT: Display 5 attached
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL EVENT: Window 2 display changed to 5
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 5
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 5 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL EVENT: Display 5 changed position
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL_EVENT_DISPLAY_MOVED 1
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 5 'Kamvas Pro 24': 1920x1080 at 0,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] Display 1 'Built-in Retina Display': 1512x982 at -1512,0
2025-01-19 01:41:24.788 testsprite[25124:19986960] SDL EVENT: Display 1 changed position
2025-01-19 01:41:24.788 testsprite[25124:19986960] 76.41 frames per second
2025-01-19 01:41:29.801 testsprite[25124:19986960] 60.64 frames per second
2025-01-19 01:41:32.736 testsprite[25124:19986960] SDL EVENT: Mouse entered window 2
2025-01-19 01:41:33.028 testsprite[25124:19986960] SDL EVENT: Window 2 gained keyboard focus
2025-01-19 01:41:33.028 testsprite[25124:19986960] SDL EVENT: Clipboard updated
^[2025-01-19 01:41:33.290 testsprite[25124:19986960] +[IMKClient subclass]: chose IMKClient_Modern
2025-01-19 01:41:33.290 testsprite[25124:19986960] +[IMKInputSession subclass]: chose IMKInputSession_Modern
2025-01-19 01:41:33.676 testsprite[25124:19986960] SDL EVENT: Keyboard: key pressed in window 2: scancode 0x00000029 = Escape, keycode 0x0000001B = Escape, mods = NONE

@slouken
Copy link
Collaborator Author

slouken commented Jan 19, 2025

In your latest logs the device really is removed for a bit before it reattaches. I think this might be an OS quirk, or just how the underlying device is attached and moved around. I think this is okay, as it ends up in the correct state at the end.

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

3 participants