5

Is there a setting that can be read / polled to determine if the global Ubuntu dark mode is enabled or not by the user. I’m writing an app and would like to honour the user’s preference for my UI.

  • 1
    shell theme or GTK theme? you mean this https://i.stack.imgur.com/5DYKM.jpg ? – PRATAP Jul 23 '20 at 11:25
  • 2
    gsettings get org.gnome.desktop.interface gtk-theme if this returns 'Yaru-dark' then it is dark mode.. – PRATAP Jul 23 '20 at 11:30
  • Is it convention to suffix -dark to dark themes? I see the same seems to be true for Adwaita. – Garry Pettet Jul 23 '20 at 12:43
  • 1
    If user install his one themes.. then it is not possible to know.. In your case if u assume user uses system default dark themes then it is possible to detect other wise any name can have any type of theme.. – PRATAP Jul 23 '20 at 12:53
  • 1
    no.. that is not necessarily suffix -dark. It can be any name.. – PRATAP Jul 23 '20 at 13:11

1 Answers1

0

This is not a fancy solution, but you can read the font color css value of e.g. some label. For dark themes this will (probably) be white(ish) and otherwise black. Same should be possible for backgroud-color and so on.

Python example:

tmp = self.label.get_style_context().get_color(Gtk.StateFlags.NORMAL)
textcolor = (tmp.red, tmp.green, tmp.blue, tmp.alpha)

Style Context docs

jl005
  • 173