flatpak-platform
flatpak-platform copied to clipboard
Remove the gtk-theme extension
I'm told we should delete this
https://github.com/elementary/flatpak-platform/blob/da803d9eb6a451c224dea50a161ea0e86599ac08/io.elementary.Sdk.json.in#L9-L11
according to @alatiera
Basically the reasoning for this is that elementary apps will only be/depending on the elementary style sheet which should be hardcoded to be the default rather than bringing in all the "theming" machinery of flatpak.
So, it's needed to install the settings overrides to runtime? But if the user have adwaita has host theme the platform theme get overridden because adwaita comes with the gnome SDK that used to build the platform.
Yes, for some reason it seems like gtk is trying to set the same stylesheet as the host is running and it doesn't respect gsettings defaults/locks inside the runtime either. I tried to debug this a while ago but it didn't seem to work.
https://github.com/alatiera/flatpak-platform/commit/cf8992f1352505ad25153de19a5e21147513bace
diff --git a/defaults.ini b/defaults.ini
new file mode 100644
index 0000000..67b3e6d
--- /dev/null
+++ b/defaults.ini
@@ -0,0 +1,4 @@
+[org.gnome.desktop.interface]
+gtk-theme='elementary'
+icon-theme='elementary'
+cursor-theme='elementary'
diff --git a/io.elementary.Sdk.json.in b/io.elementary.Sdk.json.in
index 20bae57..ce0b776 100644
--- a/io.elementary.Sdk.json.in
+++ b/io.elementary.Sdk.json.in
@@ -6,9 +6,6 @@
"runtime-version": "@GNOME_VERSION@",
"runtime": "org.gnome.Platform",
"sdk": "org.gnome.Sdk",
- "inherit-extensions": [
- "org.gtk.Gtk3theme"
- ],
"sdk-extensions": ["org.gnome.Sdk.Debug", "org.gnome.Sdk.Locale", "org.gnome.Sdk.Docs"],
"platform-extensions": [ "org.gnome.Platform.Locale"],
"finish-args": [
@@ -109,6 +106,19 @@
]
}
]
+ },
+ { "name" : "defaults",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "mkdir -p /usr/etc/glib-2.0/settings/",
+ "install -m644 -pD defaults.ini /usr/etc/glib-2.0/settings/defaults"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "path" : "defaults.ini"
+ }
+ ]
}
]
}
The only way that i can lock the theme is passing --env=GTK_THEME=elementary. but with the new stylesheet we have actually 10 themes(20 with the dark variants) instead of one.
Looking in manifest of appcenters apps in flathub. they define the theme applying a patch inside the app. maybe do the same but only if the theme is not "elementary"? the same can be applied to icons.
Thinking about this issue lately, flatpak, on X11, uses the selected system xsettings to set the theme, and if the theme don't exist in the sandbox it will use Adwaita (what is the same thing that happens if the same occurs in the system).
One solution can be patching Gtk to if they can't find the selected theme, define the gschema defined default and, if it don't exist, define Adwaita.
Another solution can be use the Gtk.Settings.set () in the application, but it lock the same in that theme, so it will need to add a signal for the colors changes, and make it reachable inside the flatpak (Using notify () in the gtk_theme property don't worked for me), so applications can make the change too.
Gave this another try using gschema overrides this time.
https://github.com/alatiera/flatpak-platform/commit/80fc7c344a0bfaccdf76408a9aaefb9bebeb679d
diff --git defaults.ini defaults.ini
new file mode 100644
index 0000000..67b3e6d
--- /dev/null
+++ defaults.ini
@@ -0,0 +1,4 @@
+[org.gnome.desktop.interface]
+gtk-theme='elementary'
+icon-theme='elementary'
+cursor-theme='elementary'
diff --git io.elementary.Sdk.json.in io.elementary.Sdk.json.in
index 8a9abdd..be815fc 100644
--- io.elementary.Sdk.json.in
+++ io.elementary.Sdk.json.in
@@ -119,6 +119,20 @@
]
}
]
+ },
+ { "name" : "defaults",
+ "buildsystem" : "simple",
+ "build-commands" : [
+ "mkdir -p /usr/share/glib-2.0/schemas/",
+ "install -m644 -pD defaults.ini /usr/share/glib-2.0/schemas/org.gnome.desktop.interface.gschema.override",
+ "glib-compile-schemas /usr/share/glib-2.0/schemas/"
+ ],
+ "sources" : [
+ {
+ "type" : "file",
+ "path" : "defaults.ini"
+ }
+ ]
}
]
}
This works as expected when invoking gsettings from the cli, but when launching the app and going through the portal it seems like the Settings portal takes precedence over it or overrides it. This results in inheriting the host .desktop.interface which might not be a bad thing after all.
➜ dippi git:(flatpak-manifest) ✗ flatpak run --command=sh com.github.cassidyjames.dippi
[📦 com.github.cassidyjames.dippi ~]$ gsettings get org.gnome.desktop.interface gtk-theme
'elementary'
[📦 com.github.cassidyjames.dippi ~]$ gsettings get org.gnome.desktop.interface icon-theme
'elementary'

Given that we ain't going to get a stylesheet api on gtk itself anytime soon it might be fine to move all the stylesheet code to Granite Application or such.
On ElementaryOS its going to inherit the host theme name and be able to use the color variants, and if it doesn't much it could default to hardcoding the default elementary stylesheet. (Should also hardcode the icon theme to be elementary regardless as we don't seem to have a way to fix that, unless we patch gtk in the runtime).
so, i made a similar service like the pefers dark, and it's work.


like the prefers dark, the app need to listen to the interface
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();
gtk_settings.gtk_theme_name = "io.elementary.stylesheet." + granite_settings.accent_color;
granite_settings.notify["accent-color"].connect (() => {
gtk_settings.gtk_theme_name = "io.elementary.stylesheet." + granite_settings.accent_color;
});
and in the app manifest:
finish-args:
...
- '--system-talk-name=org.freedesktop.Accounts'