Add synwinhk support to synergyc

This commit is contained in:
Andrew Nelless 2017-05-09 19:24:07 +01:00
parent 54632e2ceb
commit c3530a0ff3
7 changed files with 55 additions and 21 deletions

View File

@ -352,7 +352,7 @@ void
MSWindowsDesks::queryHookLibrary(HINSTANCE hookLibrary) MSWindowsDesks::queryHookLibrary(HINSTANCE hookLibrary)
{ {
// look up functions // look up functions
if (m_isPrimary && !m_noHooks) { if (!m_noHooks) {
m_install = (InstallFunc)GetProcAddress(hookLibrary, "install"); m_install = (InstallFunc)GetProcAddress(hookLibrary, "install");
m_uninstall = (UninstallFunc)GetProcAddress(hookLibrary, "uninstall"); m_uninstall = (UninstallFunc)GetProcAddress(hookLibrary, "uninstall");
m_installScreensaver = m_installScreensaver =
@ -690,7 +690,7 @@ MSWindowsDesks::deskThread(void* vdesk)
continue; continue;
case SYNERGY_MSG_SWITCH: case SYNERGY_MSG_SWITCH:
if (m_isPrimary && !m_noHooks) { if (!m_noHooks) {
m_uninstall(); m_uninstall();
if (m_screensaverNotify) { if (m_screensaverNotify) {
m_uninstallScreensaver(); m_uninstallScreensaver();

View File

@ -43,7 +43,7 @@ MSWindowsHook::~MSWindowsHook()
} }
void void
MSWindowsHook::loadLibrary() MSWindowsHook::loadLibrary(BOOL isPrimary)
{ {
// load library // load library
m_instance = LoadLibrary(g_name); m_instance = LoadLibrary(g_name);
@ -69,7 +69,7 @@ MSWindowsHook::loadLibrary()
} }
// initialize library // initialize library
if (init(GetCurrentThreadId()) == 0) { if (init(GetCurrentThreadId(), isPrimary) == 0) {
LOG((CLOG_ERR "failed to init %s.dll, another program may be using it", g_name)); LOG((CLOG_ERR "failed to init %s.dll, another program may be using it", g_name));
LOG((CLOG_INFO "restarting your computer may solve this error")); LOG((CLOG_INFO "restarting your computer may solve this error"));
throw XScreenOpenFailure(); throw XScreenOpenFailure();
@ -83,12 +83,12 @@ MSWindowsHook::getInstance() const
} }
int int
MSWindowsHook::init(DWORD threadID) MSWindowsHook::init(DWORD threadID, BOOL isPrimary)
{ {
if (m_initFunc == NULL) { if (m_initFunc == NULL) {
return NULL; return NULL;
} }
return m_initFunc(threadID); return m_initFunc(threadID, isPrimary);
} }
int int

View File

@ -30,9 +30,9 @@ public:
MSWindowsHook(); MSWindowsHook();
virtual ~MSWindowsHook(); virtual ~MSWindowsHook();
void loadLibrary(); void loadLibrary(BOOL isPrimary);
HINSTANCE getInstance() const; HINSTANCE getInstance() const;
int init(DWORD threadID); int init(DWORD threadID, BOOL isPrimary);
int cleanup(); int cleanup();
void setSides(UInt32 sides); void setSides(UInt32 sides);
void setZone(SInt32 x, SInt32 y, SInt32 w, SInt32 h, SInt32 jumpZoneSize); void setZone(SInt32 x, SInt32 y, SInt32 w, SInt32 h, SInt32 jumpZoneSize);

View File

@ -128,8 +128,8 @@ MSWindowsScreen::MSWindowsScreen(
s_screen = this; s_screen = this;
try { try {
if (m_isPrimary && !m_noHooks) { if (!m_noHooks) {
m_hook.loadLibrary(); m_hook.loadLibrary(m_isPrimary);
} }
m_screensaver = new MSWindowsScreenSaver(); m_screensaver = new MSWindowsScreenSaver();
@ -985,15 +985,16 @@ MSWindowsScreen::onPreDispatch(HWND hwnd,
if (m_isPrimary) { if (m_isPrimary) {
return onPreDispatchPrimary(hwnd, message, wParam, lParam); return onPreDispatchPrimary(hwnd, message, wParam, lParam);
} }
else {
return false; return onPreDispatchSecondary(hwnd, message, wParam, lParam);
}
} }
bool bool
MSWindowsScreen::onPreDispatchPrimary(HWND, MSWindowsScreen::onPreDispatchPrimary(HWND,
UINT message, WPARAM wParam, LPARAM lParam) UINT message, WPARAM wParam, LPARAM lParam)
{ {
LOG((CLOG_DEBUG5 "handling pre-dispatch primary")); LOG((CLOG_DEBUG1 "handling primary pre-dispatch primary"));
// handle event // handle event
switch (message) { switch (message) {
@ -1047,6 +1048,19 @@ MSWindowsScreen::onPreDispatchPrimary(HWND,
return false; return false;
} }
bool
MSWindowsScreen::onPreDispatchSecondary(HWND,
UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case SYNERGY_MSG_KEY:
case SYNERGY_MSG_MOUSE_BUTTON:
LOG((CLOG_DEBUG1 "local input detected"));
}
return false;
}
bool bool
MSWindowsScreen::onEvent(HWND, UINT msg, MSWindowsScreen::onEvent(HWND, UINT msg,
WPARAM wParam, LPARAM lParam, LRESULT* result) WPARAM wParam, LPARAM lParam, LRESULT* result)

View File

@ -151,10 +151,14 @@ private: // HACK
// the message should not be dispatched. // the message should not be dispatched.
bool onPreDispatch(HWND, UINT, WPARAM, LPARAM); bool onPreDispatch(HWND, UINT, WPARAM, LPARAM);
// handle message before it gets dispatched. returns true iff // handle primary message before it gets dispatched. returns true iff
// the message should not be dispatched. // the message should not be dispatched.
bool onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM); bool onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM);
// handle secondary message before it gets dispatched. returns true iff
// the message should not be dispatched.
bool onPreDispatchSecondary(HWND, UINT, WPARAM, LPARAM);
// handle message. returns true iff handled and optionally sets // handle message. returns true iff handled and optionally sets
// \c *result (which defaults to 0). // \c *result (which defaults to 0).
bool onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result); bool onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result);

View File

@ -120,7 +120,8 @@ static LPARAM g_deadLParam = 0;
static BYTE g_deadKeyState[256] = { 0 }; static BYTE g_deadKeyState[256] = { 0 };
static BYTE g_keyState[256] = { 0 }; static BYTE g_keyState[256] = { 0 };
static DWORD g_hookThread = 0; static DWORD g_hookThread = 0;
static bool g_fakeInput = false; static bool g_fakeServerInput = false;
static BOOL g_isPrimary = TRUE;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma data_seg() #pragma data_seg()
@ -198,7 +199,7 @@ doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
if (wParam == SYNERGY_HOOK_FAKE_INPUT_VIRTUAL_KEY && if (wParam == SYNERGY_HOOK_FAKE_INPUT_VIRTUAL_KEY &&
((lParam >> 16) & 0xffu) == SYNERGY_HOOK_FAKE_INPUT_SCANCODE) { ((lParam >> 16) & 0xffu) == SYNERGY_HOOK_FAKE_INPUT_SCANCODE) {
// update flag // update flag
g_fakeInput = ((lParam & 0x80000000u) == 0); g_fakeServerInput = ((lParam & 0x80000000u) == 0);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG, PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
0xff000000u | wParam, lParam); 0xff000000u | wParam, lParam);
@ -208,7 +209,7 @@ doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
// if we're expecting fake input then just pass the event through // if we're expecting fake input then just pass the event through
// and do not forward to the server // and do not forward to the server
if (g_fakeInput) { if (g_fakeServerInput) {
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG, PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
0xfe000000u | wParam, lParam); 0xfe000000u | wParam, lParam);
return false; return false;
@ -628,6 +629,7 @@ LRESULT CALLBACK
getMessageHook(int code, WPARAM wParam, LPARAM lParam) getMessageHook(int code, WPARAM wParam, LPARAM lParam)
{ {
if (code >= 0) { if (code >= 0) {
if (g_screenSaver) { if (g_screenSaver) {
MSG* msg = reinterpret_cast<MSG*>(lParam); MSG* msg = reinterpret_cast<MSG*>(lParam);
if (msg->message == WM_SYSCOMMAND && if (msg->message == WM_SYSCOMMAND &&
@ -671,6 +673,12 @@ keyboardLLHook(int code, WPARAM wParam, LPARAM lParam)
if (code >= 0) { if (code >= 0) {
// decode the message // decode the message
KBDLLHOOKSTRUCT* info = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam); KBDLLHOOKSTRUCT* info = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
bool const injected = (info->flags & LLKHF_INJECTED);
if (!g_isPrimary && injected) {
return CallNextHookEx (g_keyboardLL, code, wParam, lParam);
}
WPARAM wParam = info->vkCode; WPARAM wParam = info->vkCode;
LPARAM lParam = 1; // repeat code LPARAM lParam = 1; // repeat code
lParam |= (info->scanCode << 16); // scan code lParam |= (info->scanCode << 16); // scan code
@ -709,6 +717,12 @@ mouseLLHook(int code, WPARAM wParam, LPARAM lParam)
if (code >= 0) { if (code >= 0) {
// decode the message // decode the message
MSLLHOOKSTRUCT* info = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam); MSLLHOOKSTRUCT* info = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam);
bool const injected = info->flags & LLMHF_INJECTED;
if (!g_isPrimary && injected) {
return CallNextHookEx(g_mouseLL, code, wParam, lParam);
}
SInt32 x = static_cast<SInt32>(info->pt.x); SInt32 x = static_cast<SInt32>(info->pt.x);
SInt32 y = static_cast<SInt32>(info->pt.y); SInt32 y = static_cast<SInt32>(info->pt.y);
SInt32 w = static_cast<SInt16>(HIWORD(info->mouseData)); SInt32 w = static_cast<SInt16>(HIWORD(info->mouseData));
@ -871,10 +885,12 @@ void * __cdecl memcpy(void * _Dst, const void * _Src, size_t _MaxCount)
#endif #endif
int int
init(DWORD threadID) init(DWORD threadID, BOOL isPrimary)
{ {
assert(g_hinstance != NULL); assert(g_hinstance != NULL);
g_isPrimary = isPrimary;
// try to open process that last called init() to see if it's // try to open process that last called init() to see if it's
// still running or if it died without cleaning up. // still running or if it died without cleaning up.
if (g_processID != 0 && g_processID != GetCurrentProcessId()) { if (g_processID != 0 && g_processID != GetCurrentProcessId()) {
@ -950,7 +966,7 @@ install()
g_deadLParam = 0; g_deadLParam = 0;
// reset fake input flag // reset fake input flag
g_fakeInput = false; g_fakeServerInput = false;
// check for mouse wheel support // check for mouse wheel support
g_wheelSupport = getWheelSupport(); g_wheelSupport = getWheelSupport();

View File

@ -67,7 +67,7 @@ enum EHookMode {
kHOOK_RELAY_EVENTS kHOOK_RELAY_EVENTS
}; };
typedef int (*InitFunc)(DWORD targetQueueThreadID); typedef int (*InitFunc)(DWORD targetQueueThreadID, BOOL isPrimary);
typedef int (*CleanupFunc)(void); typedef int (*CleanupFunc)(void);
typedef EHookResult (*InstallFunc)(void); typedef EHookResult (*InstallFunc)(void);
typedef int (*UninstallFunc)(void); typedef int (*UninstallFunc)(void);
@ -77,7 +77,7 @@ typedef void (*SetSidesFunc)(UInt32);
typedef void (*SetZoneFunc)(SInt32, SInt32, SInt32, SInt32, SInt32); typedef void (*SetZoneFunc)(SInt32, SInt32, SInt32, SInt32, SInt32);
typedef void (*SetModeFunc)(int); typedef void (*SetModeFunc)(int);
CSYNERGYHOOK_API int init(DWORD); CSYNERGYHOOK_API int init(DWORD, BOOL);
CSYNERGYHOOK_API int cleanup(void); CSYNERGYHOOK_API int cleanup(void);
CSYNERGYHOOK_API EHookResult install(void); CSYNERGYHOOK_API EHookResult install(void);
CSYNERGYHOOK_API int uninstall(void); CSYNERGYHOOK_API int uninstall(void);