Merge lp:~fourdollars/unity-settings-daemon/fix-lowest-brightness into lp:unity-settings-daemon/14.04

Proposed by Shih-Yuan Lee
Status: Rejected
Rejected by: Iain Lane
Proposed branch: lp:~fourdollars/unity-settings-daemon/fix-lowest-brightness
Merge into: lp:unity-settings-daemon/14.04
Diff against target: 264 lines (+107/-23)
4 files modified
plugins/power/gpm-common.c (+1/-1)
plugins/power/gsd-backlight-helper.c (+86/-17)
plugins/power/gsd-backlight-linux.c (+13/-4)
plugins/power/gsd-backlight-linux.h (+7/-1)
To merge this branch: bzr merge lp:~fourdollars/unity-settings-daemon/fix-lowest-brightness
Reviewer Review Type Date Requested Status
Unity Settings Daemon Development Team Pending
Review via email: mp+278108@code.launchpad.net

Commit message

power: On raw backlight types, clamp the value to a minumum

Description of the change

Please help to review this change.
This change has been applied in xenial.
I am backporting it into trusty.

To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

You said on the bug that this isn't necessary, so closing it

Unmerged revisions

4049. By Shih-Yuan Lee

power: On raw backlight types, clamp the value to a minumum

Backlight class brightness 0 is to disable the backlight since kernel 3.18.
This behavior is by design for the backlight control in i915 kernel module.
http://lists.freedesktop.org/archives/intel-gfx/2014-August/050642.html

However gnome-settings-daemon has included some changeset to fix this issue.
https://bugzilla.gnome.org/show_bug.cgi?id=744278

