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"):
|
if sys.platform.startswith("win"):
|
||||||
# Windows: ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED
|
# Windows: ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED
|
||||||
# 0x80000000 | 0x00000002 | 0x00000001
|
# 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":
|
elif sys.platform == "linux":
|
||||||
# Linux: poskusimo z xset (če smo v X11)
|
# Zaženi inhibitor, dokler tvoj program dela (hrani handle!)
|
||||||
subprocess.Popen(["xset", "s", "off", "-dpms"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
inhibitor = subprocess.Popen([
|
||||||
|
"gnome-session-inhibit",
|
||||||
|
"--inhibit", "idle",
|
||||||
|
"--inhibit", "suspend",
|
||||||
|
"--reason", "Projecting lyrics",
|
||||||
|
"sleep", "infinity"
|
||||||
|
])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Napaka pri preprečevanju spanja: {e}")
|
print(f"Napaka pri preprečevanju spanja: {e}")
|
||||||
|
|
||||||
@@ -488,13 +496,18 @@ class SongProjector:
|
|||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
try:
|
try:
|
||||||
# ES_CONTINUOUS (0x80000000)
|
# ES_CONTINUOUS (0x80000000)
|
||||||
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
|
ctypes.windll.kernel32.SetThreadExecutionState(ctypes.c_uint(0x80000000))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
elif sys.platform == "linux":
|
elif sys.platform == "linux":
|
||||||
try:
|
try:
|
||||||
# Ponovno vklopi ohranjevalnik in DPMS (privzete vrednosti)
|
# Ponovno vklopi ohranjevalnik in DPMS (privzete vrednosti)
|
||||||
subprocess.Popen(["xset", "s", "on", "+dpms"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user