Bug 474982 - Battery applet no longer tells why the power management is inhibited
Summary: Battery applet no longer tells why the power management is inhibited
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Battery Monitor (show other bugs)
Version: master
Platform: Neon Linux
: NOR major
Target Milestone: 1.0
Assignee: Natalie Clarius
URL:
Keywords: qt6, regression
: 477120 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-09-28 12:38 UTC by Patrick Silva
Modified: 2023-12-05 15:55 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.0


Attachments
Works for me (80.91 KB, image/jpeg)
2023-11-30 19:42 UTC, Nate Graham
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Silva 2023-09-28 12:38:18 UTC
STEPS TO REPRODUCE
1. play an audio/video with VLC player or Haruna
2. click on Battery applet in the system tray
3. 

OBSERVED RESULT
"Manually block sleep and screen locking" option is active, but the applet does not tell why, like on Plasma 5.

EXPECTED RESULT
if the power management is inhibited, the Battery applet should tell why

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.27.80
KDE Frameworks Version: 5.240.0
Qt Version: 6.6.0
Graphics Platform: Wayland
Comment 1 Nate Graham 2023-09-28 20:34:07 UTC
Can reproduce. Seems like a recent regression, as I recall this working just a week or two ago.
Comment 2 Nicolas Fella 2023-09-29 11:51:10 UTC
> qt.dbus.integration: Could not connect "org.kde.Solid.PowerManagement.PolicyAgent" to inhibitionsChanged(QList<InhibitionInfo>, QStringList) : Unregistered input type in parameter list: QList<InhibitionInfo>
error connecting to inhibition changes via dbus

sounds related
Comment 3 Natalie Clarius 2023-09-29 15:28:38 UTC
(In reply to Nicolas Fella from comment #2)
> > qt.dbus.integration: Could not connect "org.kde.Solid.PowerManagement.PolicyAgent" to inhibitionsChanged(QList<InhibitionInfo>, QStringList) : Unregistered input type in parameter list: QList<InhibitionInfo>
> error connecting to inhibition changes via dbus
> 
> sounds related

Ah, quite possibly my fault with the recent sync manusl inhibition state fix, I'll look into it
Comment 4 Natalie Clarius 2023-10-27 15:12:40 UTC
> Ah, quite possibly my fault with the recent sync manusl inhibition state fix

Nope, reverting it doesn't fix the bug. And that DBus error sounds not directly related to that change anyway, so I'll look into that.
Comment 5 Natalie Clarius 2023-10-28 00:05:24 UTC
I'm getting that signal fine with dbus-monitor so currently out of ideas why the applet's data engine fails to connect to it.
Comment 6 Natalie Clarius 2023-10-28 15:56:36 UTC
Apparently the dbus connection error is a bug in Qt that will be fixed in the next release: https://codereview.qt-project.org/c/qt/qtbase/+/513362.

It may need another patch in the battery applet on top of it that I have a draft for and will revisit once the upstream fix is out.
Comment 7 Nate Graham 2023-11-17 06:02:51 UTC
*** Bug 477120 has been marked as a duplicate of this bug. ***
Comment 8 Nate Graham 2023-11-29 16:55:46 UTC
Can confirm it's fixed in Qt 6.6 for me.
Comment 9 Natalie Clarius 2023-11-29 16:57:36 UTC
(In reply to Nate Graham from comment #8)
> Can confirm it's fixed in Qt 6.6 for me.

Just the DBus connection failure or this bug?
Comment 10 Nate Graham 2023-11-29 17:02:42 UTC
The bug itself. I now see explanations again.
Comment 11 Patrick Silva 2023-11-30 12:43:57 UTC
The bug persists on Arch Linux running Plasma 6 beta.

Operating System: Arch Linux 
KDE Plasma Version: 5.90.0
KDE Frameworks Version: 5.246.0
Qt Version: 6.6.1
Graphics Platform: Wayland
Comment 12 Nate Graham 2023-11-30 19:42:06 UTC
Created attachment 163670 [details]
Works for me
Comment 13 Jin Liu 2023-12-01 01:25:09 UTC
(In reply to Nate Graham from comment #12)
> Created attachment 163670 [details]
> Works for me

I'm on Arch, and have the same problem. It only shows inhibitors present when the applet is loaded, not anything afterwards.

1. Ensure no inhibitor is present.
2. `systemd-inhibit bash`
3. In another konsole: `plasmoidviewer --applet org.kde.plasma.battery`
4. Click on the icon. It shows `bash` as the inhibitor.
5. Quit `bash`, then run `systemd-inhibit bash` again.
6. The bug.

Also notice that the kscreen applet shows the same info correctly, with roughly the same code. And I added some logging in the battery applet's DataSource.onDataChanged to verify that it indeed received the inhibitor list correctly. The bug probably is not in dbus, but in the applet's own logic.
Comment 14 Jin Liu 2023-12-01 02:04:36 UTC
The current implementation doesn't make sense at all...

The manual switch is bound to the data engine "PowerManagement" "Has Inhibition":
https://github.com/KDE/plasma-workspace/blob/e254bf301a560b9d6d70968ac43a587edab7fe19/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml#L41

Which bounds to org.freedesktop.PowerManagement.Inhibit.HasInhibitChanged:
https://github.com/KDE/plasma-workspace/blob/de5a5dbf63c5d1fb91c1cf3a3f45553b9cca417b/dataengines/powermanagement/powermanagementengine.cpp#L219

The problem is the FDO service returns HasInhibit=true for *any* inhibitors. So this code would treat any inhibitor as manually enabled in the applet.

The correct implementation would be that Powerdevil manages a special "KDE manual inhibitor" whose state can be queried individually.

BTW, I don't see why the applet hides inhibitors when the manual switch is on.
Comment 15 Natalie Clarius 2023-12-05 01:51:37 UTC
Now it shows the inhibition after setting the manual inhibition switch to off again, but it still incorrectly turns the manual inhibition switch on the first time.

(In reply to Jin Liu from comment #14)
> The current implementation doesn't make sense at all...
> 
> The manual switch is bound to the data engine "PowerManagement" "Has
> Inhibition":
> https://github.com/KDE/plasma-workspace/blob/
> e254bf301a560b9d6d70968ac43a587edab7fe19/applets/batterymonitor/package/
> contents/ui/PowerManagementItem.qml#L41
> 
> Which bounds to org.freedesktop.PowerManagement.Inhibit.HasInhibitChanged:
> https://github.com/KDE/plasma-workspace/blob/
> de5a5dbf63c5d1fb91c1cf3a3f45553b9cca417b/dataengines/powermanagement/
> powermanagementengine.cpp#L219
> 
> The problem is the FDO service returns HasInhibit=true for *any* inhibitors.
> So this code would treat any inhibitor as manually enabled in the applet.
> 
> The correct implementation would be that Powerdevil manages a special "KDE
> manual inhibitor" whose state can be queried individually.
> 
> BTW, I don't see why the applet hides inhibitors when the manual switch is
> on.

That's correct, my mentioned drafted fix addresses this, will test again.
Comment 16 Bug Janitor Service 2023-12-05 02:38:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/3654
Comment 17 Natalie Clarius 2023-12-05 02:50:52 UTC
(In reply to Jin Liu from comment #14)

> BTW, I don't see why the applet hides inhibitors when the manual switch is
> on.

I think the idea was that the information is redundant since when the manual inhibition is on, it won't go to sleep anyway. But the same applies to having more than one app inhibition, and it just makes the logic more complicated, so I would be fine with changing it to simply always showing all active inhibition sources.
Comment 18 Jin Liu 2023-12-05 02:53:36 UTC
(In reply to Natalie Clarius from comment #17)
> (In reply to Jin Liu from comment #14)
> 
> > BTW, I don't see why the applet hides inhibitors when the manual switch is
> > on.
> 
> I think the idea was that the information is redundant since when the manual
> inhibition is on, it won't go to sleep anyway. But the same applies to
> having more than one app inhibition, and it just makes the logic more
> complicated, so I would be fine with changing it to simply always showing
> all active inhibition sources.

Yeah. And also it would be consistent with the kscreen applet in that way.
Comment 19 Bug Janitor Service 2023-12-05 03:01:48 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/3655
Comment 20 Nate Graham 2023-12-05 15:53:50 UTC
Git commit feaa8903e809c86473dc329bb58feddb82962ce1 by Nate Graham, on behalf of Natalie Clarius.
Committed on 05/12/2023 at 16:53.
Pushed by ngraham into branch 'master'.

applets/battery: fix switch for manual inhibition falsely checked when inhibited by some other app
FIXED-IN: 6.0

M  +1    -0    applets/batterymonitor/package/contents/ui/PopupDialog.qml
M  +2    -1    applets/batterymonitor/package/contents/ui/PowerManagementItem.qml
M  +6    -4    applets/batterymonitor/package/contents/ui/logic.js
M  +3    -0    applets/batterymonitor/package/contents/ui/main.qml

https://invent.kde.org/plasma/plasma-workspace/-/commit/feaa8903e809c86473dc329bb58feddb82962ce1
Comment 21 Nate Graham 2023-12-05 15:55:37 UTC
Git commit afdd04821febd8c2b6ad983977721b34db112db7 by Nate Graham, on behalf of Natalie Clarius.
Committed on 05/12/2023 at 16:55.
Pushed by ngraham into branch 'master'.

applets/battery: show app inhibitions even when manually inhibited too

It doesn't hurt to inform the user what other apps additionally hold inhibitions, we don't hide the others when there are multiple app inhibitions either, and it just adds complexity to the logic, so let's simply always show all active inhibitions.

M  +3    -8    applets/batterymonitor/package/contents/ui/PowerManagementItem.qml

https://invent.kde.org/plasma/plasma-workspace/-/commit/afdd04821febd8c2b6ad983977721b34db112db7