Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for detecting screen locking event in windows

  • Loading branch information...
commit e7491f6cf5bb8968778dd1461d461d94e3ea1140 1 parent fa83f7e
Paweł Chmielowski prefiks authored
BIN  components/oneteam.xpt
View
Binary file not shown
BIN  platform/WINNT_x86-msvc/components/oneteam.dll
View
Binary file not shown
2  src/components/CMakeLists.txt
View
@@ -89,7 +89,7 @@ ELSEIF(WIN32)
src/systray/otPr0nObserver.cpp src/systray/otSystrayBase.cpp)
SET(oneteam_extra_LIBS
- shell32.lib dnsapi.lib iphlpapi.lib ws2_32.lib ole32.lib winmm.lib)
+ shell32.lib dnsapi.lib iphlpapi.lib ws2_32.lib ole32.lib winmm.lib wtsapi32.lib)
SET(oneteam_extra_DEFS
-DOT_HAS_IDLE_WIN -DOT_HAS_SYSTRAY_WIN -DOT_HAS_DNS_WIN
3  src/components/idl/otIIdle.idl
View
@@ -1,9 +1,10 @@
#include "nsISupports.idl"
-[scriptable, uuid(fbf58533-8472-4e2c-b094-df8d23a83fb5)]
+[scriptable, uuid(62c5b706-84f1-4026-bfff-c7ed3eafa69f)]
interface otIIdleCallback : nsISupports
{
void onScreenLock();
+ void onScreenUnlock();
void onIdleTimeout(in unsigned long timeout);
void onUserActive();
};
85 src/components/src/idle/otIdleWin.cpp
View
@@ -2,6 +2,7 @@
#define _WIN32_WINNT 0x0500
#include <windows.h>
+#include <wtsapi32.h>
typedef BOOL (*GETLASTINPUTINFO)(PLASTINPUTINFO plii);
@@ -9,6 +10,13 @@ static HMODULE gUser32Handle = 0;
static GETLASTINPUTINFO gGetLastInputInfo = 0;
static PRPackedBool gInitialized;
+ATOM otIdleServiceWin::myWinClass = 0;
+HWND otIdleServiceWin::myHWND = 0;
+otIdleServiceWin *otIdleServiceWin::listeners[] = {0};
+
+#define LISTENERS_COUNT sizeof(listeners)/sizeof(listeners[0])
+
+
NS_IMPL_ISUPPORTS1(otIdleServiceWin, otIIdleService)
otIdleServiceWin::otIdleServiceWin()
@@ -17,6 +25,9 @@ otIdleServiceWin::otIdleServiceWin()
otIdleServiceWin::~otIdleServiceWin()
{
+ for (int i = 0; i < LISTENERS_COUNT; i++)
+ if (listeners[i] == this)
+ listeners[i] = NULL;
}
NS_IMETHODIMP
@@ -28,6 +39,17 @@ otIdleServiceWin::Init(otIIdleCallback *callback)
if (gInitialized && !gGetLastInputInfo)
return NS_ERROR_FAILURE;
+ int emptySlot = false;
+
+ for (int i = 0; i < LISTENERS_COUNT; i++)
+ if (listeners[i] == NULL) {
+ emptySlot = true;
+ listeners[i] = this;
+ GetHWND();
+ }
+
+ if (!emptySlot)
+ return NS_ERROR_FAILURE;
if (!gGetLastInputInfo) {
gInitialized = PR_TRUE;
@@ -44,7 +66,6 @@ otIdleServiceWin::Init(otIIdleCallback *callback)
return otIdleServiceBase::Init(callback);
}
-
PRUint32
otIdleServiceWin::GetCurrentIdleTime()
{
@@ -58,3 +79,65 @@ otIdleServiceWin::GetCurrentIdleTime()
return 0;
}
+
+LRESULT CALLBACK
+otIdleServiceWin::WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg) {
+ case WM_WTSSESSION_CHANGE:
+ if (wParam == WTS_SESSION_LOCK) {
+ for (int i = 0; i < LISTENERS_COUNT; i++)
+ if (listeners[i] != NULL)
+ listeners[i]->mCallback->OnScreenLock();
+ } else if (wParam == WTS_SESSION_UNLOCK)
+ for (int i = 0; i < LISTENERS_COUNT; i++)
+ if (listeners[i] != NULL)
+ listeners[i]->mCallback->OnScreenUnlock();
+ return FALSE;
+ }
+
+ return ::CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
+}
+
+HWND
+otIdleServiceWin::GetHWND()
+{
+ HINSTANCE hInst;
+ WNDCLASS wc;
+
+ if (myHWND)
+ return myHWND;
+
+ hInst = GetModuleHandle(NULL);
+
+ memset(&wc, 0, sizeof(wc));
+ wc.style = CS_NOCLOSE | CS_GLOBALCLASS;
+ wc.lpfnWndProc = WinProc;
+ wc.hInstance = hInst;
+ wc.lpszClassName = TEXT("otIdleHandlerClass");
+ myWinClass = RegisterClass(&wc);
+
+ if (!myWinClass)
+ return NULL;
+
+ myHWND = CreateWindow((LPCSTR)myWinClass, TEXT(""),
+ WS_MINIMIZE, 0, 0, 0, 0,
+ GetDesktopWindow(), NULL, hInst, NULL);
+
+ if (!myHWND)
+ UnregisterClass((LPCSTR)myWinClass, hInst);
+
+ WTSRegisterSessionNotification(myHWND, NOTIFY_FOR_THIS_SESSION);
+
+ return myHWND;
+}
+
+void
+otIdleServiceWin::FreeHWND()
+{
+ if (!myHWND)
+ return;
+
+ DestroyWindow(myHWND);
+ UnregisterClass((LPCSTR)myWinClass, GetModuleHandle(NULL));
+}
11 src/components/src/idle/otIdleWin.h
View
@@ -1,8 +1,10 @@
+
#ifndef _otIDLEWIN_H_
#define _otIDLEWIN_H_
#include "nsCOMPtr.h"
#include "otIdleBase.h"
+#include <windows.h>
class otIdleServiceWin : public otIdleServiceBase
{
@@ -16,6 +18,15 @@ class otIdleServiceWin : public otIdleServiceBase
NS_IMETHOD Init(otIIdleCallback *callback);
PRUint32 GetCurrentIdleTime();
+
+ static LRESULT CALLBACK
+ WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+ static HWND GetHWND();
+ static void FreeHWND();
+
+ static ATOM myWinClass;
+ static HWND myHWND;
+ static otIdleServiceWin *listeners[16];
};
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.