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

Implement loading custom css in the GTK app #4200

Merged
merged 4 commits into from
Jan 2, 2025

Conversation

maciekbartczak
Copy link
Contributor

Closes #4089
Gave it a shot and implemented the custom css loading.
My general idea is to use a provider for each stylesheet the user wants to load and then when the config changes unload them and create new providers.
A separate provider has to be used for each stylesheet the user wants to load, since when the provider loads the css it clears all the previously loaded styles, so in effect we cannot use one provider to load multiple stylesheets, but maybe there is a better way to overcome this limitation which I'm not seeing.

src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
- use ArrayListUnmanaged
- read the stylesheet file using zig api
- use proper css_provider_load_ function depending on the GTK version
src/apprt/gtk/App.zig Show resolved Hide resolved
src/apprt/gtk/App.zig Show resolved Hide resolved
src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
src/apprt/gtk/App.zig Show resolved Hide resolved
- initialize custom_css_providers using a default value
- remove usage of buffered reader
- document maximum file size
- handle exceptions explicitly
src/apprt/gtk/App.zig Outdated Show resolved Hide resolved
@maciekbartczak maciekbartczak requested a review from jcollie January 1, 2025 07:58
/// Prepend a ? character to the file path to suppress errors if the file does
/// not exist. If you want to include a file that begins with a literal ?
/// character, surround the file path in double quotes (").
@"gtk-custom-css": RepeatablePath = .{},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was doing some testing and I had a crash if I didn't explicitly specify an absolute path to the custom CSS file, so for some reason the paths are not being expanded properly.

Copy link

Choose a reason for hiding this comment

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

#3811 should fix expansion not sure about the crash

Copy link
Collaborator

Choose a reason for hiding this comment

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

#3811 should fix expansion not sure about the crash

The crash is specifically because we have an assert in place to check for non-absolute paths. And #3811 won't fix it because I wasn't using a ~, just a plain filename --gtk-custom-css=custom.css. RepeatablePath should resolve that relative to Ghostty's config dir I thought but it obviously didn't.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I think that I figured out my problem, if you specify --background-image=custom.css on the CLI, Ghostty tries to resolve that based on the $PWD. If it can't be resolved, I think that the code leaves it as is without any warnings and then we eventually get a panic. So that's not a blocker for this (even though Mitchell has already merged this).

@mitchellh mitchellh enabled auto-merge January 2, 2025 22:19
@mitchellh mitchellh merged commit 602e4eb into ghostty-org:main Jan 2, 2025
21 checks passed
@github-actions github-actions bot added this to the 1.0.2 milestone Jan 2, 2025
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.

GTK: ability to load custom CSS
4 participants