Suivre

I am extremely annoyed to realize that it is IMPOSSIBLE to find the basic colors of the interface in v4.

Because yes, I use GTK V3 in to output this information. It's the only viable way. But Gtk V4 has removed the access to the context. That's crazy.

So if you want to make a background and text color retrieval routine to help a graphic library adapt to the user's theme: you're screwed.

And yes. can use others colors than GTK theme. But in facts, themes provides the adapted colors for GTK. So, I will use gtk3 context for a while, then my code will be broken...

And if you're not aware about the problem, there are plenty of developers who ask this on StackOverflow, reddit... The general answer is "we changed this because we do better things now". Better ? That was a pain to find colors, now it's impossible!

@metal3d the default GTK4 theme does not provide any source of stability for the colors, mostly because it never did, not even in GTK2 or GTK3; libadwaita, on the other hand, does: gnome.pages.gitlab.gnome.org/l

@metal3d but if you want to *draw* with CSS colors, then you need to use the gtk_render_* API in GTK3, and the GtkSnapshot API in GTK4. That has been the case since GTK 3.0. The old "ask the style machinery for a color" made sense in GTK2, where you only had colors. With the introduction of CSS, you can have gradients, textures, blended layers, or (most likely) a transparent value. There is no "color" to be queried in many cases.

@metal3d It's not a case of being "better" or "worse" (though CSS allows us to do better rendering without loading shared modules that literally put pixels inside widgets, like GTK2 engines did); it's a case of being an entirely different API.

@ebassi that's not to draw on GTK. That's to get the theme generic colors (background and foreground) to color an app using another library (fyne.io).
There is no dark/light information on gnome and nothing to get the theme base colors.
Actually I call some gjs command to get a invisible one shot window color from get_context() method. Grk4 abandoned this.

@ebassi that's something that I don't understand... OK, css is cool to make whatever we want for themes. But there are at least 2 needed information, the "dakmrk/light" switch and "foreground/background" colors. That's anormal to have to call GJS (or python) from another language/lib to find this. And anormal that now it's impossible to get these information.

@ebassi sorry for my English and sorry if I'm a bit annoyed but I spent hours to read documentation about GTK 4 to finally realize that I will not be able to continue my idea...

@metal3d I understand the annoyance, but really: what you want to achieve was never supported in 20+ years, and it's not really supportable programmatically.

At most, you can emulate the appearances of libadwaita by looking at the generated CSS, and by using the documentation; for anything else, you'll have to use the good old Eyeball Mk 1, or the GTK inspector, and then emulate the result.

@ebassi the goal is to be able, from fyne app (in go) to get information about the current gnome theme colors. Not to get the Css file or attributes with inspector to create the theme by hand.

@ebassi as the fyne app is absolutely cross platform (even with android) and statically compiled, I need a way, even by command line, to get at least the 2 majors colors. GJS was enough (with get_context().get_background_color()) with a fake window. That was really enough even if it's not very efficient.

@ebassi note that fyne apps has this problem only on Linux... Windows, osx, Android and iOS gives at least the dark/light information.

@ebassi just in case, keep in mind that I love Gnome and I'm an happy user.
I will try to use libawaita to see what it provides. Thanks

@metal3d at most you can use get_context().lookup_color("window_bg_color"), but that requires libadwaita.

Same if you want the light/dark information: you need libadwaita or libhandy, or you need to watch the system setting yourself—GTK by itself does not have a light/dark default theme.

@ebassi the goal is to "try" to get these information. If it fails I will use default colors of fyne.io API. If it works for "most people" installation... Maybe it can be enough...
But really, to help other graphic lib, getting a few color information from outside is very important.

@metal3d Again: there is no color. For instance, what's the color of this background? And if you think: "that's a special case", the background of a window can be a combination of gradients, or a repeating texture, in any theme. The only way to give you this information would literally be to expose the CSS state as public API, which is, sadly, entirely unsustainable. We're not Google, Microsoft, or Apple.

@ebassi if the window element declares a "color" so I want to get it, either I've got an empty string and that's not a problem. I only need to get it, empty or not

@ebassi That's why get_style_context() was cool, I don't mind if the theme doesn't give a color, I just want to check it

@ebassi get_context isn't implemented in grk4. You said that I can use it with libawaita but... I don't find how at this time

@metal3d I have no idea what's "grk4", but in GTK4 you still have access to the GtkStyleContext of a GtkWidget: docs.gtk.org/gtk4/method.Widge

Then you can use GtkStyleContext.lookup_color() with a named color: docs.gtk.org/gtk4/method.Style

The named colors are documented in libadwaita: gnome.pages.gitlab.gnome.org/l

@ebassi that returns default colors, not the colors that are defined in the currently used theme.
That was OK with GTK3 - a pitty

@metal3d There's no such thing as a "default color". Those colors are the ones currently used by libadwaita, if you use the names defined by libadwaita. Otherwise you need to know the names defined by the Default theme; the Default GTK theme is not API. Of course, any other theme can define its own colors.

At this point, I have *no idea* what you're expecting. Instead of using Masto, you may want to use Discourse: discourse.gnome.org/tag/gtk

@ebassi i only expect to be able to get the default font color and whatever I can get for the background of a basic window (the Css would be OK. The Css as string is enough) from a basic GTK.window. This to automatically replicate enough of the style to an app style which is not built in gtk.

@ebassi to give some news. I finally found my way with lookup_color and lookup_icon based on adwaita names. There is no clear documentation but I now can apply a bit of styling from the current Gtk theme on Fyne apps.

@ebassi (no clear documentation about icon names. For colors it's very well documented)

@metal3d Yeah, that doesn't work in GTK3 already, and won't ever work in GTK4. You either draw with GTK, or you hard code the colors you want to use. You simply can't extricate the entire CSS machinery out of GTK without breaking GTK, or making it impossible to maintain. Sorry, but that's how we can keep working on GTK with zero people full time on it.

@metal3d There's nothing really "normal" or "abnormal": there has never been any API to let you discover the colors used by GNOME/GTK applications from the outside of a GTK application.

@ebassi I feel it abnormal to not help any other library to integrate on the desktop by sharing at least some color informations.

@metal3d It was already impossible to support in GTK3, the old "give me a color" API was mostly an early migration API for applications porting from GTK2.

If you want the light/dark theme colors, then you want libadwaita's named colors from the documentation, no need to use any API.

Inscrivez-vous pour prendre part à la conversation
techlover

Technology lovers, here we are — (development, digital artwork, science…)