@@ -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-
140119static void update_bottom_buttons (CcDisplayPanel * panel );
141120static void apply_current_configuration (CcDisplayPanel * self );
142121static void reset_current_config (CcDisplayPanel * panel );
143122static void rebuild_ui (CcDisplayPanel * panel );
123+ static void regenerate_palette (CcDisplayPanel * panel , gint n_outputs );
144124static 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
150130static CcDisplayConfigType
151131config_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
12001214static 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
12061220static void
0 commit comments