If you are running Linux on your MacBookAir and want the keyboard light brightness changed automatically depending on the ambient light (just as OS X does), continue reading.
I’ve written a small daemon named lightum, source is on github and licensed under GPL-2+.
Usage: lightum [-m value] [-p value] [-f] -m 0..255 : maximum brightness value between 1 and 255 (default=255) -p num : number of seconds between light sensor polls (default=8) -f : run in foreground (do not daemonize) -v : verbose mode, useful for debugging with -f
For it to work you need dbus installed, and your MacBook should have the light sensor located in /sys/devices/platform/applesmc.768/light (should be available on all MacBookAir and MacBookPro versions which have a backlight on keyboard, as far as I know).
If you are running Ubuntu, you can install it by adding lightum-mba ppa to your system:
sudo add-apt-repository ppa:poliva/lightum-mba
sudo apt-get update
sudo apt-get install lightum
Otherwise, you can build it from source.
I just wanted to say thanks for this. I’m using it with Arch Linux on my MacBook Pro 8,2 and it works perfectly. I installed lightum from source and put the binary in my path, then added ‘lightum’ as a startup program in xfce4 – nothing to it.
Now can someone please figure out how to adjust screen brightness on a Macbook Pro 8,2 in GNU/Linux?
The following link describes the procedure for setting the screen brightness: http://www.matrix44.net/blog/?p=963
Hello, I am on Manjaro 0.8.10, so what exactly did you do, I downloaded the file but I don’t know how to work with.
Yeah, works like a charm. Thanks!
Forward ported the package in you PPA to Ubuntu Precise. No problem whatsoever.
are you going to implement also video brightness control?
most desktop environments already have mechanism in place for that, adding this to lightum will probably interfere with it.
I think, the question was “Are you going to implement also automatic video brightness control depending on the ambient light ?”
I’m interesting too.
Thank you for your job 😉
hehe good catch seb, I’ll try to implement it
New version with initial screen backlight support is now on github, please test it
Just published lightum version 2.0, with screen backlight support:
Thank you!
Would it be possible to change the minimum brightness by pressing F2 or F6 so that lightum doesn’t dimm the light under this level?
For example when I want to look a video I put the brightness of maximum by pressing the F2. At the moment lightum automatically dimms the brightness and I can’t set a dynamical minimum brightness.
Currently you can dynamically change the maximum brightness value using the function keys if you add the option ‘ignoreuser=0′ in the config file. An option that would probably suit you more is switching to manual mode instead of auto mode while viewing the video, you can use the lightum-indicator applet to do this in a quick & comfortable way.
Hi pof,
thank you but when I use the function keys in ignoreuser=0 mode lightum doesn’t accept it and change the brightness again.
The indicator seems to be very nice but it doesn’t work here. I can’t change the accommondation with the applet. Maybe something with the right from lightum.conf?
Thanks!
I’ve pushed some changes into the git repo, should fix your problems with ignoreuser setting, please test if you can.
Regarding the indicator, what is it that’s not working? can you open a bug report?
Yeah now it works great!
The problem with the indicator was that owner of the file .config/lightum was root so that the indicator wasn’t able to write the lightum.conf.
Thank again for this good work!
hey, this is awesome what you did!!!
i am going to install your program/package on my 2007 MacBook Pro (3,1) which now runs CentOS 6.2.
i will write back about how it went.
thanks.
Good to hear that! let me know if you find any bugs
Trying to compile the source from git:
[sid@alpha poliva-lightum-d1922f8]# which gcc
/usr/bin/gcc
[sid@alpha poliva-lightum-d1922f8]# gcc –version
gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[sid@alpha poliva-lightum-d1922f8]# gcc lightum.c -o lightumd
In file included from lightum.c:26:
lightum.h:1:22: error: X11/Xlib.h: No such file or directory
lightum.h:2:37: error: dbus/dbus-glib-lowlevel.h: No such file or directory
In file included from lightum.c:26:
lightum.h:30: error: expected ‘)’ before ‘*’ token
lightum.h:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
lightum.h:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
lightum.h:42: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
lightum.h:43: error: expected ‘)’ before ‘*’ token
lightum.c: In function ‘main’:
lightum.c:62: error: ‘Display’ undeclared (first use in this function)
lightum.c:62: error: (Each undeclared identifier is reported only once
lightum.c:62: error: for each function it appears in.)
lightum.c:62: error: ‘display’ undeclared (first use in this function)
lightum.c:63: error: ‘DBusGConnection’ undeclared (first use in this function)
lightum.c:63: error: ‘connection’ undeclared (first use in this function)
lightum.c:64: error: ‘DBusGProxy’ undeclared (first use in this function)
lightum.c:64: error: ‘proxy_manager’ undeclared (first use in this function)
lightum.c:65: error: ‘proxy_session’ undeclared (first use in this function)
I even tried to compile is with cc, it yields the same result.
Could someone enlighten me, please?
Thanks!
To compile it just run “make” on the source directory, you need to have the build time dependencies installed:
autotools-dev, pkg-config, libdbus-1-dev, libdbus-glib-1-dev, libxss-dev.
thanks for the prompt answer, pof!
i suppose i can’t install any “libdbus-1″. on CentOS 6.2 i have:
dbus-glib-devel-0.86-5.el6.x86_64.rpm
here’s what i figured are the equivalents (used yum search) to the packages you listed above for me:
# yum install dbus-c++-devel dbus-python-devel dbus-qt-devel dbus dbus-c++ dbus-devel dbus-glib dbus-glib-devel dbus-libs dbus-qt dbus-x11
# yum search autotools
# yum install mk-configure xorg-x11-util-macros
# yum install pkgconfig
# yum search libxss
# yum install libXScrnSaver
still, i get this after running make:
[sid@alpha poliva-lightum-d1922f8]$ make
cc `pkg-config –cflags dbus-1 –cflags dbus-glib-1` -Wall -Wextra -Wwrite-strings -O -g -c -o functions.o functions.c
functions.c:17:38: error: X11/extensions/scrnsaver.h: No such file or directory
functions.c: In function ‘get_session_idle_time’:
functions.c:240: error: ‘XScreenSaverInfo’ undeclared (first use in this function)
functions.c:240: error: (Each undeclared identifier is reported only once
functions.c:240: error: for each function it appears in.)
functions.c:240: error: expected ‘;’ before ‘info’
functions.c:243: warning: implicit declaration of function ‘XScreenSaverQueryInfo’
functions.c:243: error: ‘info’ undeclared (first use in this function)
make: *** [functions.o] Error 1
i appreciate the help…
@sidthesloth: you need to ‘yum install libXScrnSaver-devel’ (notice the -devel), so you get the include files on your system.
@pof: thanks, that made it. i was able to compile it. done “# make install”. ran it in the console:
lightum -f -v
gives:
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
light_sensor: 21 idle_time: 1.528000 auto mode brightness: 6 backlight: 7
:~[
can you try again with the last version from git? i’ve done a few changes in the code today. Also, which window manager are you using?
i will try again with latest code from git.
i am running CentOS 6.2 with Gnome2 and Metacity.
pof,
i compile again from git. i ran it in manual mode this time, and i pressed the F9 and F10 keys (the hardware brightness keys). here’s how it looks:
[sid@gamma zzzz]$ lightum -x -f -v
CONFIG:
manualmode: 1
ignoreuser: 1
workmode: 3
queryscreensaver: 0
maxbrightness: 255
minbrightness: 0
maxbacklight: 15
minbacklight: 1
polltime: 300
idleoff: 5
screenidle: 30
lightum v2.0.4 running in manual mode
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
idle_time: 0.026000 manual mode brightness: 0 backlight: 0
idle_time: 0.362000 manual mode brightness: 0 backlight: 0
idle_time: 0.664000 manual mode brightness: 0 backlight: 0
idle_time: 0.965000 manual mode brightness: 0 backlight: 0
idle_time: 1.267000 manual mode brightness: 0 backlight: 0
idle_time: 1.568000 manual mode brightness: 0 backlight: 0
idle_time: 1.870000 manual mode brightness: 0 backlight: 0
idle_time: 2.172000 manual mode brightness: 0 backlight: 0
idle_time: 0.052000 manual mode brightness: 0 backlight: 0
==============================
then, this is what i get when running it in automatic mode:
[ds@gamma Downloads]$ lightum -f -v
CONFIG:
manualmode: 0
ignoreuser: 1
workmode: 3
queryscreensaver: 0
maxbrightness: 255
minbrightness: 0
maxbacklight: 15
minbacklight: 1
polltime: 300
idleoff: 5
screenidle: 30
lightum v2.0.4 running in auto mode
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
light_sensor: 42 idle_time: 0.020000 auto mode brightness: 3 backlight: 9
light_sensor: 44 idle_time: 0.411000 auto mode brightness: 2 backlight: 9 -> Ignoring user brightness change, wants to set maxbrightness to 0
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
light_sensor: 67 idle_time: 1.147000 auto mode brightness: 1 backlight: 13 -> Ignoring user brightness change, wants to set maxbrightness to 0
Error org.freedesktop.DBus.Error.UnknownMethod: Method “GetPercentage” with signature “” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
Can’t manage screen backlight on this system
can you get/set the screen backlight values using dbus-send ? for an example on kde or gnome look at this script:
http://pastebin.com/iPwstE4H
Also, please post the output of the following command:
pof,
here’s the command from your script in pastebin:
[sid@gamma ~]$ dbus-send –session –print-reply –dest=”org.gnome.SettingsDaemon” /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:100
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetPercentage” with signature “u” on interface “org.gnome.SettingsDaemon.Power.Screen” doesn’t exist
…as for this command:
qdbus org.gnome.SettingsDaemon /org/gnome/SettingsDaemon/Power
it doesn’t output anything at all.
Please, instead of adding large comments here, open a bug report on github, and we can follow with the troubleshooting there. Please include in the bug report the output of the following commands too (run as root):
# /usr/lib/gnome-settings-daemon/gsd-backlight-helper –get-max-brightness
# /usr/lib/gnome-settings-daemon/gsd-backlight-helper –get-brightness
# /usr/lib/gnome-settings-daemon/gsd-backlight-helper –set-brightness 10
ok, i will do so.
Hello Pau,
I just would like to thank you for this project! Keep up the good work.
Great Work :D. is better than my garbage bash script.
Any KDE integration/love?
yes, it works with kde too
Wow, thank you very much for this.
There is a small problem. I have installed fedora 17 on my macbook.
Can this great package be built also for that distribution?
How do you do that, first install gcc and then …?
Thank you very much for any answer….
Bernd
I have not packaged it in rpm, but you should be able to install it running ‘make && make install’ provided you have all the required build dependencies installed.
Thank you very much. I have tried to install the program with ‘make && make install’ but got some errors. So may be i have not installed all the build dependencies you mentioned.
Seems that I have to find out first, what a build dependency is :)). I have not that much knowledge of programming with Gcc and even with Linux.
My error was:
[bernd@Nathan poliva-lightum-e7cc795]$ make && make install
cc `pkg-config –cflags dbus-1 –cflags dbus-glib-1` -Wall -Wextra -Wwrite-strings -O -g -c -o functions.o functions.c
Package dbus-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `dbus-1.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘dbus-1′ found
Package dbus-glib-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `dbus-glib-1.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘dbus-glib-1′ found
….
Seems that not all paths are defined correctly.
Finally I have succeeded in compiling the programm :)..
But I directly got an error when I wanted to try the example:
** (lightum:3632): WARNING **: GetCurrentSession failed: The name org.freedesktop.ConsoleKit was not provided by any .service files
(lightum:3632): GLib-CRITICAL **: g_variant_is_object_path: assertion `string != NULL’ failed
** (lightum:3632): CRITICAL **: dbus_g_proxy_new_for_name: assertion `g_variant_is_object_path (path)’ failed
** (lightum:3632): WARNING **: Could not get dbus session proxy
So I have to figure out that now….
What is this for an error message?
Unable to lookup session information for process ‘5275’
Does anybody know that?
Thank you for any answer…
Thank you for your work.
Am I blind, or there is not parameter for auto mode for cmd line?
I am using Mint Maya with Cinnamon and there is some problem with indicator. Once I found it appeared on panel without icon. I set it on manual mode. After that applet disappeared and I could not force lightum to run in auto mode until conf file edited.
Still indicator not appearing.
great tool. thank you very much!
maybe an idea for a future version: if the macbook is connected to power, it would be useful to have an option to automatically deactivate dimming.
Nice program! Thank you very much!
I’ve just compiled the sources from git and it seems to work. I’m just slightly annoyed by the these messages:
[mafra@linux-ahr8:lightum]$ Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SettingsDaemon was not provided by any .service files
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.Solid.PowerManagement was not provided by any .service files
sh: $’04′: command not found
sh: $’01′: command not found
sh: $’01′: command not found
sh: $’01′: command not found
and it goes one like this forever.
I assume it’s because I’m using WindowMaker, but I’m not sure where those messages are comming from.
Do you know what’s going on? Any help is appreaciated.
The above infinite repetition of
sh: $’04′: command not found
is due to the broken function set_screen_xbacklight_value() in xbacklight.c which is called if the
neither Gnome nor KDE is detected. Since I’m using Window Maker, that’s the case for me.
That function even has a printf(“%s”, name) for a totally undefined ‘name’ and I suspect that my problems to suspend to RAM were related to running lightum because of that function. In any case, deleting its content fixes things for me.
i tried to install this, through terminal, but the package can’t be found…
please fix.
thanks!
This doesn’t seem to be fetchable from the repository anymore (Ubuntu). Is there another way to install this?
W: Failed to fetch http://ppa.launchpad.net/poliva/lightum-mba/ubuntu/dists/quantal/main/source/Sources 404 Not Found
W: Failed to fetch http://ppa.launchpad.net/poliva/lightum-mba/ubuntu/dists/quantal/main/binary-amd64/Packages 404 Not Found
W: Failed to fetch http://ppa.launchpad.net/poliva/lightum-mba/ubuntu/dists/quantal/main/binary-i386/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
sudo apt-get install lightum
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package lightum
Built from source on Arch Linux running Awesome WM. I notice there is some dependencies on gnome/kde services. Could you point me in the right direction to get this running without gnome/kde? I.e. is there some alternative settings and power management daemons that only depend on x11?
Thanks for writing this! Safes me a lot of battery!
Gell
Worked great until upgrate to Ubuntu 13.10. Is there any way to get it to work again?
I built this from source on ubuntu 14.04 and it built fine with no errors.
I get this when I run it
#$ lightum
lightum v2.3.1 running in auto mode forked into background
** (lightum:20246): WARNING **: GetCurrentSession failed: Unable to lookup session information for process ‘20246’
(lightum:20246): GLib-CRITICAL **: g_variant_is_object_path: assertion ‘string != NULL’ failed
** (lightum:20246): CRITICAL **: dbus_g_proxy_new_for_name: assertion ‘g_variant_is_object_path (path)’ failed
** (lightum:20246): WARNING **: Could not get dbus session proxy
Thanks a ton…do you accept bitcoins
lol, donate them to other open source projects that deserve them more than me… i’d suggest radare: http://www.radare.org
Also could you support 14.04 ?
It should work in 14.04 (although I haven’t tried it yet), but see the comments here:
https://github.com/poliva/lightum/issues/33