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

feat: customize quick terminal size #3742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dmehala
Copy link
Collaborator

@dmehala dmehala commented Dec 28, 2024

Description

This commit introduce quick-terminal-size option which allows to define the size of the quick terminal.

It also fixes an issue where the quick terminal position was not properly updated when reloading the configuration.

Resolves #2384

This commit introduce `quick-terminal-size` option which allows to
define the size of the quick terminal.

It also fixes an issue where the quick terminal position was not
properly updated when reloading the configuration.

Resolves ghostty-org#2384
Comment on lines +1414 to +1436
/// Control the size of the quick terminal.
///
/// The size can expressed in two units:
/// * A value ending in `%` specifies a percentage of the screen size.
/// * A value ending in `px` specifies a fixed size in pixel, which is clamped by the
/// screen's maximum width or height.
///
/// The configuration accept one or two dimensions:
/// * A single value specifies the dimension that is growable based on the quick terminal
/// position:
/// * For `top` and `bottom` positions, the value applies to the height.
/// * For `right` and `left` positions, the value applies to the width.
/// * For `center`, the size applied to both the width and height.
/// * Two comma separated value specifies the width and height.
///
/// Examples:
///
/// ```
/// quick-terminal-size = 25% // 25% of the maximum size for the growable dimension
/// quick-terminal-size = 42px // 42 pixels for the growable dimension
/// quick-terminal-size = 25%,75% // 25% for the primary dimension, 75% for the secondary
/// quick-terminal-size = 300px,80% // 300px for the primary dimension, 80% for the secondary
/// ```
Copy link
Collaborator Author

@dmehala dmehala Dec 28, 2024

Choose a reason for hiding this comment

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

I am not a native English speaker, so feel free to change the wording 😅.

func apply(value: CGFloat) -> CGFloat {
switch(self) {
case .pixel(let fixed_size):
return CGFloat(fixed_size);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
return CGFloat(fixed_size);
return min(value, CGFloat(fixed_size));

};
}

