Detect dark or light theme from an application



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=9014444
[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.)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]