From 8978c98c76dbef09d2912a55fac1ac72a7918ef5 Mon Sep 17 00:00:00 2001
From: Nachanon Vetjasit <nachanon@users.noreply.github.com>
Date: Sat, 12 Sep 2015 16:32:11 +0700
Subject: Save AC-power backlight set via brightness keys in GSettings

Based on a patch by Flos Lonicerae.
---
 src/gpm-backlight.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

(limited to 'src')

diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c
index d2938a4..72cb66b 100644
--- a/src/gpm-backlight.c
+++ b/src/gpm-backlight.c
@@ -433,6 +433,7 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli
 	GError *error = NULL;
 	guint percentage;
 	gboolean hw_changed;
+	gboolean on_battery;
 	egg_debug ("Button press event type=%s", type);
 
 	if (g_strcmp0 (type, GPM_BUTTON_BRIGHT_UP) == 0) {
@@ -448,6 +449,13 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli
 			gpm_backlight_dialog_show (backlight);
 			/* save the new percentage */
 			backlight->priv->master_percentage = percentage;
+			/* if using AC power supply, save the new brightness settings */
+			g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL);
+			if (!on_battery) {
+				egg_debug ("saving brightness for ac supply: %i", percentage);
+				g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC,
+						       percentage*1.0);
+			}
 		}
 		/* we emit a signal for the brightness applet */
 		if (ret && hw_changed) {
@@ -467,6 +475,13 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli
 			gpm_backlight_dialog_show (backlight);
 			/* save the new percentage */
 			backlight->priv->master_percentage = percentage;
+			/* if using AC power supply, save the new brightness settings */
+			g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL);
+			if (!on_battery) {
+				egg_debug ("saving brightness for ac supply: %i", percentage);
+				g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC,
+						       percentage*1.0);
+			}
 		}
 		/* we emit a signal for the brightness applet */
 		if (ret && hw_changed) {
-- 
cgit v1.2.1