We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3716 - [patch] Display hotplugging
Summary: [patch] Display hotplugging
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-27 05:55 UTC by Eric Wasylishen
Modified: 2017-08-11 22:38 UTC (History)
1 user (show)

See Also:


Attachments
Cocoa display hotplugging patch (3.25 KB, patch)
2017-07-27 20:15 UTC, Eric Wasylishen
Details | Diff
Cocoa + win32 display hotplugging patch (7.68 KB, patch)
2017-08-01 23:12 UTC, Eric Wasylishen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Wasylishen 2017-07-27 05:55:46 UTC
Would be nice to have. e.g. you currently can't plug in a display, drag an SDL window to it, and go fullscreen on the new display.

Seems pretty easy to do. e.g. add a SDL_ClearVideoDisplays function to SDL_video.c that does:
    _this->displays = NULL;
    _this->num_displays = 0;
Then add OS-specific handlers that detect a configuration change, and clear + re-add all of the displays.

- Windows: handle WM_DISPLAYCHANGE, probably in the helper window created in SDL_HelperWindowCreate?
- macOS: CGDisplayRegisterReconfigurationCallback
Comment 1 Eric Wasylishen 2017-07-27 20:15:40 UTC
Created attachment 2808 [details]
Cocoa display hotplugging patch

Here is a first attempt at a Cocoa implementation.

To test it out I used this patch: https://bugzilla.libsdl.org/show_bug.cgi?id=3646
which adds Option+Left and Option+Right keybindings to the test apps to move the window between displays.
Comment 2 Eric Wasylishen 2017-07-31 00:58:30 UTC
And for X11, I think it's RRScreenChangeNotify we'll need to listen for?
https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt#n1715
Comment 3 Alex Szpakowski 2017-08-01 13:19:50 UTC
It'd be nice if SDL events were posted when this happens as well.

I can pretty easily implement the iOS backend code for this, if the functionality goes into SDL.
Comment 4 Eric Wasylishen 2017-08-01 23:12:16 UTC
Created attachment 2814 [details]
Cocoa + win32 display hotplugging patch

Yeah, an SDL event for when this happens would be good to add.

Another thing not currently handled by my patch is if the display dimensions change when a SDL window is currently fullscreen-desktop on it (e.g. if the display is rotated or the resolution is changed.)

Added a win32 implementation.
Comment 5 Eric Wasylishen 2017-08-11 22:38:49 UTC
The Windows patch needs some more work; it's causing a crash when doing fullscreen mode changes.

It seems that WM_DISPLAYCHANGE gets delivered to the helper window during the ChangeDisplaySettingsEx call in WIN_SetDisplayMode. This results in all of the SDL_VideoDisplay objects being freed and the displays re-enumerated, but WIN_SetDisplayMode still has a stale pointer to one of the freed displays which it tries to dereference.

so, I'll need to do something more involved than just freeing displays and re-creating them.. maybe setting a flag on the SDL_VideoDisplay to mark it as "removed".