macOS: Avoid redundant initial resize event#3913
Conversation
The `NSViewFrameDidChangeNotification` that we listen to is emitted when `-[NSWindow setContentView]` is called, since that sets the frame of the view as well. So now we register the notification later, so that it's not triggered at window creation.
kchibisov
left a comment
There was a problem hiding this comment.
I wonder why we not compare the current size with the new size? Just moving the place where the size observer is being set doesn't sound like the right way to solve this(though it likely does solve this).
Just generally tracking the active size and comparing should generally reduce the amount of resizes we're sending to the user.
I know it may feel brittle, but (for once in AppKit) the behaviour here is actually well documented. This documentation says:
I.e. redundant resizes are already avoided by AppKit internally. The reason this wasn't considered a redundant resize before is because the view had size (0, 0) before being added to the window. The documentation also says:
Which also exactly describes the behaviour we avoid by registering the observer after setting |
The
NSViewFrameDidChangeNotificationthat we listen to is emitted when-[NSWindow setContentView]is called, since that sets the frame of the view as well.So now we register the notification later, so that it's not triggered at window creation.
Together with #3912, this fixes #3235.
Part of #2640.
changelogmodule if knowledge of this change could be valuable to users