Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_ac_power possibly returning false when it should return true? #1

Open
jc00ke opened this issue Aug 28, 2023 · 21 comments
Open

on_ac_power possibly returning false when it should return true? #1

jc00ke opened this issue Aug 28, 2023 · 21 comments

Comments

@jc00ke
Copy link

jc00ke commented Aug 28, 2023

if ! on_ac_power; then

I'm still trying to figure out why my desktop is suspending, and I think I've tracked it down to an issue with whatever is setting on_ac_power, though I'm not 100% sure.

Here's the discussion as to why I'm looking into this.

How might I go about debugging this? I'm running Regolith 3.0 that was just released.

What's leading me to this is that upower via DisplayDevice that I use for i3status-rust battery block seems to be returning empty. I'm not sure if this is directly related, but it might be.

2023-08-28_12-03

@jc00ke
Copy link
Author

jc00ke commented Aug 28, 2023

In the meantime, how can I change my swayidle command?

@SoumyaRanjanPatnaik
Copy link
Collaborator

Can you confirm if this is the reason for the behavior you're observing by running this on a bash shell?

if on_ac_power ; then echo YES ; fi

@SoumyaRanjanPatnaik
Copy link
Collaborator

regolith-powerd/src/main.rs

Lines 125 to 139 in ca281fc

let (idle_action_bat_opt, resume_action_bat_opt) = {
use SleepInactiveBatteryType::*;
match self.power_settings.sleep_inactive_battery_type() {
Suspend => (Some("systemctl suspend"), None),
Hibernate => (Some("systemctl hibernate"), None),
Blank => (
Some("swaymsg output * dpms off"),
Some("swaymsg output * dpms on"),
),
Shutdown => (Some("poweroff"), None),
Logout => (Some("gnome-session-quit --no-prompt"), None),
Interactive => todo!("Show some gui prompt to the user"),
Nothing => (None, None),
}
};

Regardless I don't think that to be the case. If you've disabled Automatic suspend, idle_action_bat_opt and resume_action_bat_opt should both be None.

@SoumyaRanjanPatnaik
Copy link
Collaborator

dconf dump /org/gnome/settings-daemon/plugins/power/

Can you dump the output for this command?

@SoumyaRanjanPatnaik
Copy link
Collaborator

SoumyaRanjanPatnaik commented Sep 2, 2023

In the meantime, how can I change my swayidle command

Uninstalling regolith-powerd should disable swayidle. But it is probably a hard dependency of regolith-sway-session.

@jc00ke
Copy link
Author

jc00ke commented Sep 2, 2023

Thanks for the debugging steps and potential workarounds. I won't be in the office until Tuesday; I'll debug then and report back.

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

Can you confirm if this is the reason for the behavior you're observing by running this on a bash shell?

if on_ac_power ; then echo YES ; fi
jesse@jimmie:~$ if on_ac_power ; then echo YES ; fi
jesse@jimmie:~$ if ! on_ac_power ; then echo NO ; fi
NO

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

dconf dump /org/gnome/settings-daemon/plugins/power/

Can you dump the output for this command?

➜ dconf dump /org/gnome/settings-daemon/plugins/power/
[/]
sleep-inactive-ac-type='nothing'

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

❯ on_ac_power
~
❯ echo $status
255

from man(1):

EXIT STATUS
       0 (true)  System is on mains power
       1 (false) System is not on mains power
       255 (false)    Power status could not be determined

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

Ooh, so a nasty hack would be on this machine to override on_ac_power to always exit with status 0... gross.

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

Seems like these caveats apply for those that use desktops:

CAVEATS
       The vast majority of desktops and servers have no power sensors,  thus  they  return  255  "un‐
       known";  for  most purposes you'd want to consider this answer to imply mains power — note that
       255 evaluates as false for the shell.

       This program currently provides only information known to the kernel; it doesn't  (yet?)  query
       userspace daemons such as nut which may provide further information.

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

Sorry for all the comments, I'm bouncing from this to work and back. I found this bug report, which makes me think that the short term fix is either to rely on something else (override on_ac_power) or change the logic to first use on_ac_power and if it's not conclusive (status 255) then use /lib/systemd/systemd-ac-power or something else.

@jc00ke
Copy link
Author

jc00ke commented Sep 5, 2023

In the meantime, how can I change my swayidle command

Uninstalling regolith-powerd should disable swayidle. But it is probably a hard dependency of regolith-sway-session.

Nope, don't think I want to do that 😆

➜ sudo apt remove regolith-powerd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  clipman gtklock i3status-rs kanshi libplayerctl2 light playerctl regolith-avizo regolith-displayd
  regolith-inputd regolith-sway-audio-idle-inhibit regolith-sway-background
  regolith-sway-control-center-regolith regolith-sway-dbus-activation regolith-sway-default-style
  regolith-sway-gaps regolith-sway-gtklock regolith-sway-i3status-rs regolith-sway-ilia
  regolith-sway-media-keys regolith-sway-polkit regolith-sway-screensharing regolith-sway-session
  regolith-sway-unclutter sway-audio-idle-inhibit trawldb xwayland
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  regolith-powerd regolith-session-sway regolith-sway-gsd regolith-sway-root-config
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
After this operation, 651 kB disk space will be freed.
Do you want to continue? [Y/n]

@SoumyaRanjanPatnaik
Copy link
Collaborator

Hey sorry. i've been quite busy for the last two weeks.

@SoumyaRanjanPatnaik
Copy link
Collaborator

SoumyaRanjanPatnaik commented Sep 15, 2023

Your findings are definitely helpful. I'll implement the fix you suggested. I think I might also look into downgrading regolith-powerd into a soft dep.

@SoumyaRanjanPatnaik
Copy link
Collaborator

Also, I see you don't have sleep-inactive-battery-type defined in your dconf dump. This means, the default value of 'suspend' is used whenever regolith-powerd queries gsettings for this property. So a temporary fix should be to set sleep-inactive-battery-type='nothing'.

@jc00ke
Copy link
Author

jc00ke commented Sep 15, 2023

Cool, I can do that. How do I do that? 🤣

@jc00ke
Copy link
Author

jc00ke commented Sep 15, 2023

Figured it out:

> dconf write /org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-type "'nothing'"
# ----------------------------------------------------------------------------------^       ^
# notice the single quotes, which tells dconf this is a string

@jc00ke
Copy link
Author

jc00ke commented Sep 15, 2023

Current settings:

➜ dconf dump /org/gnome/settings-daemon/plugins/power/
[/]
sleep-inactive-ac-type='nothing'
sleep-inactive-battery-type='nothing'

@SoumyaRanjanPatnaik
Copy link
Collaborator

I'm hoping this workaround fixes your issue(for now). Regardless, this is a bug that requires fixing in general.

@jc00ke
Copy link
Author

jc00ke commented Sep 19, 2023

So far so good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants