-
-
Save cwendling/797796eaffdf8688f1f286b96f637a28 to your computer and use it in GitHub Desktop.
WIP to add a minimal brightness percentage to mate-power-manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/data/org.mate.power-manager.gschema.xml.in b/data/org.mate.power-manager.gschema.xml.in | |
index db0593a..0cbfcf4 100644 | |
--- a/data/org.mate.power-manager.gschema.xml.in | |
+++ b/data/org.mate.power-manager.gschema.xml.in | |
@@ -345,5 +345,10 @@ | |
<summary>When to show the notification icon</summary> | |
<description>Display options for the notification icon.</description> | |
</key> | |
+ <key name="brightness-min" type="d"> | |
+ <default>0.0</default> | |
+ <summary>Minimal LCD brightness</summary> | |
+ <description>The minimal brightness of the display. Possible values are between 0.0 and 100.0.</description> | |
+ </key> | |
</schema> | |
</schemalist> | |
diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c | |
index f687a53..fa487ac 100644 | |
--- a/src/gpm-backlight.c | |
+++ b/src/gpm-backlight.c | |
@@ -114,7 +114,7 @@ gpm_backlight_get_brightness (GpmBacklight *backlight, guint *brightness, GError | |
} | |
/* gets the current brightness */ | |
- ret = gpm_brightness_get (backlight->priv->brightness, &level); | |
+ ret = gpm_backlight_brightness_get_internal (backlight->priv->brightness, &level); | |
if (ret) { | |
*brightness = level; | |
} else { | |
@@ -149,7 +149,7 @@ gpm_backlight_set_brightness (GpmBacklight *backlight, guint percentage, GError | |
backlight->priv->master_percentage = percentage; | |
/* sets the current policy brightness */ | |
- ret = gpm_brightness_set (backlight->priv->brightness, percentage, &hw_changed); | |
+ ret = gpm_backlight_brightness_set_internal (backlight->priv->brightness, percentage, &hw_changed); | |
if (!ret) { | |
g_set_error_literal (error, gpm_backlight_error_quark (), | |
GPM_BACKLIGHT_ERROR_GENERAL, | |
@@ -266,6 +266,34 @@ gpm_common_sum_scale (gfloat value1, gfloat value2, gfloat factor) | |
return value2 + (diff * factor); | |
} | |
+/* gets the brightness value converted to the range we expose (min, max) */ | |
+static gboolean | |
+gpm_backlight_brightness_get_internal (GpmBacklight *backlight, guint *percentage) | |
+{ | |
+ guint value; | |
+ if (! gpm_brightness_get (backlight->priv->brightness, &value)) | |
+ return FALSE; | |
+ | |
+ if (percentage) { | |
+ gdouble min_brightness = g_settings_get_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_MIN); | |
+ | |
+ value = (guint) ((value - min_brightness) * 100 / (100 - min_brightness)); | |
+ *percent = CLAMP (value, 0, 100); | |
+ } | |
+ | |
+ return TRUE; | |
+} | |
+ | |
+/* sets the brightness value converted from the range we expose (min, max) */ | |
+static gboolean | |
+gpm_backlight_brightness_set_internal (GpmBacklight *backlight, guint percentage, gboolean *hw_changed) | |
+{ | |
+ gdouble min_brightness = g_settings_get_double (backlight->priv->settings, GPM_SETTINGS_BRIGHTNESS_MIN); | |
+ guint value = (guint) (min_brightness + percentage * (100 - min_brightness) / 100); | |
+ | |
+ return gpm_brightness_set (backlight->priv->brightness, value, hw_changed); | |
+} | |
+ | |
/** | |
* gpm_backlight_brightness_evaluate_and_set: | |
**/ | |
@@ -343,7 +371,7 @@ gpm_backlight_brightness_evaluate_and_set (GpmBacklight *backlight, gboolean int | |
value = (guint) ((brightness * 100.0f) + 0.5); | |
/* only do stuff if the brightness is different */ | |
- gpm_brightness_get (backlight->priv->brightness, &old_value); | |
+ gpm_backlight_brightness_get_internal (backlight->priv->brightness, &old_value); | |
if (old_value == value) { | |
g_debug ("values are the same, no action"); | |
return FALSE; | |
@@ -357,7 +385,7 @@ gpm_backlight_brightness_evaluate_and_set (GpmBacklight *backlight, gboolean int | |
gpm_backlight_dialog_show (backlight); | |
} | |
- ret = gpm_brightness_set (backlight->priv->brightness, value, &hw_changed); | |
+ ret = gpm_backlight_brightness_set_internal (backlight->priv->brightness, value, &hw_changed); | |
/* we emit a signal for the brightness applet */ | |
if (ret && hw_changed) { | |
g_debug ("emitting brightness-changed : %i", value); | |
@@ -435,11 +463,12 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli | |
if (g_strcmp0 (type, GPM_BUTTON_BRIGHT_UP) == 0) { | |
/* go up one step */ | |
+ /* FIXME: */ | |
ret = gpm_brightness_up (backlight->priv->brightness, &hw_changed); | |
/* show the new value */ | |
if (ret) { | |
- gpm_brightness_get (backlight->priv->brightness, &percentage); | |
+ gpm_backlight_brightness_get_internal (backlight->priv->brightness, &percentage); | |
gpm_backlight_dialog_init (backlight); | |
msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), | |
percentage); | |
@@ -461,11 +490,12 @@ gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBackli | |
} | |
} else if (g_strcmp0 (type, GPM_BUTTON_BRIGHT_DOWN) == 0) { | |
/* go up down step */ | |
+ /* FIXME: */ | |
ret = gpm_brightness_down (backlight->priv->brightness, &hw_changed); | |
/* show the new value */ | |
if (ret) { | |
- gpm_brightness_get (backlight->priv->brightness, &percentage); | |
+ gpm_backlight_brightness_get_internal (backlight->priv->brightness, &percentage); | |
gpm_backlight_dialog_init (backlight); | |
msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), | |
percentage); | |
diff --git a/src/gpm-common.h b/src/gpm-common.h | |
index b2b0b1a..1ced3b8 100644 | |
--- a/src/gpm-common.h | |
+++ b/src/gpm-common.h | |
@@ -65,6 +65,7 @@ G_BEGIN_DECLS | |
#define GPM_SETTINGS_IDLE_DIM_TIME "idle-dim-time" | |
#define GPM_SETTINGS_BRIGHTNESS_AC "brightness-ac" | |
#define GPM_SETTINGS_BRIGHTNESS_DIM_BATT "brightness-dim-battery" | |
+#define GPM_SETTINGS_BRIGHTNESS_MIN "brightness-min" | |
/* keyboard backlight */ | |
#define GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE "kbd-backlight-battery-reduce" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment