electron icon indicating copy to clipboard operation
electron copied to clipboard

Window snapping on Windows does not persist the window position/size after hide/show

Open Nantris opened this issue 5 years ago • 21 comments

Preflight Checklist

  • [x] I have read the Contributing Guidelines for this project.
  • [x] I agree to follow the Code of Conduct that this project adheres to.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: 9.3.x
  • Operating System: Windows 10 & Windows 7
  • Last Known Working Electron version: Never to my knowledge

Expected Behavior

Hiding/showing a window that's snapped to a screen edge should not affect the window's position/size.

Actual Behavior

Showing a window after hiding restores the window position/size to the settings from prior to the window snapping.

To Reproduce

Repro fiddle

Nantris avatar Sep 07 '20 22:09 Nantris

I saw this issue #1304, but it's very old. If it's still relevant, I don't understand why restoring the window to the same coordinates isn't possible, since the Electron window is aware of its coordinate and size, and only loses them upon calling show().

Nantris avatar Sep 07 '20 22:09 Nantris

@sofianguy @zcbenz is there any way this can be achieved? It's really all but impossible to work around and I don't know why the behavior is what it is?

I understand there's a special "Aero Snap" state, but that shouldn't make it impossible for developers to restore their application window to its last location.

In our app the user uses a global hotkey to bring it up in its last location. The last location after an Aero Snap though, is not the actual location of the window - but its last non-snapped location - even though the BrowserWindow reports the correct coordinates right before we call win.show()

That means a user can never use a global hotkey to make the app appear in the snapped position - it always reverts itself. We've gotten a number of complaints about this and tried hard to find a workaround. Can anyone comment on why things can't work this way? The current behavior is very strange and unexpected both for developers and end users.

image

Nantris avatar Mar 01 '21 22:03 Nantris

Anybody?

Nantris avatar Mar 24 '21 18:03 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

Still repros in Electron 21. Updated gist

pushkin- avatar Oct 07 '22 21:10 pushkin-

This one really drives me nuts!

Nantris avatar Oct 08 '22 03:10 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Jan 10 '23 02:01 github-actions[bot]

Not stale. I really think this should be addressed. Otherwise showing the window with a global hotkey while it's Aero-Snapped will reset the window to its previous position, or some new position which may be partially off the screen.

Nantris avatar Jan 10 '23 20:01 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Apr 12 '23 01:04 github-actions[bot]

repros in v24

pushkin- avatar Apr 12 '23 15:04 pushkin-

+1 on this

devinbinnie avatar May 24 '23 14:05 devinbinnie

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Aug 23 '23 01:08 github-actions[bot]

Not stale.

Nantris avatar Aug 23 '23 02:08 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

Not stale.

Nantris avatar Nov 22 '23 02:11 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

Not stale.

Nantris avatar Feb 22 '24 02:02 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

Not stale.

Nantris avatar May 23 '24 07:05 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

Not stale.

@MarshallOfSound I wonder if you might be willing to comment on this issue?

It makes global hotkey apps feel a lot less polished, among other things.

Nantris avatar Aug 22 '24 04:08 Nantris

Friendly bump. It would be great if this could be supported.

Nantris avatar Nov 11 '24 05:11 Nantris

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

Bump. Would really love to see this addressed.

Nantris avatar Feb 10 '25 07:02 Nantris

Still repros in Electron 28.

zhaojunyan9528 avatar Mar 06 '25 06:03 zhaojunyan9528

Repros in 34 too.

@codebytere sorry to ping - I just wonder if this might ever be addressed?

This really makes it hard to make the app feel native because Windows continues to place more and more emphasis on its snapping system. It's a big problem when users expect the global hotkey to bring an app back up to where they left it and it doesn't and can't behave as they expect no matter how they try.

Nantris avatar Mar 06 '25 21:03 Nantris

@Nantris i think i figured out a solution here actually, after reviewing it for a bit - will let you know soon :)

codebytere avatar Mar 07 '25 16:03 codebytere

@Nantris i submitted a CL upstream: https://chromium-review.googlesource.com/c/chromium/src/+/6330848 that should address this! Once it's accepted I'll open some backports to Electron.

codebytere avatar Mar 07 '25 16:03 codebytere

Thank you so much @codebytere!

Nantris avatar Mar 07 '25 21:03 Nantris