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

Allow using custom CSS for GTK applications #3901

Open
gikari opened this issue Oct 12, 2020 · 23 comments
Open

Allow using custom CSS for GTK applications #3901

gikari opened this issue Oct 12, 2020 · 23 comments

Comments

@gikari
Copy link

gikari commented Oct 12, 2020

Linux distribution and version

KDE Neon User Edition 5.19

Flatpak version

1.6.5

Description of the problem

Currently, in KDE Plasma GTK applications are trying to be consistent with the Qt applications by using the same settings, where possible (fonts, color scheme, window decorations and others). These settings are properly synced with the GTK applications, installed from repositories, however some of them are not, if the GTK application is installed using Flatpak. Those are color scheme and window decorations (appearance).

The reason for that is that both of those user preferences are synced via custom CSS files, that are placed in the $XDG_CONFIG/gtk-3.0/ folder. In particular, colors are using custom color definitions in CSS files and windows decorations are synced via window manager rendered images and CSS files. Flatpak applications seem to ignore files in this directory.

It should be also noted, that custom CSS is used only for Breeze GTK theme.

Steps to reproduce

  1. Open KDE Plasma desktop 5.19 or later.
  2. Set (in not already set by default) Breeze GTK theme
  3. Open GTK application, installed from repositories.
  4. Change color scheme in System Settings > Colors - GTK application changes its colors.
  5. Open GTK application, installed from Flatpak
  6. Change color scheme in System Settings > Colors - GTK application does not change its colors.
@eszlari
Copy link

eszlari commented Oct 13, 2020

The reason for that is that both of those user preferences are synced via custom CSS files, that are placed in the $XDG_CONFIG/gtk-3.0/ folder. In particular, colors are using custom color definitions in CSS files and windows decorations are synced via window manager rendered images and CSS files. Flatpak applications seem to ignore files in this directory.

Under flatpak, $XDG_CONFIG_HOME is ~/.var/app/org.some.App/config.

@eszlari
Copy link

eszlari commented Oct 13, 2020

I tested this with XFCE and https://flathub.org/apps/details/org.gnome.gedit, changing the appearance on the fly works. XFCE doesn't need to read .config/gtk-3.0/ for this (blocked with flatpak run --nofilesystem=host org.gnome.gedit).

@gikari
Copy link
Author

gikari commented Oct 13, 2020

Under flatpak, $XDG_CONFIG_HOME is ~/.var/app/org.some.App/config.

That means, that we should place configs (or symlinks to gtk-3.0 folder?) in every application folder. That's very inconvenient, maybe there is another way?

@eszlari
Copy link

eszlari commented Oct 13, 2020

That means, that we should place configs (or symlinks to gtk-3.0 folder?) in every application folder. That's very inconvenient, maybe there is another way?

As I wrote above: I tested this under XFCE (4.14) with org.gnome.gedit and both ~/.config/gtk-3.0 and ~/.var/app/org.gnome.gedit/config/gtk-3.0 are empty and it still works.

Maybe you can find inspiration in: https://gitlab.xfce.org/xfce/xfconf

@gikari
Copy link
Author

gikari commented Oct 13, 2020

As I wrote above: I tested this under XFCE (4.14) with org.gnome.gedit and both ~/.config/gtk-3.0 and ~/.var/app/org.gnome.gedit/config/gtk-3.0 are empty and it still works.

Yes, theme changing does indeed work, if the themes are separate packages (for example changing from Breeze to Adwaita), however, my issue was about custom CSS, placed in ~/.config/gtk-3.0 folder. If you place custom CSS in that folder and then relaunch flatpak GTK application, the GTK application won't use that CSS.

@TomaszGasior
Copy link

Use sudo flatpak override --filesystem=xdg-config/gtk-3.0.

@gikari
Copy link
Author

gikari commented Oct 18, 2020

Use sudo flatpak override --filesystem=xdg-config/gtk-3.0.

This seems to be working. Could we have this and xdg-config/gtk-4.0 permissions by default?

@eszlari
Copy link

eszlari commented Oct 19, 2020

This seems to be working. Could we have this and xdg-config/gtk-4.0 permissions by default?

You would have to ask for it to be added to the freedesktop runtime (which also the GNOME and KDE runtimes are based on):

https://gitlab.com/freedesktop-sdk/freedesktop-sdk

@gikari
Copy link
Author

gikari commented Dec 22, 2020

This seems to be working. Could we have this and xdg-config/gtk-4.0 permissions by default?

You would have to ask for it to be added to the freedesktop runtime (which also the GNOME and KDE runtimes are based on):

https://gitlab.com/freedesktop-sdk/freedesktop-sdk

Since the addition of xdg-config/gtk-3.0 for available directories is GTK specific, wouldn't it be more correct to add it to GTK Sdk, which is used by GTK applications?

