Commit b27c8dd0 authored by Benjamin Berg's avatar Benjamin Berg

display: Add UI to change nightlight color temperature

This adds a scale to change the color temperature between 2700K up to
6500K. A mark is added to the default value and a second one for
aesthetics.

Closes #147
parent 433c247f
Pipeline #36428 passed with stages
in 3 minutes and 51 seconds
......@@ -35,6 +35,7 @@ struct _CcNightLightDialog {
GtkWidget *box_manual;
GtkWidget *infobar_disabled;
GtkWidget *night_light_widget;
GtkWidget *scale_color_temperature;
GtkWidget *spinbutton_from_hours;
GtkWidget *spinbutton_from_minutes;
GtkWidget *spinbutton_to_hours;
......@@ -49,6 +50,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;
......@@ -213,6 +215,10 @@ dialog_update_state (CcNightLightDialog *self)
cc_night_light_widget_set_to (CC_NIGHT_LIGHT_WIDGET (self->night_light_widget), value);
value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
gtk_adjustment_set_value (self->adjustment_color_temperature, value);
/* set new time */
cc_night_light_widget_set_now (CC_NIGHT_LIGHT_WIDGET (self->night_light_widget), frac_day_from_dt (dt));
}
......@@ -343,6 +349,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,
......@@ -553,9 +575,11 @@ 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, night_light_widget);
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);
......@@ -574,6 +598,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);
g_type_ensure (CC_TYPE_NIGHT_LIGHT_WIDGET);
......@@ -587,6 +612,20 @@ cc_night_light_dialog_init (CcNightLightDialog *self)
gtk_widget_init_template (GTK_WIDGET (self));
/* Add a mark at 4000 (default) and half way to daylight temperature.
* This result in three sections:
* * 2700K - 4000K ("soft white" - our default)
* * 4000K - 5250K
* * 5250K - 6500K (daylight)
*/
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),
5250, GTK_POS_BOTTOM,
NULL);
self->cancellable = g_cancellable_new ();
self->settings_display = g_settings_new (DISPLAY_SCHEMA);
......
......@@ -141,7 +141,7 @@
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Schedule</property>
<property name="label" translatable="yes">Color Temperature</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
......@@ -151,6 +151,22 @@
<property name="top_attach">1</property>
</packing>
</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">Schedule</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_enable">
<property name="visible">True</property>
......@@ -163,6 +179,25 @@
<property name="top_attach">0</property>
</packing>
</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="restrict_to_fill_level">False</property>
<property name="fill_level">1</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="draw_value">False</property>
<property name="has_origin">False</property>
<property name="value_pos">bottom</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
......@@ -203,7 +238,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
......@@ -492,4 +527,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">2700</property>
<property name="upper">6500</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>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment