sleep inhibitor - popravljen za linux (bazira na gnome-session-inhibit)
This commit is contained in:
21
projector.py
21
projector.py
@@ -173,10 +173,18 @@ class SongProjector:
|
||||
if sys.platform.startswith("win"):
|
||||
# Windows: ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED
|
||||
# 0x80000000 | 0x00000002 | 0x00000001
|
||||
ctypes.windll.kernel32.SetThreadExecutionState(0x80000003)
|
||||
# Uporabimo c_uint za zagotovitev pravilnega tipa
|
||||
ctypes.windll.kernel32.SetThreadExecutionState(ctypes.c_uint(0x80000003))
|
||||
elif sys.platform == "linux":
|
||||
# Linux: poskusimo z xset (če smo v X11)
|
||||
subprocess.Popen(["xset", "s", "off", "-dpms"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
# Zaženi inhibitor, dokler tvoj program dela (hrani handle!)
|
||||
inhibitor = subprocess.Popen([
|
||||
"gnome-session-inhibit",
|
||||
"--inhibit", "idle",
|
||||
"--inhibit", "suspend",
|
||||
"--reason", "Projecting lyrics",
|
||||
"sleep", "infinity"
|
||||
])
|
||||
|
||||
except Exception as e:
|
||||
print(f"Napaka pri preprečevanju spanja: {e}")
|
||||
|
||||
@@ -488,13 +496,18 @@ class SongProjector:
|
||||
if sys.platform.startswith("win"):
|
||||
try:
|
||||
# ES_CONTINUOUS (0x80000000)
|
||||
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
|
||||
ctypes.windll.kernel32.SetThreadExecutionState(ctypes.c_uint(0x80000000))
|
||||
except:
|
||||
pass
|
||||
elif sys.platform == "linux":
|
||||
try:
|
||||
# Ponovno vklopi ohranjevalnik in DPMS (privzete vrednosti)
|
||||
subprocess.Popen(["xset", "s", "on", "+dpms"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
# Za Wayland/DBus inhibit običajno ni treba eksplicitno sprostiti,
|
||||
# če se proces konča, vendar bi za popolnost lahko uporabili UnInhibit,
|
||||
# če bi shranili cookie. Ker ga nismo, se zanašamo na to, da DBus
|
||||
# samodejno sprosti inhibit ob zaprtju povezave/procesa.
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user