Permalink
Browse files

Merge pull request #347 from pculture/fix19075

bz19075: Disable power management while we are playing video on windows
  • Loading branch information...
2 parents f4cbbe7 + 249a070 commit d9c1af09481aee4340cc5f6086413f628a3bd5fb geoffl committed May 10, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 tv/windows/plat/screensaver.py
@@ -34,11 +34,18 @@
import ctypes.wintypes
import _winreg
+# SystemParametersInfo controls the screensaver
SystemParametersInfo = ctypes.windll.user32.SystemParametersInfoA
SPI_GETSCREENSAVEACTIVE = 16
SPI_SETSCREENSAVEACTIVE = 17
+# SetThreadExecutionState controls the display sleep settings
+SetThreadExecutionState = ctypes.windll.kernel32.SetThreadExecutionState
+ES_SYSTEM_REQUIRED = 0x00000001
+ES_DISPLAY_REQUIRED = 0x00000002
+ES_CONTINUOUS = 0x80000000
+
class WindowsScreenSaverManager(object):
def __init__(self):
self.was_active = None
@@ -67,17 +74,23 @@ def check_screen_saver_active(self):
return rv.value != 0
def disable(self):
+ # For SystemParametersInfo, we need to remember the old setting
if self.check_screen_saver_active():
self.was_active = True
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, None, 0)
else:
self.was_active = False
+ # For SetThreadExecutionState, we can just set the value for our own
+ # thread.
+ SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED |
+ ES_DISPLAY_REQUIRED)
def enable(self):
if self.was_active is None:
raise AssertionError("disable() must be called before enable()")
if self.was_active:
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, None, 0)
+ SetThreadExecutionState(ES_CONTINUOUS)
self.was_active = None
def create_manager(toplevel_window):

0 comments on commit d9c1af0

Please sign in to comment.