After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 357994 - Light sensor and keyboard backlight
Light sensor and keyboard backlight
Status: RESOLVED INCOMPLETE
Product: gnome-power-manager
Classification: Deprecated
Component: gnome-power-manager
SVN TRUNK
Other Linux
: Normal enhancement
: ---
Assigned To: GNOME Power Manager Maintainer(s)
GNOME Power Manager Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2006-09-27 16:20 UTC by David Zeuthen (not reading bugmail)
Modified: 2009-01-19 19:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (33.25 KB, patch)
2006-09-28 02:22 UTC, David Zeuthen (not reading bugmail)
none Details | Review
Use ambient light sensors (34.98 KB, patch)
2006-09-29 06:35 UTC, David Zeuthen (not reading bugmail)
none Details | Review

Description David Zeuthen (not reading bugmail) 2006-09-27 16:20:41 UTC
HAL 0.5.8 exports device objects for reading from the ambient light sensors and controlling the keyboard backlight. Right now this is only implemented for Apple Macbook Pro laptops but can also be implemented for other hardware such as Apple Powerbook 15" and 17".

There is a small example policy daemon here

 http://gitweb.freedesktop.org/?p=hal.git;a=blob;hb=HEAD;f=examples/light_sensors_and_keyboard_backlight.py

that reads from the sensor and adjusts the keyboard backlight. Note the comments about not polling too often etc.

I'm not sure how to implement this if you don't have the hardware. I'd be happy to take a patch to HAL that creates a dummy-addon

 hald-fake-light-sensor-and-backlight

This addon would be a normal hal addon implemented just like the Macbook Pro addon

 http://gitweb.freedesktop.org/?p=hal.git;a=blob;hb=HEAD;f=hald/linux/addons/addon-macbookpro-backlight.c

but it would also claim a D-Bus service, say, org.freedesktop.Hal.Dummy.FakeLightSensorAndBacklight on the system message bus for control. Then you could write a small pygtk program that speaks to this service and displays

 +----------------------------------------------------+
 | keyboard backlight: 126 (range 0-255)              |
 | light sensor: [-----+----------] 100 (range 0-255) | 
 +----------------------------------------------------+

to allow you to simulate this. 

The recent commit to HAL master
 http://gitweb.freedesktop.org/?p=hal.git;a=commit;h=499e981a3055ef8bf09ef7b2737721a275698d09

makes this easy to do. You'd just add a --with-fake-lightsensor option and only

 1. include the fdi file for starting the addon;
 2. include the code for the addon

if this option is passed. The option would default to "no" of course.

Thanks.
Comment 1 Richard Hughes 2006-09-27 16:38:43 UTC
So we just control the keyboard backlight with the ambient light sensor - no problem. I imagined you might want to control the LCD panel with the ambient sensor also. Is this the case? Thanks.

Richard.
Comment 2 David Zeuthen (not reading bugmail) 2006-09-27 16:45:54 UTC
Potentially we could do both. I haven't given much thought to the integration with g-p-m yet. 

Btw, my Apple Macbook Pro got three keys overlaid on F8-F10 for controlling this

 F8: turn off keyboard backlight
 F9: keyboard backlight--
 F10: keyboard_backlight++

much like they overlay LCD backlight on F1 and F2. When I update my Macbook Pro to a more recent kernel I'll make sure that HAL emits the right signals here.

Hmm, we probably want stuff like Totem to be able to turn off the keyboard backlight when watching a full screen move; not sure how to do that in general.
Comment 3 David Zeuthen (not reading bugmail) 2006-09-28 01:30:30 UTC
Just upgraded the box to rawhide, HAL actually does the right thing here

F8:  ButtonPressed = kbd-illum-toggle
F9:  ButtonPressed = kbd-illum-down
F10: ButtonPressed = kbd-illum-up

w00t!
Comment 4 David Zeuthen (not reading bugmail) 2006-09-28 02:22:22 UTC
Created attachment 73529 [details] [review]
Proposed patch

OK, here's a patch for the keyboard backlight. It's stored in gconf and can be controlled via the kbd-illum-[up|down]. 

Not entirely sure about whether we want to store this in gconf when we get the ambient light sensor parts in... we probably do.

Left a TODO about the feedback display should take a parameter on what icon to display. What do you think about this approach?

Will do the ambient light sensor bit when this is merged.

