Make DPI_CHANGED event handling async #2520
Open
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.
With this PR, all the widgets scale themselves asynchronously independent of the order saving the wait time over their children to scale.
Earlier, the widgets would scale synchronously on a
DPI_CHANGED
event from the OS, i.e., the shell receives the callback from the OS and calls and waits for its children to execute theirhandleDPIChange
(Over all the superclasses of course) and every widget onhandleDPIChange
method being triggered, would callhandDPIChange
for their children widgets or associated widgets and wait for them to finish and them execute he remaining scaling statements and pass the control to their parents. This whole flow would keep the thread busy for a significant amount of time making the UI freeze for sometime.With this approach, the Shell receives the callback from the OS and executes its
handleDPIChange
(Over all the superclasses of course) and sends a notification asynchronously, i.e., queues thenotifyListeners
to be executed for its children when the thread is free. Once the first queuednotifyListeners
runs, it would invoke thehandleDPIChange
for that particular widget, which would then schedule DPI scaling calls for its children and associated widgets and move on with itshandleDPIChange
execution. This would definitely change the hierarchical order in which the widgets scale themselves. Considering that the parents need to resize them on the basis of the size of the children, there needs to be a recalibration of the bounds for the widgets once all the widgets have scaled themselves. Hence, we keep a note of when all the widgets have completed their scaling, the last widget to scale itself triggers a Resize event, leading every widget to recalibrate their bounds. This leads to a better UI freeze free scaling where all the widgets inside the shell are still operable/clickable amidst the scaling.Only the last commit is relevant to this PR.
Depends on #2483