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

Set an initial start position #3929

Merged
merged 12 commits into from
Jan 2, 2025
Merged

Conversation

aw1875
Copy link
Contributor

@aw1875 aw1875 commented Dec 29, 2024

Allow the ability to set an initial start position from the config. Adds window-initial-position-{x,y} to the config as an optional i16 value (see swift docs in this comment for the reasoning behind this if needed) and handles setting the position when the initial window is created

Closes #3362

src/apprt/gtk/Surface.zig Outdated Show resolved Hide resolved
src/config/Config.zig Outdated Show resolved Hide resolved
@"window-position-x": i32 = 0,
@"window-position-y": i32 = 0,
@"start-position-x": i32 = 0,
@"start-position-y": i32 = 0,

Copy link
Collaborator

Choose a reason for hiding this comment

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

window-initial-position-x and window-initial-position-y I think would be clearer as to their purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool sounds good, I'll revert that change

Copy link
Collaborator

@jcollie jcollie Dec 30, 2024

Choose a reason for hiding this comment

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

The should also be unsigned and optional. That way you can tell if the user did not set these in their config. Defaulting to 0,0 is probably not what users want if those settings are unspecified. 32 bits is probably too much, I think that a u16 should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct me if I'm wrong but you can't you have negative coordinates depending on your monitor layout? I might just be mixing this up with something else but I thought that was a possibility

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't say for 100% sure, you'd need to check the documentation of the various APIs used to position the window. We definitely want these to be optional though. If the user didn't set them in the config, we don't want to force them into a specific location.

Copy link
Contributor Author

@aw1875 aw1875 Dec 30, 2024

Choose a reason for hiding this comment

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

I'm going to drop this here for later but macOS allows negative values (my understanding is that this value is based on your primary monitor's bottom left corner). I'll also dig into the Linux side later to see if I can find any docs supporting this behaviour.

https://developer.apple.com/documentation/appkit/nswindow/setframetopleftpoint(_:)#Discussion
https://developer.apple.com/documentation/appkit/nswindow/setframeorigin(_:)#Discussion

Copy link
Contributor

Choose a reason for hiding this comment

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

macOS does allow negative values to try to put the window offscreen. Various macOS settings may affect this. We can document it that it is OS dependent how that's handled.

@jcollie
Copy link
Collaborator

jcollie commented Dec 30, 2024

After some thinking, I think that this is the wrong approach. There shouldn't be any need to store the position in the core Surface struct or to use an apprt action to position the window. First, only the first surface that initiates the window creation should control the position of the window. If a new tab or split can affect the position of the window you'll have windows jumping back to their initial position after the user has moved them around and then creates a new tab or split.

When a new window is created it should check to see if these settings are configured and position the window at window creation time. There's no need for a message to be sent to the window at a later time.

@jcollie
Copy link
Collaborator

jcollie commented Dec 30, 2024

I don't program in Swift but there should be some existing machinery from macOS's state restoration that can be reused to set the initial window position from the config.

@jsejcksn
Copy link

I'm considering renaming window-position-{x,y} to start-position-{x,y} for clarity

I have no strong opinion about the name, but because existing configuration keys already use the term initial instead of start (e.g. initial-window), I suggest initial-window-position — or, as @jcollie mentioned, window-initial-position.


if let windowPositionX = x, let windowPositionY = y {
// Offset titlebar if needed, otherwise use default padding of 12
// NOTE: Not 100% certain where this extra padding comes from but I'd love
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Highlighting this note here in case a reviewer has more knowledge in the mac window space, I couldn't find anything helpful here but my hunch is this is default gap/padding/margin for NSWindow frames

@aw1875 aw1875 marked this pull request as ready for review December 31, 2024 06:56
@mitchellh mitchellh force-pushed the InitialStartPosition branch from 590eed0 to 29b96be Compare January 2, 2025 21:19
Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

I made some modifications (see my commit), but overall great job!

I renamed the config to window-position-x and y. The initial was a bit redundant there since the position is only ever relevant at start. I don't see a future where we have any other position values.

I also removed the titlebar math you had. I'm not fully sure I understood it, and the magic numbers were freaking me out. If there is a bug here in some circumstances we should open a discussion and figure that out in a more robust manner.

@"window-position-x": i32 = 0,
@"window-position-y": i32 = 0,
@"start-position-x": i32 = 0,
@"start-position-y": i32 = 0,

Copy link
Contributor

Choose a reason for hiding this comment

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

macOS does allow negative values to try to put the window offscreen. Various macOS settings may affect this. We can document it that it is OS dependent how that's handled.

@mitchellh mitchellh enabled auto-merge January 2, 2025 21:20
@mitchellh mitchellh merged commit 898d988 into ghostty-org:main Jan 2, 2025
21 checks passed
mitchellh added a commit that referenced this pull request Jan 2, 2025
Allow the ability to set an initial start position from the config. Adds
`window-initial-position-{x,y}` to the config as an optional i16 value
(see swift docs in [this
comment](#3929 (comment))
for the reasoning behind this if needed) and handles setting the
position when the initial window is created

Closes #3362
@github-actions github-actions bot added this to the 1.0.2 milestone Jan 2, 2025
@aw1875 aw1875 deleted the InitialStartPosition branch January 2, 2025 21:36
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.

Configure initial window position
4 participants