[Sugar-devel] More details on brightness control in Sugar

Martin Abente martin.abente.lahaye at gmail.com
Tue May 5 18:27:59 EDT 2015

Hello Sam and James,

I am moving our discussion from Sam's pull request (
https://github.com/sugarlabs/sugar/pull/437) to here because this
particular post is bit long.

Regarding James request: "...instead understand how both
gnome-settings-daemon and unity-settings-daemon implement what they do (for
brightness), and reimplement that in Sugar?"

I have been reading GSD (gnome-settings-daemon) sources and I think I am
making sense of it. Basically, GSD makes use of a tool called
"gsd-backlight-helper", which is provided by GSD. This tool queries Udev
for the proper backlight device, and directly reads and writes to the
device file. GSD uses a special PolKit action policy to allow unprivileged
users to run this tool without root privileges for writing to the device.


[tch at tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-brightness
[tch at tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-max-brightness
[tch at tch polkit-1]$ pkexec /usr/libexec/gsd-backlight-helper
--set-brightness 4437


0) when using GSD over DBUS:
dbus-send --session --print-reply --dest=org.gnome.SettingsDaemon
/org/gnome/SettingsDaemon/Power  org.freedesktop.DBus.Properties.Set
string:"org.gnome.SettingsDaemon.Power.Screen" string:"Brightness"

1) which is defined here:

2) triggers a callback in GSD, which makes a call to "backlight_step_up":

3) "backlight_step_up" is defined here:

4) when running under Linux, "backlight_step_up()" calls to a function
called to "backlight_helper_set_value":

5) then, "backlight_helper_set_value" makes a __system call__ to
"gsd-backlight-helper", which is a tool provided by GSD:
NOTE: this system calls uses pkexec, and requires a PolKit action policy to
allow unpriviledge users to write to the device without being root.

6) this "gsd-backlight-helper" tool is implemented here:

7) and uses "gsd_backlight_helper_get_best_backlight" to find the proper

8) lastly, the PolKit policy file is here:


It would not be too difficult to re-implement the same mechanism for Sugar.
In fact I have re-implemented the exact same functionality provided by
"gsd-backlight-helper" in Python.
(this also works for the XO btw). @James, can you also give it a try?

Regarding the use of a separate tool to deal with permissions, I wonder if
GSD deliberately separated that tool to simplify the integration with
PolKit. The question is: should we do something similar with sugar? I
personally think is a valid option, but I wonder if there is another way of
using PolKit to grant permissions directly to Sugar for writing to the
device. I don't have much experience with PolKit.

@Sam, @James, if we think we can go this direction, I can will some changes
on top of Sam's previous work tomorrow.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20150505/6804081b/attachment.html>

More information about the Sugar-devel mailing list