From 4e83c39a9ca00a3cd8fea56e45a028f7290a3a7b Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 17 Apr 2018 12:36:00 +1200 Subject: [PATCH] Prefer the dark theme if it successfully darkened the textview. Or rather brightened the text. 11min. --- src/window.vala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/window.vala b/src/window.vala index c5eea4b..a3a6bfc 100644 --- a/src/window.vala +++ b/src/window.vala @@ -47,7 +47,13 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow { var css = ""; if (dark_mode) { - css = "* {background: black; color: white;}"; + // Try to detect whether the system provided a better dark mode. + var text_color = styles.get_color(Gtk.StateFlags.ACTIVE); + double h, s, v; + Gtk.rgb_to_hsv(text_color.red, text_color.green, text_color.blue, + out h, out s, out v); + + if (v < 0.5) css = "* {background: black; color: white;}"; } cur_styles = new Gtk.CssProvider(); cur_styles.load_from_data(css);