From 892cf01dabdd7e58221d40e501b19161b142f6c2 Mon Sep 17 00:00:00 2001 From: Tom Beckmann Date: Sat, 9 Aug 2014 11:55:41 +0200 Subject: [PATCH] grab colors for labels from theme (.label and .title) --- data/gala.css | 4 +++ plugins/notify/NormalNotification.vala | 34 ++++++++++++++++++++++++++ plugins/notify/Notification.vala | 18 ++++++++++---- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/data/gala.css b/data/gala.css index 5ff67983..c8e347ba 100644 --- a/data/gala.css +++ b/data/gala.css @@ -24,3 +24,7 @@ border-radius: 4px; } +.gala-notification .title, .gala-notification .label { + color: #333; +} + diff --git a/plugins/notify/NormalNotification.vala b/plugins/notify/NormalNotification.vala index e8e0e5cd..9962e5d4 100644 --- a/plugins/notify/NormalNotification.vala +++ b/plugins/notify/NormalNotification.vala @@ -55,6 +55,40 @@ namespace Gala.Plugins.Notify body_label.use_markup = true; body_label.line_wrap_mode = Pango.WrapMode.WORD_CHAR; + var style_path = new Gtk.WidgetPath (); + style_path.append_type (typeof (Gtk.Window)); + style_path.append_type (typeof (Gtk.EventBox)); + style_path.iter_add_class (1, "gala-notification"); + style_path.append_type (typeof (Gtk.Label)); + + var label_style_context = new Gtk.StyleContext (); + label_style_context.add_provider (Notification.default_css, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK); + label_style_context.set_path (style_path); + + Gdk.RGBA color; + + label_style_context.save (); + label_style_context.add_class ("title"); + color = label_style_context.get_color (Gtk.StateFlags.NORMAL); + summary_label.color = { + (uint8) (color.red * 255), + (uint8) (color.green * 255), + (uint8) (color.blue * 255), + (uint8) (color.alpha * 255) + }; + label_style_context.restore (); + + label_style_context.save (); + label_style_context.add_class ("label"); + color = label_style_context.get_color (Gtk.StateFlags.NORMAL); + body_label.color = { + (uint8) (color.red * 255), + (uint8) (color.green * 255), + (uint8) (color.blue * 255), + (uint8) (color.alpha * 255) + }; + label_style_context.restore (); + add_child (summary_label); add_child (body_label); } diff --git a/plugins/notify/Notification.vala b/plugins/notify/Notification.vala index d952a0a9..5906d40c 100644 --- a/plugins/notify/Notification.vala +++ b/plugins/notify/Notification.vala @@ -22,6 +22,8 @@ namespace Gala.Plugins.Notify { public abstract class Notification : Actor { + public static Gtk.CssProvider? default_css = null; + public const int WIDTH = 300; public const int ICON_SIZE = 48; public const int MARGIN = 12; @@ -111,11 +113,13 @@ namespace Gala.Plugins.Notify add_child (icon_container); add_child (close_button); - var default_css = new Gtk.CssProvider (); - try { - default_css.load_from_path (Config.PKGDATADIR + "/gala.css"); - } catch (Error e) { - warning ("Loading default styles failed: %s", e.message); + if (default_css == null) { + default_css = new Gtk.CssProvider (); + try { + default_css.load_from_path (Config.PKGDATADIR + "/gala.css"); + } catch (Error e) { + warning ("Loading default styles failed: %s", e.message); + } } var style_path = new Gtk.WidgetPath (); @@ -127,6 +131,10 @@ namespace Gala.Plugins.Notify style_context.add_class ("gala-notification"); style_context.set_path (style_path); + var label_style_path = style_path.copy (); + label_style_path.iter_add_class (1, "gala-notification"); + label_style_path.append_type (typeof (Gtk.Label)); + var canvas = new Canvas (); canvas.draw.connect (draw); content = canvas;