Also need some bits to turn off the backlight when user is idle etc. etc. But I thought I'd start with this.
Comment 5 Richard Hughes 2006-09-28 09:23:47 UTC
Legend, thanks for this. I'll make a few changes to the core code (moving in gpm_feedback_display_value to the brightness rather than the manager class) and then we'll get some feedback for pressing those buttons.

I'm thinking of just overlaying the keyboard icon on the brightness icon and showing that - does that sound sane?
Comment 6 Richard Hughes 2006-09-28 17:13:02 UTC
I'm about to commit a heavily modified version of your patch.

Do we need:

does_own_updates;	/* keys are hardwired */
does_own_dimming;	/* hardware auto-fades */

i.e. does the macbook pro change it's own brightness and send an event, or send the key event and then lets g-p-m change the brightness?

Thanks.
Comment 7 David Zeuthen (not reading bugmail) 2006-09-28 17:43:34 UTC
Re comment 5: sounds good
Re comment 6: agree - no events are sent for the Macbook Pro but other hardware may do this
Comment 8 Richard Hughes 2006-09-28 18:00:09 UTC
2006-09-28  Richard Hughes  <richard@hughsie.com>

	* src/gpm-gconf.h:
	* src/gpm-manager.c:
	* src/gpm-hal-brightness-kbd.c:
	* src/gpm-hal-brightness-kbd.h:
	Add a heavily modified patch from David Zeuthen to add keyboard
	backlight (write) support to gnome-power-manager. Many thanks!

In a few minutes, can you give HEAD a go and see if it all works okay. I've made lots of changes...

FWIW: This is the ChangeLog entry:

2006-09-28  Richard Hughes  <richard@hughsie.com>

	* data/icons/16x16/Makefile.am:
	* data/icons/16x16/gpm-brightness-kbd.png:
	* data/icons/16x16/gpm-brightness-lcd.png:
	* data/icons/16x16/gpm-brightness.png:
	* data/icons/16x16/gpm-primary-missing.png:
	* data/icons/16x16/gpm-ups-100-charging.png:
	* data/icons/22x22/Makefile.am:
	* data/icons/22x22/gpm-brightness-kbd.png:
	* data/icons/22x22/gpm-brightness-lcd.png:
	* data/icons/22x22/gpm-brightness.png:
	* data/icons/24x24/Makefile.am:
	* data/icons/24x24/gpm-brightness-kbd.png:
	* data/icons/24x24/gpm-brightness-lcd.png:
	* data/icons/24x24/gpm-brightness.png:
	* data/icons/scalable/Makefile.am:
	* data/icons/scalable/gpm-brightness-kbd.svg:
	* data/icons/scalable/gpm-brightness-lcd.svg:
	* data/icons/scalable/gpm-brightness.svg:
	Rename gpm-brightness to gpm-brightness-lcd and add gpm-brightness-kbd.
	This is for the feedback widget for keyboard backlight feedback.

	* data/gnome-power-manager.schemas.in:
	* po/POTFILES.in:
	* src/Makefile.am:
	* src/gpm-hal-brightness.c:
	* src/gpm-hal-brightness.h:
	* src/gpm-hal-brightness-lcd.c:
	* src/gpm-hal-brightness-lcd.h:
	Rename as we have a new kid on the block, namely kbd.

	* src/gpm-hal-brightness.c:
	* src/gpm-hal-brightness.h:
	When stepping down, actually use the step value. (David Zeuthen)
	Check for overflow / underflow when step value > 1.
	Used signed integers when stepping down as we may underflow.
	Should fix #358067.

	* src/gpm-common.c:
	* src/gpm-common.h:
	Add gpm_percent_to_discrete() and gpm_discrete_to_percent() generic
	functions.

	* src/gpm-feedback-widget.c:
	* src/gpm-feedback-widget.h:
	* src/gpm-stock-icons.h:
	Add gpm_feedback_set_icon_name() so we can set different icons on the
	feedback widget.
	Also load the feedback widget here and get rid of the manager signal -
	this allows us to save memory if we don't have the hardware.

	* src/gpm-hal.c:
	* src/gpm-hal.h:
	Add a dummy function gpm_hal_device_get_uint() so we don't have to muck
	about with casting.

	* src/gpm-gconf.h:
	* src/gpm-manager.c:
	* src/gpm-hal-brightness-kbd.c:
	* src/gpm-hal-brightness-kbd.h:
	Add a heavily modified patch from David Zeuthen to add keyboard
	backlight (write) support to gnome-power-manager. Many thanks!
