DPI change events in Sdl2App and GlfwApp #423
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #243. As usual, doesn't seem to be as straightforward as I would think, and I'm actually not sure about the workflow at all.
The simple goal at first was to detect when an app goes to a differently dense display and emitting a
viewportEvent()
so the app can rescale itself according to the new DPI. However, not so easy:Type
enum that differentiates between resize and DPI scaling change. An alternative could be having the DPI scaling event separate, however in 90% cases the app needs to do some relayouting based either on the new size or the new density (which also implies new size), so having two separate events for this would mean the app needs to duplicate all that code (ugh) or put it in a helper function that's called from both (also ugh).Cause
? Rename this whole thing towindowEvent()
?accept()
or some such, and ignore the DPI change otherwise? How does the user code calculate it? What if the user just always wants the physical DPI (to have the content match some physical size or whatever) while they always get just the virtual DPI from the WM?accept()
?)WM_DPICHANGED
in SDL (which is actually easy to grab when SysWMEvent is enabled), I discovered it's possible to "subclass" theWndProc
(source, docs, getting the procedure out of a window handle), catch the relevant events, do what I need and pass the rest to GLFW. Ugly but possibly doable?GLFW_SCALE_TO_MONITOR
hint that makes the resizing somehow automagic (and without this feedback loop) but it's too automagic for my taste, and should be under app control instead -- i.e., the app might only work well on particular sizes and it needs to "snap" to one of themWM_DPICHANGED
rectangle hint to position+size the window both whenGLFW_SCALE_TO_MONITOR
is used and when it isn't, but it only does something in the first case .. why?GLFW_SCALE_TO_MONITOR
automagic, provide a way to do this on a per-event basis, depending on what the app actually needs? Again by supplying something toaccept()
?GLFW_SCALE_TO_MONITOR
. Not good for my OCD. Solutions? GLFW is doing some calculations in its WM_GETDPISCALEDSIZE handler in order to keep the window the same size whenGLFW_SCALE_TO_MONITOR
is not enabled, maybe I could get inspired by that to ensure proper scaling?WM_DPICHANGED
can be caught on SDL (which doesn't support it natively) by enabling SDL_SYSWMEVENT that's disabled by default. Should this one be propagated toanyEvent()
as well? It generates a lot of noise, however not propagating it might be limiting for the user :/And then ... the final
bossbosses:viewDidChangeBackingProperties
?