Commit 7ba5ecf0 authored by Nishal Kulkarni's avatar Nishal Kulkarni
Browse files

cc-night-light-page: Add brightness controls

Add UI controls for setting dim and default brightness.

Necessary for new feature that may be added to gnome-settings-daemon

Using 2 spin buttons instead of a single slider because
while the slider allowed for setting dim brightness level,
I couldn't figure out a way to revert to the brightness before
nightlight was enabled.

By allowing the user to set the default brightness level,
it becomes easier to reset the brightness when night light is off.

More information about the feature can be found in the GSD MR

GSD MR: gnome-settings-daemon!230

Closes GSD Issue: gnome-settings-daemon#528
parent ff574e2b
Pipeline #273597 passed with stages
in 5 minutes and 31 seconds
......@@ -33,6 +33,7 @@
struct _CcNightLightPage {
GtkBin parent;
GtkWidget *box_brightness;
GtkWidget *box_manual;
GtkButton *button_from_am;
GtkButton *button_from_pm;
......@@ -40,9 +41,13 @@ struct _CcNightLightPage {
GtkButton *button_to_pm;
GtkWidget *infobar_disabled;
GtkListBox *listbox;
GtkListBox *listbox_brightness;
GtkWidget *scale_color_temperature;
GtkWidget *night_light_brightness_toggle_switch;
GtkWidget *night_light_toggle_switch;
GtkComboBox *schedule_type_combo;
GtkWidget *spinbutton_default_percent;
GtkWidget *spinbutton_dim_percent;
GtkWidget *spinbutton_from_hours;
GtkWidget *spinbutton_from_minutes;
GtkWidget *spinbutton_to_hours;
......@@ -55,6 +60,8 @@ struct _CcNightLightPage {
GtkAdjustment *adjustment_to_hours;
GtkAdjustment *adjustment_to_minutes;
GtkAdjustment *adjustment_color_temperature;
GtkAdjustment *adjustment_brightness_dim_percent;
GtkAdjustment *adjustment_brightness_default_percent;
GSettings *settings_display;
GSettings *settings_clock;
......@@ -144,6 +151,8 @@ dialog_update_state (CcNightLightPage *self)
gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
gtk_widget_set_sensitive (self->box_brightness, enabled);
gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
/* set from */
......@@ -203,6 +212,10 @@ dialog_update_state (CcNightLightPage *self)
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);
value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-brightness-default");
gtk_adjustment_set_value (self->adjustment_brightness_default_percent, value);
value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-brightness-dim");
gtk_adjustment_set_value (self->adjustment_brightness_dim_percent, value);
self->ignore_value_changed = FALSE;
}
......@@ -379,6 +392,58 @@ dialog_color_temperature_value_changed_cb (GtkAdjustment *adjustment,
g_settings_set_uint (self->settings_display, "night-light-temperature", (guint) value);
}
static void
dialog_brightness_dim_value_changed_cb (GtkAdjustment *adjustment,
CcNightLightPage *self)
{
gdouble value;
if (self->ignore_value_changed)
return;
value = gtk_adjustment_get_value (adjustment);
g_debug ("new dim brightness value = %.0f", value);
if (self->proxy_color != NULL)
g_dbus_proxy_call (self->proxy_color,
"NightLightPreview",
g_variant_new ("(u)", NIGHT_LIGHT_PREVIEW_TIMEOUT_SECONDS),
G_DBUS_CALL_FLAGS_NONE,
5000,
NULL,
NULL,
NULL);
g_settings_set_uint (self->settings_display, "night-light-brightness-dim", (guint) value);
}
static void
dialog_brightness_default_value_changed_cb (GtkAdjustment *adjustment,
CcNightLightPage *self)
{
gdouble value;
if (self->ignore_value_changed)
return;
value = gtk_adjustment_get_value (adjustment);
g_debug ("new default brightness value = %.0f", value);
if (self->proxy_color != NULL)
g_dbus_proxy_call (self->proxy_color,
"NightLightPreview",
g_variant_new ("(u)", NIGHT_LIGHT_PREVIEW_TIMEOUT_SECONDS),
G_DBUS_CALL_FLAGS_NONE,
5000,
NULL,
NULL,
NULL);
g_settings_set_uint (self->settings_display, "night-light-brightness-default", (guint) value);
}
static void
dialog_color_properties_changed_cb (CcNightLightPage *self)
{
......@@ -583,16 +648,23 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_hours);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_brightness_default_percent);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_brightness_dim_percent);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_brightness);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox_brightness);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_brightness_toggle_switch);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, schedule_type_combo);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, scale_color_temperature);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_default_percent);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_dim_percent);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_from_hours);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_from_minutes);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, spinbutton_to_hours);
......@@ -608,6 +680,8 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
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_brightness_default_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, dialog_brightness_dim_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, dialog_undisable_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, on_schedule_type_combo_active_changed_cb);
......@@ -666,6 +740,14 @@ cc_night_light_page_init (CcNightLightPage *self)
self->spinbutton_to_minutes, "sensitive",
FALSE);
g_settings_bind (self->settings_display, "night-light-brightness-enabled",
self->night_light_brightness_toggle_switch, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind_writable (self->settings_display, "night-light-brightness-enabled",
self->night_light_brightness_toggle_switch, "sensitive",
FALSE);
/* use custom CSS */
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/display/night-light.css");
......
......@@ -403,6 +403,157 @@
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="label">Brightness dimming allows you to set screen brightness when night light mode is enabled.</property>
<property name="wrap">True</property>
<property name="max_width_chars">60</property>
<property name="xalign">0</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="sensitive" bind-source="night_light_toggle_switch" bind-property="active" bind-flags="default|sync-create" />
<child>
<object class="GtkListBox" id="listbox_brightness">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection-mode">none</property>
<!-- Brightness Switch -->
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="title">Brightness Dimming</property>
<property name="activatable-widget">night_light_brightness_toggle_switch</property>
<child>
<object class="GtkSwitch" id="night_light_brightness_toggle_switch">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<!-- Brightness Levels -->
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="title">Brightness Level</property>
<property name="sensitive" bind-source="night_light_brightness_toggle_switch" bind-property="active" bind-flags="default|sync-create" />
<child>
<object class="GtkBox" id="box_brightness">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<style>
<class name="time-widget" />
</style>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Dim</property>
<property name="mnemonic_widget">spinbutton_dim_percent</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkSpinButton" id="spinbutton_dim_percent">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_width_chars">2</property>
<property name="text">4</property>
<property name="orientation">horizontal</property>
<property name="adjustment">adjustment_brightness_dim_percent</property>
<property name="numeric">True</property>
<property name="wrap">False</property>
<property name="value">4</property>
<style>
<class name="padded-spinbutton"/>
</style>
<child internal-child="accessible">
<object class="AtkObject" id="dim_h_spinbutton-atkobject">
<property name="AtkObject::accessible-description">Percent</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin-start">6</property>
<property name="label">Default</property>
<property name="mnemonic_widget">spinbutton_default_percent</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkSpinButton" id="spinbutton_default_percent">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_width_chars">2</property>
<property name="text">4</property>
<property name="input_purpose">number</property>
<property name="orientation">horizontal</property>
<property name="adjustment">adjustment_brightness_default_percent</property>
<property name="numeric">True</property>
<property name="wrap">False</property>
<property name="value">4</property>
<style>
<class name="padded-spinbutton"/>
</style>
<child internal-child="accessible">
<object class="AtkObject" id="default_h_spinbutton-atkobject">
<property name="AtkObject::accessible-description" >Percent</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
......@@ -440,4 +591,18 @@
<property name="page_increment">500</property>
<signal name="value-changed" handler="dialog_color_temperature_value_changed_cb" object="CcNightLightPage" swapped="no" />
</object>
<object class="GtkAdjustment" id="adjustment_brightness_dim_percent">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="step_increment">5</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="dialog_brightness_dim_value_changed_cb" object="CcNightLightPage" swapped="no" />
</object>
<object class="GtkAdjustment" id="adjustment_brightness_default_percent">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="step_increment">5</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="dialog_brightness_default_value_changed_cb" object="CcNightLightPage" swapped="no" />
</object>
</interface>
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