Use ClutterColor instead of GdkRGBA
This commit is contained in:
parent
f53773f58e
commit
d9ba3fbc7f
@ -39,20 +39,22 @@ shell_realms_window_frames_new (ShellRealms *realms)
|
||||
static void
|
||||
shell_realms_window_frames_process_color (ShellRealmsWindowFrames *frames, const char *entry)
|
||||
{
|
||||
GdkRGBA rgba;
|
||||
ClutterColor *rgba = clutter_color_alloc();
|
||||
|
||||
gchar **split = g_strsplit (entry, ":", -1);
|
||||
|
||||
if (g_strv_length (split) != 2) {
|
||||
g_warning ("ShellRealmsWindowFrames: Unable to parse realm-frame-colors entry: %s", entry);
|
||||
clutter_color_free(rgba);
|
||||
g_strfreev (split);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gdk_rgba_parse (&rgba, split[1])) {
|
||||
if (!clutter_color_from_string(rgba, split[1])) {
|
||||
g_warning ("ShellRealmsWindowFrames: Failed to parse RGBA component of realm frame color entry: %s", entry);
|
||||
clutter_color_free(rgba);
|
||||
} else {
|
||||
g_hash_table_insert (frames->realm_frame_colors, g_strdup (split[0]), gdk_rgba_copy (&rgba));
|
||||
g_hash_table_insert (frames->realm_frame_colors, g_strdup (split[0]), rgba);
|
||||
}
|
||||
g_strfreev (split);
|
||||
}
|
||||
@ -85,18 +87,19 @@ load_default_colors (ShellRealmsWindowFrames *frames)
|
||||
{
|
||||
guint n_entries, i;
|
||||
char **entries;
|
||||
GdkRGBA rgba;
|
||||
ClutterColor *rgba = clutter_color_alloc();
|
||||
|
||||
entries = g_settings_get_strv (frames->settings, FRAME_COLOR_LIST_KEY);
|
||||
n_entries = g_strv_length (entries);
|
||||
|
||||
g_clear_list (&frames->default_colors, (GDestroyNotify) gdk_rgba_free);
|
||||
g_clear_list (&frames->default_colors, (GDestroyNotify) clutter_color_free);
|
||||
|
||||
for (i = 0; i < n_entries; i++) {
|
||||
if (gdk_rgba_parse (&rgba, entries[i])) {
|
||||
frames->default_colors = g_list_append (frames->default_colors, gdk_rgba_copy(&rgba));
|
||||
if (clutter_color_from_string(rgba, entries[i])) {
|
||||
frames->default_colors = g_list_append (frames->default_colors, clutter_color_copy(rgba));
|
||||
}
|
||||
}
|
||||
clutter_color_free(rgba);
|
||||
g_strfreev (entries);
|
||||
}
|
||||
|
||||
@ -110,7 +113,7 @@ static void
|
||||
shell_realms_window_frames_init (ShellRealmsWindowFrames *frames)
|
||||
{
|
||||
frames->settings = g_settings_new (CITADEL_SETTINGS_SCHEMA);
|
||||
frames->realm_frame_colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gdk_rgba_free);
|
||||
frames->realm_frame_colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) clutter_color_free);
|
||||
frames->default_colors = NULL;
|
||||
frames->frame_disabled_windows = NULL;
|
||||
|
||||
@ -135,7 +138,7 @@ shell_realms_window_frames_finalize (GObject *obj)
|
||||
ShellRealmsWindowFrames *frames = SHELL_REALMS_WINDOW_FRAMES (obj);
|
||||
g_object_unref (frames->settings);
|
||||
g_hash_table_destroy (frames->realm_frame_colors);
|
||||
g_list_free_full (frames->default_colors, (GDestroyNotify) gdk_rgba_free);
|
||||
g_list_free_full (frames->default_colors, (GDestroyNotify) clutter_color_free);
|
||||
g_list_free (frames->frame_disabled_windows);
|
||||
G_OBJECT_CLASS (shell_realms_window_frames_parent_class)->finalize (obj);
|
||||
}
|
||||
@ -185,25 +188,23 @@ add_to_disabled_list (ShellRealmsWindowFrames *frames, guint32 window_id)
|
||||
|
||||
static gint
|
||||
color_compare (gconstpointer c1, gconstpointer c2) {
|
||||
return gdk_rgba_equal (c1, c2) ? 0 : 1;
|
||||
return clutter_color_equal(c1, c2) ? 0 : 1;
|
||||
}
|
||||
|
||||
static GdkRGBA *
|
||||
static ClutterColor *
|
||||
allocate_color (ShellRealmsWindowFrames *frames)
|
||||
{
|
||||
guint n_colors = g_list_length (frames->default_colors);
|
||||
|
||||
// 1) No default colors? return a built in color
|
||||
if (n_colors == 0) {
|
||||
GdkRGBA rgba;
|
||||
gdk_rgba_parse (&rgba, "rgb(153, 193, 241)");
|
||||
return gdk_rgba_copy (&rgba);
|
||||
return clutter_color_new(153, 193, 241, REALM_FRAME_ALPHA);
|
||||
}
|
||||
|
||||
// 2) No default colors? Find first color on default color list that isn't used already
|
||||
GList *used_colors = g_hash_table_get_values (frames->realm_frame_colors);
|
||||
for (GList *iter = frames->default_colors; iter; iter = iter->next) {
|
||||
GdkRGBA *rgba = iter->data;
|
||||
ClutterColor *rgba = iter->data;
|
||||
if (!g_list_find_custom (used_colors, rgba, color_compare)) {
|
||||
return rgba;
|
||||
}
|
||||
@ -227,8 +228,8 @@ shell_realms_window_frames_store_colors (ShellRealmsWindowFrames *frames)
|
||||
|
||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||
gchar *name = key;
|
||||
GdkRGBA *rgba = value;
|
||||
char *rgba_str = gdk_rgba_to_string (rgba);
|
||||
ClutterColor *rgba = value;
|
||||
char *rgba_str = clutter_color_to_string(rgba);
|
||||
gchar *entry = g_strconcat (name, ":", rgba_str, NULL);
|
||||
g_ptr_array_add (entries, entry);
|
||||
g_free (rgba_str);
|
||||
@ -328,16 +329,6 @@ shell_realms_window_frames_set_frame_enabled (ShellRealmsWindowFrames *frames, M
|
||||
}
|
||||
}
|
||||
|
||||
static ClutterColor *
|
||||
rgba_to_clutter_color(GdkRGBA *rgba)
|
||||
{
|
||||
guint8 r = (guint8) (0.5 + CLAMP(rgba->red, 0.0, 1.0) * 255.0);
|
||||
guint8 g = (guint8) (0.5 + CLAMP(rgba->green, 0.0, 1.0) * 255.0);
|
||||
guint8 b = (guint8) (0.5 + CLAMP(rgba->blue, 0.0, 1.0) * 255.0);
|
||||
|
||||
return clutter_color_new (r, g, b, REALM_FRAME_ALPHA);
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_realms_window_frames_color_for_window:
|
||||
* @frames: a #ShellRealmsWindowFrames instance
|
||||
@ -360,15 +351,16 @@ shell_realms_window_frames_color_for_window (ShellRealmsWindowFrames *frames, Me
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GdkRGBA *rgba = g_hash_table_lookup (frames->realm_frame_colors, name);
|
||||
ClutterColor *rgba = g_hash_table_lookup (frames->realm_frame_colors, name);
|
||||
|
||||
if (!rgba) {
|
||||
rgba = allocate_color (frames);
|
||||
g_hash_table_insert (frames->realm_frame_colors, g_strdup(name), rgba);
|
||||
shell_realms_window_frames_store_colors (frames);
|
||||
}
|
||||
|
||||
return rgba_to_clutter_color (rgba);
|
||||
ClutterColor *copy = clutter_color_copy(rgba);
|
||||
copy->alpha = REALM_FRAME_ALPHA;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user