diff options
| -rw-r--r-- | data/gpm-prefs.ui | 6 | ||||
| -rw-r--r-- | data/org.mate.power-manager.gschema.xml.in | 5 | ||||
| -rw-r--r-- | src/gpm-backlight.c | 65 | ||||
| -rw-r--r-- | src/gpm-common.h | 1 | ||||
| -rw-r--r-- | src/gpm-kbd-backlight.c | 25 |
5 files changed, 69 insertions, 33 deletions
diff --git a/data/gpm-prefs.ui b/data/gpm-prefs.ui index 996fc60..070028d 100644 --- a/data/gpm-prefs.ui +++ b/data/gpm-prefs.ui @@ -23,6 +23,7 @@ <property name="title" translatable="yes">Power Management Preferences</property> <property name="icon_name">mate-power-manager</property> <property name="type_hint">dialog</property> + <property name="border-width">5</property> <signal name="delete-event" handler="on_dialog_preferences_delete_event" swapped="no"/> <child> <placeholder/> @@ -94,10 +95,7 @@ <object class="GtkNotebook" id="notebook_preferences"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="margin_left">12</property> - <property name="margin_right">12</property> - <property name="margin_top">12</property> - <property name="margin_bottom">12</property> + <property name="border-width">5</property> <child> <object class="GtkBox" id="box_ac"> <property name="visible">True</property> diff --git a/data/org.mate.power-manager.gschema.xml.in b/data/org.mate.power-manager.gschema.xml.in index db0593a..c7cfe00 100644 --- a/data/org.mate.power-manager.gschema.xml.in +++ b/data/org.mate.power-manager.gschema.xml.in @@ -61,6 +61,11 @@ <summary>Reduce the backlight brightness when on battery power</summary> <description>If the screen should be reduced in brightness when the computer is on battery power.</description> </key> + <key name="kbd-backlight-enable" type="b"> + <default>true</default> + <summary>Allow keyboard backlight brightness adjustment</summary> + <description>If the keyboard backlight brightness should be switched automatically.</description> + </key> <key name="kbd-backlight-battery-reduce" type="b"> <default>true</default> <summary>Reduce the keyboard backlight when on battery power</summary> diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c index c4e95ab..6f4ea7c 100644 --- a/src/gpm-backlight.c +++ b/src/gpm-backlight.c @@ -405,6 +405,52 @@ gpm_backlight_client_changed_cb (UpClient *client, GParamSpec *pspec, GpmBacklig } /** + * gpm_backlight_save_settings: + * @backlight: This class instance + * @percentage: Current brightess in percent + **/ +static void +gpm_backlight_save_settings (GpmBacklight *backlight, guint percentage) +{ + gint battery_reduce; + gfloat brightness_ac; + gboolean on_battery; + + backlight->priv->master_percentage = percentage; + g_object_get (backlight->priv->client, "on-battery", &on_battery, NULL); + if (on_battery) { + /* If using battery, saving settings needs a bit of trickery. + * IMHO this shows that using two factors for setting + * brightness level is a crooked idea to begin with, but + * this is still less random than only saving changes when + * running on AC. + */ + brightness_ac = g_settings_get_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC); + if (brightness_ac) { + battery_reduce = 100 - (gint) (percentage * 100.0f / brightness_ac); + } else { + /* Any negative number indicates we surpassed brightness_ac. 0 indicates nothing changed. */ + battery_reduce = - (gint) percentage; + } + if (battery_reduce < 0) { + /* Brightness set higher than brightness_ac - we have to adjust that value. */ + g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC, + percentage * 1.0); + battery_reduce = 0; + g_debug ("saving brightness for ac supply: %u", percentage); + } + g_debug ("saving brightness for battery - master percent: %u; ac supply: %f; dim battery: %u", + percentage, brightness_ac, battery_reduce); + g_settings_set_uint (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_DIM_BATT, (guint) battery_reduce); + } else { + /* if using AC power supply, save the new brightness settings */ + g_debug ("saving brightness for ac supply: %u", percentage); + g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC, + percentage * 1.0); + } +} + +/** * gpm_backlight_button_pressed_cb: * @power: The power class instance * @type: The button type, e.g. "power" @@ -418,7 +464,6 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli GError *error = NULL; guint percentage; gboolean hw_changed; - gboolean on_battery; g_debug ("Button press event type=%s", type); if (g_strcmp0 (type, GPM_BUTTON_BRIGHT_UP) == 0) { @@ -433,14 +478,7 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli percentage); 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) { - g_debug ("saving brightness for ac supply: %u", percentage); - g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC, - percentage*1.0); - } + gpm_backlight_save_settings (backlight, percentage); } /* we emit a signal for the brightness applet */ if (ret && hw_changed) { @@ -459,14 +497,7 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli percentage); 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) { - g_debug ("saving brightness for ac supply: %u", percentage); - g_settings_set_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_AC, - percentage*1.0); - } + gpm_backlight_save_settings (backlight, percentage); } /* we emit a signal for the brightness applet */ if (ret && hw_changed) { diff --git a/src/gpm-common.h b/src/gpm-common.h index e4a3a2b..f165918 100644 --- a/src/gpm-common.h +++ b/src/gpm-common.h @@ -68,6 +68,7 @@ G_BEGIN_DECLS #define GPM_SETTINGS_BRIGHTNESS_DIM_BATT "brightness-dim-battery" /* keyboard backlight */ +#define GPM_SETTINGS_KBD_BACKLIGHT_ENABLE "kbd-backlight-enable" #define GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE "kbd-backlight-battery-reduce" #define GPM_SETTINGS_KBD_BRIGHTNESS_ON_AC "kbd-brightness-on-ac" #define GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT "kbd-brightness-dim-by-on-battery" diff --git a/src/gpm-kbd-backlight.c b/src/gpm-kbd-backlight.c index 7adf0a8..bb7e9c0 100644 --- a/src/gpm-kbd-backlight.c +++ b/src/gpm-kbd-backlight.c @@ -383,6 +383,11 @@ gpm_kbd_backlight_evaluate_power_source_and_set (GpmKbdBacklight *backlight) guint value; guint dim_by = 0; + if (g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_ENABLE) == FALSE) { + g_debug ("policy is no dimming"); + return TRUE; + } + if (up_client_get_on_battery (backlight->priv->client) && g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE)) { dim_by = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT); @@ -440,19 +445,9 @@ gpm_kbd_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmKbdBacklight *backlight) { - static guint saved_brightness = ~0u; + static guint saved_brightness; gboolean ret; - if (saved_brightness == ~0u) { - saved_brightness = backlight->priv->brightness_percent; - /* If the initial value is 0, which probably means we saved on_ac=0, we - * try and restore some arbitrary value for the toggle not to seem - * broken */ - if (saved_brightness == 0) { - saved_brightness = 100u; - } - } - if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_UP) == 0) { ret = gpm_kbd_backlight_brightness_up (backlight); @@ -475,7 +470,13 @@ gpm_kbd_backlight_button_pressed_cb (GpmButton *button, } else if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_TOGGLE) == 0) { if (backlight->priv->brightness_percent == 0) { - /* backlight is off turn it back on */ + /* backlight is off turn it back on. + * If the initial value is 0, which probably means we saved on_ac=0, we + * try and restore some arbitrary value for the toggle not to seem + * broken. */ + if (saved_brightness == 0) { + saved_brightness = 100u; + } gpm_kbd_backlight_set (backlight, saved_brightness, TRUE); } else { /* backlight is on, turn it off and save current value */ |
