2001-11-19 00:33:36 +00:00
|
|
|
#include "CMSWindowsScreen.h"
|
2002-06-23 21:53:31 +00:00
|
|
|
#include "CMSWindowsScreenSaver.h"
|
2001-11-19 00:33:36 +00:00
|
|
|
#include "CThread.h"
|
|
|
|
#include "CLock.h"
|
|
|
|
#include "TMethodJob.h"
|
|
|
|
#include "CLog.h"
|
|
|
|
#include "CString.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include <cstring>
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-06-19 17:03:29 +00:00
|
|
|
//
|
|
|
|
// add backwards compatible multihead support (suppress bogus warning)
|
|
|
|
//
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4706) // assignment within conditional
|
|
|
|
#define COMPILE_MULTIMON_STUBS
|
|
|
|
#include <multimon.h>
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
2001-11-19 00:33:36 +00:00
|
|
|
//
|
|
|
|
// CMSWindowsScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
HINSTANCE CMSWindowsScreen::s_instance = NULL;
|
2001-11-25 18:32:41 +00:00
|
|
|
CMSWindowsScreen* CMSWindowsScreen::s_screen = NULL;
|
2001-11-19 00:33:36 +00:00
|
|
|
|
|
|
|
CMSWindowsScreen::CMSWindowsScreen() :
|
2002-06-10 22:06:45 +00:00
|
|
|
m_class(0),
|
|
|
|
m_cursor(NULL),
|
2002-06-19 17:03:29 +00:00
|
|
|
m_x(0), m_y(0),
|
2002-06-10 22:06:45 +00:00
|
|
|
m_w(0), m_h(0),
|
2002-06-23 21:53:31 +00:00
|
|
|
m_thread(0),
|
|
|
|
m_screenSaver(NULL)
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
2001-11-25 18:32:41 +00:00
|
|
|
assert(s_screen == NULL);
|
|
|
|
s_screen = this;
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMSWindowsScreen::~CMSWindowsScreen()
|
|
|
|
{
|
|
|
|
assert(m_class == 0);
|
2001-11-25 18:32:41 +00:00
|
|
|
s_screen = NULL;
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CMSWindowsScreen::init(HINSTANCE instance)
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
s_instance = instance;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::doRun()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
2002-05-22 17:08:37 +00:00
|
|
|
// save thread id for posting quit message
|
2001-11-19 00:33:36 +00:00
|
|
|
m_thread = GetCurrentThreadId();
|
2002-05-22 17:08:37 +00:00
|
|
|
|
|
|
|
// event loop
|
2001-11-19 00:33:36 +00:00
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
MSG msg;
|
|
|
|
getEvent(&msg);
|
|
|
|
|
|
|
|
// handle quit message
|
|
|
|
if (msg.message == WM_QUIT) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// dispatch message
|
2001-11-25 18:32:41 +00:00
|
|
|
if (!onPreTranslate(&msg)) {
|
2001-11-19 00:33:36 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::doStop()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
PostThreadMessage(m_thread, WM_QUIT, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::openDisplay()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
assert(s_instance != NULL);
|
|
|
|
assert(m_class == 0);
|
|
|
|
|
2002-07-11 18:58:49 +00:00
|
|
|
// create the transparent cursor
|
|
|
|
createBlankCursor();
|
2001-11-19 00:33:36 +00:00
|
|
|
|
|
|
|
// register a window class
|
|
|
|
WNDCLASSEX classInfo;
|
|
|
|
classInfo.cbSize = sizeof(classInfo);
|
|
|
|
classInfo.style = CS_DBLCLKS | CS_NOCLOSE;
|
|
|
|
classInfo.lpfnWndProc = &CMSWindowsScreen::wndProc;
|
|
|
|
classInfo.cbClsExtra = 0;
|
|
|
|
classInfo.cbWndExtra = 0;
|
|
|
|
classInfo.hInstance = s_instance;
|
|
|
|
classInfo.hIcon = NULL;
|
|
|
|
classInfo.hCursor = m_cursor;
|
|
|
|
classInfo.hbrBackground = NULL;
|
|
|
|
classInfo.lpszMenuName = NULL;
|
|
|
|
classInfo.lpszClassName = "Synergy";
|
|
|
|
classInfo.hIconSm = NULL;
|
2002-07-11 18:58:49 +00:00
|
|
|
m_class = RegisterClassEx(&classInfo);
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-06-19 17:03:29 +00:00
|
|
|
// get screen shape
|
|
|
|
updateScreenShape();
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-06-23 21:53:31 +00:00
|
|
|
// initialize the screen saver
|
|
|
|
m_screenSaver = new CMSWindowsScreenSaver();
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::closeDisplay()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
2002-06-23 21:53:31 +00:00
|
|
|
assert(s_instance != NULL);
|
|
|
|
|
|
|
|
// done with screen saver
|
|
|
|
delete m_screenSaver;
|
|
|
|
m_screenSaver = NULL;
|
2001-11-19 00:33:36 +00:00
|
|
|
|
|
|
|
// unregister the window class
|
2002-07-11 18:58:49 +00:00
|
|
|
if (m_class != 0) {
|
|
|
|
UnregisterClass((LPCTSTR)m_class, s_instance);
|
|
|
|
m_class = 0;
|
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
|
|
|
// delete resources
|
2002-07-11 18:58:49 +00:00
|
|
|
if (m_cursor != NULL) {
|
|
|
|
DestroyCursor(m_cursor);
|
|
|
|
m_cursor = NULL;
|
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
|
|
|
log((CLOG_DEBUG "closed display"));
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
HINSTANCE
|
|
|
|
CMSWindowsScreen::getInstance()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
ATOM
|
|
|
|
CMSWindowsScreen::getClass() const
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
return m_class;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-19 17:03:29 +00:00
|
|
|
CMSWindowsScreen::updateScreenShape()
|
2002-05-24 17:54:28 +00:00
|
|
|
{
|
2002-06-19 17:03:29 +00:00
|
|
|
m_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
m_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
|
|
|
m_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
m_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
|
|
|
log((CLOG_INFO "screen shape: %d,%d %dx%d", m_x, m_y, m_w, m_h));
|
2002-05-24 17:54:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-07-11 18:58:49 +00:00
|
|
|
CMSWindowsScreen::getScreenShape(SInt32& x, SInt32& y,
|
|
|
|
SInt32& w, SInt32& h) const
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
assert(m_class != 0);
|
|
|
|
|
2002-06-19 17:03:29 +00:00
|
|
|
x = m_x;
|
|
|
|
y = m_y;
|
|
|
|
w = m_w;
|
|
|
|
h = m_h;
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
|
2002-07-11 18:58:49 +00:00
|
|
|
void
|
|
|
|
CMSWindowsScreen::getCursorPos(SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
POINT pos;
|
|
|
|
GetCursorPos(&pos);
|
|
|
|
x = pos.x;
|
|
|
|
y = pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CMSWindowsScreen::getCursorCenter(SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
x = GetSystemMetrics(SM_CXSCREEN) >> 1;
|
|
|
|
y = GetSystemMetrics(SM_CYSCREEN) >> 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HCURSOR
|
|
|
|
CMSWindowsScreen::getBlankCursor() const
|
|
|
|
{
|
|
|
|
return m_cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CMSWindowsScreen::createBlankCursor()
|
|
|
|
{
|
|
|
|
// create a transparent cursor
|
|
|
|
int cw = GetSystemMetrics(SM_CXCURSOR);
|
|
|
|
int ch = GetSystemMetrics(SM_CYCURSOR);
|
|
|
|
UInt8* cursorAND = new UInt8[ch * ((cw + 31) >> 2)];
|
|
|
|
UInt8* cursorXOR = new UInt8[ch * ((cw + 31) >> 2)];
|
|
|
|
memset(cursorAND, 0xff, ch * ((cw + 31) >> 2));
|
|
|
|
memset(cursorXOR, 0x00, ch * ((cw + 31) >> 2));
|
|
|
|
m_cursor = CreateCursor(s_instance, 0, 0, cw, ch, cursorAND, cursorXOR);
|
|
|
|
delete[] cursorXOR;
|
|
|
|
delete[] cursorAND;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
HDESK
|
|
|
|
CMSWindowsScreen::openInputDesktop() const
|
2002-06-08 21:48:00 +00:00
|
|
|
{
|
|
|
|
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
|
|
|
DESKTOP_CREATEWINDOW |
|
|
|
|
DESKTOP_HOOKCONTROL |
|
|
|
|
GENERIC_WRITE);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
2002-06-17 13:31:21 +00:00
|
|
|
CMSWindowsScreen::getDesktopName(HDESK desk) const
|
2002-06-08 21:48:00 +00:00
|
|
|
{
|
|
|
|
if (desk == NULL) {
|
|
|
|
return CString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DWORD size;
|
|
|
|
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
|
|
|
|
TCHAR* name = new TCHAR[size / sizeof(TCHAR) + 1];
|
|
|
|
GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
|
|
|
|
CString result(name);
|
|
|
|
delete[] name;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CMSWindowsScreen::isCurrentDesktop(HDESK desk) const
|
2002-06-08 21:48:00 +00:00
|
|
|
{
|
|
|
|
return CStringUtil::CaselessCmp::equal(getDesktopName(desk),
|
|
|
|
getCurrentDesktopName());
|
|
|
|
}
|
|
|
|
|
2002-06-23 21:53:31 +00:00
|
|
|
CMSWindowsScreenSaver*
|
|
|
|
CMSWindowsScreen::getScreenSaver() const
|
|
|
|
{
|
|
|
|
return m_screenSaver;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CMSWindowsScreen::getEvent(MSG* msg) const
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
// wait for an event in a cancellable way
|
2002-06-14 18:08:20 +00:00
|
|
|
CThread::waitForEvent();
|
2001-11-19 00:33:36 +00:00
|
|
|
GetMessage(msg, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
LRESULT CALLBACK
|
2002-06-17 13:31:21 +00:00
|
|
|
CMSWindowsScreen::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
2001-11-25 18:32:41 +00:00
|
|
|
assert(s_screen != NULL);
|
|
|
|
return s_screen->onEvent(hwnd, msg, wParam, lParam);
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|