From 3fbba447dbffdf0e08970e43a7ecb481f5a729d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Thu, 6 Sep 2018 21:40:18 +0200 Subject: [PATCH] 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 --- gajim/common/idle.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gajim/common/idle.py b/gajim/common/idle.py index 5bce7699f..ec04ef7ad 100644 --- a/gajim/common/idle.py +++ b/gajim/common/idle.py @@ -20,6 +20,7 @@ # along with Gajim. If not, see . import sys +import time import ctypes import ctypes.util import logging @@ -151,6 +152,8 @@ class WindowsIdleMonitor: self.GetTickCount = ctypes.windll.kernel32.GetTickCount self.GetLastInputInfo = ctypes.windll.user32.GetLastInputInfo + self._locked_time = None + class LASTINPUTINFO(ctypes.Structure): _fields_ = [('cbSize', ctypes.c_uint), ('dwTime', ctypes.c_uint)] @@ -165,17 +168,29 @@ class WindowsIdleMonitor: # Check if Screen Saver is running # 0x72 is SPI_GETSCREENSAVERRUNNING 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: return True # 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) - if not desk: - return True + unlocked = bool(desk) self.CloseDesktop(desk) - return False + if unlocked: + self._locked_time = None + 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: