Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/Background/Background.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ public class Gala.Background : Object {
#else
var color = Clutter.Color.from_string (color_string);
#endif
if (color == null) {
#if HAS_MUTTER47
color = Cogl.Color.from_string ("#000000");
#else
color = Clutter.Color.from_string ("black");
#endif
}

var shading_type = settings.get_enum ("color-shading-type");

Expand All @@ -120,13 +113,6 @@ public class Gala.Background : Object {
#else
var second_color = Clutter.Color.from_string (color_string);
#endif
if (second_color == null) {
#if HAS_MUTTER47
second_color = Cogl.Color.from_string ("#000000");
#else
second_color = Clutter.Color.from_string ("black");
#endif
}

background.set_gradient ((GDesktop.BackgroundShading) shading_type, color, second_color);
}
Expand Down
41 changes: 41 additions & 0 deletions tests/lib/CustomCoglVapiTest.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Leo "lenemter" <lenemter@gmail.com>
*/

public class Gala.CustomCoglVapiTest : TestCase {
#if HAS_MUTTER47
construct {
add_test ("Test _vala_cogl_color_from_string", test_vala_cogl_color_from_string);
}

private void test_vala_cogl_color_from_string () {
assert_cogl_color_is_white ("#ffffff");
assert_cogl_color_is_white ("#ffffffff");
assert_cogl_color_is_white ("#fff");
assert_cogl_color_is_white ("#ffff");
assert_cogl_color_is_white ("rgb(255, 255, 255)");
assert_cogl_color_is_white ("rgba(255, 255, 255, 1)");
assert_cogl_color_is_white ("hsl(0, 0%, 100%)");
assert_cogl_color_is_white ("hsla(0, 0%, 100%, 1)");

assert_cogl_color_is_black ("#55555");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that invalid strings should return a black color.

assert_cogl_color_is_black ("#555555555555");
assert_cogl_color_is_black ("#555555555555555555555555");
assert_cogl_color_is_black ("");
assert_cogl_color_is_black ("qwerty");
}

private void assert_cogl_color_is_white (string color_str) {
var color = Cogl.Color.from_string (color_str);
assert_true (color.red == 255u && color.green == 255u && color.blue == 255u);
}

private void assert_cogl_color_is_black (string color_str) {
var color = Cogl.Color.from_string (color_str);
assert_true (color.red == 0u && color.green == 0u && color.blue == 0u);
}
#endif
}
1 change: 1 addition & 0 deletions tests/lib/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Gala {

private TestCase? get_test_case (string name) {
Type[] test_types = {
typeof (CustomCoglVapiTest),
typeof (GestureControllerTest),
typeof (PropertyTargetTest),
typeof (SetupTest),
Expand Down
1 change: 1 addition & 0 deletions tests/lib/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests = [
'CustomCoglVapiTest',
'GestureControllerTest',
'PropertyTargetTest',
'SetupTest',
Expand Down
8 changes: 3 additions & 5 deletions vapi/Cogl-15-custom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace Cogl {
[CCode (cname="cogl_color_init_from_hsl")]
public Color.from_hsl (float hue, float saturation, float luminance);
[CCode (cname = "_vala_cogl_color_from_string")]
public static Cogl.Color? from_string (string str) {
public static Cogl.Color from_string (string str) {
Cogl.Color color = {};
if (color.init_from_string (str))
return color;

return null;
color.init_from_string (str);
return color;
}
}
[CCode (cheader_filename = "cogl/cogl.h", has_type_id = false)]
Expand Down
8 changes: 3 additions & 5 deletions vapi/Cogl-16-custom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace Cogl {
[CCode (cname="cogl_color_init_from_hsl")]
public Color.from_hsl (float hue, float saturation, float luminance);
[CCode (cname = "_vala_cogl_color_from_string")]
public static Cogl.Color? from_string (string str) {
public static Cogl.Color from_string (string str) {
Cogl.Color color = {};
if (color.init_from_string (str))
return color;

return null;
color.init_from_string (str);
return color;
}
}
[CCode (cheader_filename = "cogl/cogl.h", has_type_id = false)]
Expand Down
8 changes: 3 additions & 5 deletions vapi/Cogl-17-custom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace Cogl {
[CCode (cname="cogl_color_init_from_hsl")]
public Color.from_hsl (float hue, float saturation, float luminance);
[CCode (cname = "_vala_cogl_color_from_string")]
public static Cogl.Color? from_string (string str) {
public static Cogl.Color from_string (string str) {
Cogl.Color color = {};
if (color.init_from_string (str))
return color;

return null;
color.init_from_string (str);
return color;
}
}
[CCode (cheader_filename = "cogl/cogl.h", has_type_id = false)]
Expand Down
8 changes: 3 additions & 5 deletions vapi/Cogl-18-custom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace Cogl {
[CCode (cname="cogl_color_init_from_hsl")]
public Color.from_hsl (float hue, float saturation, float luminance);
[CCode (cname = "_vala_cogl_color_from_string")]
public static Cogl.Color? from_string (string str) {
public static Cogl.Color from_string (string str) {
Cogl.Color color = {};
if (color.init_from_string (str))
return color;

return null;
color.init_from_string (str);
return color;
}
}
[CCode (cheader_filename = "cogl/cogl.h", has_type_id = false)]
Expand Down
8 changes: 3 additions & 5 deletions vapi/mutter-cogl-14.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,10 @@ namespace Cogl {
public Color.from_hsl (float hue, float saturation, float luminance);
#if HAS_MUTTER47
[CCode (cname = "_vala_cogl_color_from_string")]
public static Cogl.Color? from_string (string str) {
public static Cogl.Color from_string (string str) {
Cogl.Color color = { };
if (color.init_from_string (str)) {
return color;
}
return null;
color.init_from_string (str);
return color;
}
#endif
public float get_alpha ();
Expand Down