fn parseValue(input: []const u8) !Size {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[Nitpick] Parsing could be improve, quick-terminal-size: 20%, 30% will probably fail due to the space after the comma. I could/should fix it, but other config suffers from the same issue and should probably be fixed in a subsequent PR.

@mitchellh mitchellh added this to the 1.0.1 milestone Dec 29, 2024
init?(c_dimension: ghostty_config_quick_terminal_dimension_s) {
switch(c_dimension.unit) {
case GHOSTTY_QUICK_TERMINAL_PIXEL_UNIT:
self = .pixel(value: UInt(c_dimension.value))
Copy link
Collaborator Author

@dmehala dmehala Dec 29, 2024

Choose a reason for hiding this comment

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

[TODO] Use screen scale (IIRC retina has a scale of 2-3 while standard display is 1. backingScaleFactor?

@Jaycedam
Copy link

Jaycedam commented Dec 29, 2024

Hi I've been trying this out, thank you for working on this.
I have some issues but I could be doing something wrong, when using:

quick-terminal-position = center
quick-terminal-size = 80%

only the width is modified

image

using two values works as expected
quick-terminal-size = 80%,80%

image

Also the global keybind stopped working but maybe that's a different issue?

@dmehala
Copy link
Collaborator Author

dmehala commented Dec 29, 2024

Hey @Jaycedam

I have some issues but I could be doing something wrong, when using:
quick-terminal-position = center
quick-terminal-size = 80%
only the width is modified

This is the expected behaviour, howver, I agree for center position it seems natural to expect the size to change on both dimensions unless a second dimension is specified. I am planning to push this change. Here's a preview:

Screen Recording 2024-12-29 at 23 36 12

NOTE: I have an ultrawide monitor.

Also the global keybind stopped working but maybe that's a different issue?

The PR doesn't include any changes related to global keybindings, so that would be a surprising side effect. Unfortunately, I am not able to reproduce the issue. Could you share the steps to reproduce it with you configuration? Thank you.

@Jaycedam
Copy link

This is the expected behaviour, howver, I agree for center position it seems natural to expect the size to change on both dimensions

I was confused by the wording of the documentation added here, but as long as it reflects the usage I think it will be easy to understand.

The configuration accept one or two dimensions:

  • A single value specifies the dimension that is growable based on the quick terminal position:
    • For center, the size applied to both the width and height.

The global keybind was a problem on my end so ignore it. Re-enabling the accesibility toggle fixed it.

@YANOUSHek
Copy link

I know I'm a little late to the party but I just started using ghostty today. Shouldn't we also allow to specify the size of the quick terminal in rows and cols? So

quick-terminal-size = 120,50

would create a window that has 120 columns and 50 rows.

@Dolvur
Copy link

Dolvur commented Dec 30, 2024

I know I'm a little late to the party but I just started using ghostty today. Shouldn't we also allow to specify the size of the quick terminal in rows and cols? So

quick-terminal-size = 120,50

would create a window that has 120 columns and 50 rows.

This was mentioned as a future enhancement due to it being more complex #2384 (comment)

Also thank you dmehala for working on this. I always use a fullscreen hotkey toggle for my terminal needs

@mitchellh mitchellh removed this from the 1.0.1 milestone Dec 30, 2024
Copy link

@donaldguy donaldguy left a comment

Choose a reason for hiding this comment

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

locally rebased this onto tip (at 8f5f432)

there were some detected-conflicts in QuickTerminalController.swift (vs #4055 )

they are all fairly obvious resolutions but to (potentially) save you the trouble (modulo if you have strong feelings about a different order)

[see below for one ~substantive question]

@@ -390,25 +393,32 @@ class QuickTerminalController: BaseTerminalController {

// Update our derived config
self.derivedConfig = DerivedConfig(config)

self.position = self.derivedConfig.quickTerminalPosition

syncAppearance(config)

Choose a reason for hiding this comment

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

Suggested change
syncAppearance(config)
syncAppearance()

Comment on lines +405 to +406
let quickTerminalPosition: QuickTerminalPosition
let quickTerminalSize: QuickTerminalSize

Choose a reason for hiding this comment

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

Suggested change
let quickTerminalPosition: QuickTerminalPosition
let quickTerminalSize: QuickTerminalSize
let quickTerminalPosition: QuickTerminalPosition
let quickTerminalSize: QuickTerminalSize
let windowColorspace: String
let backgroundOpacity: Double

or your preferred order

Comment on lines +420 to +421
self.quickTerminalPosition = config.quickTerminalPosition
self.quickTerminalSize = config.quickTerminalSize

Choose a reason for hiding this comment

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

Suggested change
self.quickTerminalPosition = config.quickTerminalPosition
self.quickTerminalSize = config.quickTerminalSize
self.quickTerminalPosition = config.quickTerminalPosition
self.quickTerminalSize = config.quickTerminalSize
self.windowColorspace = config.windowColorspace
self.backgroundOpacity = config.backgroundOpacity

Comment on lines +412 to +413
self.quickTerminalPosition = .top
self.quickTerminalSize = .init()

Choose a reason for hiding this comment

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

Suggested change
self.quickTerminalPosition = .top
self.quickTerminalSize = .init()
self.quickTerminalPosition = .top
self.quickTerminalSize = .init()
self.windowColorspace = ""
self.backgroundOpacity = 1.0

Comment on lines +309 to +311

// Update the quick terminal size right away
config.quickTerminalSize.apply(window, config.quickTerminalPosition)
Copy link

@donaldguy donaldguy Jan 4, 2025

Choose a reason for hiding this comment

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

FYI, since you removed the function param this config symbol no longer resolves and tanks the swift compilation.

not sure if the invocation up at 75 (72 in my rebased version) is adequate or if this wants to stay but go:

Suggested change
// Update the quick terminal size right away
config.quickTerminalSize.apply(window, config.quickTerminalPosition)
// Update the quick terminal size right away
self.derivedConfig.quickTerminalSize.apply(window, self.position)

or something else

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.

Customize initial size for quick terminal
6 participants