[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.
Examples:
[tch at tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-brightness
4000
[tch at tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-max-brightness
4437
[tch at tch polkit-1]$ pkexec /usr/libexec/gsd-backlight-helper
--set-brightness 4437
Details:
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"
variant:int32:100
1) which is defined here:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n82
2) triggers a callback in GSD, which makes a call to "backlight_step_up":
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n2620
3) "backlight_step_up" is defined here:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n647
4) when running under Linux, "backlight_step_up()" calls to a function
called to "backlight_helper_set_value":
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n692
5) then, "backlight_helper_set_value" makes a __system call__ to
"gsd-backlight-helper", which is a tool provided by GSD:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n491
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:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-helper.c
7) and uses "gsd_backlight_helper_get_best_backlight" to find the proper
device:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-linux.c#n49
8) lastly, the PolKit policy file is here:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in
Conclusions:
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.
https://github.com/tchx84/sugar-backlight-helper/blob/master/sugar-backlight-helper.py
(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.
Regards,
Martin.
-------------- 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