Documentation request: how to use current system accent colour in custom components?
Problem
The documentation page on colour scheme doesn’t currently have information on how to make use of the person’s chosen access colour.
Proposal
Add documentation on how to use accent colours to the colour scheme page.
Prior Art
n/a
What led to this request
I’m trying to get the colour set as the system accent colour to use in a gala plugin.
I tried accessing it via Granite.Settings but I get:
/home/aral/Projects/other/gala-alt-tab-plus/src/Main.vala:72.33-72.69: error: The name `prefers_accent_color' does not exist in the context of `Granite.Settings' (granite)
var accent_colour = granite_settings.prefers_accent_color;
(granite_settings is Granite.Settings.get_default())
This seems specific to Gala, so probably not something that really fits in the docs for app developers. For GTK apps, accent colors "just work"
Since Gala doesn't use GTK, it relies on the foreign drawing API to get accent color information. There's a utility function to get a Gdk.RGBA for this here: https://github.com/elementary/gala/blob/87d51c50fbd5a28d2d0d6c3872b4e15e39c9131a/src/InternalUtils.vala#L344
There's also the case of needing to build a custom widget for something. I was having a play around with something where I wanted to draw an audio waveform derived from a GTK DrawingArea recently, and found it was a nice touch to draw it in the user's accent colour. So that's at least a use case outside of Gala.
@danrabbit Thanks for the link, will check it out. Also, regarding the non-Gala use case, what @davidmhewitt said (that’s why I specifically put “in custom components” in the title, as I could see myself wanting to do just that outside of my current use case) :)
@danrabbit It looks like I can’t access InternalUtils although it looks like a public class and the method looks like public static method. I’m getting:
The name `InternalUtils' does not exist in the context of `Gala'
var theme_accent_colour = new Granite.Drawing.Color.from_rgba(Gala.InternalUtils.get_theme_accent_color());
(Assuming it’s somehow otherwise hidden. Would make sense for a class called InternalUtils, I guess.)
Anyway, I’m way out of my depth here. Will probably have to return to this once I have time to really dig into Vala and platform internals :)
Gala
Im wondering to how one would to such a thing