[gnome-control-center] power: Refactor brightness scale code into a CcBrightnessScale class
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] power: Refactor brightness scale code into a CcBrightnessScale class
- Date: Tue, 18 Aug 2020 03:03:40 +0000 (UTC)
commit 3893a1da77d6afcc663225f4832df11bb8177fce
Author: Ian Douglas Scott <idscott system76 com>
Date: Wed Aug 5 13:55:07 2020 -0700
power: Refactor brightness scale code into a CcBrightnessScale class
This reduces some redundancy between the screen brightness and keyboard
brightness code.
Such refactoring is a prerequisite for including a keyboard backlight
control in the Keyboard panel, as has been [proposed][1]. But hopefully
this makes the code a bit neater and more managable even without that.
[1]:
https://gitlab.gnome.org/Teams/Design/settings-mockups/-/blob/master/keyboard/Keyboard-with-dialogs.png
panels/power/cc-brightness-scale.c | 282 ++++++++++++++++++++++++++++++++++++
panels/power/cc-brightness-scale.h | 38 +++++
panels/power/cc-power-panel.c | 286 ++++++-------------------------------
panels/power/meson.build | 9 +-
4 files changed, 372 insertions(+), 243 deletions(-)
---
diff --git a/panels/power/cc-brightness-scale.c b/panels/power/cc-brightness-scale.c
new file mode 100644
index 000000000..517177771
--- /dev/null
+++ b/panels/power/cc-brightness-scale.c
@@ -0,0 +1,282 @@
+/* cc-brightness-scale.c
+ *
+ * Copyright (C) 2010 Red Hat, Inc
+ * Copyright (C) 2008 William Jon McCann <jmccann redhat com>
+ * Copyright (C) 2010,2015 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2020 System76, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "cc-brightness-scale.h"
+#include "shell/cc-object-storage.h"
+
+struct _CcBrightnessScale {
+ GtkScale parent_instance;
+
+ GCancellable *cancellable;
+ BrightnessDevice device;
+ gboolean has_brightness;
+ GDBusProxy *proxy;
+ gboolean setting_brightness;
+};
+
+enum
+{
+ PROP_0,
+ PROP_HAS_BRIGHTNESS,
+ PROP_DEVICE,
+};
+
+G_DEFINE_TYPE (CcBrightnessScale, cc_brightness_scale, GTK_TYPE_SCALE)
+
+static void
+set_brightness_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) result = NULL;
+ GDBusProxy *proxy = G_DBUS_PROXY (source_object);
+
+ result = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (result == NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_printerr ("Error setting brightness: %s\n", error->message);
+ return;
+ }
+
+ CcBrightnessScale *self = CC_BRIGHTNESS_SCALE (user_data);
+
+ /* not setting, so pay attention to changed signals */
+ self->setting_brightness = FALSE;
+}
+
+static void
+brightness_slider_value_changed_cb (CcBrightnessScale *self, GtkRange *range)
+{
+ guint percentage;
+ g_autoptr(GVariant) variant = NULL;
+
+ percentage = (guint) gtk_range_get_value (range);
+
+ /* do not loop */
+ if (self->setting_brightness)
+ return;
+
+ self->setting_brightness = TRUE;
+
+ if (self->device == BRIGHTNESS_DEVICE_KBD)
+ variant = g_variant_new_parsed ("('org.gnome.SettingsDaemon.Power.Keyboard',"
+ "'Brightness', %v)",
+ g_variant_new_int32 (percentage));
+ else
+ variant = g_variant_new_parsed ("('org.gnome.SettingsDaemon.Power.Screen',"
+ "'Brightness', %v)",
+ g_variant_new_int32 (percentage));
+
+ /* push this to g-s-d */
+ g_dbus_proxy_call (self->proxy,
+ "org.freedesktop.DBus.Properties.Set",
+ g_variant_ref_sink (variant),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ self->cancellable,
+ set_brightness_cb,
+ self);
+}
+
+static void
+sync_brightness (CcBrightnessScale *self)
+{
+ g_autoptr(GVariant) result = NULL;
+ gint brightness;
+ GtkRange *range;
+
+ result = g_dbus_proxy_get_cached_property (self->proxy, "Brightness");
+
+ if (result)
+ {
+ /* set the slider */
+ brightness = g_variant_get_int32 (result);
+ self->has_brightness = brightness >= 0.0;
+ }
+ else
+ {
+ self->has_brightness = FALSE;
+ }
+
+ g_object_notify (G_OBJECT (self), "has-brightness");
+
+ if (self->has_brightness)
+ {
+ range = GTK_RANGE (self);
+ self->setting_brightness = TRUE;
+ gtk_range_set_value (range, brightness);
+ self->setting_brightness = FALSE;
+ }
+}
+
+static void
+got_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ g_autoptr(GError) error = NULL;
+ CcBrightnessScale *self;
+ GDBusProxy *proxy;
+
+ self = CC_BRIGHTNESS_SCALE (user_data);
+
+ proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
+ if (proxy == NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_printerr ("Error creating proxy: %s\n", error->message);
+ return;
+ }
+
+ self->proxy = proxy;
+
+ g_signal_connect_object (proxy, "g-properties-changed",
+ G_CALLBACK (sync_brightness), self, G_CONNECT_SWAPPED);
+
+ sync_brightness (self);
+}
+
+static void
+cc_brightness_scale_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ CcBrightnessScale *self;
+
+ self = CC_BRIGHTNESS_SCALE (object);
+
+ switch (prop_id) {
+ case PROP_HAS_BRIGHTNESS:
+ g_value_set_boolean (value, self->has_brightness);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_brightness_scale_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ CcBrightnessScale *self;
+
+ self = CC_BRIGHTNESS_SCALE (object);
+
+ switch (prop_id) {
+ case PROP_DEVICE:
+ self->device = g_value_get_enum (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_brightness_scale_constructed (GObject *object)
+{
+ CcBrightnessScale *self;
+ const gchar *interface;
+
+ G_OBJECT_CLASS (cc_brightness_scale_parent_class)->constructed (object);
+
+ self = CC_BRIGHTNESS_SCALE (object);
+
+ self->cancellable = g_cancellable_new();
+
+ g_signal_connect_object (GTK_SCALE (self), "value-changed",
+ G_CALLBACK (brightness_slider_value_changed_cb), self, G_CONNECT_SWAPPED);
+
+ if (self->device == BRIGHTNESS_DEVICE_KBD)
+ interface = "org.gnome.SettingsDaemon.Power.Keyboard";
+ else
+ interface = "org.gnome.SettingsDaemon.Power.Screen";
+
+ cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.SettingsDaemon.Power",
+ "/org/gnome/SettingsDaemon/Power",
+ interface,
+ self->cancellable,
+ got_proxy_cb,
+ self);
+
+ gtk_range_set_range (GTK_RANGE (self), 0, 100);
+ gtk_range_set_increments (GTK_RANGE (self), 1, 10);
+ gtk_range_set_round_digits (GTK_RANGE (self), 0);
+ gtk_scale_set_draw_value (GTK_SCALE (self), FALSE);
+}
+
+static void
+cc_brightness_scale_finalize (GObject *object)
+{
+ CcBrightnessScale *self = CC_BRIGHTNESS_SCALE (object);
+
+ g_cancellable_cancel (self->cancellable);
+
+ G_OBJECT_CLASS (cc_brightness_scale_parent_class)->finalize (object);
+}
+
+void
+cc_brightness_scale_class_init (CcBrightnessScaleClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = cc_brightness_scale_get_property;
+ object_class->set_property = cc_brightness_scale_set_property;
+ object_class->constructed = cc_brightness_scale_constructed;
+ object_class->finalize = cc_brightness_scale_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_DEVICE,
+ g_param_spec_enum ("device",
+ "device",
+ "device",
+ brightness_device_get_type(),
+ BRIGHTNESS_DEVICE_SCREEN,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_HAS_BRIGHTNESS,
+ g_param_spec_boolean ("has-brightness",
+ "has brightness",
+ "has brightness",
+ FALSE,
+ G_PARAM_READABLE));
+}
+
+static void
+cc_brightness_scale_init (CcBrightnessScale *self)
+{
+}
+
+
+gboolean
+cc_brightness_scale_get_has_brightness (CcBrightnessScale *self)
+{
+ g_return_val_if_fail (CC_IS_BRIGHTNESS_SCALE (self), FALSE);
+
+ return self->has_brightness;
+}
diff --git a/panels/power/cc-brightness-scale.h b/panels/power/cc-brightness-scale.h
new file mode 100644
index 000000000..b55d05b33
--- /dev/null
+++ b/panels/power/cc-brightness-scale.h
@@ -0,0 +1,38 @@
+/* cc-brightness-scale.h
+ *
+ * Copyright (C) 2020 System76, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include "cc-brightness-scale-types.h"
+
+G_BEGIN_DECLS
+
+typedef enum {
+ BRIGHTNESS_DEVICE_SCREEN,
+ BRIGHTNESS_DEVICE_KBD,
+} BrightnessDevice;
+
+#define CC_TYPE_BRIGHTNESS_SCALE (cc_brightness_scale_get_type())
+G_DECLARE_FINAL_TYPE (CcBrightnessScale, cc_brightness_scale, CC, BRIGHTNESS_SCALE, GtkBox)
+
+gboolean cc_brightness_scale_get_has_brightness (CcBrightnessScale*);
+
+G_END_DECLS
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index e565ee934..044f633f9 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -31,6 +31,7 @@
#include "shell/cc-object-storage.h"
#include "list-box-helper.h"
+#include "cc-brightness-scale.h"
#include "cc-power-panel.h"
#include "cc-power-resources.h"
#include "cc-util.h"
@@ -75,8 +76,6 @@ struct _CcPowerPanel
GtkListStore *liststore_power_button;
UpClient *up_client;
GPtrArray *devices;
- GDBusProxy *screen_proxy;
- GDBusProxy *kbd_proxy;
gboolean has_batteries;
char *chassis_type;
@@ -99,11 +98,9 @@ struct _CcPowerPanel
GtkWidget *dim_screen_row;
GtkWidget *brightness_row;
- GtkWidget *brightness_scale;
- gboolean setting_brightness;
+ CcBrightnessScale *brightness_scale;
GtkWidget *kbd_brightness_row;
- GtkWidget *kbd_brightness_scale;
- gboolean kbd_setting_brightness;
+ CcBrightnessScale *kbd_brightness_scale;
GtkWidget *automatic_suspend_row;
GtkWidget *automatic_suspend_label;
@@ -150,8 +147,6 @@ cc_power_panel_dispose (GObject *object)
g_clear_object (&self->session_settings);
g_clear_object (&self->interface_settings);
g_clear_pointer (&self->automatic_suspend_dialog, gtk_widget_destroy);
- g_clear_object (&self->screen_proxy);
- g_clear_object (&self->kbd_proxy);
g_clear_pointer (&self->devices, g_ptr_array_unref);
g_clear_object (&self->up_client);
g_clear_object (&self->bt_rfkill);
@@ -1034,144 +1029,6 @@ up_client_device_added (CcPowerPanel *self,
up_client_changed (self);
}
-static void
-set_brightness_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- CcPowerPanel *self = CC_POWER_PANEL (user_data);
- g_autoptr(GError) error = NULL;
- g_autoptr(GVariant) result = NULL;
- GDBusProxy *proxy = G_DBUS_PROXY (source_object);
-
- /* not setting, so pay attention to changed signals */
- if (proxy == self->screen_proxy)
- self->setting_brightness = FALSE;
- else if (proxy == self->kbd_proxy)
- self->kbd_setting_brightness = FALSE;
-
- result = g_dbus_proxy_call_finish (proxy, res, &error);
- if (result == NULL)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_printerr ("Error setting brightness: %s\n", error->message);
- return;
- }
-}
-
-static void
-brightness_slider_value_changed_cb (CcPowerPanel *self, GtkRange *range)
-{
- guint percentage;
- g_autoptr(GVariant) variant = NULL;
- GDBusProxy *proxy;
-
- percentage = (guint) gtk_range_get_value (range);
-
- if (range == GTK_RANGE (self->brightness_scale))
- {
- /* do not loop */
- if (self->setting_brightness)
- return;
-
- self->setting_brightness = TRUE;
- proxy = self->screen_proxy;
-
- variant = g_variant_new_parsed ("('org.gnome.SettingsDaemon.Power.Screen',"
- "'Brightness', %v)",
- g_variant_new_int32 (percentage));
- }
- else
- {
- /* do not loop */
- if (self->kbd_setting_brightness)
- return;
-
- self->kbd_setting_brightness = TRUE;
- proxy = self->kbd_proxy;
-
- variant = g_variant_new_parsed ("('org.gnome.SettingsDaemon.Power.Keyboard',"
- "'Brightness', %v)",
- g_variant_new_int32 (percentage));
- }
-
- /* push this to g-s-d */
- g_dbus_proxy_call (proxy,
- "org.freedesktop.DBus.Properties.Set",
- g_variant_ref_sink (variant),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- cc_panel_get_cancellable (CC_PANEL (self)),
- set_brightness_cb,
- self);
-}
-
-static void
-sync_kbd_brightness (CcPowerPanel *self)
-{
- g_autoptr(GVariant) result = NULL;
- gint brightness;
- gboolean visible;
- GtkRange *range;
-
- result = g_dbus_proxy_get_cached_property (self->kbd_proxy, "Brightness");
- if (result)
- {
- /* set the slider */
- brightness = g_variant_get_int32 (result);
- visible = brightness >= 0.0;
- }
- else
- {
- visible = FALSE;
- }
-
- gtk_widget_set_visible (self->kbd_brightness_row, visible);
-
- if (visible)
- {
- range = GTK_RANGE (self->kbd_brightness_scale);
- gtk_range_set_range (range, 0, 100);
- gtk_range_set_increments (range, 1, 10);
- self->kbd_setting_brightness = TRUE;
- gtk_range_set_value (range, brightness);
- self->kbd_setting_brightness = FALSE;
- }
-}
-
-static void
-sync_screen_brightness (CcPowerPanel *self)
-{
- g_autoptr(GVariant) result = NULL;
- gint brightness;
- gboolean visible;
- GtkRange *range;
-
- result = g_dbus_proxy_get_cached_property (self->screen_proxy, "Brightness");
-
- if (result)
- {
- /* set the slider */
- brightness = g_variant_get_int32 (result);
- visible = brightness >= 0.0;
- }
- else
- {
- visible = FALSE;
- }
-
- gtk_widget_set_visible (self->brightness_row, visible);
- gtk_widget_set_visible (self->dim_screen_row, visible);
-
- if (visible)
- {
- range = GTK_RANGE (self->brightness_scale);
- gtk_range_set_range (range, 0, 100);
- gtk_range_set_increments (range, 1, 10);
- self->setting_brightness = TRUE;
- gtk_range_set_value (range, brightness);
- self->setting_brightness = FALSE;
- }
-}
-
static void
als_switch_changed (CcPowerPanel *self)
{
@@ -1188,12 +1045,7 @@ als_enabled_state_changed (CcPowerPanel *self)
gboolean has_brightness = FALSE;
gboolean visible = FALSE;
- if (self->screen_proxy != NULL)
- {
- g_autoptr(GVariant) v = g_dbus_proxy_get_cached_property (self->screen_proxy, "Brightness");
- if (v != NULL)
- has_brightness = g_variant_get_int32 (v) >= 0.0;
- }
+ has_brightness = cc_brightness_scale_get_has_brightness (self->brightness_scale);
if (self->iio_proxy != NULL)
{
@@ -1210,69 +1062,6 @@ als_enabled_state_changed (CcPowerPanel *self)
g_signal_handlers_unblock_by_func (self->als_switch, als_switch_changed, self);
}
-static void
-on_screen_property_change (CcPowerPanel *self)
-{
- sync_screen_brightness (self);
-}
-
-static void
-got_screen_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- g_autoptr(GError) error = NULL;
- CcPowerPanel *self;
- GDBusProxy *screen_proxy;
-
- screen_proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
- if (screen_proxy == NULL)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_printerr ("Error creating screen proxy: %s\n", error->message);
- return;
- }
-
- self = CC_POWER_PANEL (user_data);
- self->screen_proxy = screen_proxy;
-
- /* we want to change the bar if the user presses brightness buttons */
- g_signal_connect_object (screen_proxy, "g-properties-changed",
- G_CALLBACK (on_screen_property_change), self, G_CONNECT_SWAPPED);
-
- sync_screen_brightness (self);
- als_enabled_state_changed (self);
-}
-
-static void
-on_kbd_property_change (CcPowerPanel *self)
-{
- sync_kbd_brightness (self);
-}
-
-static void
-got_kbd_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- CcPowerPanel *self;
- g_autoptr(GError) error = NULL;
- GDBusProxy *kbd_proxy;
-
- kbd_proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
- if (kbd_proxy == NULL)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_printerr ("Error creating keyboard proxy: %s\n", error->message);
- return;
- }
-
- self = CC_POWER_PANEL (user_data);
- self->kbd_proxy = kbd_proxy;
-
- /* we want to change the bar if the user presses brightness buttons */
- g_signal_connect_object (kbd_proxy, "g-properties-changed",
- G_CALLBACK (on_kbd_property_change), self, G_CONNECT_SWAPPED);
-
- sync_kbd_brightness (self);
-}
-
static void
combo_time_changed_cb (CcPowerPanel *self, GtkWidget *widget)
{
@@ -1739,9 +1528,10 @@ combo_power_button_changed_cb (CcPowerPanel *self)
}
static GtkWidget *
-add_brightness_row (CcPowerPanel *self,
- const char *text,
- GtkWidget **brightness_scale)
+add_brightness_row (CcPowerPanel *self,
+ BrightnessDevice device,
+ const char *text,
+ CcBrightnessScale **brightness_scale)
{
GtkWidget *row, *box, *label, *title, *box2, *w, *scale;
@@ -1759,15 +1549,14 @@ add_brightness_row (CcPowerPanel *self,
gtk_box_pack_start (GTK_BOX (box2), w, FALSE, TRUE, 0);
gtk_size_group_add_widget (self->charge_sizegroup, w);
- *brightness_scale = scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
+ scale = g_object_new (CC_TYPE_BRIGHTNESS_SCALE,
+ "device", device,
+ NULL);
gtk_widget_show (scale);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), scale);
- gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0);
gtk_size_group_add_widget (self->level_sizegroup, scale);
- gtk_range_set_round_digits (GTK_RANGE (scale), 0);
- g_signal_connect_object (scale, "value-changed",
- G_CALLBACK (brightness_slider_value_changed_cb), self, G_CONNECT_SWAPPED);
+ *brightness_scale = CC_BRIGHTNESS_SCALE (scale);
gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);
@@ -2008,6 +1797,32 @@ can_suspend_or_hibernate (CcPowerPanel *self,
return g_strcmp0 (s, "yes") == 0;
}
+static void
+has_brightness_cb (CcPowerPanel *self)
+{
+ gboolean has_brightness;
+
+ has_brightness = cc_brightness_scale_get_has_brightness (self->brightness_scale);
+
+ gtk_widget_set_visible (self->brightness_row, has_brightness);
+ gtk_widget_set_visible (self->dim_screen_row, has_brightness);
+
+ als_enabled_state_changed (self);
+
+}
+
+static void
+has_kbd_brightness_cb (CcPowerPanel *self,
+ GParamSpec *pspec,
+ GObject *object)
+{
+ gboolean has_brightness;
+
+ has_brightness = cc_brightness_scale_get_has_brightness (self->kbd_brightness_scale);
+
+ gtk_widget_set_visible (self->kbd_brightness_row, has_brightness);
+}
+
static void
add_power_saving_section (CcPowerPanel *self)
{
@@ -2054,7 +1869,9 @@ add_power_saving_section (CcPowerPanel *self)
gtk_container_add (GTK_CONTAINER (box), widget);
gtk_box_pack_start (GTK_BOX (self->vbox_power), box, FALSE, TRUE, 0);
- row = add_brightness_row (self, _("_Screen Brightness"), &self->brightness_scale);
+ row = add_brightness_row (self, BRIGHTNESS_DEVICE_SCREEN, _("_Screen Brightness"),
&self->brightness_scale);
+ g_signal_connect_object (self->brightness_scale, "notify::has-brightness",
+ G_CALLBACK (has_brightness_cb), self, G_CONNECT_SWAPPED);
gtk_widget_show (row);
self->brightness_row = row;
@@ -2088,7 +1905,9 @@ add_power_saving_section (CcPowerPanel *self)
g_signal_connect_object (self->als_switch, "notify::active",
G_CALLBACK (als_switch_changed), self, G_CONNECT_SWAPPED);
- row = add_brightness_row (self, _("_Keyboard Brightness"), &self->kbd_brightness_scale);
+ row = add_brightness_row (self, BRIGHTNESS_DEVICE_KBD, _("_Keyboard Brightness"),
&self->kbd_brightness_scale);
+ g_signal_connect_object (self->kbd_brightness_scale, "notify::has-brightness",
+ G_CALLBACK (has_kbd_brightness_cb), self, G_CONNECT_SWAPPED);
gtk_widget_show (row);
self->kbd_brightness_row = row;
@@ -2548,23 +2367,6 @@ cc_power_panel_init (CcPowerPanel *self)
gtk_widget_init_template (GTK_WIDGET (self));
load_custom_css (self);
- cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.gnome.SettingsDaemon.Power",
- "/org/gnome/SettingsDaemon/Power",
- "org.gnome.SettingsDaemon.Power.Screen",
- cc_panel_get_cancellable (CC_PANEL (self)),
- got_screen_proxy_cb,
- self);
- cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.gnome.SettingsDaemon.Power",
- "/org/gnome/SettingsDaemon/Power",
- "org.gnome.SettingsDaemon.Power.Keyboard",
- cc_panel_get_cancellable (CC_PANEL (self)),
- got_kbd_proxy_cb,
- self);
-
self->chassis_type = get_chassis_type (cc_panel_get_cancellable (CC_PANEL (self)));
self->up_client = up_client_new ();
diff --git a/panels/power/meson.build b/panels/power/meson.build
index 737d86817..1700c91e8 100644
--- a/panels/power/meson.build
+++ b/panels/power/meson.build
@@ -17,7 +17,14 @@ i18n.merge_file(
install_dir: control_center_desktopdir
)
-sources = files('cc-power-panel.c')
+sources = files(
+ 'cc-brightness-scale.c',
+ 'cc-power-panel.c'
+)
+
+sources += gnome.mkenums_simple(
+ 'cc-brightness-scale-types',
+ sources: ['cc-brightness-scale.h'])
resource_data = files('cc-power-panel.ui')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]