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 334212 - Wrong icon when starting on laptop battery
Wrong icon when starting on laptop battery
Status: RESOLVED FIXED
Product: gnome-power-manager
Classification: Deprecated
Component: general
2.13.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Power Manager Maintainer(s)
GNOME Power Manager Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2006-03-11 12:48 UTC by Julien Valroff
Modified: 2006-09-19 00:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
lshal output (88.37 KB, application/octet-stream)
2006-03-11 13:18 UTC, Julien Valroff
  Details
gpm debug output (13.00 KB, application/octet-stream)
2006-03-11 13:19 UTC, Julien Valroff
  Details
Handle broken batteries somewhat better (1.35 KB, patch)
2006-03-26 22:11 UTC, Paul Betts
none Details | Review
Improved version of previous patch (764 bytes, patch)
2006-04-03 03:08 UTC, Paul Betts
none Details | Review
Improved patch with Changelog (1.16 KB, patch)
2006-04-03 03:18 UTC, Paul Betts
none Details | Review
Handles case where battery is full (1.71 KB, patch)
2006-04-15 16:51 UTC, Paul Betts
none Details | Review

Description Julien Valroff 2006-03-11 12:48:33 UTC
Hi,

When I start my laptop with AC unplugged, the tray icon is most of the time wrong. Sometimes, it shows the empty battery, sometimes it shows the full battery with AC plugged in. The tooltip is OK, saying "running on battery - discharging etc.". Once I plugged AC or reload gpm, the icon is ok, thus I cannot post debug output.

Cheers,
Julien
Comment 1 Richard Hughes 2006-03-11 13:02:46 UTC
Odd.. Can you attach a lshal, and a description of what you think the icon should be, when the icon is "incorrect". Also, you might be able to get a trace of the initial "wrong" icon if you set g-p-m to log to a file when it is started up, which depends how your distro chooses to set this up.
Comment 2 Julien Valroff 2006-03-11 13:18:44 UTC
Created attachment 61086 [details]
lshal output
Comment 3 Julien Valroff 2006-03-11 13:19:07 UTC
Created attachment 61087 [details]
gpm debug output
Comment 4 Julien Valroff 2006-03-11 13:22:27 UTC
OK, here are the attachments (I simply started gpm manually to get the debug output).

I noticed the tooltip is also wrong, as it says:
"Running on battery
laptop battery - fully charged (93%)"

The icon displayed when debugging was http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/battery-charged.png?rev=1.1
whereas it should have been: http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/battery-discharging-100.png?rev=1.1

(depending on the remaining battery power of course)

I was also wrong in the first message as killing and reloading gpm doesn't fix the issue (plugging the AC adapter does). I guess it is a HAL issue, what do you think?

Cheers,

Julien
Comment 5 Julien Valroff 2006-03-11 13:26:26 UTC
Oh, forgot to mention I'm running gpm 2.13.93 with hal 0.5.7 on Debian testing/unstable
Comment 6 Richard Hughes 2006-03-11 13:55:40 UTC
I'm a bit confused. The battery "full" icon only appears when !charging && !discharging && percentage_charge > 90, and your lshal clearly states that battery.rechargeable.is_discharging = true.

"is_discharging = true" would explain the "Running on battery power" tooltip, but not the icon.

And I'm more confused as:

gpm-power.c:374 (14:16:22):	 charge     0	rate       0
gpm-power.c:376 (14:16:22):	 discharge  0	remaining  0

g-p-m seems to think that you are not discharging at all, but hal says you are... Maybe the dbus struct issue you are running into, but I thought that was solved in 2.13.93.

You've not compiled g-p-m from source, and then updated dbus 0.31 have you? Or some other weird update combination? To test this, can you do:

lshal -m

and then plug the ac_adapter in and out 3 times after about 30 seconds delay in each state.

We should get lots of battery.rechargeable.is_discharging type changes if dbus is okay, but none if not.

Thanks Julien.
Comment 7 Julien Valroff 2006-03-11 17:53:57 UTC
To answer shortly, I run dbus 0.60 and built a Debian package from gpm sources.

Here is the results of the test you proposed (starting with AC unplugged, thus the first change is when plugging the adapter):

julien@hera:~$ lshal -m

Start monitoring devicelist:
-------------------------------------------------
acpi_ACAD property ac_adapter.present = true
acpi_BAT1 property battery.charge_level.percentage = 100 (0x64)
acpi_BAT1 property battery.remaining_time removed
acpi_BAT1 property battery.charge_level.current = 48840000 (0x2e93d40)
acpi_BAT1 property battery.reporting.current = 4400 (0x1130)
acpi_BAT1 property battery.rechargeable.is_discharging = false
acpi_ACAD property ac_adapter.present = false
acpi_BAT1 property battery.charge_level.percentage = 98 (0x62)
acpi_BAT1 property battery.remaining_time = 3541 (0xdd5) (new)
acpi_BAT1 property battery.charge_level.current = 47863200 (0x2da55a0)
acpi_BAT1 property battery.reporting.current = 4312 (0x10d8)
acpi_BAT1 property battery.rechargeable.is_discharging = true
acpi_ACAD property ac_adapter.present = true
acpi_BAT1 property battery.charge_level.percentage = 100 (0x64)
acpi_BAT1 property battery.remaining_time removed
acpi_BAT1 property battery.charge_level.current = 48840000 (0x2e93d40)
acpi_BAT1 property battery.reporting.current = 4400 (0x1130)
acpi_BAT1 property battery.rechargeable.is_discharging = false

Cheers,
Julien
Comment 8 Richard Hughes 2006-03-11 20:50:04 UTC
Okay... so it's not DBUS at fault. Thanks for the quick reply btw.
I think this may be a coldplug issue, with g-p-m at fault, but I've still not ruled out the possibility of a HAL problem. When your battery is fully charged, what it its charge? 100%?
Comment 9 Julien Valroff 2006-03-12 10:02:21 UTC
yes:
  battery.charge_level.percentage = 100 (0x64)   (int)

And in gpm tooltip: "laptop battery fully charged (100%)"

Cheers,
Julien
Comment 10 Richard Hughes 2006-03-24 11:34:23 UTC
Does this stil happen with 2.14.0?
Comment 11 Julien Valroff 2006-03-24 17:26:14 UTC
Yes, exactly the same issue with 2.14

Cheers,
Julien
Comment 12 Paul Betts 2006-03-26 22:10:25 UTC
I've seen this problem as well. The issue is when the battery reports it is neither charging nor discharging (ie the ACPI info from the battery is crap), the icon defaults to empty but charging battery (gpm-manager.c line 300'ish). 

I've had this problem as well, and I wrote a patch to try to use whatever info that it's got that's valid (specifically, if the battery still returns the charge %). The patch is against 2.14.0 but I'm sure it wouldn't be hard to patch against HEAD. 

What is puzzling to me is that the tooltip is still correct, it says "plugged in / charging" or "discharging". I suspect the tooltip info is coming from ACPI/ac_adaptor? 
Comment 13 Paul Betts 2006-03-26 22:11:18 UTC
Created attachment 62071 [details] [review]
Handle broken batteries somewhat better
Comment 14 Richard Hughes 2006-03-26 22:38:59 UTC
Sure, I don't mind adding bodges for this case as we get it for free, and if the user battery is broken then they shouldn't expect clever multi-battery charge calcuations to work anyway.

I would probably go one stage further, and check for the ac_adapter value to decide if the battery is (probably) charging.

And we should probably fix this in gpm-power.c, over-riding the value of status->is_discharging and status->is_charging where appropriate, and then the other parts of g-p-m (tooltip, icon, warnings, etc.) will just work without a bodge in each case.

Do you want to have a go at a patch to gpm-power.c or want me to have a go?

You can use 2.14 or head, although I would prefer the latter if you don't mind.

p.s. in HEAD we have:

	} else {
		/* We have a broken battery, not sure what to display here */
		gpm_debug ("BROKEN BATTERY...");
		filename = g_strdup_printf ("gpm-%s-broken", prefix);
	}

A specific "broken" icon -- but any fix may make this extra icon redundant.

Thanks for your patch,

Richard.
Comment 15 Paul Betts 2006-03-27 07:25:02 UTC
Sure, I'll see what I can do; shouldn't be too much of a fix
Comment 16 Julien Valroff 2006-03-27 08:14:04 UTC
Hi,

I have tried the previous patch against 2.14.0 but it doesn't work for me.
When starting on battery, the icon displayed is still not the right one.

The tooltip says: 'Running on battery power - laptop battery fully charged (93%)'

At the same time, lshal is ok:
  battery.remaining_time = 2632  (0xa48)  (int)
  battery.charge_level.percentage = 94  (0x5e)  (int)
  battery.charge_level.rate = 0  (0x0)  (int)
  battery.charge_level.last_full = 48840000  (0x2e93d40)  (int)
  battery.charge_level.current = 45909600  (0x2bc8660)  (int)
[...]
  battery.charge_level.capacity_state = 'ok'  (string)
  battery.rechargeable.is_discharging = true  (bool)
  battery.rechargeable.is_charging = false  (bool)

Cheers,
Julien
Comment 17 Paul Betts 2006-03-27 08:52:44 UTC
What icon does it display? Also, the patch I attached isn't a complete fix, but it should at least get rid of the problem where it displays the empty-but-charging icon.

From the looks of your lshal, that patch won't be in effect; it's only when is_discharging and is_charging are both false (not this case). 

One thing I noticed that was going wrong when I was trying to debug this, try the following:

1. Note the icon (correct/incorrect)
2. Switch the AC adaptor state (ie plug it in, or unplug it; whatever you didn't start on)
3. Wait a bit and see what the icon is
4. Switch the AC adaptor back
5. Wait a bit and see what the icon is again.
6. killall gnome-power-manager && gnome-power-manager --no-daemon --verbose
7. What does the icon look like now?

In my experience, the icon is correct from step 3-5, it looks like (for me anyways) that g-p-m is only incorrect when it starts. 
Comment 18 Julien Valroff 2006-03-27 18:15:28 UTC
> What icon does it display?
full, plugged and not charging icon (http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/battery-charged.png?rev=1.1)

I also sometimes see the empty but charging icon (http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/gpm-battery-charging-000.png?rev=1.1), I think, but am far from sure, that below a certain charge level, it changes (I have to check this).

> 1. Note the icon (correct/incorrect)
> 2. Switch the AC adaptor state (ie plug it in, or unplug it; whatever you
> didn't start on)
I only have this problem when starting on battery power.

> 3. Wait a bit and see what the icon is
> 4. Switch the AC adaptor back
As already explained, the icon is ok once I plug the ac adapter, but reloading gpm does not change anything.

Cheers,
Julien
Comment 19 Paul Drain 2006-03-29 06:56:02 UTC
I've got the same issue on a bunch of older laptops (Toshiba's and Compaq's) with older batteries that will never charge to 100% due to age.

On battery power, the icons are correct and the tooltip reports sane percentages (90%, 80%, 60%, etc) when charging and discharging.

On AC, the icons are correct and the tooltip reports sane percentages when initially charging, but are incorrect once the battery becomes fully charged.

Without Paul's patch, the icon is always empty-but-on-AC
(http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/gpm-battery-charging-000.png?rev=1.1)
when on AC, but the tooltip says that the laptop is on AC and fully charged at anywhere from 82% to 95% (varies by laptop).

With it, the icon is the full-on-battery (http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/data/icons/24x24/gpm-battery-discharging-100.png?rev=1.1)
but the tooltip says "Computer is running on AC power, Laptop battery charging (xx%)"

Same problem in 2.13.93 (ubuntu dapper) and 2.14.0 (GARNOME on CentOS4)
Comment 20 Richard Hughes 2006-04-02 14:50:38 UTC
Paul, how's it going? Want me to have a go?
Comment 21 Paul Betts 2006-04-02 23:50:44 UTC
I haven't had a chance to work on it, but I'll have a lot more time to work on it this week, I want to track down the actual problem more than just hacking something
Comment 22 Paul Betts 2006-04-03 03:08:01 UTC
Created attachment 62649 [details] [review]
Improved version of previous patch

I didn't include a changelog because CVS went a little weird on me
Comment 23 Paul Betts 2006-04-03 03:18:46 UTC
Created attachment 62651 [details] [review]
Improved patch with Changelog
Comment 24 Richard Hughes 2006-04-03 08:30:46 UTC
Two things, when you do cvs diff, do "cvs diff -u" and you get the unified format. Second, what happens when the battery is actually charged on a non-broken system? You probably need to use the gpm_power_battery_is_charged () function in gpm-power.c

Otherwise the patch looks good. Do you want me to take the baton from here?
Comment 25 Paul Betts 2006-04-03 19:03:04 UTC
Ah! Good call, I forgot about that case. 
Comment 26 Richard Hughes 2006-04-15 13:55:10 UTC
Paul, do you have an updated patch?
Comment 27 Paul Betts 2006-04-15 16:49:15 UTC
Yeah, I had this done awhile ago, I forgot to send in the patch though! Sorry
Comment 28 Paul Betts 2006-04-15 16:51:09 UTC
Created attachment 63596 [details] [review]
Handles case where battery is full
Comment 29 Julien Valroff 2006-04-29 07:05:43 UTC
Hi,

FYI I have built the latest 2.14.3 release and the problem isn't fixed in it. I cannot try the 2.15 branch because hal and co. are not up-to-date in Debian testing for the moment.

Cheers,
Julien
Comment 30 Jean Pierre Rupp 2006-07-19 20:12:22 UTC
First of all, I'm using Ubuntu Dapper with version 2.14.3. I applied the last patch (#28) with a little modification (not line 266 but 254), and it worked seamlessly. I don't really understand why this bug is labeled as needing more info or why this simple patch hasn't been applied upstream yet.

If it's fixed by 2.15 then just ignore this comment. I'm posting this bug to the Ubuntu Launchpad site too. I just felt I should report upstream too.
Comment 31 Julien Valroff 2006-07-20 19:11:17 UTC
This patch does not work for me, at least, it seems it fixes the problem when starting on the battery, but the issue now happens when I (un)plug the power cable (which it did not before applying the patch).

After a few seconds (let's say 15 to 30s), the icon displays correctly.

I don't think it is gpm fault, as lshal displays the same information that gpm, but I think gpm should deal with such cases, or maybe Richard can talk to Hal developers so that they fix this (once again, I know they already refused some proposals).

Cheers,
Julien
Comment 32 Jean Pierre Rupp 2006-07-20 21:47:15 UTC
(In reply to comment #31)

This is so because HAL apparently reports the percentage a few moments after (un)plugging the power cord. This is not really an issue. I think we can stand 15 seconds of the wrong icon. Don't you?
Comment 33 Julien Valroff 2006-07-23 14:50:41 UTC
I do ;-)

But I also think it would be great if gpm could handle these cases - I would prefer it not to update the icon rather than seeing a wrong icon, what do you think?

Cheers,
Julien
Comment 34 Andrew J. Montalenti 2006-09-02 16:01:03 UTC
Though I haven't tried to patch it yet, the bug on my laptop seems to be caused by  the FIXME on line 219 of gpm-power.c.  If it sees a charge rate of 0, it sets charging and discharging to 0, strangely.  When gpm starts up for me, it claims a broken battery since the charging and discharging booleans are both false.  Yet, lshal displays one as true and one as false as necessary.
Comment 35 Andrew J. Montalenti 2006-09-02 16:47:36 UTC
Just to confirm, by commenting out the FIXMEs in gpm-power.c, gpm no longer claims my battery is broken and the icons show up as they should.
Comment 36 Richard Hughes 2006-09-08 14:20:25 UTC
2006-09-08  Richard Hughes  <richard@hughsie.com>

	* src/gpm-power.c:
	Remove the FIXME to fix #334212. It's breaking more laptops that it
	was intended to fix and also breaks my (already broken) iBook.
Comment 37 Richard Hughes 2006-09-18 20:35:12 UTC
Please reopen if not fixed. Thanks.
Comment 38 Paul Betts 2006-09-19 00:22:52 UTC
The patch in #36 fixed the issues on my computer; thanks for the help!