Comment 9 David Zeuthen (not reading bugmail) 2006-09-28 22:51:45 UTC
Works nice except that if hitting both brightness+ and kbd_brightness+ (or -) in an alternating way the feedback popups overlap. Should probably clear all existing popups when putting up a new one.
Comment 10 Richard Hughes 2006-09-28 23:07:41 UTC
(In reply to comment #9)
> Works nice except that if hitting both brightness+ and kbd_brightness+ (or -)
> in an alternating way the feedback popups overlap. Should probably clear all
> existing popups when putting up a new one.

Gahh. Not sure how to do this as they are different instances. I'll have a think.

What is kbd-illum-toggle meant to do btw?
Comment 11 David Zeuthen (not reading bugmail) 2006-09-28 23:11:09 UTC
kbd-illum-toggle should 

 - turn off light if it's on 
 - turn it on if it's off

Do you want a patch for this?

for e.g. "watching movie" mode. Are you sure it's good to close this bug? Do you want a patch for the other part this bug mentioned, e.g. ambient light sensor? I guess I could wrap on up in an hour or two...

Comment 12 Richard Hughes 2006-09-28 23:20:24 UTC
(In reply to comment #11)
> kbd-illum-toggle should 
> 
>  - turn off light if it's on 
>  - turn it on if it's off

Cool. We can use the foo_dim and foo_undim calls for this I guess.

> Do you want a patch for this?

If you are feeling in a hacky mood, yes please. I have to sleep now.

> for e.g. "watching movie" mode. Are you sure it's good to close this bug?

Nope. OOps. Re-opened.

> Do
> you want a patch for the other part this bug mentioned, e.g. ambient light
> sensor? I guess I could wrap on up in an hour or two...

Let me commit some boilerplate stuff I've half finished.

Have a look at gpm-hal-brightness-sensor.[c|h] - I want to make that a singleton class and instantiate that from gpm-hal-brightness-kbd and gpm-hal-brightness-lcd, so that signals can be passed into the GpmHalBrightnessX classes for processing in whatever way each sees fit.

If you could do that, then it would be most appreciated; I'll probably get a chance tmw to look at this further at some stage.

Thanks.

Richard.
Comment 13 David Zeuthen (not reading bugmail) 2006-09-29 06:35:22 UTC
Created attachment 73612 [details] [review]
Use ambient light sensors

So I took a stab at this.

There's some bugfixes for GetBrightness D-Bus calls, you used UINT for return value, that made it silently return the wrong value... that explains why g-p-m fades up and down like crazy when logging in I think.

Anyway, implemented the BrightnessSensor... I kinda disagree with the name it should be LightSensor or AmbientLightSensor.. anyway, the implementation now polls using a timer, that should probably be changed, mostly a detail. It's a singleton too so other pieces can pull it in as desired.

Second, I removed the gconf settings for keyboard brightness as I didn't think it made sense.

Third, I implemented the toggle key so the user can disable it. Note that pressing illum+ or illum- will enable it back again.

Fifth, I integrated with the ambient light sensor and tried to be smart about it. E.g. when we _transition_ to very dark, try to turn on the keyboard backlight. When we _transition_ to very bright try to turn it off again. This will help respect the users settings (made through illum+ and illum- keys).

Sixth, I've implemented a function for the g-p-m core to disable resp. enable the keyboard backlight when going idle resp. non-idle.

Comments welcome. It works pretty well for me now, will try to user it for real use for a couple of days.
Comment 14 David Zeuthen (not reading bugmail) 2006-10-10 00:52:23 UTC
Ping?
Comment 15 Richard Hughes 2006-10-10 18:15:59 UTC
Sorry, so much email to get through!

I've applied most of this in a modified form, but I was still going to think about the policy. I want this to stay quite similar to the -lcd class in public functions and stuff like that. Could you resync (sorry) your patch against what I've got in CVS head? I'm crazy busy at the moment.

Thanks.

Richard.
Comment 16 Richard Hughes 2007-06-14 21:29:46 UTC
This should be fixed in 2.19.x - does rawhide work okay with the brightness sensor?
Comment 17 Christoph Wurm 2009-01-19 19:27:26 UTC
Closing this bug report as no further information has been provided. Please feel free to reopen this bug if you can provide the information asked for.
Thanks!