Windows: Improve locked screen detection
UAC prompts count as locked screens, so only trigger extended away when the screen is more than 10 seconds locked Fixes #9117
This commit is contained in:
parent
fcda077493
commit
3fbba447db
|
@ -20,6 +20,7 @@
|
||||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import ctypes
|
import ctypes
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
import logging
|
import logging
|
||||||
|
@ -151,6 +152,8 @@ class WindowsIdleMonitor:
|
||||||
self.GetTickCount = ctypes.windll.kernel32.GetTickCount
|
self.GetTickCount = ctypes.windll.kernel32.GetTickCount
|
||||||
self.GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo
|
self.GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo
|
||||||
|
|
||||||
|
self._locked_time = None
|
||||||
|
|
||||||
class LASTINPUTINFO(ctypes.Structure):
|
class LASTINPUTINFO(ctypes.Structure):
|
||||||
_fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)]
|
_fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)]
|
||||||
|
|
||||||
|
@ -165,18 +168,30 @@ class WindowsIdleMonitor:
|
||||||
# Check if Screen Saver is running
|
# Check if Screen Saver is running
|
||||||
# 0x72 is SPI_GETSCREENSAVERRUNNING
|
# 0x72 is SPI_GETSCREENSAVERRUNNING
|
||||||
saver_runing = ctypes.c_int(0)
|
saver_runing = ctypes.c_int(0)
|
||||||
info = self.SystemParametersInfo(0x72, 0, ctypes.byref(saver_runing), 0)
|
info = self.SystemParametersInfo(
|
||||||
|
0x72, 0, ctypes.byref(saver_runing), 0)
|
||||||
if info and saver_runing.value:
|
if info and saver_runing.value:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check if Screen is locked
|
# Check if Screen is locked
|
||||||
|
# Also a UAC prompt counts as locked
|
||||||
|
# So just return True if we are more than 10 seconds locked
|
||||||
desk = self.OpenInputDesktop(0, False, 0)
|
desk = self.OpenInputDesktop(0, False, 0)
|
||||||
if not desk:
|
unlocked = bool(desk)
|
||||||
return True
|
|
||||||
self.CloseDesktop(desk)
|
self.CloseDesktop(desk)
|
||||||
|
|
||||||
|
if unlocked:
|
||||||
|
self._locked_time = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if self._locked_time is None:
|
||||||
|
self._locked_time = time.time()
|
||||||
|
return False
|
||||||
|
|
||||||
|
threshold = time.time() - 10
|
||||||
|
if threshold > self._locked_time:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class IdleMonitor:
|
class IdleMonitor:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue