night-light: Add Color Temperature slider
This adds a scale to change the color temperature from 3000K to 6000K. A mark is added to the default value and a second one for aesthetics. Initial implementation by Benjamin Berg Color choices by Daniel Foré and elementary OS Closes #147
This commit is contained in:
parent
a5f902c124
commit
d1fc7e64b3
4 changed files with 112 additions and 14 deletions
|
@ -33,6 +33,7 @@ struct _CcNightLightDialog {
|
|||
|
||||
GtkWidget *box_manual;
|
||||
GtkWidget *infobar_disabled;
|
||||
GtkWidget *scale_color_temperature;
|
||||
GtkWidget *spinbutton_from_hours;
|
||||
GtkWidget *spinbutton_from_minutes;
|
||||
GtkWidget *spinbutton_to_hours;
|
||||
|
@ -48,6 +49,7 @@ struct _CcNightLightDialog {
|
|||
GtkAdjustment *adjustment_from_minutes;
|
||||
GtkAdjustment *adjustment_to_hours;
|
||||
GtkAdjustment *adjustment_to_minutes;
|
||||
GtkAdjustment *adjustment_color_temperature;
|
||||
|
||||
GSettings *settings_display;
|
||||
GSettings *settings_clock;
|
||||
|
@ -147,6 +149,7 @@ dialog_update_state (CcNightLightDialog *self)
|
|||
self->ignore_value_changed = FALSE;
|
||||
|
||||
gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
|
||||
gtk_widget_set_sensitive (self->scale_color_temperature, enabled);
|
||||
|
||||
/* Don't show the off button if it can't be turned off */
|
||||
/* Don't allow choosing Manual or "Sunset to Sunrise" if it can't be turned on */
|
||||
|
@ -225,6 +228,10 @@ dialog_update_state (CcNightLightDialog *self)
|
|||
self->adjustment_to_minutes,
|
||||
self->stack_to);
|
||||
|
||||
self->ignore_value_changed = TRUE;
|
||||
value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
|
||||
gtk_adjustment_set_value (self->adjustment_color_temperature, value);
|
||||
self->ignore_value_changed = FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -361,6 +368,22 @@ dialog_time_to_value_changed_cb (GtkAdjustment *adjustment,
|
|||
g_settings_set_double (self->settings_display, "night-light-schedule-to", value);
|
||||
}
|
||||
|
||||
static void
|
||||
dialog_color_temperature_value_changed_cb (GtkAdjustment *adjustment,
|
||||
CcNightLightDialog *self)
|
||||
{
|
||||
gdouble value;
|
||||
|
||||
if (self->ignore_value_changed)
|
||||
return;
|
||||
|
||||
value = gtk_adjustment_get_value (adjustment);
|
||||
|
||||
g_debug ("new value = %.0f", value);
|
||||
|
||||
g_settings_set_uint (self->settings_display, "night-light-temperature", (guint) value);
|
||||
}
|
||||
|
||||
static void
|
||||
dialog_color_properties_changed_cb (GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
|
@ -571,8 +594,10 @@ cc_night_light_dialog_class_init (CcNightLightDialogClass *klass)
|
|||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, adjustment_from_minutes);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, adjustment_to_hours);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, adjustment_to_minutes);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, adjustment_color_temperature);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, box_manual);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, infobar_disabled);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, scale_color_temperature);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, spinbutton_from_hours);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, spinbutton_from_minutes);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcNightLightDialog, spinbutton_to_hours);
|
||||
|
@ -592,6 +617,7 @@ cc_night_light_dialog_class_init (CcNightLightDialogClass *klass)
|
|||
gtk_widget_class_bind_template_callback (widget_class, dialog_mode_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, dialog_time_from_value_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, dialog_time_to_value_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, dialog_color_temperature_value_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, dialog_undisable_clicked_cb);
|
||||
|
||||
}
|
||||
|
@ -601,9 +627,28 @@ cc_night_light_dialog_init (CcNightLightDialog *self)
|
|||
{
|
||||
g_autoptr(GtkCssProvider) provider = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autofree gchar *text = NULL;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
text = g_strdup_printf ("%s", "More Warm");
|
||||
gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
|
||||
3000, GTK_POS_BOTTOM,
|
||||
text);
|
||||
|
||||
gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
|
||||
4000, GTK_POS_BOTTOM,
|
||||
NULL);
|
||||
|
||||
gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
|
||||
5000, GTK_POS_BOTTOM,
|
||||
NULL);
|
||||
|
||||
text = g_strdup_printf ("%s", "Less Warm");
|
||||
gtk_scale_add_mark (GTK_SCALE (self->scale_color_temperature),
|
||||
6000, GTK_POS_BOTTOM,
|
||||
text);
|
||||
|
||||
self->cancellable = g_cancellable_new ();
|
||||
self->settings_display = g_settings_new (DISPLAY_SCHEMA);
|
||||
|
||||
|
@ -624,20 +669,7 @@ cc_night_light_dialog_init (CcNightLightDialog *self)
|
|||
|
||||
/* use custom CSS */
|
||||
provider = gtk_css_provider_new ();
|
||||
if (!gtk_css_provider_load_from_data (provider,
|
||||
".padded-spinbutton {\n"
|
||||
" font-size: 110%;\n"
|
||||
" min-width: 50px;\n"
|
||||
"}\n"
|
||||
".unpadded-button {\n"
|
||||
" padding: 6px;\n"
|
||||
"}\n",
|
||||
-1,
|
||||
&error))
|
||||
{
|
||||
g_error ("Failed to load CSS: %s", error->message);
|
||||
}
|
||||
|
||||
gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/display/night-light.css");
|
||||
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
|
||||
GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
|
|
@ -438,6 +438,36 @@
|
|||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes">Color Temperature</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="scale_color_temperature">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="adjustment">adjustment_color_temperature</property>
|
||||
<property name="inverted">True</property>
|
||||
<property name="restrict_to_fill_level">False</property>
|
||||
<property name="fill_level">1</property>
|
||||
<property name="digits">0</property>
|
||||
<property name="draw_value">False</property>
|
||||
<property name="has_origin">False</property>
|
||||
<property name="value_pos">bottom</property>
|
||||
<style>
|
||||
<class name="night-light-temperature"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -478,4 +508,11 @@
|
|||
<property name="page_increment">10</property>
|
||||
<signal name="value-changed" handler="dialog_time_to_value_changed_cb" object="CcNightLightDialog" swapped="no" />
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment_color_temperature">
|
||||
<property name="lower">3000</property>
|
||||
<property name="upper">6000</property>
|
||||
<property name="step_increment">100</property>
|
||||
<property name="page_increment">500</property>
|
||||
<signal name="value-changed" handler="dialog_color_temperature_value_changed_cb" object="CcNightLightDialog" swapped="no" />
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<gresource prefix="/org/gnome/control-center/display">
|
||||
<file preprocess="xml-stripblanks">cc-night-light-dialog.ui</file>
|
||||
<file>display-arrangement.css</file>
|
||||
<file>night-light.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
28
panels/display/night-light.css
Normal file
28
panels/display/night-light.css
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* color selection by Daniel Foré and elementary OS */
|
||||
@define-color ORANGE_100 #ffc27d;
|
||||
@define-color ORANGE_500 #f37329;
|
||||
@define-color base_color white;
|
||||
@define-color bg_color shade (@base_color, 0.96);
|
||||
|
||||
/* Hide the marks at the beginning and the end */
|
||||
.night-light-temperature mark indicator:nth-child(even) {
|
||||
color:transparent;
|
||||
}
|
||||
|
||||
.night-light-temperature trough {
|
||||
min-height: 8px;
|
||||
background-image: linear-gradient(to right, mix(@bg_color, @ORANGE_100, 0.5), @ORANGE_500);
|
||||
}
|
||||
|
||||
.night-light-temperature:dir(rtl) trough {
|
||||
background-image: linear-gradient(to left, mix(@bg_color, @ORANGE_100, 0.5), @ORANGE_500);
|
||||
}
|
||||
|
||||
.padded-spinbutton {
|
||||
font-size: 110%;
|
||||
min-width: 50px;
|
||||
}
|
||||
|
||||
.unpadded-button {
|
||||
padding: 6px;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue