Winit: [X11] `ScaleFactorChanged` not received when `EventLoop` is run

Created on 9 Jan 2020  路  2Comments  路  Source: rust-windowing/winit

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.

X11 bug

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 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?

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

francesca64 picture francesca64  路  5Comments

felixrabe picture felixrabe  路  4Comments

dhardy picture dhardy  路  3Comments

chrisduerr picture chrisduerr  路  3Comments

tomaka picture tomaka  路  3Comments