1/*
2 *
3 * Copyright (C) 2018 - Jente Hidskes <hjdskes@gmail.com>
4 *
5 * gitg is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * gitg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with gitg. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19namespace Gitg
20{
21
22public class Theme : Gtk.Widget
23{
24	private static GLib.Once<Theme> _instance;
25
26	public static unowned Theme instance ()
27	{
28		return _instance.once (() => { return new Theme (); });
29	}
30
31	public bool is_theme_dark()
32	{
33		var settings = Gtk.Settings.get_default();
34		var theme = Environment.get_variable("GTK_THEME");
35
36		var dark = settings.gtk_application_prefer_dark_theme || (theme != null && theme.has_suffix(":dark"));
37
38		if (!dark) {
39			var stylecontext = get_style_context();
40			Gdk.RGBA rgba;
41			var background_set = stylecontext.lookup_color("theme_bg_color", out rgba);
42
43			if (background_set && rgba.red + rgba.green + rgba.blue < 1.0)
44			{
45				dark = true;
46			}
47		}
48
49		return dark;
50	}
51}
52
53}
54
55// ex:ts=4 noet
56