Skip to content

macOS: Avoid redundant initial resize event#3913

Merged
madsmtm merged 3 commits intomasterfrom
madsmtm/macos-avoid-extra-resize
Dec 3, 2024
Merged

macOS: Avoid redundant initial resize event#3913
madsmtm merged 3 commits intomasterfrom
madsmtm/macos-avoid-extra-resize

Conversation

@madsmtm
Copy link
Copy Markdown
Member

@madsmtm madsmtm commented Sep 11, 2024

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.

Together with #3912, this fixes #3235.

Part of #2640.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users

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.
@madsmtm madsmtm added B - bug Dang, that shouldn't have happened DS - appkit Affects the AppKit/macOS backend labels Sep 11, 2024
Copy link
Copy Markdown
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@madsmtm
Copy link
Copy Markdown
Member Author

madsmtm commented Dec 2, 2024

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:

The notification is not posted when you set the frame rectangle to the value it already has.

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:

If the value of this property is currently false and and the frame has changed, changing the value to true causes the view to post a NSViewFrameDidChangeNotification notification immediately. This happens even when there has been no net change in the view’s frame rectangle.

Which also exactly describes the behaviour we avoid by registering the observer after setting postsFrameChangedNotifications.

@madsmtm madsmtm requested a review from kchibisov December 2, 2024 22:32
@madsmtm madsmtm added this to the Version 0.31.0 milestone Dec 3, 2024
@madsmtm madsmtm merged commit 3657506 into master Dec 3, 2024
@madsmtm madsmtm deleted the madsmtm/macos-avoid-extra-resize branch December 3, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B - bug Dang, that shouldn't have happened DS - appkit Affects the AppKit/macOS backend

Development

Successfully merging this pull request may close these issues.

NewEvents(StartCause::Init) fires after RedrawRequested on MacOS

2 participants