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

✨ Option to use macOS center instead of screen center #77

Closed
2 tasks done
Zabriskije opened this issue Oct 28, 2023 · 7 comments · Fixed by #150
Closed
2 tasks done

✨ Option to use macOS center instead of screen center #77

Zabriskije opened this issue Oct 28, 2023 · 7 comments · Fixed by #150
Assignees
Labels

Comments

@Zabriskije
Copy link
Contributor

Feature Request Description

Press return to center a window uses the actual screen center, but I found more ergonomic to have windows in the default macOS center by using func center(). I'd like to propose it as an alternative, making the user select the preferred one.

Screenshots

macOS center:

macOS center

Screen center:

Screen center

Additional Context

No response

Final Checks

  • My issue title is descriptive
  • This is a single feature request (multiple feature requests should be reported individually)
@MrKai77
Copy link
Owner

MrKai77 commented Oct 28, 2023

Definitely interested in implementing this! Unfortunately, Loop doesn't have access to any other app's window's NSWindow, which means that we can't call NSWindow.center() on a target window. This is why Loop uses the window's AXUIElement to resize the window.
I can't seem to find any resources which explain how MacOS calculates a window's "center" position on the screen, but do you have any insight on this? I'm guessing that MacOS does it by moving the window a certain percentage up the screen and calling that the center position?

@MrKai77 MrKai77 self-assigned this Oct 28, 2023
@Zabriskije
Copy link
Contributor Author

Unfortunately, I can't help with that :(
I came up with func center() by a quick Google search. I don't know Swift, so the best I can do is guess.
Center window in screen – Stack Overflow, would this be helpful? I only found examples with NSWindowController but none with AXUIElement.

@MrKai77
Copy link
Owner

MrKai77 commented Oct 30, 2023

Unfortunately not :(
But thanks for your effort!

macOS center:

Out of curiosity, how were you able to "MacOS center" the Safari window in the screenshot? Is there a built-in command to center a window? Or was it a different window manager?
This might hint a way to calculate the MacOS's center position for a window.

@Zabriskije
Copy link
Contributor Author

Out of curiosity, how were you able to "MacOS center" the Safari window in the screenshot? Is there a built-in command to center a window? Or was it a different window manager? This might hint a way to calculate the MacOS's center position for a window.

Still Moom

@MrKai77
Copy link
Owner

MrKai77 commented Dec 31, 2023

Alright, I found the formula to center a window on a screen (I spent way too much time on this 😂), and it places windows in the equivalent position of NSWindow.center()!

let halfScreenHeight = screenFrame.height / 2
let windowHeightPercent = windowFrame.height / screenFrame.height
let yOffset: CGFloat = (0.5 * windowHeightPercent - 0.5) * halfScreenHeight

newWindowFrame = CGRect(
        x: screenFrame.midX - windowFrame.width / 2,
        y: screenFrame.midY - windowFrame.height / 2 + yOffset,
        width: windowFrame.width,
        height: windowFrame.height
)

Now I guess all that's left is to actually put it in Loop!

@MrKai77
Copy link
Owner

MrKai77 commented Jan 1, 2024

Alright, sorry for the wait!
Here's a working build: Loop.zip
Happy new year!

@Zabriskije
Copy link
Contributor Author

Happy New Year too!
Seems working 🚀

@MrKai77 MrKai77 linked a pull request Jan 2, 2024 that will close this issue
MrKai77 added a commit that referenced this issue Jan 2, 2024
…-instead-of-screen-center`

✨ #77 Option to use macOS center instead of screen center
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants