Skip to content

Commit 3ab95fe

Browse files
committed
display module: Fix color selection for monitor labels.
The dynamic color palette shouldn't have been removed in 7360582, as it took the current number of outputs into consideration also.
1 parent 7360582 commit 3ab95fe

File tree

3 files changed

+60
-47
lines changed

3 files changed

+60
-47
lines changed

panels/display/cc-display-arrangement.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,6 @@ cc_display_arrangement_draw (GtkWidget *widget,
626626
if (cc_display_monitor_is_primary (output) || cc_display_config_is_cloning (self->config))
627627
gtk_style_context_add_class (context, "primary");
628628

629-
/* Set in cc-display-panel.c */
630-
num = cc_display_monitor_get_ui_number (output);
631-
632629
monitor_get_drawing_rect (self, output, &x1, &y1, &x2, &y2);
633630
w = x2 - x1;
634631
h = y2 - y1;
@@ -656,9 +653,11 @@ cc_display_arrangement_draw (GtkWidget *widget,
656653

657654
cairo_save (cr);
658655

656+
/* Set in cc-display-panel.c */
657+
num = cc_display_monitor_get_ui_number (output) - 1; // ui_numbers start at 1, our color index is 0-based.
659658
gchar *rgba_str;
660659

661-
g_signal_emit_by_name (G_OBJECT (widget), "get-output-color", output, &rgba_str);
660+
g_signal_emit_by_name (G_OBJECT (widget), "get-output-color", num, &rgba_str);
662661

663662
if (gdk_rgba_parse (&bg_rgba, rgba_str))
664663
{
@@ -970,7 +969,7 @@ cc_display_arrangement_class_init (CcDisplayArrangementClass *klass)
970969
CC_TYPE_DISPLAY_ARRANGEMENT,
971970
G_SIGNAL_RUN_LAST,
972971
0, NULL, NULL, NULL,
973-
G_TYPE_STRING, 1, CC_TYPE_DISPLAY_MONITOR);
972+
G_TYPE_STRING, 1, G_TYPE_INT);
974973
}
975974

976975
static void

panels/display/cc-display-labeler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ cc_display_labeler_class_init (CcDisplayLabelerClass *klass)
136136
CC_TYPE_DISPLAY_LABELER,
137137
G_SIGNAL_RUN_LAST,
138138
0, NULL, NULL, NULL,
139-
G_TYPE_STRING, 1, CC_TYPE_DISPLAY_MONITOR);
139+
G_TYPE_STRING, 1, G_TYPE_INT);
140140
}
141141

142142
static void
@@ -442,7 +442,7 @@ cc_display_labeler_show (CcDisplayLabeler *labeler)
442442
if (!created_window_for_clone) {
443443
gchar *rgba_str;
444444

445-
g_signal_emit_by_name (G_OBJECT (labeler), "get-output-color", output, &rgba_str);
445+
g_signal_emit_by_name (G_OBJECT (labeler), "get-output-color", i, &rgba_str);
446446
labeler->priv->windows[i] = create_label_window (labeler, output, rgba_str, i + 1);
447447

448448
if (cc_display_config_is_cloning (labeler->priv->config))

panels/display/cc-display-panel.c

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ struct _CcDisplayPanel
9292
GtkWidget *cancel_button;
9393

9494
GtkListStore *output_selection_list;
95+
GdkRGBA *palette;
96+
gint n_outputs;
9597

9698
GtkWidget *arrangement_frame;
9799
GtkWidget *arrangement_bin;
@@ -114,38 +116,16 @@ CC_PANEL_REGISTER (CcDisplayPanel, cc_display_panel)
114116

115117
#define WAYLAND_SESSION() (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default()))
116118

117-
static const gchar *COLORS[] = {
118-
"rgb(255,102,102)",
119-
"rgb(255,133,102)",
120-
"rgb(255,163,102)",
121-
"rgb(255,194,102)",
122-
"rgb(255,224,102)",
123-
"rgb(255,255,102)",
124-
"rgb(224,255,102)",
125-
"rgb(194,255,102)",
126-
"rgb(163,255,102)",
127-
"rgb(133,255,102)",
128-
"rgb(102,255,102)",
129-
"rgb(102,255,133)",
130-
"rgb(102,255,163)",
131-
"rgb(102,255,194)",
132-
"rgb(102,255,224)",
133-
"rgb(102,255,255)",
134-
"rgb(102,224,255)",
135-
"rgb(102,194,255)",
136-
"rgb(102,163,255)",
137-
"rgb(102,133,255)",
138-
};
139-
140119
static void update_bottom_buttons (CcDisplayPanel *panel);
141120
static void apply_current_configuration (CcDisplayPanel *self);
142121
static void reset_current_config (CcDisplayPanel *panel);
143122
static void rebuild_ui (CcDisplayPanel *panel);
123+
static void regenerate_palette (CcDisplayPanel *panel, gint n_outputs);
144124
static void set_current_output (CcDisplayPanel *panel,
145125
CcDisplayMonitor *output,
146126
gboolean force);
147-
static gchar *get_color_string_for_output (CcDisplayMonitor *output);
148-
static gchar *get_output_color (GObject *source, CcDisplayMonitor *output, CcDisplayPanel *self);
127+
static gchar *get_color_string_for_output (CcDisplayPanel *panel, gint index);
128+
static gchar *get_output_color (GObject *source, gint index, CcDisplayPanel *self);
149129

150130
static CcDisplayConfigType
151131
config_get_current_type (CcDisplayPanel *panel)
@@ -386,7 +366,7 @@ show_labels_dbus (CcDisplayPanel *self)
386366

387367
gint color_index = 0;
388368

389-
for (l = outputs; l != NULL; l = l->next)
369+
for (l = outputs, color_index = 0; l != NULL; l = l->next, color_index++)
390370
{
391371
CcDisplayMonitor *output = l->data;
392372

@@ -400,13 +380,11 @@ show_labels_dbus (CcDisplayPanel *self)
400380
number,
401381
cc_display_config_is_cloning (self->current_config),
402382
cc_display_monitor_get_display_name (output),
403-
COLORS[color_index]);
383+
self->palette[color_index]);
404384

