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

gtk: add support for theming Flatpak apps #693

Merged
merged 10 commits into from
Dec 26, 2024
Merged

Conversation

brckd
Copy link
Contributor

@brckd brckd commented Dec 22, 2024

Resolves #465 and adds support for theming Flatpak apps by making the GTK theme accessible to them. This support can be enabled using targets.gtk.flatpakSupport.enable. See this article for an in-depth explanation of Flatpak theming.

To enable Flatpak theming support, this module writes to Flatpak's overrides configuration which currently does not have a dedicated Home Manager option. It might therefore create conflicts with other modules that write directly to this file, such as those defined by nix-flatpak.

Here are some Flatpak apps with a Catppuccin GTK theme.

Flatpak Calculator screenshot
Flatpak Palette screenshot

See #465 (comment) and replies for previous discussions on this matter.

This support can be enabled using `targets.gtk.flatpakSupport.enable`.
It is likey incompatible with other modules that write to this file and
is therefore disabled by default.
@brckd
Copy link
Contributor Author

brckd commented Dec 22, 2024

I added support for nix-flatpak overrides. If nix-flatpak is imported externally, its option is used for compatibility purposes. Otherwise, file is manually created. Sadly this solution is not very easy to read and maintain.

Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

The overall approach looks good.

modules/gtk/hm.nix Outdated Show resolved Hide resolved
modules/gtk/hm.nix Outdated Show resolved Hide resolved
modules/gtk/hm.nix Outdated Show resolved Hide resolved
modules/gtk/hm.nix Outdated Show resolved Hide resolved
modules/gtk/hm.nix Outdated Show resolved Hide resolved
brckd and others added 2 commits December 23, 2024 19:50
This uses stdenvNoCC as a more lightweight alternative to stdenv.

Co-authored-by: NAHO <[email protected]>
This is the more conventional method and enables the option by default.

Co-authored-by: NAHO <[email protected]>
@brckd brckd requested a review from trueNAHO December 23, 2024 20:57
modules/gtk/hm.nix Outdated Show resolved Hide resolved
@brckd
Copy link
Contributor Author

brckd commented Dec 25, 2024

Thanks for updating your review! I may be slow to respond and will take more time testing the suggested changes during the festive season, just so you know.

Uses the `?` operator instead of `lib.hasAttrByPath`.

Co-authored-by: NAHO <[email protected]>
@brckd brckd requested a review from trueNAHO December 26, 2024 22:09
Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

LGTM. Great job!

Reviewed-by: NAHO <[email protected]>

I do not have any Flatpak applications to test this patchset, but I can confirm that this does not break non-Flatpak applications:

Tested-by: NAHO <[email protected]>

@trueNAHO trueNAHO merged commit 963e77a into danth:master Dec 26, 2024
12 checks passed
@baduhai
Copy link
Contributor

baduhai commented Jan 2, 2025

I'm having some issues with this, flatpaked GTK apps are fully transparent for me. I do use nix-flatpak, but I don't have any specific configuration, feel free to check out my config.

image

@brckd
Copy link
Contributor Author

brckd commented Jan 2, 2025

@baduhai Thanks for reporting on this issue! I was able to reproduce it with some Flatpak apps and opened #720 for further discussion.

stylix-automation bot pushed a commit that referenced this pull request Jan 4, 2025
Add support for theming Flatpak applications by making the GTK theme
accessible to them. [1]

[1]: https://itsfoss.com/flatpak-app-apply-theme

Closes: #465
Link: #693

Reviewed-by: NAHO <[email protected]>
Tested-by: NAHO <[email protected]>
(cherry picked from commit 963e77a)
@stylix-automation
Copy link

Successfully created backport PR for release-24.11:

trueNAHO pushed a commit that referenced this pull request Jan 4, 2025
Add support for theming Flatpak applications by making the GTK theme
accessible to them. [1]

[1]: https://itsfoss.com/flatpak-app-apply-theme

Closes: #465
Link: #693

Reviewed-by: NAHO <[email protected]>
Tested-by: NAHO <[email protected]>
(cherry picked from commit 963e77a)
@brckd
Copy link
Contributor Author

brckd commented Jan 4, 2025

FYI I just tried Stylix on the got the new GIMP 3.0 RC Flatpak and it works right out of the box after changing GIMP's theme to "System"!

Preview

image

@brckd
Copy link
Contributor Author

brckd commented Jan 8, 2025

I just noticed some other potential issues with the current implementation.

It's discouraged to use GTK_THEME, as that's reserved for debugging purposes. Apparently, the following should be used instead.

gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3'

Flatpak apps shouldn't be able to access /nix/store, but that's where the symlink in $HOME/.themes points to. Perhaps Flatpak also follows that symlink when granting file access? I hope so.

Perhaps I'll find a solution that just uses $HOME/.local/share/themes and $HOME/.config/gtk-{3.0,4.0} instead of $HOME/.themes that might also fix #720.

@danth
Copy link
Owner

danth commented Jan 11, 2025

gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3'

Note that gsettings is built on top of dconf, if that's helpful at all. Home Manager has a module for it but I doubt that takes effect inside Flatpak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlatPak PrusaSlicer doesn't get styled
4 participants