coadmunkee / gnome-shell-extension-espresso

Enable controlling conditions to prevent the usual auto suspend and screensaver functions from taking effect.
https://extensions.gnome.org/extension/4135/espresso/
GNU General Public License v2.0
69 stars 14 forks source link

Inhibit sleep on lid switch #38

Open martindmtrv opened 2 years ago

martindmtrv commented 2 years ago

Bumping from the caffeine side as this is a feature I would love to use

https://github.com/eonpatapon/gnome-shell-extension-caffeine/issues/16

By default in my setup a lid close with always suspend even connected while docked as this is the behavior I prefer most of the time.

However there are times I like to close the lid and not go to sleep so it would be amazing if this could be done through a gnome extension such as this one!

From reading up on this issue there is totally two camps on this so having it available as a toggle in the settings would be best.

In terms of potential solutions; it seems spawning a process like @jomority mentioned in that thread would be best

systemd-inhibit --what=handle-lid-switch --mode=block /bin/sh

as this would keep it blocked and clean it up later by killing that process. The display stays on while the lid is closed but I'm not sure if that could be fixed (to act like HandleLidSwitch=ignore temporarily, where everything is shifted to a second monitor if one is connected).

Office runner does work but it seems odd to have a timer game running just to keep the lid from locking me out, would prefer just a simple system toggle!

martindmtrv commented 2 years ago

As far as I can tell, there isnt a way to retain the PID directly from the call to Util.spawnCommandLine(...) as the method returns nothing. However if running the command and making a temporary .pid file somewhere with echo we can get the PID. Something like this:

systemd-inhibit --what=handle-lid-switch --mode=block /bin/sh & echo "$!" > /tmp/espressoInhibit.pid

Which then later we can

kill -9 <pid from /tmp/espressoInhibit.pid>

This effectively disables the lid switch and re-enables it at some later time, however I am new to Gnome extensions and am unfamiliar with perhaps some pitfalls this approach that this could bring or if it is even possible in a Gnome extension.