405385
g_variant_builder_add (&builder, "{sv}",
406386
cc_display_monitor_get_connector_name (output),
407387
var);
408-
409-
color_index++;
410388
}
411389

412390
g_variant_builder_close (&builder);
@@ -500,6 +478,7 @@ cc_display_panel_dispose (GObject *object)
500478

501479
g_clear_object (&self->muffin_settings);
502480
g_clear_object (&self->labeler);
481+
g_clear_pointer (&self->palette, g_free);
503482

504483
g_signal_handlers_disconnect_by_func (self, widget_visible_changed, NULL);
505484

@@ -711,6 +690,7 @@ rebuild_ui (CcDisplayPanel *panel)
711690
GList *outputs, *l;
712691
CcDisplayConfigType type;
713692
gboolean cloned = FALSE;
693+
gint index = 0;
714694

715695
panel->rebuilding_counter++;
716696

@@ -722,14 +702,16 @@ rebuild_ui (CcDisplayPanel *panel)
722702
return;
723703
}
724704

725-
ensure_monitor_labels (panel);
726-
727705
cloned = config_get_current_type (panel);
728706

729707
n_active_outputs = 0;
730708
n_usable_outputs = 0;
731709
outputs = cc_display_config_get_ui_sorted_monitors (panel->current_config);
732-
for (l = outputs; l; l = l->next)
710+
711+
regenerate_palette (panel, g_list_length (outputs));
712+
ensure_monitor_labels (panel);
713+
714+
for (l = outputs, index = 0; l; l = l->next, index++)
733715
{
734716
GtkTreeIter iter;
735717
CcDisplayMonitor *output = l->data;
@@ -1182,25 +1164,57 @@ defaults_button_clicked_cb (GtkWidget *widget,
11821164
}
11831165
}
11841166

1185-
static gchar *
1186-
get_color_string_for_output (CcDisplayMonitor *output)
1167+
static void
1168+
regenerate_palette (CcDisplayPanel *panel, gint n_outputs)
11871169
{
1188-
guint32 id;
1170+
/* The idea is that we go around an hue color wheel. We want to start
1171+
* at red, go around to green/etc. and stop at blue.
1172+
*
1173+
*/
1174+
double start_hue;
1175+
double end_hue;
1176+
int i;
1177+
1178+
g_clear_pointer (&panel->palette, g_free);
1179+
panel->palette = g_new (GdkRGBA, n_outputs);
1180+
1181+
start_hue = 0.0; /* red */
1182+
end_hue = 2.0/3; /* blue */
1183+
1184+
for (i = 0; i < n_outputs; i++) {
1185+
double h, s, v;
1186+
double r, g, b;
1187+
1188+
h = start_hue + (end_hue - start_hue) / n_outputs * i;
1189+
s = 0.6;
1190+
v = 1.0;
1191+
1192+
gtk_hsv_to_rgb (h, s, v, &r, &g, &b);
1193+
1194+
panel->palette[i].red = r;
1195+
panel->palette[i].green = g;
1196+
panel->palette[i].blue = b;
1197+
panel->palette[i].alpha = 1.0;
1198+
}
11891199

1190-
id = cc_display_monitor_get_id (output);
1200+
panel->n_outputs = n_outputs;
1201+
}
11911202

1192-
if (id < 0 || id > G_N_ELEMENTS (COLORS) - 1)
1203+
static gchar *
1204+
get_color_string_for_output (CcDisplayPanel *panel, gint index)
1205+
{
1206+
if (index < 0 || index > panel->n_outputs - 1)
11931207
{
11941208
return g_strdup ("white");
11951209
}
11961210

1197-
return g_strdup (COLORS[id]);
1211+
return gdk_rgba_to_string (&panel->palette[index]);
11981212
}
11991213

12001214
static gchar *
1201-
get_output_color (GObject *source, CcDisplayMonitor *output, CcDisplayPanel *self)
1215+
get_output_color (GObject *source, gint index, CcDisplayPanel *self)
12021216
{
1203-
return get_color_string_for_output (output);
1217+
return get_color_string_for_output (self, index);
12041218
}
12051219

12061220
static void

0 commit comments

Comments
 (0)