From 869aa70cfeb1db0396e7e5813b170ec7f80aec02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 9 Nov 2021 22:27:45 -0800 Subject: [PATCH] Tooltip: get text color from style context (#1295) * Tooltip: get text color from style context * cache the math --- src/Widgets/Tooltip.vala | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Widgets/Tooltip.vala b/src/Widgets/Tooltip.vala index bda1efbd..2bd54437 100644 --- a/src/Widgets/Tooltip.vala +++ b/src/Widgets/Tooltip.vala @@ -47,17 +47,33 @@ public class Gala.Tooltip : Clutter.Actor { public float max_width; static construct { - var label_widget_path = new Gtk.WidgetPath (); - label_widget_path.append_type (GLib.Type.from_name ("label")); - label_widget_path.iter_set_object_name (-1, "tooltip"); + var tooltip_widget_path = new Gtk.WidgetPath (); + var pos = tooltip_widget_path.append_type (typeof (Gtk.Window)); + tooltip_widget_path.iter_set_object_name (pos, "tooltip"); + tooltip_widget_path.iter_add_class (pos, Gtk.STYLE_CLASS_CSD); + tooltip_widget_path.iter_add_class (pos, Gtk.STYLE_CLASS_BACKGROUND); style_context = new Gtk.StyleContext (); - style_context.add_class (Gtk.STYLE_CLASS_BACKGROUND); - style_context.set_path (label_widget_path); + style_context.set_path (tooltip_widget_path); padding = style_context.get_padding (Gtk.StateFlags.NORMAL); - text_color = Clutter.Color.from_string ("#ffffff"); + tooltip_widget_path.append_type (typeof (Gtk.Label)); + + var label_style_context = new Gtk.StyleContext (); + label_style_context.set_path (tooltip_widget_path); + + var text_rgba = (Gdk.RGBA) label_style_context.get_property ( + Gtk.STYLE_PROPERTY_COLOR, + Gtk.StateFlags.NORMAL + ); + + text_color = Clutter.Color () { + red = (uint8) text_rgba.red * uint8.MAX, + green = (uint8) text_rgba.green * uint8.MAX, + blue = (uint8) text_rgba.blue * uint8.MAX, + alpha = (uint8) text_rgba.alpha * uint8.MAX, + }; } construct {