Re: Detect dark or light theme from an application

2018-11-06 Thread Emmanuele Bassi via gtk-app-devel-list
On Wed, 7 Nov 2018 at 00:48, Yuri Khan via gtk-app-devel-list <
gtk-app-devel-list@gnome.org> wrote:

> Hello everybody,
>
> I know in the GTK+3 theming engine a theme can define a light variant
> and a dark variant. Is it possible, in an application, to know which
> variant is currently used, and/or specify which widget in the
> application uses which variant?
>

No.

"Variants" are really only used by applications themselves, i.e. your
application explicitly says that it prefers a dark variant of the current
theme, if it's available. This is opt-in from the application perspective,
though of course themes may not have a dark variant.

User options do not change the theme variant: they change the theme; in
other words, if a user decides to enable a dark theme globally, they will
enable a dark theme, not the dark variant of the current theme.

The only way to respect the GTK theme is to use GTK to render UI elements
according to that theme—using the `gtk_render_*` API. Anything else is, by
and large, impossible unless you literally parse the CSS with your own CSS
parser, determine the colours of every UI element you care about, and then
detect whether those colours are "light" or "dark".

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Detect dark or light theme from an application

2018-11-06 Thread Yuri Khan via gtk-app-devel-list
Hello everybody,

I know in the GTK+3 theming engine a theme can define a light variant
and a dark variant. Is it possible, in an application, to know which
variant is currently used, and/or specify which widget in the
application uses which variant?

Here’s the wider context: Mozilla Firefox uses GTK+3 for some of its
widgets. However, lately, there is a push for custom widgets, on the
grounds that GTK widgets cause problems for the users.

A couple examples:

* The user has a dark theme, which means normal input boxes use light
text on dark background. Suppose that input box is used on a web page
developed by an ignorant person who has never seen a dark theme, and
has specified a dark text color for the input box, without also
specifying a background. Now the user cannot see the text. One
workaround often suggested in the bug tracker is to always run Firefox
with a light theme variant, but a better solution would be to force
light theme inputs in web pages, at least until much of the Web
catches on to dark themes.

* Firefox has Developer Tools, which allow the user to choose a light
or a dark theme. This poses a problem: If the user has a light GTK
theme but selects the dark DevTools theme, the GTK scrollbar would
clash with the overall DevTools UI. Same thing happens in the reverse
situation. Here is an example:
https://bug1471163.bmoattachments.org/attachment.cgi?id=901
[disclaimer: I do not know what that theme is.] This has led Firefox
to develop a substitute scroll bar, which is inferior to the GTK
scroll bar in every way except the ability to control its colors from
the application. In the 64 Nightly version, in place of a scrollbar,
Firefox DevTools display a flat rectangular gray thumb in a flat
rectangular other-shade-of-gray trough.

What would be the Correct Way to solve these problems, from a GTK
developer’s point of view? (Except the obvious “Use GTK widgets as
much as possible, and never allow web content to override GTK widgets’
colors”; that’s not gonna fly for political reasons.)
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list