gnome-shell-extension-caffeine icon indicating copy to clipboard operation
gnome-shell-extension-caffeine copied to clipboard

Should suppress suspend when lid is closed

Open renatomefi opened this issue 11 years ago • 30 comments

I'm using it on a notebook, but when I'm without power cord it will suspend then the lid is closed, it should suppress this features when caffeine is on.

renatomefi avatar Sep 05 '13 18:09 renatomefi

Strange, the suspend should be inhibited. The extention creates an inhibitor in gnome session manager so if gnome is suspending the machine it is doing wrong. An another possibility is that an other program that doesn't care about the inhibitor is putting the computer to suspend.

What distribution are you using ? gnome-session-manager version ?

eonpatapon avatar Sep 06 '13 07:09 eonpatapon

I can confirm this. I enabled caffeine closed the lid, my laptop was suspended and when I woke it up again caffeine was disabled. I'm on archlinux, gnome-session version 3.8.4-1.

maufl avatar Sep 08 '13 11:09 maufl

Hmm I think it is due to the lock screen that disable all extensions

eonpatapon avatar Sep 09 '13 16:09 eonpatapon

I'm using ubuntu 13.04 and gnome 3.8.2.1

It would be great if your extension suppress this configuration above:

[image: Inline image 1]


On Mon, Sep 9, 2013 at 1:28 PM, Jean-Philippe Braun < [email protected]> wrote:

Hmm I think it is due to the lock screen that disable all extensions

— Reply to this email directly or view it on GitHubhttps://github.com/eonpatapon/gnome-shell-extension-caffeine/issues/16#issuecomment-24092047 .

renatomefi avatar Sep 09 '13 16:09 renatomefi

@renatomefidf sorry I don't see you image

eonpatapon avatar Sep 10 '13 07:09 eonpatapon

With the last commit, the gnome-session daemon will add an systemd inhibitor to block system suspend.

systemd inhibitors can be listed with: systemd-inhibit --list. An item should be added in the list when Caffeine is enabled (if not gnome-session failed to add it): Who: user (UID ...) What: shutdown:sleep Why: user session inhibited Mode: block

See also: https://bugzilla.gnome.org/show_bug.cgi?id=687277 http://www.freedesktop.org/wiki/Software/systemd/inhibit/ https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html#org.gnome.SessionManager.Inhibit

eonpatapon avatar Dec 29 '13 21:12 eonpatapon

Works now on gnome 3.12 + systemd 212 on Archlinux

eonpatapon avatar Apr 05 '14 08:04 eonpatapon

Does not work on gnome 3.8.4-8 + systemd 204 on Debian.

With "systemd-inhibit --list", I do see an item for "shutdown:sleep":

Who: Telepathy (UID 1000/pietro, PID 4248/mission-control)
What: shutdown:sleep
Why: Disconnecting IM accounts before suspend/shutdown...
Mode: delay

... but when I close the lid, the system suspends. Notice that manually giving the command

 systemd-inhibit --what=handle-lid-switch --who=me --why=because --mode=block /bin/sh

works instead.

toobaz avatar Jun 08 '14 10:06 toobaz

The item that should be added when Caffeine enabled is:

Who: eon (UID 1000/eon, PID 953/gnome-session)
What: shutdown:sleep
Why: user session inhibited
Mode: block

It's handled by gnome-session daemon itself when creating an inhibitor in the session but as you noticed it's not supported everywhere. This blocks suspend but not the lock screen.

Maybe I could switch to your solution but this means that I need to call systemd-inhibit manually to add or remove the systemd inhibitor.

eonpatapon avatar Jun 08 '14 10:06 eonpatapon

@eonpatapon I cannot judge, because I didn't look at the internals of Caffeine, and i don't know what "it's not supported everywhere" exactly means. What I can tell is that I would like such feature so much that if you think it is not fit for Caffeine, I will probably write a simple extensions doing only that. Notice that other people may be interested, see: https://bugzilla.gnome.org/show_bug.cgi?id=638865 https://bugzilla.gnome.org/show_bug.cgi?id=687277

Let me know your plans!

toobaz avatar Jun 09 '14 08:06 toobaz

(by the way: yes, I do see that item with "systemd-inhibit --list")

toobaz avatar Jun 09 '14 08:06 toobaz

I noticed that this systemd inhibit doesn't work anymore for me too.

Currently Caffeine create inhibitors in the gnome session (https://github.com/eonpatapon/gnome-shell-extension-caffeine/blob/master/caffeine%40patapon.info/extension.js#L174). The 12 param in the call tells gnome-session manager to also add an systemd inhibitor to block suspend.

Anyway I think I'll try with your solution. handle-lid seems more reliable.

eonpatapon avatar Jun 09 '14 09:06 eonpatapon

@toobaz the handle-lid-switch inhibit is now added by Caffeine. Let me know if that works for you!

eonpatapon avatar Jun 09 '14 19:06 eonpatapon

I use caffeine on gnome-shell 3.8. So I cherrypicked your last two commits on the gnome-shell-before-3.10 branch:

https://github.com/toobaz/gnome-shell-extension-caffeine/tree/lid-switch-before-3.10

Now, with this branch, when I activate Caffeine, I do see

  Who: Caffeine (UID 1000/pietro, PID 4145/gnome-shell)
 What: handle-lid-switch
  Why: suspend is disabled
 Mode: block

... but it does not work! If I close the lid, suspend happens. While the manual "system-inhibit ..." command works.

I am a bit lost. In particular considering that on your 3.12 (I suppose), this works.

Initially, I though it might be related to the fact that every time I resume from suspend, the Caffeine message pops up saying "Caffeine is active" - as if it was being (re)started in that moment, that is, as if it had been stopped before suspend. But I don't see how this could explain the misbehaviour (that is why gnome-shell ever knows that a suspend is in progress - given that it was inhibited - and hence stops Caffeine).

toobaz avatar Jun 12 '14 13:06 toobaz

Hmm, the problem is that the extension is disabled by the lock screen. And when disabled Caffeine clean up the inhibitors...

I should try to disable the lock screen instead. And finally the inhibit from gnome-session manager must be enough...

eonpatapon avatar Jun 12 '14 13:06 eonpatapon

I think disabling the lock screen is not optimal... but if it is the only way (i.e. if the Caffeine inhibitors must necessarily be cleaned up on lock screen), then it would certainly be a useful fix, yes.

toobaz avatar Jun 12 '14 16:06 toobaz

Disabling the lock screen doesn't help. IIRC it's the shield screen that disable extensions but I don't find how and when exactly.

It's a pity that gnome doesn't expose a setting to choose how to handle the lid. According to the inhibitors it manage everything but the lid :/

 Who: eon (UID 1000/eon, PID 1200/gnome-settings-)
What: handle-power-key:handle-suspend-key:handle-hibernate-key
 Why: GNOME handling keypresses
Mode: block

Anyway I'm out of luck on this one.

eonpatapon avatar Jun 12 '14 19:06 eonpatapon

systemd does: sudo nano /etc/systemd/logind.conf, then: HandleLidSwitch=ignore, Please don't change this setting again, I thought there was a bug in Manjaro. I dont' know for upstart (Ubuntu Gnome with upstart)

cyberalex4life avatar Sep 23 '15 16:09 cyberalex4life

Not sure what you are saying. I'm not changing the handle-lid-switch setting anymore

eonpatapon avatar Sep 25 '15 09:09 eonpatapon

that's what I was talking about. The solution I gave is actually capable of overriding whatever you're extension does about lid-switch, this is what I used when it didn't work by default (HandleLidSwitch=suspend)

cyberalex4life avatar Sep 25 '15 11:09 cyberalex4life

I'm quite happy that suspend on lid close is working while caffeine is on and I don't need to turn caffeine off before closing the lid (and might even forget that in a hurry!). But if you want to e.g. listen to music with a closed lid, you can start your player like that: systemd-inhibit --what=handle-lid-switch --mode=block playercmd

pothos avatar Jul 19 '16 23:07 pothos

Any alternative/workaround to achieve this globally, other than @pothos solution?

smarquez1 avatar Jan 12 '18 23:01 smarquez1

Sorry for pushing this old thread, but I would really love to have this feature. It should be made configurable, because some people don't like it.

@smarquez1 You could start a random process like systemd-inhibit --what=handle-lid-switch --mode=block /bin/sh and kill it for deactivation. I don't know if something like that is possible within a gnome extension.

jomority avatar Jul 15 '20 14:07 jomority

@jomority @smarquez1 You can use https://flathub.org/apps/details/org.gnome.OfficeRunner

pothos avatar Jul 15 '20 20:07 pothos

Sorry for pushing this old thread, but I would really love to have this feature. It should be made configurable, because some people don't like it.

I'm one that doesn't want this. That way if I close my lid but forget to disable it doesn't drain my battery.

sparkie3 avatar Feb 19 '22 02:02 sparkie3

Bump

khaled-0 avatar Jun 14 '23 14:06 khaled-0

Hey, I found this extension that changes the gnome settings directly. Maybe you guys could implement something similar https://github.com/jenspfahl/KeepAwake/blob/master/KeepAwake%40jepfa.de/extension.js

khaled-0 avatar Jun 28 '23 13:06 khaled-0

I'll look into this at some point, but IIRC changing GNOME settings with an extension is discouraged in most cases, as they need to be correctly reverted when the extension is disabled. If the system then crashed, they wouldn't be restored correctly, leaving the user's system different to how it was before.

stuarthayhurst avatar Jun 28 '23 13:06 stuarthayhurst

changing GNOME settings with an extension is discouraged in most cases, as they need to be correctly reverted when the extension is disabled

Currently, when I need to prevent suspend I manually run this command from a terminal:

systemd-inhibit --what=handle-lid-switch zenity --info --text='Lid switch suspend blocked while open' --ok-label=Close

Would it be possible for the extension to launch something like this in the background (and kill when the Caffeine timer expires, or when the extension is disabled). This would do what we need, without changing any settings.

In the past, gnome-tweaks used to have support for this, but it has since been removed, and gnome-settings still hasn't implemented this. It would be perfect if Caffeine could do this, regardless of a gnome-settings implementation. I generally would want suspend to always be on, but to have a quick way of enabling it. It fits perfectly with Caffeine as usually I would want it disabled while Caffeine is active.

karypid avatar Sep 14 '24 12:09 karypid

Actually, let me share my lid-suspend-control.sh for anyone looking for a workaround while this feature request is pending:

#!/bin/sh

WHAT=handle-lid-switch
PID=$(systemd-inhibit --list | grep $WHAT | sed "s/.*$USER//" | cut -d ' ' -f 2)

if [ -z $PID ]; then
        systemd-inhibit --what=$WHAT zenity --info --text='Lid suspend blocked while open' --ok-label=Close &
        echo Started suspend prevention process $!
else
        echo Killing suspend prevention process $PID
        kill $PID
fi

I have added a custom keyboard shortcut in gnome settings to execute this script with Ctrl-Alt-S and use it to toggle the lid suspension before I close the lid, then press again to turn it off after I open the lid.

image

karypid avatar Sep 14 '24 12:09 karypid