Hi,
I’m trying to make some routines to get style definition from Gtk/Gnmoe to apply more or less the same theme to an app that is built with Fyne.io (Golang).
To be clear, I know that GTK4 now uses a purely CSS-made theme and I had a long discussion on Mastodon where someone explained to me that GTK4 has no “color” definition.
So I will try to explain what’s the problem and what is missing to help whatever the outside library we can use to be well integrated in Gnome. And maybe you will provide me with some track or solution.
Before, with GTK3, I only called this GJS script from my app to get some information:
imports.gi.versions.Gtk = "3.0";
const Gtk = imports.gi.Gtk;
Gtk.init(null);
// create a simple window
let window = new Gtk.Window({
title: "Hello World",
default_width: 200,
default_height: 200,
});
// get the background color of the window
let bg = window
.get_style_context()
.get_background_color(Gtk.STATE_FLAG_NORMAL)
.to_string();
print(bg);
This worked because there was only basic color in GTK3. I only had to parse the rgba string and I could then apply the same colors (background, foreground) to the current app made with in Fyne.
But, GTK4 is born… and everything is now, more than complex, impossible to use like this.
imports.gi.versions.Gtk = "4.0";
const Gtk = imports.gi.Gtk;
Gtk.init();
// create a simple window
let window = new Gtk.Window({
title: "Hello World",
default_width: 200,
default_height: 200,
});
// get the background color of the window
let [ok, bg] = window.get_style_context().lookup_color("theme_bg_color");
print(`rgb(${bg.red * 255}, ${bg.green * 255}, ${bg.blue * 255})`);
The given color is absolutely not the one used by the displayed window. It’s a black (very dark grey) color that returns this call, while the Gnome theme uses “Nord” as background (rgb(59,66,82)
) -
GTK3 was OK, not GTK4.
Of course, maybe the theme declares other overridden colors, or maybe it doesn’t declare the Adw color. But, the window in GTK4 uses the right background, when I really display it, the theme is well applied. So, what’s the deal to get this applied color/background ?
Today, with GTK4, I’m simply in the impossibility to get at least a few pieces of information from a very tiny standard window… More become less…
Is there a way to get the background definition of a simple window that is created with Gtk.Window
?
Of course, the easiest thing would be to have a CSS selector like window.get_theme_css()
as a string