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

Documentation request: how to use current system accent colour in custom components? #118

Open
aral opened this issue Aug 17, 2021 · 5 comments

Comments

@aral
Copy link
Contributor

aral commented Aug 17, 2021

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())

@aral aral changed the title Documentation: how to use the chosen accent colour to use in custom components? Documentation: how to use current system accent colour in custom components? Aug 17, 2021
@aral aral changed the title Documentation: how to use current system accent colour in custom components? Documentation request: how to use current system accent colour in custom components? Aug 17, 2021
@danirabbit
Copy link
Member

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

@davidmhewitt
Copy link
Member

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.

@aral
Copy link
Contributor Author

aral commented Aug 17, 2021

@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) :)

@aral
Copy link
Contributor Author

aral commented Aug 17, 2021

@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 :)

@BAProductions
Copy link

Gala

Im wondering to how one would to such a thing

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

4 participants