[gnome-control-center] night-light: Add Color Temperature slider
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] night-light: Add Color Temperature slider
- Date: Mon, 7 Jan 2019 14:18:00 +0000 (UTC)
commit d1fc7e64b36462ee127e3097cf3f071291c103f6
Author: Jeremy Bicha <jbicha ubuntu com>
Date: Mon Dec 10 19:28:46 2018 -0500
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
panels/display/cc-night-light-dialog.c | 60 +++++++++++++++++++++++++--------
panels/display/cc-night-light-dialog.ui | 37 ++++++++++++++++++++
panels/display/display.gresource.xml | 1 +
panels/display/night-light.css | 28 +++++++++++++++
4 files changed, 112 insertions(+), 14 deletions(-)
---
diff --git a/panels/display/cc-night-light-dialog.c b/panels/display/cc-night-light-dialog.c
index 9f458df22..462c69198 100644
--- a/panels/display/cc-night-light-dialog.c
+++ b/panels/display/cc-night-light-dialog.c
@@ -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);
diff --git a/panels/display/cc-night-light-dialog.ui b/panels/display/cc-night-light-dialog.ui
index 2ff3e0a4c..86ff69576 100644
--- a/panels/display/cc-night-light-dialog.ui
+++ b/panels/display/cc-night-light-dialog.ui
@@ -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>
diff --git a/panels/display/display.gresource.xml b/panels/display/display.gresource.xml
index d90ac14af..5ecf8c596 100644
--- a/panels/display/display.gresource.xml
+++ b/panels/display/display.gresource.xml
@@ -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>
diff --git a/panels/display/night-light.css b/panels/display/night-light.css
new file mode 100644
index 000000000..a318f2b20
--- /dev/null
+++ b/panels/display/night-light.css
@@ -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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]