From 6b4fd4ebc58919866e27204306550199ba9a71fe Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 20:41:53 -0600 Subject: [PATCH 01/10] Utils: add use_elementary_style () --- lib/Widgets/Utils.vala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index d0771a2ab..86f23ea0b 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -290,6 +290,26 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { return fg_color; } +/** + * Sets the app's icon theme and stylesheet to elementary defaults. Optionally takes a specific stylesheet accent variant as a string. + * + * @param accent optional stylesheet accent variant to use, e.g. "blueberry" + */ +public void use_elementary_style (string? accent = "blueberry") { + const string STYLESHEET_PREFIX = "io.elementary.stylesheet."; + var gtk_settings = Gtk.Settings.get_default (); + var current_stylesheet = gtk_settings.gtk_theme_name; + + gtk_settings.gtk_icon_theme_name = "elementary"; + + if ( + !current_stylesheet.has_prefix (STYLESHEET_PREFIX) || + current_stylesheet.replace (STYLESHEET_PREFIX, "") != accent + ) { + gtk_settings.gtk_theme_name = STYLESHEET_PREFIX + accent; + } +} + } /** From 70557a899f56998a24c889442c5f9470cee746c3 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 20:52:19 -0600 Subject: [PATCH 02/10] =?UTF-8?q?Utils:=20use=20=E2=86=92=20force?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Widgets/Utils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 86f23ea0b..dffe5dc76 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -295,7 +295,7 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { * * @param accent optional stylesheet accent variant to use, e.g. "blueberry" */ -public void use_elementary_style (string? accent = "blueberry") { +public void force_elementary_style (string? accent = "blueberry") { const string STYLESHEET_PREFIX = "io.elementary.stylesheet."; var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; From 5524c57c45de70fedb963000388c8578835b45f2 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 22:10:11 -0600 Subject: [PATCH 03/10] Make accent optional but not nullable --- lib/Widgets/Utils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index dffe5dc76..18e43e47e 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -295,7 +295,7 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { * * @param accent optional stylesheet accent variant to use, e.g. "blueberry" */ -public void force_elementary_style (string? accent = "blueberry") { +public void force_elementary_style (string accent = "blueberry") { const string STYLESHEET_PREFIX = "io.elementary.stylesheet."; var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; From 012b5a0a3c08d1c6e76d15cc93ec635b384a4654 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 22:27:28 -0600 Subject: [PATCH 04/10] Simplify force_elementary_style () for now --- lib/Widgets/Utils.vala | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 18e43e47e..195363033 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -291,22 +291,18 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { } /** - * Sets the app's icon theme and stylesheet to elementary defaults. Optionally takes a specific stylesheet accent variant as a string. - * - * @param accent optional stylesheet accent variant to use, e.g. "blueberry" + * Sets the app's icon theme and stylesheet to elementary defaults. */ -public void force_elementary_style (string accent = "blueberry") { +public void force_elementary_style () { const string STYLESHEET_PREFIX = "io.elementary.stylesheet."; + var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; gtk_settings.gtk_icon_theme_name = "elementary"; - if ( - !current_stylesheet.has_prefix (STYLESHEET_PREFIX) || - current_stylesheet.replace (STYLESHEET_PREFIX, "") != accent - ) { - gtk_settings.gtk_theme_name = STYLESHEET_PREFIX + accent; + if (!current_stylesheet.has_prefix (STYLESHEET_PREFIX)) { + gtk_settings.gtk_theme_name = STYLESHEET_PREFIX + "blueberry"; } } From b05bbff63c7a0759ef46bbebf12fbf7d09603611 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 22:32:16 -0600 Subject: [PATCH 05/10] Use string.join --- lib/Widgets/Utils.vala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 195363033..ed4605fd3 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -294,7 +294,8 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { * Sets the app's icon theme and stylesheet to elementary defaults. */ public void force_elementary_style () { - const string STYLESHEET_PREFIX = "io.elementary.stylesheet."; + const string STYLESHEET_PREFIX = "io.elementary.stylesheet"; + const string DEFAULT_ACCENT = "blueberry"; var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; @@ -302,7 +303,7 @@ public void force_elementary_style () { gtk_settings.gtk_icon_theme_name = "elementary"; if (!current_stylesheet.has_prefix (STYLESHEET_PREFIX)) { - gtk_settings.gtk_theme_name = STYLESHEET_PREFIX + "blueberry"; + gtk_settings.gtk_theme_name = string.join (".", STYLESHEET_PREFIX, DEFAULT_ACCENT); } } From a996a94235750294e2e82b115a2f336c5df825aa Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Mon, 19 Apr 2021 23:11:35 -0600 Subject: [PATCH 06/10] Don't set const that's only used once --- lib/Widgets/Utils.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index ed4605fd3..5e005473d 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -295,7 +295,6 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { */ public void force_elementary_style () { const string STYLESHEET_PREFIX = "io.elementary.stylesheet"; - const string DEFAULT_ACCENT = "blueberry"; var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; @@ -303,7 +302,7 @@ public void force_elementary_style () { gtk_settings.gtk_icon_theme_name = "elementary"; if (!current_stylesheet.has_prefix (STYLESHEET_PREFIX)) { - gtk_settings.gtk_theme_name = string.join (".", STYLESHEET_PREFIX, DEFAULT_ACCENT); + gtk_settings.gtk_theme_name = string.join (".", STYLESHEET_PREFIX, "blueberry"); } } From 499b1fe71efb8bc6dfb86320ea91b93fb428c6ba Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Tue, 20 Apr 2021 09:21:28 -0600 Subject: [PATCH 07/10] Also set cursor name --- lib/Widgets/Utils.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 5e005473d..94d7e6e0a 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -299,6 +299,7 @@ public void force_elementary_style () { var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; + gtk_settings.gtk_cursor_theme_name = "elementary"; gtk_settings.gtk_icon_theme_name = "elementary"; if (!current_stylesheet.has_prefix (STYLESHEET_PREFIX)) { From b270e4c9f36d65380807a5af47e1f5ecc9ae1630 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Tue, 20 Apr 2021 10:46:30 -0600 Subject: [PATCH 08/10] Bump version, update AppData --- data/granite.appdata.xml.in | 13 +++++++++++++ lib/Widgets/Utils.vala | 4 ++-- meson.build | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/data/granite.appdata.xml.in b/data/granite.appdata.xml.in index 2556963ac..59393bab6 100644 --- a/data/granite.appdata.xml.in +++ b/data/granite.appdata.xml.in @@ -10,6 +10,19 @@

A companion library for GTK and GLib that provides complex widgets and convenience methods designed for use in apps built for elementary OS.

+ + +

Additions:

+
    +
  • Settings.prefers_accent_color to get a user's accent color preference
  • +
  • force_elementary_style to set the app's icons, cursors, and stylesheet to elementary defaults
  • +
+

Other Changes:

+
    +
  • Updated translations
  • +
+
+

Additions:

diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 94d7e6e0a..bdc972cc6 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012–2019 elementary, Inc. + * Copyright (C) 2012–2021 elementary, Inc. * * This program or library is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public @@ -291,7 +291,7 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { } /** - * Sets the app's icon theme and stylesheet to elementary defaults. + * Sets the app's icons, cursors, and stylesheet to elementary defaults. */ public void force_elementary_style () { const string STYLESHEET_PREFIX = "io.elementary.stylesheet"; diff --git a/meson.build b/meson.build index da0f2112a..5dd8d0dfd 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'granite', 'vala', 'c', meson_version: '>= 0.48.2', - version: '6.0.0' + version: '6.1.0' ) if meson.get_compiler('vala').version().version_compare('<0.40.0') From 87269e3536eeb74e21585ea96e2dfb0e52d8b8cc Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Tue, 20 Apr 2021 13:51:09 -0600 Subject: [PATCH 09/10] Update lib/Widgets/Utils.vala MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Foré --- lib/Widgets/Utils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index bdc972cc6..07b05fbc5 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -296,7 +296,7 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { public void force_elementary_style () { const string STYLESHEET_PREFIX = "io.elementary.stylesheet"; - var gtk_settings = Gtk.Settings.get_default (); + unowned var gtk_settings = Gtk.Settings.get_default (); var current_stylesheet = gtk_settings.gtk_theme_name; gtk_settings.gtk_cursor_theme_name = "elementary"; From b6569a72bacb5f324eb0557ca2d49ebfb8587146 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Tue, 20 Apr 2021 13:55:26 -0600 Subject: [PATCH 10/10] Don't cache theme name --- lib/Widgets/Utils.vala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Widgets/Utils.vala b/lib/Widgets/Utils.vala index 07b05fbc5..adb715d20 100644 --- a/lib/Widgets/Utils.vala +++ b/lib/Widgets/Utils.vala @@ -295,14 +295,12 @@ public static Gdk.RGBA contrasting_foreground_color (Gdk.RGBA bg_color) { */ public void force_elementary_style () { const string STYLESHEET_PREFIX = "io.elementary.stylesheet"; - unowned var gtk_settings = Gtk.Settings.get_default (); - var current_stylesheet = gtk_settings.gtk_theme_name; gtk_settings.gtk_cursor_theme_name = "elementary"; gtk_settings.gtk_icon_theme_name = "elementary"; - if (!current_stylesheet.has_prefix (STYLESHEET_PREFIX)) { + if (!gtk_settings.gtk_theme_name.has_prefix (STYLESHEET_PREFIX)) { gtk_settings.gtk_theme_name = string.join (".", STYLESHEET_PREFIX, "blueberry"); } }