This commit is contained in:
sankalp committed 2024-11-15 19:41:33 +05:45
1 parent f1f90d57dd
commit 6e366a8b0d
1 file changed
-43
-43
View File
@@ -1,43 +0,0 @@
import subprocess
import re
class Inhibit:
def __init__(self):
self._id = None
@property
def is_inhibit(self):
"""Check if inhibition is active."""
return self._id is not None
def _inhibit(self, command, data):
"""Send a command to the DBus service to inhibit or un-inhibit."""
dbus_command = (
f"dbus-send --print-reply --dest=org.freedesktop.ScreenSaver "
f"/org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.{command} {data}"
)
output = subprocess.run(
dbus_command, shell=True, capture_output=True, text=True
)
if command == "Inhibit":
match = re.search(r"uint32\s+(\d+)", output.stdout)
return int(match.group(1)) if match else None
return None
def toggle(self):
"""Toggle the inhibition state."""
if self._id is None:
self._id = self._inhibit("Inhibit", "string:'ags' string:'Manual pause'")
else:
self._id = self._inhibit("UnInhibit", f"uint32:{self._id}")
# Notify that the state has changed
self.changed("is-inhibit")
def changed(self, property_name):
"""Notify listeners that a property has changed."""
print(
f"Property '{property_name}' changed. Inhibition is now {'active' if self.is_inhibit else 'inactive'}."
)