@eszlari
Copy link

eszlari commented Dec 22, 2020

The Gtk version that is used for every flatpak app is maintained by the freedesktop runtime:
https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/blob/release/20.08/elements/components/gtk3.bst

@gikari
Copy link
Author

gikari commented Dec 23, 2020

The Gtk version that is used for every flatpak app is maintained by the freedesktop runtime:
https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/blob/release/20.08/elements/components/gtk3.bst

But how does that relates to the choice of where to propose the default filesystem permission?

@eszlari
Copy link

eszlari commented Dec 23, 2020

By default, a flatpak app has only read/write access to ~/.var/app/$APP_ID. For safe access to the rest of the system, an app should ideally make use of portals: https://docs.flatpak.org/en/latest/sandbox-permissions.html#portals

If portals are not supported or can't be used, the --filesystem option can be set either:

  1. by the user
  2. in the app manifest
  3. in the runtime manifest

@gikari
Copy link
Author

gikari commented Dec 23, 2020

3. in the runtime manifest

I understand, but we have two runtimes: GNOME/GTK and FreeDesktop one. Since gtk-3.0 folder is used only by GTK apps, that use GTK runtime, wouldn't it be reasonable to propose default filesystem permission only for GNOME/GTK runtime?

@eszlari
Copy link

eszlari commented Dec 23, 2020

Both, the GNOME and the KDE runtime, are based on the freedesktop runtime and inherit its permissions.

@Bleuzen
Copy link

Bleuzen commented Dec 26, 2021

You would have to ask for it to be added to the freedesktop runtime (which also the GNOME and KDE runtimes are based on):

I created this:
https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/issues/1362

@Bleuzen
Copy link

Bleuzen commented Dec 26, 2021

As one commented over on freedesktop-sdk gitlab, setting permissions on runtime seems not possible as of now, so created this:
#4633

@MohammedMehdiTBER
Copy link

Use sudo flatpak override --filesystem=xdg-config/gtk-3.0.

It worked almost perfectly for me; it didn't override the default Windows decorations, and there is still the Breeze windows decoration.

@Flashwalker
Copy link

Flashwalker commented Mar 5, 2023

Run:

flatpak -u override --filesystem=xdg-config/gtk-3.0
flatpak -u override --filesystem=xdg-config/gtk-4.0

user_confdir="${XDG_CONFIG_HOME:-$HOME/.config}"
for dir in ${HOME}/.var/app/*; do
    flat_confdir3="${dir}/config/gtk-3.0"
    flat_confdir4="${dir}/config/gtk-4.0"
    mkdir -p "$flat_confdir3"
    mkdir -p "$flat_confdir4"

    ln -s "${user_confdir}/gtk-3.0/settings.ini" "${flat_confdir3}"/
    ln -s "${user_confdir}/gtk-3.0/gtk.css" "${flat_confdir3}"/
    ln -s "${user_confdir}/gtk-4.0/settings.ini" "${flat_confdir4}"/
    ln -s "${user_confdir}/gtk-4.0/gtk.css" "${flat_confdir4}"/
done

also for prefer dark theme:

for dir in ${HOME}/.var/app/*; do flatpak run --command=bash<<<"gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'" "${dir##*/}"; done

@RokeJulianLockhart
Copy link

RokeJulianLockhart commented May 1, 2023

#3901 (comment)

@Flashwalker, could you comment your code at all? I'm hesitant to run what I don't particularly understand.

@rusty-snake
Copy link

If you do not understand the code, how can you trust the comment?

@RokeJulianLockhart
Copy link

RokeJulianLockhart commented May 1, 2023

#3901 (comment)

@rusty-snake, because it gives me a much better starting-point to understanding.

@Flashwalker
Copy link

Flashwalker commented May 1, 2023

@Flashwalker, could you comment your code at all? I'm hesitant to run what I don't particularly understand.

@RokeJulianLockhart

First code block just makes symlinks to yours ~/.config/gtk-3.0/settings.ini and ~/.config/gtk-4.0/settings.ini and ~/gtk-3.0/.config/gtk.css and ~/gtk-4.0/.config/gtk.css files
to Flatpak's sandboxed folders in ~/.var/app/ for all your installed Flatpak apps.

Second code block just toggle the prefer-dark for all your installed Flatpak apps in Flatpak's sandboxed dconf registry.

But it will probably be quite enough for you to:
flatpak -u override --filesystem=xdg-config/gtk-3.0
and
flatpak -u override --filesystem=xdg-config/gtk-4.0
it tells to Flatpak to prefer your settings in ~/.config/gtk-3.0 and ~/.config/gtk-4.0 folders

@SteavenGamerYT
Copy link

doesnt work

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

No branches or pull requests

9 participants