<div dir="ltr"><div>Hello Sam and James,</div><div><br></div><div>I am moving our discussion from Sam's pull request (<a href="https://github.com/sugarlabs/sugar/pull/437">https://github.com/sugarlabs/sugar/pull/437</a>) to here because this particular post is bit long.</div><div><br></div><div>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?"</div><div><br></div><div>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.</div><div><br></div><div>Examples:</div><div><br></div><div><span class="" style="white-space:pre">   </span>[tch@tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-brightness</div><div><span class="" style="white-space:pre">     </span>4000</div><div><span class="" style="white-space:pre">       </span>[tch@tch polkit-1]$ /usr/libexec/gsd-backlight-helper --get-max-brightness</div><div><span class="" style="white-space:pre"> </span>4437</div><div><span class="" style="white-space:pre">       </span>[tch@tch polkit-1]$ pkexec /usr/libexec/gsd-backlight-helper --set-brightness 4437</div><div><br></div><div>Details:</div><div><br></div><div>0) when using GSD over DBUS:</div><div>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</div><div><br></div><div>1) which is defined here:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n82">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n82</a></div><div><br></div><div>2) triggers a callback in GSD, which makes a call to "backlight_step_up":</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n2620">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c#n2620</a></div><div><br></div><div>3) "backlight_step_up" is defined here:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n647">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n647</a></div><div><br></div><div>4) when running under Linux, "backlight_step_up()" calls to a function called to "backlight_helper_set_value":</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n692">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n692</a></div><div><br></div><div>5) then, "backlight_helper_set_value" makes a __system call__ to "gsd-backlight-helper", which is a tool provided by GSD:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n491">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gpm-common.c#n491</a></div><div>NOTE: this system calls uses pkexec, and requires a PolKit action policy to allow unpriviledge users to write to the device without being root.</div><div><br></div><div>6) this "gsd-backlight-helper" tool is implemented here:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-helper.c">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-helper.c</a></div><div><br></div><div>7) and uses "gsd_backlight_helper_get_best_backlight" to find the proper device:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-linux.c#n49">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-backlight-linux.c#n49</a></div><div><br></div><div>8) lastly, the PolKit policy file is here:</div><div><a href="https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in">https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in</a></div><div><br></div><div>Conclusions:</div><div><br></div><div>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. <a href="https://github.com/tchx84/sugar-backlight-helper/blob/master/sugar-backlight-helper.py">https://github.com/tchx84/sugar-backlight-helper/blob/master/sugar-backlight-helper.py</a> (this also works for the XO btw). @James, can you also give it a try?</div><div><br></div><div>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.</div><div><br></div><div>@Sam, @James, if we think we can go this direction, I can will some changes on top of Sam's previous work tomorrow.</div><div><br></div><div>Regards,</div><div>Martin.</div><div><br></div><div><br></div></div>