From d489029800ea59637d818c2d1983b5a11f16add3 Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 28 Oct 2025 22:23:44 +0300 Subject: [PATCH] Avoid using Gdk.RGBA --- lib/Drawing/Color.vala | 67 ++++++++++--------- src/Widgets/MultitaskingView/Tooltip.vala | 20 +----- .../WindowSwitcher/WindowSwitcher.vala | 24 +++---- 3 files changed, 49 insertions(+), 62 deletions(-) diff --git a/lib/Drawing/Color.vala b/lib/Drawing/Color.vala index 33f60bebf..1733c6d13 100644 --- a/lib/Drawing/Color.vala +++ b/lib/Drawing/Color.vala @@ -9,14 +9,25 @@ namespace Gala.Drawing { * A class containing an RGBA color and methods for more powerful color manipulation. */ public class Color : GLib.Object { - public const Gdk.RGBA LIGHT_BACKGROUND = { (250f / 255f), (250f / 255f), (250f / 255f), 1}; - public const Gdk.RGBA DARK_BACKGROUND = { (51 / 255f), (51 / 255f), (51 / 255f), 1}; - public const Gdk.RGBA LIGHT_BORDER = { 0, 0, 0, 0.2f}; - public const Gdk.RGBA DARK_BORDER = { 0, 0, 0, 0.75f}; - public const Gdk.RGBA LIGHT_HIGHLIGHT = { 255, 255, 255, 1}; - public const Gdk.RGBA DARK_HIGHLIGHT = { 255, 255, 255, 0.05f}; - public const Gdk.RGBA TOOLTIP_BACKGROUND = { 0, 0, 0, 1}; - public const Gdk.RGBA TOOLTIP_TEXT_COLOR = { 1, 1, 1, 1}; +#if !HAS_MUTTER47 + public const Clutter.Color LIGHT_BACKGROUND = { 250, 250, 250, 255}; + public const Clutter.Color DARK_BACKGROUND = { 51, 51, 51, 255}; + public const Clutter.Color LIGHT_BORDER = { 0, 0, 0, 51}; + public const Clutter.Color DARK_BORDER = { 0, 0, 0, 191}; + public const Clutter.Color LIGHT_HIGHLIGHT = { 255, 255, 255, 255}; + public const Clutter.Color DARK_HIGHLIGHT = { 255, 255, 255, 13}; + public const Clutter.Color TOOLTIP_BACKGROUND = { 0, 0, 0, 255}; + public const Clutter.Color TOOLTIP_TEXT_COLOR = { 255, 255, 255, 255}; +#else + public const Cogl.Color LIGHT_BACKGROUND = { 250, 250, 250, 255}; + public const Cogl.Color DARK_BACKGROUND = { 51, 51, 51, 255}; + public const Cogl.Color LIGHT_BORDER = { 0, 0, 0, 51}; + public const Cogl.Color DARK_BORDER = { 0, 0, 0, 191}; + public const Cogl.Color LIGHT_HIGHLIGHT = { 255, 255, 255, 255}; + public const Cogl.Color DARK_HIGHLIGHT = { 255, 255, 255, 13}; + public const Cogl.Color TOOLTIP_BACKGROUND = { 0, 0, 0, 255}; + public const Cogl.Color TOOLTIP_TEXT_COLOR = { 255, 255, 255, 255}; +#endif /** * The value of the red channel, with 0 being the lowest value and 1.0 being the greatest value. @@ -93,15 +104,6 @@ namespace Gala.Drawing { this.A = A; } - /** - * Constructs a new {@link Gala.Drawing.Color} from a {@link Gdk.RGBA}. - * - * @param color the {@link Gdk.RGBA} - */ - public Color.from_rgba (Gdk.RGBA color) { - set_from_rgba (color); - } - /** * Constructs a new {@link Gala.Drawing.Color} from a string. * @@ -112,14 +114,20 @@ namespace Gala.Drawing { * * A RGB color in the form “rgb(r,g,b)” (In this case the color will have full opacity) * * A RGBA color in the form “rgba(r,g,b,a)” * - * For more details on formatting and how this function works see {@link Gdk.RGBA.parse} + * For more details on formatting and how this function works see {@link Clutter.Color.from_string} * * @param color the string specifying the color */ public Color.from_string (string color) { - Gdk.RGBA rgba = Gdk.RGBA (); - rgba.parse (color); - set_from_rgba (rgba); +#if !HAS_MUTTER47 + var parsed_color = Clutter.Color.from_string (color); +#else + var parsed_color = Cogl.Color.from_string (color); +#endif + R = parsed_color.red / 255.0; + G = parsed_color.green / 255.0; + B = parsed_color.blue / 255.0; + A = parsed_color.alpha / 255.0; } /** @@ -508,13 +516,17 @@ namespace Gala.Drawing { * Note: that this string representation may lose some precision, since r, g and b are represented * as 8-bit integers. If this is a concern, you should use a different representation. * - * This returns the same string as a {@link Gdk.RGBA} would return in {@link Gdk.RGBA.to_string} + * This returns the same string as a {@link Clutter.Color} would return in {@link Clutter.Color.to_string} * * @return the text string */ public string to_string () { - Gdk.RGBA rgba = {(float)R, (float)G, (float)B, (float)A}; - return rgba.to_string (); +#if !HAS_MUTTER47 + Clutter.Color color = { (uint8) (R * 255), (uint8) (G * 255), (uint8) (B * 255), (uint8) (A * 255) }; +#else + Cogl.Color color = { (uint8) (R * 255), (uint8) (G * 255), (uint8) (B * 255), (uint8) (A * 255) }; +#endif + return color.to_string (); } /** @@ -546,12 +558,5 @@ namespace Gala.Drawing { return (alpha << 24) | (red << 16) | (green << 8) | blue; } - - private void set_from_rgba (Gdk.RGBA color) { - R = color.red; - G = color.green; - B = color.blue; - A = color.alpha; - } } } diff --git a/src/Widgets/MultitaskingView/Tooltip.vala b/src/Widgets/MultitaskingView/Tooltip.vala index 8f071cfb6..e8e0e4ac5 100644 --- a/src/Widgets/MultitaskingView/Tooltip.vala +++ b/src/Widgets/MultitaskingView/Tooltip.vala @@ -14,35 +14,19 @@ public class Gala.Tooltip : Clutter.Actor { private Gala.Text text_actor; construct { -#if HAS_MUTTER47 - Cogl.Color text_color = { -#else - Clutter.Color text_color = { -#endif - (uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.red * uint8.MAX, - (uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.green * uint8.MAX, - (uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.blue * uint8.MAX, - (uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.alpha * uint8.MAX, - }; - text_actor = new Gala.Text () { margin_left = 6, margin_top = 6, margin_bottom = 6, margin_right = 6, ellipsize = Pango.EllipsizeMode.MIDDLE, - color = text_color + color = Drawing.Color.TOOLTIP_TEXT_COLOR }; add_child (text_actor); layout_manager = new Clutter.BinLayout (); - background_color = { - (uint8) (Drawing.Color.TOOLTIP_BACKGROUND.red * uint8.MAX), - (uint8) (Drawing.Color.TOOLTIP_BACKGROUND.green * uint8.MAX), - (uint8) (Drawing.Color.TOOLTIP_BACKGROUND.blue * uint8.MAX), - (uint8) (Drawing.Color.TOOLTIP_BACKGROUND.alpha * uint8.MAX) - }; + background_color = Drawing.Color.TOOLTIP_BACKGROUND; add_effect (new RoundedCornersEffect (3, 1.0f)); } diff --git a/src/Widgets/WindowSwitcher/WindowSwitcher.vala b/src/Widgets/WindowSwitcher/WindowSwitcher.vala index f084b1d8b..8fb39dd75 100644 --- a/src/Widgets/WindowSwitcher/WindowSwitcher.vala +++ b/src/Widgets/WindowSwitcher/WindowSwitcher.vala @@ -170,8 +170,6 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget { highlight_color = Drawing.Color.DARK_HIGHLIGHT; } - background_color.alpha = 0.6f; - #if HAS_MUTTER47 caption.color = Cogl.Color.from_string (caption_color); #else @@ -195,19 +193,19 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget { ); ctx.set_source_rgba ( - background_color.red, - background_color.green, - background_color.blue, - background_color.alpha + background_color.red / 255.0, + background_color.green / 255.0, + background_color.blue / 255.0, + 0.6 ); ctx.fill_preserve (); ctx.set_line_width (stroke_width); ctx.set_source_rgba ( - border_color.red, - border_color.green, - border_color.blue, - border_color.alpha + border_color.red / 255.0, + border_color.green / 255.0, + border_color.blue / 255.0, + border_color.alpha / 255.0 ); ctx.stroke (); ctx.restore (); @@ -221,9 +219,9 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget { ctx.set_line_width (stroke_width); ctx.set_source_rgba ( - highlight_color.red, - highlight_color.green, - highlight_color.blue, + highlight_color.red / 255.0, + highlight_color.green / 255.0, + highlight_color.blue / 255.0, 0.3 ); ctx.stroke ();