8000 feat: Add will-resize event to TopLevelWindow by poiru · Pull Request #13649 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add will-resize event to TopLevelWindow #13649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2018
Merged

Conversation

poiru
Copy link
Contributor
@poiru poiru commented Jul 12, 2018

The new will-resize event can be used to prevent the resize from
happening before the native window is actually resized. This is in
contrast to the existing the resize event, which is sent after the
native window has already been resized. For apps with e.g. custom window
snapping logic, the resize event is not sufficient because it will
result in flickering between the dragged size and the snapped size.

will-resize is only emitted on macOS and Windows. It may be
possible to implement for Linux/X11 as well.

Unfortunately it is not possible to test this because the event is only
emitted when the window is being resized manually. Resizing the window
with setBounds/setSize will not emit this event.

@poiru poiru requested review from a team July 12, 2018 18:19
@poiru poiru force-pushed the will-resize-event branch 2 times, most recently from a8d2d55 to a91e6e4 Compare July 13, 2018 13:12
@poiru poiru changed the title feat: Add will-resize event to TopLevelWindow (WIP) feat: Add will-resize event to TopLevelWindow Jul 24, 2018
@poiru poiru force-pushed the will-resize-event branch 2 times, most recently from d097aab to 651f4ab Compare July 24, 2018 22:38
@poiru poiru requested a review from zcbenz July 25, 2018 11:06
@poiru
Copy link
Contributor Author
poiru commented Jul 25, 2018

@zcbenz Could you review this?

If you want to test this, I used:

const {app, BrowserWindow} = require('electron')

let win = null

function createWindow() {
  win = new BrowserWindow({width: 800, height: 600})

  win.on('will-resize', (e, newBounds) => {
    console.log('will-resize', newBounds, win.getBounds())
    e.preventDefault()
  })

  win.on('resize', () => {
    console.log('resize', win.getBounds())
  })
}

app.on('ready', createWindow)

@nornagon
Copy link
Contributor

Capturing what I talked with @poiru about on Slack, I think this API should support this feature on Linux too.

Copy link
Contributor
@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

Need a minor change, other parts look good to me.

@@ -194,6 +194,18 @@ void TopLevelWindow::OnWindowRestore() {
Emit("restore");
}

void HandleWillResizeCallback(gfx::Rect* new_bounds,
gfx::Rect overridden_bounds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use const gfx::Rect&

@poiru poiru force-pushed the will-resize-event branch from 651f4ab to bdb5263 Compare July 27, 2018 07:57
The new `will-resize` event can be used to prevent the resize from
happening before the native window is actually resized. This is in
contrast to the existing the `resize` event, which is sent *after* the
native window has already been resized. For apps with e.g. custom window
snapping logic, the `resize` event is not sufficient because it will
result in flickering between the dragged size and the snapped size.

`will-resize` is only emitted on macOS and Windows.
@poiru poiru force-pushed the will-resize-event branch from bdb5263 to 9748e98 Compare July 27, 2018 08:00
@zcbenz zcbenz merged commit c8dc2d3 into master Jul 27, 2018
@zcbenz zcbenz deleted the will-resize-event branch July 27, 2018 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0