This is in X11. The dpi documentation says:
If a window hasn't received a ScaleFactorChanged event, then its scale factor is 1.0.
However, my window.scale_factor() returns 1.166...7 and I do not seem to get the event once I run the event loop.
You're right. I must have missed the memo on this because X11 is missing this behavior entirely. I'll put together a fix later tonight.
I've thought about this some more and I wonder whether that part of the documentation should perhaps be changed. Here's my reasoning: On X11, the scale factor of a window is known at the time of window creation (not for certain, but it's likely correct; the details are not relevant to this issue). An application can get the (likely) correct scale factor by calling window.scale_factor() immediately after the window is created, before any events have arrived and even before EventLoop::run is called.
However, winit cannot deliver a ScaleFactorChanged event when a window is created because that function does not have access to the callback provided to EventLoop::run and, as mentioned above, there may not even be a running event loop at this time and thus no callback. Therefore, to deliver a ScaleFactorChanged event as soon as possible would require a tricky bit of logic, which may never be able to guarantee that such event would arrive before any RedrawRequested event in a multithreaded application, defeating the purpose of trying to deliver this event at all.
So, rather than force the X11 backend to jump through some possibly tricky hoops to deliver a ScaleFactorChanged event as soon as possible, I propose that the documentation should no longer give a 1.0 scale factor assumption and instead instruct DPI-aware applications to check window.scale_factor() when drawing window contents.
@Osspial Any objections to or thoughts on this proposed documentation change?
Most helpful comment
I've thought about this some more and I wonder whether that part of the documentation should perhaps be changed. Here's my reasoning: On X11, the scale factor of a window is known at the time of window creation (not for certain, but it's likely correct; the details are not relevant to this issue). An application can get the (likely) correct scale factor by calling
window.scale_factor()immediately after the window is created, before any events have arrived and even beforeEventLoop::runis called.However, winit cannot deliver a
ScaleFactorChangedevent when a window is created because that function does not have access to the callback provided toEventLoop::runand, as mentioned above, there may not even be a running event loop at this time and thus no callback. Therefore, to deliver aScaleFactorChangedevent as soon as possible would require a tricky bit of logic, which may never be able to guarantee that such event would arrive before anyRedrawRequestedevent in a multithreaded application, defeating the purpose of trying to deliver this event at all.So, rather than force the X11 backend to jump through some possibly tricky hoops to deliver a
ScaleFactorChangedevent as soon as possible, I propose that the documentation should no longer give a1.0scale factor assumption and instead instruct DPI-aware applications to checkwindow.scale_factor()when drawing window contents.@Osspial Any objections to or thoughts on this proposed documentation change?