wakepy icon indicating copy to clipboard operation
wakepy copied to clipboard

Method using gtk_application_inhibit()

Open fohrloop opened this issue 5 months ago • 2 comments

Aims to close: #404

Add support for unix systems with GTK

  • The solution supports both, GTK3 and GTK4, and adds keep.running and keep.presenting modes to all platforms with the GTK graphical toolkit. Many desktop environments are based on GTK. A few examples are GNOME, Xfce, Cinnamon, LXDE, MATE, Unity, Budgie and Pantheon.
  • The requirements for this method to work are (1) GTK installed on the system (this a bit vague, but if you're running a DE which is based on GTK, that's most likely enough) 2) The python bindings for it; the PyGObject (gi) python library installed either on the current python environment or the system python site packages.

Details

  • Use the Gtk.Application.inhibit() from the GObject Instrospection python package (import name: gi, package name: PyGObject) for inhibiting sleep/idle. This is the PyGObject interface to the gtk_application_inhibit() function.
  • Add new server script which can be started with any python interpreter. The idea is that this is called with the system interpreter since that is expected to have the gi module for accessing GTK functions from python. User is not required to have installed the in their current (virtual) environment. It's just faster to use (300ms vs 5ms) if gi is available in the current python environment. Most people probably won't care if their long running script takes a 300ms more, and not having to install PyGObject is a nice thing as the installation will require compilation step(s), so it's a bit trickier and slower to install than a pure python package.
  • New concept: Inhibit module. This is a python module (a .py file), which should contain one class with the name Inhibitor, which should comply with the new Inhibitor protocol: There must be a start(self, *args) and stop(self) methods. The *args are positional arguments given to the server and passed to the inhibitor.

TODO

  • [ ] Add logic to get the system python interpreter path
  • [x] Add logic for creating a random socket
  • [x] Create wakepy.Method for this
  • [ ] Pass down the IDLE vs SUSPEND argument from the Method
  • [ ] Add tests
  • [ ] Update documentation
  • [ ] Check that the solution is not considerably slower than the other altenatives (like: D-Bus based methods)

fohrloop avatar Sep 25 '24 12:09 fohrloop