Skip to content
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

Fix window-restoration (PR #27) #33

Merged
merged 8 commits into from Jul 6, 2019

Conversation

Mortennn
Copy link
Contributor

@Mortennn Mortennn commented Apr 23, 2019

I have modified @DivineDominion's code a bit to get centering and restoring the preferences window to work.

  1. Call showWindow().
  2. Get the screen the window is located on and calculates the new coordinates.

window.center() does not work. I don't know why.

@Mortennn Mortennn changed the title Fixes window-restoration (PR #27) Fix window-restoration (PR #27) Apr 23, 2019
* Suggested approach: sindresorhus/touch-bar-simulator:Touch%20Bar%20Simulator/TouchBarWindow.swift@23f7c1c#L121-L125
* use `visibleFrame` instead of `frame` to calculate the right coordinates
@Mortennn
Copy link
Contributor Author

I've change the code according to your approach.

setFrameOrigin(CGPoint(x: frame.origin.x, y: 100))
In my opinion, it is better to calculate the coordinates based on the screen the preferences window is located on than relying on a hard-coded value for the y-axis in case anything changes later on.

@DivineDominion DivineDominion merged commit cc25d58 into sindresorhus:master Jul 6, 2019
@DivineDominion
Copy link
Collaborator

In my tests, this worked great! Thanks @Mortennn

@tonyarnold
Copy link
Contributor

Does this work still work under macOS 11? It's not restoring to the position I drag it to on next launch.

Should this be using NSWindowRestoration instead of the frame autosave name?

@sindresorhus
Copy link
Owner

I just tried the bundled example app on macOS 11.5.2 and it correctly preserves its position between launches.


Should this be using NSWindowRestoration instead of the frame autosave name?

It's not clear to me which of these solutions that are the most correct solution.

@sindresorhus
Copy link
Owner

Maybe try switching the order of these to ensure it's not some kind of race issue: https://github.com/sindresorhus/Preferences/blob/main/Sources/Preferences/PreferencesWindowController.swift#L98-L99

dezinezync pushed a commit to dezinezync/Preferences that referenced this pull request Dec 17, 2022
They are now `true` by default.

Fixes sindresorhus#33
dezinezync pushed a commit to dezinezync/Preferences that referenced this pull request Dec 17, 2022
They are now `true` by default.

Fixes sindresorhus#33
dezinezync pushed a commit to dezinezync/Preferences that referenced this pull request Dec 17, 2022
* Suggested approach: sindresorhus/touch-bar-simulator:Touch%20Bar%20Simulator/TouchBarWindow.swift@23f7c1c#L121-L125
* use `visibleFrame` instead of `frame` to calculate the right coordinates
* Remove `window?.center()` and `showWindow()` which had no effect
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.

None yet

4 participants