[Linux] Fallback to Adwaita light Gtk theme when system uses dark theme

NEW
Assigned to

Status

()

defect
P2
normal
3 months ago
9 days ago

People

(Reporter: asdfghrbljzmkd, Assigned: stransky)

Tracking

67 Branch
Points:
---

Firefox Tracking Flags

(firefox66 wontfix, firefox67 affected, firefox68 affected)

Details

Attachments

(2 attachments)

Reporter

Description

3 months ago

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0

Steps to reproduce:

Go to web pages with input boxes with a dark GTK theme set

Actual results:

Input boxes look weird

Expected results:

Input boxes look normal

This is a known issue. The solution is to set widget.content.gtk-theme-override to Adwaita by default. This report is specifically about setting this pref by default. Adwaita will always be present on systems with GTK+, which is already required by Firefox, so this change should have no chance of breaking things. https://bugzilla.mozilla.org/show_bug.cgi?id=1411425 is the real fix, this is just a stop-gap measure.

Component: Untriaged → Widget: Gtk
Product: Firefox → Core

Perhaps a slightly less dramatic version would be to change any theme name ending in ":dark" into the equivalent ending in ":light"... although I'm not sure how safe that is.

Assignee

Comment 3

26 days ago

I'm going to support that if we enable it only when:

  • dark theme is used by system wide
  • light variant of the theme is not available

that needs some tests at browser start but generally looks doable to me. Karl, do you think it's such solution suitable?

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(karlt)
Priority: -- → P2
Assignee

Comment 4

26 days ago

btw. it also expects that widget.content.gtk-theme-override is empty.

That sounds good to me if you can see or find a good way to do that.

When I wrote https://bugzilla.mozilla.org/show_bug.cgi?id=1461538#c9, I couldn't see an easy way to determine whether a light variant was available.

Flags: needinfo?(karlt)
Assignee

Comment 6

19 days ago

(In reply to Karl Tomlinson (:karlt) from comment #5)

That sounds good to me if you can see or find a good way to do that.

When I wrote https://bugzilla.mozilla.org/show_bug.cgi?id=1461538#c9, I
couldn't see an easy way to determine whether a light variant was available.

We should avoid themes with white text on black background. That causes black control elements which stands up from the web page. And when the page defines custom color of input elements (usually light) it leads to white-on-white scenario.

I think we can calculate saturation/lightness values and define a range of accepted text/background colors. IMHO we generally want light background with dark text and the color itself is not so important.

Assignee

Comment 7

19 days ago

We may also need to test it with some popular Gtk themes like Adwaita dark, Arc, Yaru.

Assignee

Comment 8

19 days ago

We recently disable system dark themes for Firefox chrome and content by gtk-application-prefer-dark-theme settings.
That option is no longer prefered by gnome project and was removed from tweaks tools. Theme makers are encouraged to use
a different name for the dark theme variants, like Adwaita-dark, Yaru-dark and so on. This option also does not
work when the Gtk theme si missing the light variant completelly.

To address that this patch implements a heuristicts based on https://www.w3.org/TR/AERT/#color-contrast
to check if the recent system Gtk theme has good contrast/visibility with default HTML colors
(white background and black text).

If the system theme fails the test we try to check and set gtk-application-prefer-dark-theme to false. If that also
fails we use Gtk theme defined by widget.content.gtk-theme-override for content. If widget.content.gtk-theme-override
is empty Adwaita:light theme is used.

This Gtk theme automation can be disabled by widget.content.gtk-dark-theme-autodetection preference. When set to false
the old widget.content.allow-gtk-dark-theme, widget.chrome.allow-gtk-dark-theme and widget.content.gtk-theme-override
work as before this patch.

This patch was tested with some distro default light themes (Ambiance, Radiance, Yaru - Ubuntu, Arc - KDE, Menta - MATE)
and dark/light themes are recognized correctly.

Assignee

Updated

19 days ago
Summary: Set widget.content.gtk-theme-override to Adwaita by default to work around dark theme issues → [Linux] Fallback to Adwaita light Gtk theme when system uses dark theme
Assignee

Updated

19 days ago
Duplicate of this bug: 1466131
Assignee

Comment 11

16 days ago

A follow up bug may be to detect the theme and try a light variant of it. Gnome-tweks does pain directory scan to get all installed themes:

valid = ['Adwaita', 'HighContrast', 'HighContrastInverse']
valid += walk_directories(get_resource_dirs("themes"), lambda d:
os.path.exists(os.path.join(d, "gtk-3.0", "gtk.css")) or
os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver))))

and if a theme with "-dark" suffix is active we can try to set a theme without it, like Yaru-dark -> Yaru, Adwaita-dark -> Adwaita and so on.

Assignee

Updated

9 days ago
Assignee: nobody → stransky

Use standard Gtk/Gnome way to set Firefox Gtk theme. Gtk theme of web content can be still configured
by widget.content.allow-gtk-dark-theme and widget.content.gtk-theme-override.

Depends on D29823

You need to log in before you can comment on or make changes to this bug.