unity-settings-daemon should include the same changeset to fix this issue. (LP: #1381625)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/power/gpm-common.c'
--- plugins/power/gpm-common.c 2013-12-04 23:55:26 +0000
+++ plugins/power/gpm-common.c 2015-11-20 08:06:29 +0000
@@ -1248,7 +1248,7 @@
1248#endif1248#endif
1249 if (get_primary_output (rr_screen) != NULL)1249 if (get_primary_output (rr_screen) != NULL)
1250 return TRUE;1250 return TRUE;
1251 path = gsd_backlight_helper_get_best_backlight ();1251 path = gsd_backlight_helper_get_best_backlight (NULL);
1252 if (path == NULL)1252 if (path == NULL)
1253 return FALSE;1253 return FALSE;
12541254
12551255
=== modified file 'plugins/power/gsd-backlight-helper.c'
--- plugins/power/gsd-backlight-helper.c 2013-01-23 22:53:38 +0000
+++ plugins/power/gsd-backlight-helper.c 2015-11-20 08:06:29 +0000
@@ -21,6 +21,7 @@
2121
22#include "config.h"22#include "config.h"
2323
24#include <stdlib.h>
24#include <unistd.h>25#include <unistd.h>
25#include <glib-object.h>26#include <glib-object.h>
26#include <locale.h>27#include <locale.h>
@@ -41,13 +42,16 @@
41static gboolean42static gboolean
42gsd_backlight_helper_write (const gchar *filename, gint value, GError **error)43gsd_backlight_helper_write (const gchar *filename, gint value, GError **error)
43{44{
45 gchar *filename_path = NULL;
44 gchar *text = NULL;46 gchar *text = NULL;
45 gint retval;47 gint retval;
46 gint length;48 gint length;
47 gint fd = -1;49 gint fd = -1;
48 gboolean ret = TRUE;50 gboolean ret = TRUE;
4951
50 fd = open (filename, O_WRONLY);52 filename_path = g_build_filename (filename, "brightness", NULL);
53
54 fd = open (filename_path, O_WRONLY);
51 if (fd < 0) {55 if (fd < 0) {
52 ret = FALSE;56 ret = FALSE;
53 g_set_error (error, 1, 0, "failed to open filename: %s", filename);57 g_set_error (error, 1, 0, "failed to open filename: %s", filename);
@@ -69,9 +73,64 @@
69 if (fd >= 0)73 if (fd >= 0)
70 close (fd);74 close (fd);
71 g_free (text);75 g_free (text);
76 g_free (filename_path);
72 return ret;77 return ret;
73}78}
7479
80static gint
81gsd_backlight_helper_read_value (const gchar *filename, GError **error)
82{
83 gchar *contents = NULL;
84 gint value;
85
86 if (g_file_get_contents (filename, &contents, NULL, error))
87 value = atoi (contents);
88 else
89 value = -1;
90 g_free (contents);
91
92 return value;
93}
94
95static gint
96gsd_backlight_helper_get (const gchar *filename, GError **error)
97{
98 gchar *filename_path = NULL;
99 gint value;
100
101 filename_path = g_build_filename (filename, "brightness", NULL);
102 value = gsd_backlight_helper_read_value (filename_path, error);
103 g_free (filename_path);
104 return value;
105}
106
107static gint
108gsd_backlight_helper_get_max (const gchar *filename, GError **error)
109{
110 gchar *filename_path = NULL;
111 gint value;
112
113 filename_path = g_build_filename (filename, "max_brightness", NULL);
114 value = gsd_backlight_helper_read_value (filename_path, error);
115 g_free (filename_path);
116 return value;
117}
118
119static gint
120clamp_minimum (gint max, gint value)
121{
122 gint minimum;
123 /* If the interface has less than 100 possible values, it's
124 * likely that 0 doesn't turn the backlight off so we let 0 be
125 * set in that case. */
126 if (max > 99)
127 minimum = 1;
128 else
129 minimum = 0;
130
131 return MAX (value, minimum);
132}
133
75int134int
76main (int argc, char *argv[])135main (int argc, char *argv[])
77{136{
@@ -80,13 +139,11 @@
80 gint euid;139 gint euid;
81 guint retval = 0;140 guint retval = 0;
82 GError *error = NULL;141 GError *error = NULL;
83 gboolean ret = FALSE;
84 gint set_brightness = -1;142 gint set_brightness = -1;
85 gboolean get_brightness = FALSE;143 gboolean get_brightness = FALSE;
86 gboolean get_max_brightness = FALSE;144 gboolean get_max_brightness = FALSE;
87 gchar *filename = NULL;145 gchar *filename = NULL;
88 gchar *filename_file = NULL;146 GsdBacklightType type;
89 gchar *contents = NULL;
90147
91 const GOptionEntry options[] = {148 const GOptionEntry options[] = {
92 { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,149 { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,
@@ -121,7 +178,7 @@
121 }178 }
122179
123 /* find device */180 /* find device */
124 filename = gsd_backlight_helper_get_best_backlight ();181 filename = gsd_backlight_helper_get_best_backlight (&type);
125 if (filename == NULL) {182 if (filename == NULL) {
126 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_NO_DEVICES;183 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_NO_DEVICES;
127 g_print ("%s: %s\n",184 g_print ("%s: %s\n",
@@ -132,9 +189,9 @@
132189
133 /* GetBrightness */190 /* GetBrightness */
134 if (get_brightness) {191 if (get_brightness) {
135 filename_file = g_build_filename (filename, "brightness", NULL);192 gint value;
136 ret = g_file_get_contents (filename_file, &contents, NULL, &error);193 value = gsd_backlight_helper_get (filename, &error);
137 if (!ret) {194 if (value < 0) {
138 g_print ("%s: %s\n",195 g_print ("%s: %s\n",
139 "Could not get the value of the backlight",196 "Could not get the value of the backlight",
140 error->message);197 error->message);
@@ -144,16 +201,16 @@
144 }201 }
145202
146 /* just print the contents to stdout */203 /* just print the contents to stdout */
147 g_print ("%s", contents);204 g_print ("%d", value);
148 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;205 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;
149 goto out;206 goto out;
150 }207 }
151208
152 /* GetSteps */209 /* GetSteps */
153 if (get_max_brightness) {210 if (get_max_brightness) {
154 filename_file = g_build_filename (filename, "max_brightness", NULL);211 gint value;
155 ret = g_file_get_contents (filename_file, &contents, NULL, &error);212 value = gsd_backlight_helper_get_max (filename, &error);
156 if (!ret) {213 if (value < 0) {
157 g_print ("%s: %s\n",214 g_print ("%s: %s\n",
158 "Could not get the maximum value of the backlight",215 "Could not get the maximum value of the backlight",
159 error->message);216 error->message);
@@ -163,7 +220,7 @@
163 }220 }
164221
165 /* just print the contents to stdout */222 /* just print the contents to stdout */
166 g_print ("%s", contents);223 g_print ("%d", value);
167 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;224 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;
168 goto out;225 goto out;
169 }226 }
@@ -180,8 +237,22 @@
180237
181 /* SetBrightness */238 /* SetBrightness */
182 if (set_brightness != -1) {239 if (set_brightness != -1) {
183 filename_file = g_build_filename (filename, "brightness", NULL);240 gboolean ret = FALSE;
184 ret = gsd_backlight_helper_write (filename_file, set_brightness, &error);241 gint max = gsd_backlight_helper_get_max (filename, &error);
242
243 if (max < 0) {
244 g_print ("%s: %s\n",
245 "Could not get the maximum value of the backlight",
246 error->message);
247 g_error_free (error);
248 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID;
249 goto out;
250 }
251
252 if (type == GSD_BACKLIGHT_TYPE_RAW)
253 set_brightness = clamp_minimum (max, set_brightness);
254
255 ret = gsd_backlight_helper_write (filename, set_brightness, &error);
185 if (!ret) {256 if (!ret) {
186 g_print ("%s: %s\n",257 g_print ("%s: %s\n",
187 "Could not set the value of the backlight",258 "Could not set the value of the backlight",
@@ -196,8 +267,6 @@
196 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;267 retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;
197out:268out:
198 g_free (filename);269 g_free (filename);
199 g_free (filename_file);
200 g_free (contents);
201 return retval;270 return retval;
202}271}
203272
204273
=== modified file 'plugins/power/gsd-backlight-linux.c'
--- plugins/power/gsd-backlight-linux.c 2013-03-27 11:59:18 +0000
+++ plugins/power/gsd-backlight-linux.c 2015-11-20 08:06:29 +0000
@@ -44,7 +44,7 @@
44#endif /* HAVE_GUDEV */44#endif /* HAVE_GUDEV */
4545
46char *46char *
47gsd_backlight_helper_get_best_backlight (void)47gsd_backlight_helper_get_best_backlight (GsdBacklightType *type)
48{48{
49#ifdef HAVE_GUDEV49#ifdef HAVE_GUDEV
50 gchar *path = NULL;50 gchar *path = NULL;
@@ -59,14 +59,23 @@
59 /* search the backlight devices and prefer the types:59 /* search the backlight devices and prefer the types:
60 * firmware -> platform -> raw */60 * firmware -> platform -> raw */
61 path = gsd_backlight_helper_get_type (devices, "firmware");61 path = gsd_backlight_helper_get_type (devices, "firmware");
62 if (path != NULL)62 if (path != NULL) {
63 if (type)
64 *type = GSD_BACKLIGHT_TYPE_FIRMWARE;
63 goto out;65 goto out;
66 }
64 path = gsd_backlight_helper_get_type (devices, "platform");67 path = gsd_backlight_helper_get_type (devices, "platform");
65 if (path != NULL)68 if (path != NULL) {
69 if (type)
70 *type = GSD_BACKLIGHT_TYPE_PLATFORM;
66 goto out;71 goto out;
72 }
67 path = gsd_backlight_helper_get_type (devices, "raw");73 path = gsd_backlight_helper_get_type (devices, "raw");
68 if (path != NULL)74 if (path != NULL) {
75 if (type)
76 *type = GSD_BACKLIGHT_TYPE_RAW;
69 goto out;77 goto out;
78 }
70out:79out:
71 g_object_unref (client);80 g_object_unref (client);
72 g_list_foreach (devices, (GFunc) g_object_unref, NULL);81 g_list_foreach (devices, (GFunc) g_object_unref, NULL);
7382
=== modified file 'plugins/power/gsd-backlight-linux.h'
--- plugins/power/gsd-backlight-linux.h 2013-01-23 22:53:38 +0000
+++ plugins/power/gsd-backlight-linux.h 2015-11-20 08:06:29 +0000
@@ -19,4 +19,10 @@
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */20 */
2121
22char *gsd_backlight_helper_get_best_backlight (void);22typedef enum {
23 GSD_BACKLIGHT_TYPE_FIRMWARE,
24 GSD_BACKLIGHT_TYPE_PLATFORM,
25 GSD_BACKLIGHT_TYPE_RAW,
26} GsdBacklightType;
27
28char *gsd_backlight_helper_get_best_backlight (GsdBacklightType *type);

Subscribers

People subscribed via source and target branches