Skip to content

Commit

Permalink
#540: poll for screensaver changes
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@18242 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 1, 2018
1 parent 75e680f commit c148e68
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/xpra/platform/win32/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from ctypes import WinDLL, POINTER, WINFUNCTYPE, GetLastError, Structure, c_ulong, c_ushort, c_ubyte, c_int, c_long, c_void_p, c_size_t, c_wchar
from ctypes import WinDLL, POINTER, WINFUNCTYPE, GetLastError, Structure, c_ulong, c_ushort, c_ubyte, c_int, c_long, c_void_p, c_size_t, c_wchar, byref
from ctypes.wintypes import HWND, DWORD, WPARAM, LPARAM, HDC, HMONITOR, HMODULE, SHORT, ATOM, RECT, POINT
from ctypes.wintypes import HANDLE, LPCWSTR, UINT, INT, BOOL, HGDIOBJ, LONG, LPVOID, HBITMAP, LPCSTR, LPWSTR, HWINSTA, HINSTANCE
#imported from this module but not used here:
Expand Down Expand Up @@ -219,6 +219,13 @@ def _callback(monitor, dc, rect, data):
_EnumDisplayMonitors(0, 0, callback, 0)
return results

def GetIntSystemParametersInfo(key):
rv = INT()
r = SystemParametersInfoA(key, 0, byref(rv), 0)
if r==0:
return None
return rv.value


WNDPROC = WINFUNCTYPE(LRESULT, HWND, UINT, WPARAM, LPARAM)

Expand Down
27 changes: 23 additions & 4 deletions src/xpra/platform/win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
UnhookWindowsHookEx, CallNextHookEx, SetWindowsHookExA,
SetConsoleCtrlHandler,
GetDeviceCaps,
GetIntSystemParametersInfo,
user32)
from xpra.util import AdHocStruct, csv, envint, envbool
from xpra.os_util import PYTHON2, PYTHON3

CONSOLE_EVENT_LISTENER = envbool("XPRA_CONSOLE_EVENT_LISTENER", True)
USE_NATIVE_TRAY = envbool("XPRA_USE_NATIVE_TRAY", True)
SCREENSAVER_LISTENER_POLL_DELAY = envint("XPRA_SCREENSAVER_LISTENER_POLL_DELAY", 10)


from ctypes import WinDLL, CFUNCTYPE, c_int, POINTER, Structure, byref, sizeof
Expand Down Expand Up @@ -631,10 +633,9 @@ def get_ydpi():


def _add_SPI(info, constant, name, convert, default=None):
SystemParametersInfo = user32.SystemParametersInfoA
i = ctypes.c_uint32()
if SystemParametersInfo(constant, 0, byref(i), 0):
info[name] = convert(i.value)
v = GetIntSystemParametersInfo(constant)
if v is not None:
info[name] = convert(v)
elif default is not None:
info[name] = default

Expand Down Expand Up @@ -900,6 +901,20 @@ def __init__(self, client, _opts):
self.client = client
self._kh_warning = False
self._console_handler_added = False
self._screensaver_state = False
self._screensaver_timer = 0
if SCREENSAVER_LISTENER_POLL_DELAY>0:
def log_screensaver():
v = bool(GetIntSystemParametersInfo(win32con.SPI_GETSCREENSAVERRUNNING))
log("SPI_GETSCREENSAVERRUNNING=%s", v)
if self._screensaver_state!=v:
self._screensaver_state = v
if v:
self.client.suspend()
else:
self.client.resume()
return True
self._screensaver_timer = client.timeout_add(SCREENSAVER_LISTENER_POLL_DELAY*1000, log_screensaver)
if CONSOLE_EVENT_LISTENER:
self._console_handler_added = self.setup_console_event_listener(True)
from xpra.platform.win32.win32_events import get_win32_event_listener
Expand Down Expand Up @@ -938,6 +953,10 @@ def cleanup(self):
if khid:
self.keyboard_hook_id = None
UnhookWindowsHookEx(khid)
sst = self._screensaver_timer
if sst:
self._screensaver_timer = 0
self.client.source_remove(sst)
log("ClientExtras.cleanup() ended")
#self.client = None

Expand Down
7 changes: 1 addition & 6 deletions src/xpra/platform/win32/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ctypes
from ctypes.wintypes import HANDLE

from xpra.platform.win32.common import GetKeyState, GetKeyboardLayoutList, GetKeyboardLayout, SystemParametersInfoA
from xpra.platform.win32.common import GetKeyState, GetKeyboardLayoutList, GetKeyboardLayout, GetIntSystemParametersInfo
from xpra.platform.win32 import constants as win32con
from xpra.platform.keyboard_base import KeyboardBase
from xpra.keyboard.layouts import WIN32_LAYOUTS
Expand All @@ -28,11 +28,6 @@ def _GetKeyboardLayoutList():
layouts.append(int(handle_list[i]))
return layouts

def GetIntSystemParametersInfo(key):
rv = ctypes.wintypes.INT()
SystemParametersInfoA(key, 0, ctypes.byref(rv), 0)
return rv.value


EMULATE_ALTGR = envbool("XPRA_EMULATE_ALTGR", True)
EMULATE_ALTGR_CONTROL_KEY_DELAY = envint("XPRA_EMULATE_ALTGR_CONTROL_KEY_DELAY", 50)
Expand Down

0 comments on commit c148e68

Please sign in to comment.