From 9d8f3a79b098b969aad7e5f05ba9217e0d480db3 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 17 Dec 2017 04:50:04 +1100 Subject: [PATCH] [host] detect switch user event and wait instead of terminating Fixes #22 --- host/Service.cpp | 8 ++++++++ host/Service.h | 1 + 2 files changed, 9 insertions(+) diff --git a/host/Service.cpp b/host/Service.cpp index c2750c3c..383e2a22 100644 --- a/host/Service.cpp +++ b/host/Service.cpp @@ -46,6 +46,7 @@ Service::Service() : m_cursorData(NULL), m_shapePending(false) { + m_consoleSessionID = WTSGetActiveConsoleSessionId(); m_ivshmem = IVSHMEM::Get(); } @@ -233,6 +234,13 @@ bool Service::Process() case GRAB_STATUS_REINIT: DEBUG_INFO("ReInitialize Requested"); + if(WTSGetActiveConsoleSessionId() != m_consoleSessionID) + { + DEBUG_INFO("User switch detected, waiting to regain control"); + while (WTSGetActiveConsoleSessionId() != m_consoleSessionID) + Sleep(100); + } + if (!m_capture->ReInitialize() || !InitPointers()) { DEBUG_ERROR("ReInitialize Failed"); diff --git a/host/Service.h b/host/Service.h index aeb81260..3c77ed03 100644 --- a/host/Service.h +++ b/host/Service.h @@ -49,6 +49,7 @@ private: ~Service(); bool m_initialized; + DWORD m_consoleSessionID; uint8_t * m_memory; IVSHMEM * m_ivshmem; HANDLE m_timer;