Restored lost files and changes in version 1.3.1 to depot.

This commit is contained in:
crs
2007-06-17 11:19:18 +00:00
parent 73acb7860d
commit 52ae656411
199 changed files with 27622 additions and 13726 deletions

View File

@@ -122,7 +122,7 @@ CArch::CArch(ARCH_ARGS* args)
m_sleep = new ARCH_SLEEP;
m_string = new ARCH_STRING;
m_time = new ARCH_TIME;
m_console = new ARCH_CONSOLE;
m_console = new ARCH_CONSOLE(args);
m_daemon = new ARCH_DAEMON;
m_taskbar = new ARCH_TASKBAR(args);
@@ -170,6 +170,12 @@ CArch::closeConsole()
m_console->closeConsole();
}
void
CArch::showConsole(bool showIfEmpty)
{
m_console->showConsole(showIfEmpty);
}
void
CArch::writeConsole(const char* str)
{
@@ -254,6 +260,12 @@ CArch::closeLog()
m_log->closeLog();
}
void
CArch::showLog(bool showIfEmpty)
{
m_log->showLog(showIfEmpty);
}
void
CArch::writeLog(ELevel level, const char* msg)
{
@@ -488,6 +500,12 @@ CArch::setNoDelayOnSocket(CArchSocket s, bool noDelay)
return m_net->setNoDelayOnSocket(s, noDelay);
}
bool
CArch::setReuseAddrOnSocket(CArchSocket s, bool reuse)
{
return m_net->setReuseAddrOnSocket(s, reuse);
}
std::string
CArch::getHostName()
{

View File

@@ -74,6 +74,7 @@ public:
// IArchConsole overrides
virtual void openConsole(const char*);
virtual void closeConsole();
virtual void showConsole(bool showIfEmpty);
virtual void writeConsole(const char*);
virtual const char* getNewlineForConsole();
@@ -99,6 +100,7 @@ public:
// IArchLog overrides
virtual void openLog(const char*);
virtual void closeLog();
virtual void showLog(bool showIfEmpty);
virtual void writeLog(ELevel, const char*);
// IArchMultithread overrides
@@ -143,6 +145,7 @@ public:
const void* buf, size_t len);
virtual void throwErrorOnSocket(CArchSocket);
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
virtual bool setReuseAddrOnSocket(CArchSocket, bool reuse);
virtual std::string getHostName();
virtual CArchNetAddress newAnyAddr(EAddressFamily);
virtual CArchNetAddress copyAddr(CArchNetAddress);

View File

@@ -19,7 +19,7 @@
// CArchConsoleUnix
//
CArchConsoleUnix::CArchConsoleUnix()
CArchConsoleUnix::CArchConsoleUnix(void*)
{
// do nothing
}
@@ -41,6 +41,12 @@ CArchConsoleUnix::closeConsole()
// do nothing
}
void
CArchConsoleUnix::showConsole(bool)
{
// do nothing
}
void
CArchConsoleUnix::writeConsole(const char* str)
{

View File

@@ -22,12 +22,13 @@
//! Unix implementation of IArchConsole
class CArchConsoleUnix : public IArchConsole {
public:
CArchConsoleUnix();
CArchConsoleUnix(void*);
virtual ~CArchConsoleUnix();
// IArchConsole overrides
virtual void openConsole(const char* title);
virtual void closeConsole();
virtual void showConsole(bool);
virtual void writeConsole(const char*);
virtual const char* getNewlineForConsole();
};

View File

@@ -15,90 +15,100 @@
#include "CArchConsoleWindows.h"
#include "IArchMultithread.h"
#include "CArch.h"
#include <cstdio>
#include "CArchMiscWindows.h"
#include <richedit.h>
#define SYNERGY_MSG_CONSOLE_OPEN WM_APP + 0x0021
#define SYNERGY_MSG_CONSOLE_CLOSE WM_APP + 0x0022
#define SYNERGY_MSG_CONSOLE_SHOW WM_APP + 0x0023
#define SYNERGY_MSG_CONSOLE_WRITE WM_APP + 0x0024
#define SYNERGY_MSG_CONSOLE_CLEAR WM_APP + 0x0025
//
// CArchConsoleWindows
//
CArchThread CArchConsoleWindows::s_thread = 0;
CArchConsoleWindows* CArchConsoleWindows::s_instance = NULL;
HINSTANCE CArchConsoleWindows::s_appInstance = NULL;
CArchConsoleWindows::CArchConsoleWindows() :
m_output(NULL)
CArchConsoleWindows::CArchConsoleWindows(void* appInstance) :
m_show(false),
m_maxLines(1000),
m_numCharacters(0),
m_maxCharacters(65536)
{
s_thread = ARCH->newCurrentThread();
// save the singleton instance
s_instance = this;
m_mutex = ARCH->newMutex();
// save app instance
s_appInstance = reinterpret_cast<HINSTANCE>(appInstance);
// we need a mutex
m_mutex = ARCH->newMutex();
// and a condition variable which uses the above mutex
m_ready = false;
m_condVar = ARCH->newCondVar();
// we're going to want to get a result from the thread we're
// about to create to know if it initialized successfully.
// so we lock the condition variable.
ARCH->lockMutex(m_mutex);
// open a window and run an event loop in a separate thread.
// this has to happen in a separate thread because if we
// create a window on the current desktop with the current
// thread then the current thread won't be able to switch
// desktops if it needs to.
m_thread = ARCH->newThread(&CArchConsoleWindows::threadEntry, this);
// wait for child thread
while (!m_ready) {
ARCH->waitCondVar(m_condVar, m_mutex, -1.0);
}
// ready
ARCH->unlockMutex(m_mutex);
// dummy write to stderr to create locks in stdio from the main
// thread. if we open the console from another thread then we
// can deadlock in stdio when trying to write from a 3rd thread.
// writes to stderr without a console don't go anywhere so the
// user won't notice this.
fprintf(stderr, "\n");
}
CArchConsoleWindows::~CArchConsoleWindows()
{
if (m_thread != NULL) {
PostMessage(m_hwnd, WM_QUIT, 0, 0);
ARCH->wait(m_thread, -1.0);
ARCH->closeThread(m_thread);
}
ARCH->closeCondVar(m_condVar);
ARCH->closeMutex(m_mutex);
ARCH->closeThread(s_thread);
s_instance = NULL;
}
void
CArchConsoleWindows::openConsole(const char* title)
{
ARCH->lockMutex(m_mutex);
if (m_output == NULL) {
if (AllocConsole()) {
// get console output handle
m_output = GetStdHandle(STD_ERROR_HANDLE);
// set console title
if (title != NULL) {
SetConsoleTitle(title);
}
// prep console. windows 95 and its ilk have braindead
// consoles that can't even resize independently of the
// buffer size. use a 25 line buffer for those systems.
OSVERSIONINFO osInfo;
COORD size = { 80, 1000 };
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
if (GetVersionEx(&osInfo) &&
osInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
size.Y = 25;
SetConsoleScreenBufferSize(m_output, size);
SetConsoleTextAttribute(m_output,
FOREGROUND_RED |
FOREGROUND_GREEN |
FOREGROUND_BLUE);
// catch console signals
SetConsoleCtrlHandler(&CArchConsoleWindows::signalHandler, TRUE);
// reopen stderr to point at console
freopen("con", "w", stderr);
}
}
ARCH->unlockMutex(m_mutex);
SetWindowText(m_frame, title);
SendMessage(m_frame, SYNERGY_MSG_CONSOLE_OPEN, 0, 0);
}
void
CArchConsoleWindows::closeConsole()
{
ARCH->lockMutex(m_mutex);
if (m_output != NULL) {
if (FreeConsole()) {
m_output = NULL;
}
}
ARCH->unlockMutex(m_mutex);
SendMessage(m_frame, SYNERGY_MSG_CONSOLE_CLOSE, 0, 0);
SendMessage(m_frame, SYNERGY_MSG_CONSOLE_CLEAR, 0, 0);
}
void
CArchConsoleWindows::showConsole(bool showIfEmpty)
{
SendMessage(m_frame, SYNERGY_MSG_CONSOLE_SHOW, showIfEmpty ? 1 : 0, 0);
}
void
CArchConsoleWindows::writeConsole(const char* str)
{
fprintf(stderr, "%s", str);
SendMessage(m_frame, SYNERGY_MSG_CONSOLE_WRITE,
reinterpret_cast<WPARAM>(str), 0);
}
const char*
@@ -107,21 +117,322 @@ CArchConsoleWindows::getNewlineForConsole()
return "\r\n";
}
BOOL WINAPI
CArchConsoleWindows::signalHandler(DWORD ctrlType)
void
CArchConsoleWindows::clearBuffer()
{
// terminate app and skip remaining handlers
switch (ctrlType) {
case CTRL_C_EVENT:
ARCH->raiseSignal(CArch::kINTERRUPT);
return TRUE;
m_buffer.clear();
m_numCharacters = 0;
SetWindowText(m_hwnd, "");
}
case CTRL_BREAK_EVENT:
ARCH->raiseSignal(CArch::kTERMINATE);
return TRUE;
void
CArchConsoleWindows::appendBuffer(const char* msg)
{
bool wasEmpty = m_buffer.empty();
// get current selection
CHARRANGE selection;
SendMessage(m_hwnd, EM_EXGETSEL, 0, reinterpret_cast<LPARAM>(&selection));
// remove tail of buffer
size_t removedCharacters = 0;
while (m_buffer.size() >= m_maxLines) {
removedCharacters += m_buffer.front().size();
m_buffer.pop_front();
}
// remove lines from top of control
if (removedCharacters > 0) {
CHARRANGE range;
range.cpMin = 0;
range.cpMax = static_cast<LONG>(removedCharacters);
SendMessage(m_hwnd, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&range));
SendMessage(m_hwnd, EM_REPLACESEL, FALSE, reinterpret_cast<LPARAM>(""));
// adjust selection
if (selection.cpMin < static_cast<LONG>(removedCharacters) ||
selection.cpMax < static_cast<LONG>(removedCharacters)) {
selection.cpMin = 0;
selection.cpMax = 0;
}
else {
selection.cpMin -= static_cast<LONG>(removedCharacters);
selection.cpMax -= static_cast<LONG>(removedCharacters);
}
m_numCharacters -= removedCharacters;
}
// append message
m_buffer.push_back(msg);
size_t newNumCharacters = m_numCharacters + m_buffer.back().size();
// add line to bottom of control
if (newNumCharacters > m_maxCharacters) {
m_maxCharacters = newNumCharacters;
SendMessage(m_hwnd, EM_EXLIMITTEXT, 0, m_maxCharacters);
}
CHARRANGE range;
range.cpMin = m_numCharacters;
range.cpMax = m_numCharacters;
SendMessage(m_hwnd, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&range));
SendMessage(m_hwnd, EM_REPLACESEL, FALSE,
reinterpret_cast<LPARAM>(m_buffer.back().c_str()));
// adjust selection
bool atEnd = false;
if (selection.cpMax == static_cast<LONG>(m_numCharacters)) {
selection.cpMin = static_cast<LONG>(newNumCharacters);
selection.cpMax = static_cast<LONG>(newNumCharacters);
atEnd = true;
}
// restore the selection
SendMessage(m_hwnd, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&selection));
if (atEnd) {
SendMessage(m_hwnd, EM_SCROLLCARET, 0, 0);
}
if (wasEmpty && m_show) {
ShowWindow(m_frame, TRUE);
}
m_numCharacters = newNumCharacters;
}
void
CArchConsoleWindows::setSize(int width, int height)
{
DWORD style = GetWindowLong(m_frame, GWL_STYLE);
DWORD exStyle = GetWindowLong(m_frame, GWL_EXSTYLE);
RECT rect;
rect.left = 100;
rect.top = 100;
rect.right = rect.left + width * m_wChar;
rect.bottom = rect.top + height * m_hChar;
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
SetWindowPos(m_frame, NULL, 0, 0, rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
LRESULT
CArchConsoleWindows::wndProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CLOSE:
ShowWindow(m_frame, FALSE);
m_show = false;
return 0;
case SYNERGY_MSG_CONSOLE_OPEN:
return 0;
case SYNERGY_MSG_CONSOLE_CLOSE:
SendMessage(m_frame, WM_CLOSE, 0, 0);
m_show = false;
return 0;
case SYNERGY_MSG_CONSOLE_SHOW:
m_show = true;
if (wParam != 0 || !m_buffer.empty()) {
ShowWindow(m_frame, TRUE);
}
return 0;
case SYNERGY_MSG_CONSOLE_WRITE:
appendBuffer(reinterpret_cast<const char*>(wParam));
return 0;
case SYNERGY_MSG_CONSOLE_CLEAR:
clearBuffer();
return 0;
case WM_SIZE:
if (hwnd == m_frame) {
MoveWindow(m_hwnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
}
break;
case WM_SIZING:
if (hwnd == m_frame) {
// get window vs client area info
int wBase = 40 * m_wChar;
int hBase = 40 * m_hChar;
DWORD style = GetWindowLong(m_frame, GWL_STYLE);
DWORD exStyle = GetWindowLong(m_frame, GWL_EXSTYLE);
RECT rect;
rect.left = 100;
rect.top = 100;
rect.right = rect.left + wBase;
rect.bottom = rect.top + hBase;
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
wBase = rect.right - rect.left - wBase;
hBase = rect.bottom - rect.top - hBase;
// get closest size that's a multiple of the character size
RECT* newRect = (RECT*)lParam;
int width = (newRect->right - newRect->left - wBase) / m_wChar;
int height = (newRect->bottom - newRect->top - hBase) / m_hChar;
width = width * m_wChar + wBase;
height = height * m_hChar + hBase;
// adjust sizing rect
switch (wParam) {
case WMSZ_LEFT:
case WMSZ_TOPLEFT:
case WMSZ_BOTTOMLEFT:
newRect->left = newRect->right - width;
break;
case WMSZ_RIGHT:
case WMSZ_TOPRIGHT:
case WMSZ_BOTTOMRIGHT:
newRect->right = newRect->left + width;
break;
}
switch (wParam) {
case WMSZ_TOP:
case WMSZ_TOPLEFT:
case WMSZ_TOPRIGHT:
newRect->top = newRect->bottom - height;
break;
case WMSZ_BOTTOM:
case WMSZ_BOTTOMLEFT:
case WMSZ_BOTTOMRIGHT:
newRect->bottom = newRect->top + height;
break;
}
return TRUE;
}
break;
default:
ARCH->raiseSignal(CArch::kINTERRUPT);
return TRUE;
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK
CArchConsoleWindows::staticWndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
// forward the message
if (s_instance != NULL) {
return s_instance->wndProc(hwnd, msg, wParam, lParam);
}
else {
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
void
CArchConsoleWindows::threadMainLoop()
{
LoadLibrary("RICHED32.DLL");
// get the app icons
HICON largeIcon, smallIcon;
CArchMiscWindows::getIcons(largeIcon, smallIcon);
// register a window class
WNDCLASSEX classInfo;
classInfo.cbSize = sizeof(classInfo);
classInfo.style = 0;
classInfo.lpfnWndProc = &CArchConsoleWindows::staticWndProc;
classInfo.cbClsExtra = 0;
classInfo.cbWndExtra = sizeof(CArchConsoleWindows*);
classInfo.hInstance = s_appInstance;
classInfo.hIcon = largeIcon;
classInfo.hCursor = NULL;
classInfo.hbrBackground = NULL;
classInfo.lpszMenuName = NULL;
classInfo.lpszClassName = TEXT("SynergyConsole");
classInfo.hIconSm = smallIcon;
ATOM windowClass = RegisterClassEx(&classInfo);
// create frame window
m_frame = CreateWindowEx(0,
reinterpret_cast<LPCTSTR>(windowClass),
TEXT("Synergy Log"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
NULL,
NULL,
s_appInstance,
NULL);
// create log window
m_hwnd = CreateWindowEx(0,
"RichEdit",
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
ES_MULTILINE | ES_READONLY,
0, 0, 1, 1,
m_frame,
(HMENU)1,
s_appInstance,
NULL);
// select font and get info
HDC hdc = GetDC(m_hwnd);
HGDIOBJ oldFont = SelectObject(hdc, GetStockObject(ANSI_FIXED_FONT));
TEXTMETRIC metrics;
GetTextMetrics(hdc, &metrics);
CHARFORMAT format;
format.cbSize = sizeof(format);
format.dwMask = CFM_CHARSET | CFM_COLOR | CFM_FACE |
CFM_OFFSET | CFM_SIZE | CFM_PROTECTED |
CFM_BOLD | CFM_ITALIC |
CFM_STRIKEOUT | CFM_UNDERLINE;
format.dwEffects = 0;
format.yHeight = metrics.tmHeight;
format.yOffset = 0;
format.crTextColor = RGB(0, 0, 0);
format.bCharSet = DEFAULT_CHARSET;
format.bPitchAndFamily = FIXED_PITCH | FF_MODERN;
GetTextFace(hdc, sizeof(format.szFaceName), format.szFaceName);
SelectObject(hdc, oldFont);
ReleaseDC(m_hwnd, hdc);
// prep window
SendMessage(m_hwnd, EM_EXLIMITTEXT, 0, m_maxCharacters);
SendMessage(m_hwnd, EM_SETCHARFORMAT, 0, reinterpret_cast<LPARAM>(&format));
SendMessage(m_hwnd, EM_SETBKGNDCOLOR, 0, RGB(255, 255, 255));
m_wChar = metrics.tmAveCharWidth;
m_hChar = metrics.tmHeight + metrics.tmExternalLeading;
setSize(80, 25);
// signal ready
ARCH->lockMutex(m_mutex);
m_ready = true;
ARCH->broadcastCondVar(m_condVar);
ARCH->unlockMutex(m_mutex);
// handle failure
if (m_hwnd == NULL) {
UnregisterClass(reinterpret_cast<LPCTSTR>(windowClass), s_appInstance);
return;
}
// main loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// clean up
DestroyWindow(m_hwnd);
UnregisterClass(reinterpret_cast<LPCTSTR>(windowClass), s_appInstance);
}
void*
CArchConsoleWindows::threadEntry(void* self)
{
reinterpret_cast<CArchConsoleWindows*>(self)->threadMainLoop();
return NULL;
}

View File

@@ -19,6 +19,7 @@
#include "IArchConsole.h"
#include "IArchMultithread.h"
#include "stddeque.h"
#include <windows.h>
#define ARCH_CONSOLE CArchConsoleWindows
@@ -26,23 +27,51 @@
//! Win32 implementation of IArchConsole
class CArchConsoleWindows : public IArchConsole {
public:
CArchConsoleWindows();
CArchConsoleWindows(void*);
virtual ~CArchConsoleWindows();
// IArchConsole overrides
virtual void openConsole(const char* title);
virtual void closeConsole();
virtual void showConsole(bool showIfEmpty);
virtual void writeConsole(const char*);
virtual const char* getNewlineForConsole();
private:
static BOOL WINAPI signalHandler(DWORD);
void clearBuffer();
void appendBuffer(const char*);
void setSize(int width, int height);
LRESULT wndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK
staticWndProc(HWND, UINT, WPARAM, LPARAM);
void threadMainLoop();
static void* threadEntry(void*);
private:
static CArchThread s_thread;
typedef std::deque<std::string> MessageBuffer;
static CArchConsoleWindows* s_instance;
static HINSTANCE s_appInstance;
// multithread data
CArchMutex m_mutex;
HANDLE m_output;
CArchCond m_condVar;
bool m_ready;
CArchThread m_thread;
// child thread data
HWND m_frame;
HWND m_hwnd;
LONG m_wChar;
LONG m_hChar;
bool m_show;
// messages
size_t m_maxLines;
size_t m_maxCharacters;
size_t m_numCharacters;
MessageBuffer m_buffer;
};
#endif

View File

@@ -136,10 +136,11 @@ CArchDaemonWindows::installDaemon(const char* name,
NULL);
if (service == NULL) {
// can't create service
// FIXME -- handle ERROR_SERVICE_EXISTS
DWORD err = GetLastError();
CloseServiceHandle(mgr);
throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
if (err != ERROR_SERVICE_EXISTS) {
CloseServiceHandle(mgr);
throw XArchDaemonInstallFailed(new XArchEvalWindows(err));
}
}
// done with service and manager
@@ -148,7 +149,7 @@ CArchDaemonWindows::installDaemon(const char* name,
// open the registry key for this service
HKEY key = openNTServicesKey();
key = CArchMiscWindows::openKey(key, name);
key = CArchMiscWindows::addKey(key, name);
if (key == NULL) {
// can't open key
DWORD err = GetLastError();
@@ -165,7 +166,7 @@ CArchDaemonWindows::installDaemon(const char* name,
CArchMiscWindows::setValue(key, _T("Description"), description);
// set command line
key = CArchMiscWindows::openKey(key, _T("Parameters"));
key = CArchMiscWindows::addKey(key, _T("Parameters"));
if (key == NULL) {
// can't open key
DWORD err = GetLastError();
@@ -224,7 +225,7 @@ CArchDaemonWindows::uninstallDaemon(const char* name, bool allUsers)
}
// open the service. oddly, you must open a service to delete it.
SC_HANDLE service = OpenService(mgr, name, DELETE);
SC_HANDLE service = OpenService(mgr, name, DELETE | SERVICE_STOP);
if (service == NULL) {
DWORD err = GetLastError();
CloseServiceHandle(mgr);
@@ -234,6 +235,10 @@ CArchDaemonWindows::uninstallDaemon(const char* name, bool allUsers)
throw XArchDaemonUninstallNotInstalled(new XArchEvalWindows(err));
}
// stop the service. we don't care if we fail.
SERVICE_STATUS status;
ControlService(service, SERVICE_CONTROL_STOP, &status);
// delete the service
const bool okay = (DeleteService(service) == 0);
const DWORD err = GetLastError();
@@ -244,6 +249,10 @@ CArchDaemonWindows::uninstallDaemon(const char* name, bool allUsers)
// handle failure. ignore error if service isn't installed anymore.
if (!okay && isDaemonInstalled(name, allUsers)) {
if (err == ERROR_IO_PENDING) {
// this seems to be a spurious error
return;
}
if (err != ERROR_SERVICE_MARKED_FOR_DELETE) {
throw XArchDaemonUninstallFailed(new XArchEvalWindows(err));
}
@@ -317,7 +326,7 @@ CArchDaemonWindows::daemonize(const char* name, DaemonFunc func)
}
bool
CArchDaemonWindows::canInstallDaemon(const char* name, bool allUsers)
CArchDaemonWindows::canInstallDaemon(const char* /*name*/, bool allUsers)
{
// if not for all users then use the user's autostart registry.
// key. if windows 95 family then use windows 95 services key.
@@ -338,10 +347,10 @@ CArchDaemonWindows::canInstallDaemon(const char* name, bool allUsers)
}
CloseServiceHandle(mgr);
// check if we can open the registry key for this service
// check if we can open the registry key
HKEY key = openNTServicesKey();
key = CArchMiscWindows::openKey(key, name);
key = CArchMiscWindows::openKey(key, _T("Parameters"));
// key = CArchMiscWindows::addKey(key, name);
// key = CArchMiscWindows::addKey(key, _T("Parameters"));
CArchMiscWindows::closeKey(key);
return (key != NULL);
@@ -415,7 +424,7 @@ CArchDaemonWindows::openNTServicesKey()
NULL
};
return CArchMiscWindows::openKey(HKEY_LOCAL_MACHINE, s_keyNames);
return CArchMiscWindows::addKey(HKEY_LOCAL_MACHINE, s_keyNames);
}
HKEY
@@ -430,7 +439,7 @@ CArchDaemonWindows::open95ServicesKey()
NULL
};
return CArchMiscWindows::openKey(HKEY_LOCAL_MACHINE, s_keyNames);
return CArchMiscWindows::addKey(HKEY_LOCAL_MACHINE, s_keyNames);
}
HKEY
@@ -445,7 +454,7 @@ CArchDaemonWindows::openUserStartupKey()
NULL
};
return CArchMiscWindows::openKey(HKEY_CURRENT_USER, s_keyNames);
return CArchMiscWindows::addKey(HKEY_CURRENT_USER, s_keyNames);
}
bool

View File

@@ -41,6 +41,12 @@ CArchLogUnix::closeLog()
closelog();
}
void
CArchLogUnix::showLog(bool)
{
// do nothing
}
void
CArchLogUnix::writeLog(ELevel level, const char* msg)
{

View File

@@ -28,6 +28,7 @@ public:
// IArchLog overrides
virtual void openLog(const char* name);
virtual void closeLog();
virtual void showLog(bool);
virtual void writeLog(ELevel, const char*);
};

View File

@@ -47,6 +47,12 @@ CArchLogWindows::closeLog()
}
}
void
CArchLogWindows::showLog(bool)
{
// do nothing
}
void
CArchLogWindows::writeLog(ELevel level, const char* msg)
{

View File

@@ -31,6 +31,7 @@ public:
// IArchLog overrides
virtual void openLog(const char* name);
virtual void closeLog();
virtual void showLog(bool showIfEmpty);
virtual void writeLog(ELevel, const char*);
private:

View File

@@ -33,6 +33,8 @@ typedef DWORD EXECUTION_STATE;
CArchMiscWindows::CDialogs* CArchMiscWindows::s_dialogs = NULL;
DWORD CArchMiscWindows::s_busyState = 0;
CArchMiscWindows::STES_t CArchMiscWindows::s_stes = NULL;
HICON CArchMiscWindows::s_largeIcon = NULL;
HICON CArchMiscWindows::s_smallIcon = NULL;
void
CArchMiscWindows::init()
@@ -87,6 +89,20 @@ CArchMiscWindows::isWindowsModern()
return result;
}
void
CArchMiscWindows::setIcons(HICON largeIcon, HICON smallIcon)
{
s_largeIcon = largeIcon;
s_smallIcon = smallIcon;
}
void
CArchMiscWindows::getIcons(HICON& largeIcon, HICON& smallIcon)
{
largeIcon = s_largeIcon;
smallIcon = s_smallIcon;
}
int
CArchMiscWindows::runDaemon(RunFunc runFunc)
{
@@ -113,6 +129,30 @@ CArchMiscWindows::getDaemonQuitMessage()
HKEY
CArchMiscWindows::openKey(HKEY key, const TCHAR* keyName)
{
return openKey(key, keyName, false);
}
HKEY
CArchMiscWindows::openKey(HKEY key, const TCHAR* const* keyNames)
{
return openKey(key, keyNames, false);
}
HKEY
CArchMiscWindows::addKey(HKEY key, const TCHAR* keyName)
{
return openKey(key, keyName, true);
}
HKEY
CArchMiscWindows::addKey(HKEY key, const TCHAR* const* keyNames)
{
return openKey(key, keyNames, true);
}
HKEY
CArchMiscWindows::openKey(HKEY key, const TCHAR* keyName, bool create)
{
// ignore if parent is NULL
if (key == NULL) {
@@ -123,7 +163,7 @@ CArchMiscWindows::openKey(HKEY key, const TCHAR* keyName)
HKEY newKey;
LONG result = RegOpenKeyEx(key, keyName, 0,
KEY_WRITE | KEY_QUERY_VALUE, &newKey);
if (result != ERROR_SUCCESS) {
if (result != ERROR_SUCCESS && create) {
DWORD disp;
result = RegCreateKeyEx(key, keyName, 0, TEXT(""),
0, KEY_WRITE | KEY_QUERY_VALUE,
@@ -140,11 +180,11 @@ CArchMiscWindows::openKey(HKEY key, const TCHAR* keyName)
}
HKEY
CArchMiscWindows::openKey(HKEY key, const TCHAR* const* keyNames)
CArchMiscWindows::openKey(HKEY key, const TCHAR* const* keyNames, bool create)
{
for (size_t i = 0; key != NULL && keyNames[i] != NULL; ++i) {
// open next key
key = openKey(key, keyNames[i]);
key = openKey(key, keyNames[i], create);
}
return key;
}

View File

@@ -56,6 +56,18 @@ public:
*/
static bool isWindowsModern();
//! Set the application icons
/*!
Set the application icons.
*/
static void setIcons(HICON largeIcon, HICON smallIcon);
//! Get the application icons
/*!
Get the application icons.
*/
static void getIcons(HICON& largeIcon, HICON& smallIcon);
//! Run the daemon
/*!
Delegates to CArchDaemonWindows.
@@ -86,6 +98,12 @@ public:
//! Open and return a registry key, closing the parent key
static HKEY openKey(HKEY parent, const TCHAR* const* keyPath);
//! Open/create and return a registry key, closing the parent key
static HKEY addKey(HKEY parent, const TCHAR* child);
//! Open/create and return a registry key, closing the parent key
static HKEY addKey(HKEY parent, const TCHAR* const* keyPath);
//! Close a key
static void closeKey(HKEY);
@@ -144,6 +162,13 @@ public:
static void removeBusyState(DWORD busyModes);
private:
//! Open and return a registry key, closing the parent key
static HKEY openKey(HKEY parent, const TCHAR* child, bool create);
//! Open and return a registry key, closing the parent key
static HKEY openKey(HKEY parent, const TCHAR* const* keyPath,
bool create);
//! Read a string value from the registry
static std::string readBinaryOrString(HKEY, const TCHAR* name, DWORD type);
@@ -159,6 +184,8 @@ private:
static CDialogs* s_dialogs;
static DWORD s_busyState;
static STES_t s_stes;
static HICON s_largeIcon;
static HICON s_smallIcon;
};
#endif

View File

@@ -49,6 +49,7 @@ setSignalSet(sigset_t* sigset)
sigaddset(sigset, SIGHUP);
sigaddset(sigset, SIGINT);
sigaddset(sigset, SIGTERM);
sigaddset(sigset, SIGUSR2);
}
//
@@ -771,7 +772,7 @@ CArchMultithreadPosix::threadSignalHandler(void*)
for (;;) {
// wait
#if HAVE_POSIX_SIGWAIT
int signal;
int signal = 0;
sigwait(&sigset, &signal);
#else
sigwait(&sigset);
@@ -791,6 +792,10 @@ CArchMultithreadPosix::threadSignalHandler(void*)
ARCH->raiseSignal(kHANGUP);
break;
case SIGUSR2:
ARCH->raiseSignal(kUSER);
break;
default:
// ignore
break;

View File

@@ -31,9 +31,6 @@
#if HAVE_POLL
# include <poll.h>
# if HAVE_ALLOCA_H
# include <alloca.h>
# endif
#else
# if HAVE_SYS_SELECT_H
# include <sys/select.h>
@@ -47,13 +44,6 @@
# include <stdio.h>
#endif
#if HAVE_ALLOCA_H
# define freea(x_)
#else
# define alloca(x_) malloc(x_)
# define freea(x_) free(x_)
#endif
static const int s_family[] = {
PF_UNSPEC,
PF_INET
@@ -291,8 +281,7 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout)
}
// allocate space for translated query
struct pollfd* pfd = reinterpret_cast<struct pollfd*>(
alloca((1 + num) * sizeof(struct pollfd)));
struct pollfd* pfd = new struct pollfd[1 + num];
// translate query
for (int i = 0; i < num; ++i) {
@@ -322,7 +311,7 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout)
n = poll(pfd, n, t);
// reset the unblock pipe
if (unblockPipe != NULL && (pfd[num].revents & POLLIN) != 0) {
if (n > 0 && unblockPipe != NULL && (pfd[num].revents & POLLIN) != 0) {
// the unblock event was signalled. flush the pipe.
char dummy[100];
do {
@@ -338,10 +327,10 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout)
if (errno == EINTR) {
// interrupted system call
ARCH->testCancelThread();
freea(pfd);
delete[] pfd;
return 0;
}
freea(pfd);
delete[] pfd;
throwError(errno);
}
@@ -362,7 +351,7 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout)
}
}
freea(pfd);
delete[] pfd;
return n;
}
@@ -452,7 +441,7 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout)
SELECT_TYPE_ARG5 timeout2P);
// reset the unblock pipe
if (unblockPipe != NULL && FD_ISSET(unblockPipe[0], &readSet)) {
if (n > 0 && unblockPipe != NULL && FD_ISSET(unblockPipe[0], &readSet)) {
// the unblock event was signalled. flush the pipe.
char dummy[100];
do {
@@ -594,6 +583,29 @@ CArchNetworkBSD::setNoDelayOnSocket(CArchSocket s, bool noDelay)
return (oflag != 0);
}
bool
CArchNetworkBSD::setReuseAddrOnSocket(CArchSocket s, bool reuse)
{
assert(s != NULL);
// get old state
int oflag;
socklen_t size = sizeof(oflag);
if (getsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR,
(optval_t*)&oflag, &size) == -1) {
throwError(errno);
}
int flag = reuse ? 1 : 0;
size = sizeof(flag);
if (setsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR,
(optval_t*)&flag, size) == -1) {
throwError(errno);
}
return (oflag != 0);
}
std::string
CArchNetworkBSD::getHostName()
{

View File

@@ -73,6 +73,7 @@ public:
const void* buf, size_t len);
virtual void throwErrorOnSocket(CArchSocket);
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
virtual bool setReuseAddrOnSocket(CArchSocket, bool reuse);
virtual std::string getHostName();
virtual CArchNetAddress newAnyAddr(EAddressFamily);
virtual CArchNetAddress copyAddr(CArchNetAddress);

View File

@@ -612,6 +612,30 @@ CArchNetworkWinsock::setNoDelayOnSocket(CArchSocket s, bool noDelay)
return (oflag != 0);
}
bool
CArchNetworkWinsock::setReuseAddrOnSocket(CArchSocket s, bool reuse)
{
assert(s != NULL);
// get old state
BOOL oflag;
int size = sizeof(oflag);
if (getsockopt_winsock(s->m_socket, SOL_SOCKET,
SO_REUSEADDR, &oflag, &size) == SOCKET_ERROR) {
throwError(getsockerror_winsock());
}
// set new state
BOOL flag = reuse ? 1 : 0;
size = sizeof(flag);
if (setsockopt_winsock(s->m_socket, SOL_SOCKET,
SO_REUSEADDR, &flag, size) == SOCKET_ERROR) {
throwError(getsockerror_winsock());
}
return (oflag != 0);
}
std::string
CArchNetworkWinsock::getHostName()
{

View File

@@ -70,6 +70,7 @@ public:
const void* buf, size_t len);
virtual void throwErrorOnSocket(CArchSocket);
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
virtual bool setReuseAddrOnSocket(CArchSocket, bool reuse);
virtual std::string getHostName();
virtual CArchNetAddress newAnyAddr(EAddressFamily);
virtual CArchNetAddress copyAddr(CArchNetAddress);

View File

@@ -19,6 +19,9 @@
#include "CArch.h"
#include <limits.h>
#include <string.h>
#if HAVE_LOCALE_H
# include <locale.h>
#endif
#if HAVE_WCHAR_H || defined(_MSC_VER)
# include <wchar.h>
#elif __APPLE__
@@ -56,6 +59,15 @@ static CArchMutex s_mutex = NULL;
ARCH_STRING::ARCH_STRING()
{
s_mutex = ARCH->newMutex();
#if HAVE_LOCALE_H
// see if we can convert a Latin-1 character
char mb[MB_LEN_MAX];
if (wctomb(mb, 0xe3) == -1) {
// can't convert. try another locale so we can convert latin-1.
setlocale(LC_CTYPE, "en_US");
}
#endif
}
ARCH_STRING::~ARCH_STRING()

View File

@@ -43,6 +43,15 @@ public:
*/
virtual void closeConsole() = 0;
//! Show the console
/*!
Causes the console to become visible. This generally only makes sense
for a console in a graphical user interface. Other implementations
will do nothing. Iff \p showIfEmpty is \c false then the implementation
may optionally only show the console if it's not empty.
*/
virtual void showConsole(bool showIfEmpty) = 0;
//! Write to the console
/*!
Writes the given string to the console, opening it if necessary.

View File

@@ -52,6 +52,15 @@ public:
*/
virtual void closeLog() = 0;
//! Show the log
/*!
Causes the log to become visible. This generally only makes sense
for a log in a graphical user interface. Other implementations
will do nothing. Iff \p showIfEmpty is \c false then the implementation
may optionally only show the log if it's not empty.
*/
virtual void showLog(bool showIfEmpty) = 0;
//! Write to the log
/*!
Writes the given string to the log with the given level.

View File

@@ -80,6 +80,7 @@ public:
kINTERRUPT, //!< Interrupt (e.g. Ctrl+C)
kTERMINATE, //!< Terminate (e.g. Ctrl+Break)
kHANGUP, //!< Hangup (SIGHUP)
kUSER, //!< User (SIGUSR2)
kNUM_SIGNALS
};
//! Type of signal handler function

View File

@@ -226,6 +226,13 @@ public:
*/
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay) = 0;
//! Turn address reuse on or off on socket
/*!
Allows the address this socket is bound to to be reused while in the
TIME_WAIT state. Returns the previous state.
*/
virtual bool setReuseAddrOnSocket(CArchSocket, bool reuse) = 0;
//! Return local host's name
virtual std::string getHostName() = 0;

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\arch.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\arch.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\base" /I "..\mt" /I "..\common" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\arch.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\base" /I "..\mt" /I "..\common" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\arch.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -22,15 +22,17 @@
CEvent::CEvent() :
m_type(kUnknown),
m_target(NULL),
m_data(NULL)
m_data(NULL),
m_flags(0)
{
// do nothing
}
CEvent::CEvent(Type type, void* target, void* data) :
CEvent::CEvent(Type type, void* target, void* data, Flags flags) :
m_type(type),
m_target(target),
m_data(data)
m_data(data),
m_flags(flags)
{
// do nothing
}
@@ -53,6 +55,12 @@ CEvent::getData() const
return m_data;
}
CEvent::Flags
CEvent::getFlags() const
{
return m_flags;
}
CEvent::Type
CEvent::registerType(const char* name)
{
@@ -82,7 +90,9 @@ CEvent::deleteData(const CEvent& event)
break;
default:
free(event.getData());
if ((event.getFlags() & kDontFreeData) == 0) {
free(event.getData());
}
break;
}
}

View File

@@ -33,6 +33,13 @@ public:
kLast //!< Must be last
};
typedef UInt32 Flags;
enum {
kNone = 0x00, //!< No flags
kDeliverImmediately = 0x01, //!< Dispatch and free event immediately
kDontFreeData = 0x02 //!< Don't free data in deleteData
};
CEvent();
//! Create \c CEvent with data
@@ -41,9 +48,10 @@ public:
The \p data must be POD (plain old data) allocated by malloc(),
which means it cannot have a constructor, destructor or be
composed of any types that do. \p target is the intended
recipient of the event.
recipient of the event. \p flags is any combination of \c Flags.
*/
CEvent(Type type, void* target = NULL, void* data = NULL);
CEvent(Type type, void* target = NULL, void* data = NULL,
UInt32 flags = kNone);
//! @name manipulators
//@{
@@ -97,12 +105,19 @@ public:
*/
void* getData() const;
//! Get event flags
/*!
Returns the event flags.
*/
Flags getFlags() const;
//@}
private:
Type m_type;
void* m_target;
void* m_data;
Flags m_flags;
};
#endif

View File

@@ -206,18 +206,24 @@ CEventQueue::addEvent(const CEvent& event)
default:
break;
}
CArchMutexLock lock(m_mutex);
// store the event's data locally
UInt32 eventID = saveEvent(event);
// add it
if (!m_buffer->addEvent(eventID)) {
// failed to send event
removeEvent(eventID);
if ((event.getFlags() & CEvent::kDeliverImmediately) != 0) {
dispatchEvent(event);
CEvent::deleteData(event);
}
else {
CArchMutexLock lock(m_mutex);
// store the event's data locally
UInt32 eventID = saveEvent(event);
// add it
if (!m_buffer->addEvent(eventID)) {
// failed to send event
removeEvent(eventID);
CEvent::deleteData(event);
}
}
}
CEventQueueTimer*

View File

@@ -100,42 +100,7 @@ CLog::getInstance()
}
void
CLog::print(const char* fmt, ...) const
{
// check if fmt begins with a priority argument
int priority = 4;
if (fmt[0] == '%' && fmt[1] == 'z') {
priority = fmt[2] - '\060';
fmt += 3;
}
// done if below priority threshold
if (priority > getFilter()) {
return;
}
// compute prefix padding length
int pad = g_priorityPad;
// print to buffer
char stack[1024];
va_list args;
va_start(args, fmt);
char* buffer = CStringUtil::vsprint(stack,
sizeof(stack) / sizeof(stack[0]),
pad, m_maxNewlineLength, fmt, args);
va_end(args);
// output buffer
output(priority, buffer);
// clean up
if (buffer != stack)
delete[] buffer;
}
void
CLog::printt(const char* file, int line, const char* fmt, ...) const
CLog::print(const char* file, int line, const char* fmt, ...) const
{
// check if fmt begins with a priority argument
int priority = 4;
@@ -151,35 +116,61 @@ CLog::printt(const char* file, int line, const char* fmt, ...) const
// compute prefix padding length
char stack[1024];
sprintf(stack, "%d", line);
int pad = strlen(file) + 1 /* comma */ +
strlen(stack) + 1 /* colon */ + 1 /* space */ +
g_priorityPad;
int pPad = g_priorityPad;
if (file != NULL) {
sprintf(stack, "%d", line);
pPad += strlen(file) + 1 /* comma */ +
strlen(stack) + 1 /* colon */ + 1 /* space */;
}
// print to buffer, leaving space for a newline at the end
va_list args;
va_start(args, fmt);
char* buffer = CStringUtil::vsprint(stack,
sizeof(stack) / sizeof(stack[0]),
pad, m_maxNewlineLength, fmt, args);
va_end(args);
// compute suffix padding length
int sPad = m_maxNewlineLength;
// print to buffer, leaving space for a newline at the end and prefix
// at the beginning.
char* buffer = stack;
int len = (int)(sizeof(stack) / sizeof(stack[0]));
while (true) {
// try printing into the buffer
va_list args;
va_start(args, fmt);
int n = ARCH->vsnprintf(buffer + pPad, len - pPad - sPad, fmt, args);
va_end(args);
// if the buffer wasn't big enough then make it bigger and try again
if (n < 0 || n > (int)len) {
if (buffer != stack) {
delete[] buffer;
}
len *= 2;
buffer = new char[len];
}
// if the buffer was big enough then continue
else {
break;
}
}
// print the prefix to the buffer. leave space for priority label.
sprintf(buffer + g_priorityPad, "%s,%d:", file, line);
buffer[pad - 1] = ' ';
// discard file and line if priority < 0
char* message = buffer;
if (priority < 0) {
message += pad - g_priorityPad;
if (file != NULL) {
sprintf(buffer + g_priorityPad, "%s,%d:", file, line);
buffer[pPad - 1] = ' ';
// discard file and line if priority < 0
if (priority < 0) {
message += pPad - g_priorityPad;
}
}
// output buffer
output(priority, message);
// clean up
if (buffer != stack)
if (buffer != stack) {
delete[] buffer;
}
}
void
@@ -199,6 +190,8 @@ CLog::insert(ILogOutputter* outputter, bool alwaysAtHead)
if (newlineLength > m_maxNewlineLength) {
m_maxNewlineLength = newlineLength;
}
outputter->open(kAppVersion);
outputter->show(false);
}
void
@@ -279,9 +272,6 @@ CLog::output(int priority, char* msg) const
// put an appropriate newline at the end
strcpy(end, outputter->getNewline());
// open the outputter
outputter->open(kApplication);
// write message
outputter->write(static_cast<ILogOutputter::ELevel>(priority),
msg + g_maxPriorityLength - n);
@@ -294,9 +284,6 @@ CLog::output(int priority, char* msg) const
// put an appropriate newline at the end
strcpy(end, outputter->getNewline());
// open the outputter
outputter->open(kApplication);
// write message and break out of loop if it returns false
if (!outputter->write(static_cast<ILogOutputter::ELevel>(priority),
msg + g_maxPriorityLength - n)) {

View File

@@ -102,18 +102,13 @@ public:
//! @name accessors
//@{
//! Print a log message
/*!
Print a log message using the printf-like \c format and arguments.
*/
void print(const char* format, ...) const;
//! Print a log message
/*!
Print a log message using the printf-like \c format and arguments
preceded by the filename and line number.
preceded by the filename and line number. If \c file is NULL then
neither the file nor the line are printed.
*/
void printt(const char* file, int line,
void print(const char* file, int line,
const char* format, ...) const;
//! Get the minimum priority level.
@@ -175,9 +170,9 @@ without the leading \c k. For example, \c CLOG_INFO. The special
filename and line number.
If \c NOLOGGING is defined during the build then this macro expands to
nothing. If \c NDEBUG is defined during the build then it expands to a
call to CLog::print. Otherwise it expands to a call to CLog::printt,
which includes the filename and line number.
nothing. If \c NDEBUG is not defined during the build then it expands
to a call to CLog::print that prints the filename and line number,
otherwise it expands to a call that doesn't.
*/
#if defined(NOLOGGING)
@@ -187,10 +182,10 @@ which includes the filename and line number.
#elif defined(NDEBUG)
#define LOG(_a1) CLOG->print _a1
#define LOGC(_a1, _a2) if (_a1) CLOG->print _a2
#define CLOG_TRACE
#define CLOG_TRACE NULL, 0,
#else
#define LOG(_a1) CLOG->printt _a1
#define LOGC(_a1, _a2) if (_a1) CLOG->printt _a2
#define LOG(_a1) CLOG->print _a1
#define LOGC(_a1, _a2) if (_a1) CLOG->print _a2
#define CLOG_TRACE __FILE__, __LINE__,
#endif

View File

@@ -115,55 +115,38 @@ CStringUtil::vformat(const char* fmt, va_list args)
CString
CStringUtil::print(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
CString result = vprint(fmt, args);
va_end(args);
return result;
}
CString
CStringUtil::vprint(const char* fmt, va_list args)
{
char tmp[1024];
char* buffer = vsprint(tmp, sizeof(tmp) / sizeof(tmp[0]), 0, 0, fmt, args);
if (buffer == tmp) {
return buffer;
}
else {
CString result(buffer);
delete[] buffer;
return result;
}
}
char* buffer = tmp;
int len = (int)(sizeof(tmp) / sizeof(tmp[0]));
CString result;
while (buffer != NULL) {
// try printing into the buffer
va_list args;
va_start(args, fmt);
int n = ARCH->vsnprintf(buffer, len, fmt, args);
va_end(args);
char*
CStringUtil::vsprint(char* buffer, int len,
int prefix, int suffix, const char* fmt, va_list args)
{
assert(len > 0);
// if the buffer wasn't big enough then make it bigger and try again
if (n < 0 || n > len) {
if (buffer != tmp) {
delete[] buffer;
}
len *= 2;
buffer = new char[len];
}
// try writing to input buffer
int n;
if (buffer != NULL && len >= prefix + suffix) {
n = ARCH->vsnprintf(buffer + prefix,
len - (prefix + suffix), fmt, args);
if (n >= 0 && n <= len - (prefix + suffix))
return buffer;
// if it was big enough then save the string and don't try again
else {
result = buffer;
if (buffer != tmp) {
delete[] buffer;
}
buffer = NULL;
}
}
// start allocating buffers until we write the whole string
buffer = NULL;
do {
delete[] buffer;
len *= 2;
buffer = new char[len + (prefix + suffix)];
n = ARCH->vsnprintf(buffer + prefix,
len - (prefix + suffix), fmt, args);
} while (n < 0 || n > len - (prefix + suffix));
return buffer;
return result;
}

View File

@@ -48,28 +48,6 @@ public:
*/
static CString print(const char* fmt, ...);
//! Print a string using printf-style formatting
/*!
Same as print() except takes va_list.
*/
static CString vprint(const char* fmt, va_list);
//! Print a string using printf-style formatting into a buffer
/*!
This is like print but print into a given buffer. If the resulting
string will not fit into \c buffer then a new buffer is allocated and
returned, otherwise \c buffer is returned. the caller must delete[]
the returned memory if is not \c buffer.
\c prefix and \c suffix must be >= 0. Exactly \c prefix characters and
at least \c suffix characters are available in the buffer before
and after the printed string, respectively. \c bufferLength is the
length of buffer and should not be adjusted by the caller to
account for \c prefix or \c suffix.
*/
static char* vsprint(char* buffer, int bufferLength,
int prefix, int suffix, const char* fmt, va_list);
//! Case-insensitive comparisons
/*!
This class provides case-insensitve comparison functions.

View File

@@ -45,6 +45,15 @@ public:
*/
virtual void close() = 0;
//! Show the outputter
/*!
Causes the output to become visible. This generally only makes sense
for a logger in a graphical user interface. Other implementations
will do nothing. Iff \p showIfEmpty is \c false then the implementation
may optionally only show the log if it's not empty.
*/
virtual void show(bool showIfEmpty) = 0;
//! Write a message with level
/*!
Writes \c message, which has the given \c level, to a log.

View File

@@ -41,6 +41,12 @@ CStopLogOutputter::close()
// do nothing
}
void
CStopLogOutputter::show(bool)
{
// do nothing
}
bool
CStopLogOutputter::write(ELevel, const char*)
{
@@ -80,6 +86,12 @@ CConsoleLogOutputter::close()
ARCH->closeConsole();
}
void
CConsoleLogOutputter::show(bool showIfEmpty)
{
ARCH->showConsole(showIfEmpty);
}
bool
CConsoleLogOutputter::write(ELevel, const char* msg)
{
@@ -120,6 +132,12 @@ CSystemLogOutputter::close()
ARCH->closeLog();
}
void
CSystemLogOutputter::show(bool showIfEmpty)
{
ARCH->showLog(showIfEmpty);
}
bool
CSystemLogOutputter::write(ELevel level, const char* msg)
{
@@ -162,22 +180,27 @@ CSystemLogOutputter::getNewline() const
// CSystemLogger
//
CSystemLogger::CSystemLogger(const char* title)
CSystemLogger::CSystemLogger(const char* title, bool blockConsole) :
m_stop(NULL)
{
// redirect log messages
if (blockConsole) {
m_stop = new CStopLogOutputter;
CLOG->insert(m_stop);
}
m_syslog = new CSystemLogOutputter;
m_stop = new CStopLogOutputter;
m_syslog->open(title);
CLOG->insert(m_stop);
CLOG->insert(m_syslog);
}
CSystemLogger::~CSystemLogger()
{
CLOG->remove(m_syslog);
CLOG->remove(m_stop);
delete m_stop;
delete m_syslog;
if (m_stop != NULL) {
CLOG->remove(m_stop);
delete m_stop;
}
}
@@ -221,6 +244,12 @@ CBufferedLogOutputter::close()
m_buffer.clear();
}
void
CBufferedLogOutputter::show(bool)
{
// do nothing
}
bool
CBufferedLogOutputter::write(ELevel, const char* message)
{

View File

@@ -34,6 +34,7 @@ public:
// ILogOutputter overrides
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual const char* getNewline() const;
};
@@ -51,6 +52,7 @@ public:
// ILogOutputter overrides
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual const char* getNewline() const;
};
@@ -67,6 +69,7 @@ public:
// ILogOutputter overrides
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual const char* getNewline() const;
};
@@ -81,7 +84,7 @@ the scope.
*/
class CSystemLogger {
public:
CSystemLogger(const char* title);
CSystemLogger(const char* title, bool blockConsole);
~CSystemLogger();
private:
@@ -117,6 +120,7 @@ public:
// ILogOutputter overrides
virtual void open(const char* title);
virtual void close();
virtual void show(bool showIfEmpty);
virtual bool write(ELevel level, const char* message);
virtual const char* getNewline() const;

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\base.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\base.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\base.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\base.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -47,17 +47,32 @@ CClient::CClient(const CString& name, const CNetworkAddress& address,
m_stream(NULL),
m_timer(NULL),
m_server(NULL),
m_active(false)
m_ready(false),
m_active(false),
m_suspended(false),
m_connectOnResume(false)
{
assert(m_socketFactory != NULL);
assert(m_screen != NULL);
// do nothing
// register suspend/resume event handlers
EVENTQUEUE->adoptHandler(IScreen::getSuspendEvent(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleSuspend));
EVENTQUEUE->adoptHandler(IScreen::getResumeEvent(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleResume));
}
CClient::~CClient()
{
EVENTQUEUE->removeHandler(IScreen::getSuspendEvent(),
getEventTarget());
EVENTQUEUE->removeHandler(IScreen::getResumeEvent(),
getEventTarget());
cleanupTimer();
cleanupScreen();
cleanupConnecting();
@@ -72,6 +87,10 @@ CClient::connect()
if (m_stream != NULL) {
return;
}
if (m_suspended) {
m_connectOnResume = true;
return;
}
try {
// resolve the server hostname. do this every time we connect
@@ -111,8 +130,10 @@ CClient::connect()
void
CClient::disconnect(const char* msg)
{
m_connectOnResume = false;
cleanupTimer();
cleanupScreen();
cleanupConnecting();
cleanupConnection();
if (msg != NULL) {
sendConnectionFailedEvent(msg);
@@ -142,6 +163,12 @@ CClient::isConnecting() const
return (m_timer != NULL);
}
CNetworkAddress
CClient::getServerAddress() const
{
return m_serverAddress;
}
CEvent::Type
CClient::getConnectedEvent()
{
@@ -216,13 +243,16 @@ void
CClient::setClipboard(ClipboardID id, const IClipboard* clipboard)
{
m_screen->setClipboard(id, clipboard);
m_ownClipboard[id] = false;
m_sentClipboard[id] = false;
}
void
CClient::grabClipboard(ClipboardID id)
{
m_screen->grabClipboard(id);
m_ownClipboard[id] = false;
m_ownClipboard[id] = false;
m_sentClipboard[id] = false;
}
void
@@ -275,9 +305,9 @@ CClient::mouseRelativeMove(SInt32 dx, SInt32 dy)
}
void
CClient::mouseWheel(SInt32 delta)
CClient::mouseWheel(SInt32 xDelta, SInt32 yDelta)
{
m_screen->mouseWheel(delta);
m_screen->mouseWheel(xDelta, yDelta);
}
void
@@ -330,8 +360,9 @@ CClient::sendClipboard(ClipboardID id)
// marshall the data
CString data = clipboard.marshall();
// save and send data if different
if (data != m_dataClipboard[id]) {
// save and send data if different or not yet sent
if (!m_sentClipboard[id] || data != m_dataClipboard[id]) {
m_sentClipboard[id] = true;
m_dataClipboard[id] = data;
m_server->onClipboardChanged(id, &clipboard);
}
@@ -490,6 +521,7 @@ CClient::handleConnected(const CEvent&, void*)
// reset clipboard state
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
m_ownClipboard[id] = false;
m_sentClipboard[id] = false;
m_timeClipboard[id] = 0;
}
}
@@ -513,6 +545,7 @@ CClient::handleConnectTimeout(const CEvent&, void*)
{
cleanupTimer();
cleanupConnecting();
cleanupConnection();
delete m_stream;
m_stream = NULL;
LOG((CLOG_DEBUG1 "connection timed out"));
@@ -557,6 +590,7 @@ CClient::handleClipboardGrabbed(const CEvent& event, void*)
// we now own the clipboard and it has not been sent to the server
m_ownClipboard[info->m_id] = true;
m_sentClipboard[info->m_id] = false;
m_timeClipboard[info->m_id] = 0;
// if we're not the active screen then send the clipboard now,
@@ -605,3 +639,24 @@ CClient::handleHello(const CEvent&, void*)
m_stream->getEventTarget()));
}
}
void
CClient::handleSuspend(const CEvent&, void*)
{
LOG((CLOG_INFO "suspend"));
m_suspended = true;
bool wasConnected = isConnected();
disconnect(NULL);
m_connectOnResume = wasConnected;
}
void
CClient::handleResume(const CEvent&, void*)
{
LOG((CLOG_INFO "resume"));
m_suspended = false;
if (m_connectOnResume) {
m_connectOnResume = false;
connect();
}
}

View File

@@ -89,6 +89,13 @@ public:
*/
bool isConnecting() const;
//! Get address of server
/*!
Returns the address of the server the client is connected (or wants
to connect) to.
*/
CNetworkAddress getServerAddress() const;
//! Get connected event type
/*!
Returns the connected event type. This is sent when the client has
@@ -136,7 +143,7 @@ public:
virtual void mouseUp(ButtonID);
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
virtual void mouseWheel(SInt32 delta);
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
virtual void screensaver(bool activate);
virtual void resetOptions();
virtual void setOptions(const COptionsList& options);
@@ -162,7 +169,9 @@ private:
void handleShapeChanged(const CEvent&, void*);
void handleClipboardGrabbed(const CEvent&, void*);
void handleHello(const CEvent&, void*);
void handleSuspend(const CEvent& event, void*);
void handleResume(const CEvent& event, void*);
private:
CString m_name;
CNetworkAddress m_serverAddress;
@@ -174,7 +183,10 @@ private:
CServerProxy* m_server;
bool m_ready;
bool m_active;
bool m_suspended;
bool m_connectOnResume;
bool m_ownClipboard[kClipboardEnd];
bool m_sentClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd];
CString m_dataClipboard[kClipboardEnd];

View File

@@ -32,7 +32,6 @@
CServerProxy::CServerProxy(CClient* client, IStream* stream) :
m_client(client),
m_stream(stream),
m_timer(NULL),
m_seqNum(0),
m_compressMouse(false),
m_compressMouseRelative(false),
@@ -41,7 +40,8 @@ CServerProxy::CServerProxy(CClient* client, IStream* stream) :
m_dxMouse(0),
m_dyMouse(0),
m_ignoreMouse(false),
m_heartRate(0.0),
m_keepAliveAlarm(0.0),
m_keepAliveAlarmTimer(NULL),
m_parser(&CServerProxy::parseHandshakeMessage)
{
assert(m_client != NULL);
@@ -58,32 +58,40 @@ CServerProxy::CServerProxy(CClient* client, IStream* stream) :
&CServerProxy::handleData));
// send heartbeat
installHeartBeat(kHeartRate);
setKeepAliveRate(kKeepAliveRate);
}
CServerProxy::~CServerProxy()
{
installHeartBeat(-1.0);
setKeepAliveRate(-1.0);
EVENTQUEUE->removeHandler(IStream::getInputReadyEvent(),
m_stream->getEventTarget());
}
void
CServerProxy::installHeartBeat(double heartRate)
CServerProxy::resetKeepAliveAlarm()
{
if (m_timer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_timer);
EVENTQUEUE->deleteTimer(m_timer);
if (m_keepAliveAlarmTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_keepAliveAlarmTimer);
EVENTQUEUE->deleteTimer(m_keepAliveAlarmTimer);
m_keepAliveAlarmTimer = NULL;
}
m_heartRate = heartRate;
if (m_heartRate > 0.0) {
m_timer = EVENTQUEUE->newTimer(m_heartRate, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_timer,
if (m_keepAliveAlarm > 0.0) {
m_keepAliveAlarmTimer =
EVENTQUEUE->newOneShotTimer(m_keepAliveAlarm, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveAlarmTimer,
new TMethodEventJob<CServerProxy>(this,
&CServerProxy::handleHeartBeat));
&CServerProxy::handleKeepAliveAlarm));
}
}
void
CServerProxy::setKeepAliveRate(double rate)
{
m_keepAliveAlarm = rate * kKeepAlivesUntilDeath;
resetKeepAliveAlarm();
}
void
CServerProxy::handleData(const CEvent&, void*)
{
@@ -105,7 +113,7 @@ CServerProxy::handleData(const CEvent&, void*)
break;
case kUnknown:
LOG((CLOG_ERR "invalid message from server"));
LOG((CLOG_ERR "invalid message from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
m_client->disconnect("invalid message from server");
return;
@@ -143,6 +151,12 @@ CServerProxy::parseHandshakeMessage(const UInt8* code)
resetOptions();
}
else if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
// echo keep alives and reset alarm
CProtocolUtil::writef(m_stream, kMsgCKeepAlive);
resetKeepAliveAlarm();
}
else if (memcmp(code, kMsgCNoop, 4) == 0) {
// accept and discard no-op
}
@@ -222,6 +236,12 @@ CServerProxy::parseMessage(const UInt8* code)
keyRepeat();
}
else if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
// echo keep alives and reset alarm
CProtocolUtil::writef(m_stream, kMsgCKeepAlive);
resetKeepAliveAlarm();
}
else if (memcmp(code, kMsgCNoop, 4) == 0) {
// accept and discard no-op
}
@@ -290,9 +310,10 @@ CServerProxy::parseMessage(const UInt8* code)
}
void
CServerProxy::handleHeartBeat(const CEvent&, void*)
CServerProxy::handleKeepAliveAlarm(const CEvent&, void*)
{
CProtocolUtil::writef(m_stream, kMsgCNoop);
LOG((CLOG_NOTE "server is dead"));
m_client->disconnect("server is not responding");
}
void
@@ -699,12 +720,12 @@ CServerProxy::mouseWheel()
flushCompressedMouse();
// parse
SInt16 delta;
CProtocolUtil::readf(m_stream, kMsgDMouseWheel + 4, &delta);
LOG((CLOG_DEBUG2 "recv mouse wheel %+d", delta));
SInt16 xDelta, yDelta;
CProtocolUtil::readf(m_stream, kMsgDMouseWheel + 4, &xDelta, &yDelta);
LOG((CLOG_DEBUG2 "recv mouse wheel %+d,%+d", xDelta, yDelta));
// forward
m_client->mouseWheel(delta);
m_client->mouseWheel(xDelta, yDelta);
}
void
@@ -728,11 +749,8 @@ CServerProxy::resetOptions()
// forward
m_client->resetOptions();
// reset heart rate and send heartbeat if necessary
installHeartBeat(kHeartRate);
if (m_heartRate >= 0.0) {
CProtocolUtil::writef(m_stream, kMsgCNoop);
}
// reset keep alive
setKeepAliveRate(kKeepAliveRate);
// reset modifier translation table
for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id) {
@@ -770,11 +788,8 @@ CServerProxy::setOptions()
id = kKeyModifierIDSuper;
}
else if (options[i] == kOptionHeartbeat) {
// update heart rate and send heartbeat if necessary
installHeartBeat(1.0e-3 * static_cast<double>(options[i + 1]));
if (m_heartRate >= 0.0) {
CProtocolUtil::writef(m_stream, kMsgCNoop);
}
// update keep alive
setKeepAliveRate(1.0e-3 * static_cast<double>(options[i + 1]));
}
if (id != kKeyModifierIDNull) {
m_modifierTranslationTable[id] =

View File

@@ -59,7 +59,8 @@ private:
void sendInfo(const CClientInfo&);
void installHeartBeat(double);
void resetKeepAliveAlarm();
void setKeepAliveRate(double);
// modifier key translation
KeyID translateKey(KeyID) const;
@@ -67,7 +68,7 @@ private:
// event handlers
void handleData(const CEvent&, void*);
void handleHeartBeat(const CEvent&, void*);
void handleKeepAliveAlarm(const CEvent&, void*);
// message handlers
void enter();
@@ -93,7 +94,6 @@ private:
CClient* m_client;
IStream* m_stream;
CEventQueueTimer* m_timer;
UInt32 m_seqNum;
@@ -105,7 +105,9 @@ private:
bool m_ignoreMouse;
KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast];
double m_heartRate;
double m_keepAliveAlarm;
CEventQueueTimer* m_keepAliveAlarmTimer;
MessageParser m_parser;
};

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\client.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\client.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\client.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\client.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -14,9 +14,9 @@
#include "Version.h"
const char* kApplication = "synergy";
const char* kApplication = "Synergy";
const char* kCopyright = "Copyright (C) 2002 Chris Schoeneman";
const char* kContact = "Chris Schoeneman, crs23@bigfoot.com";
const char* kWebsite = "http://synergy2.sourceforge.net/";
const char* kVersion = VERSION;
const char* kAppVersion = "synergy " VERSION;
const char* kAppVersion = "Synergy " VERSION;

View File

@@ -19,7 +19,7 @@
// set version macro if not set yet
#if !defined(VERSION)
# define VERSION "1.3.0"
# define VERSION "1.3.1"
#endif
// important strings

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\common.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\common.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\common.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\common.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -19,6 +19,11 @@
#if HAVE_CONFIG_H
# include "config.h"
// don't use poll() on mac
# if defined(__APPLE__)
# undef HAVE_POLL
# endif
#else
// we may not have run configure on win32
# if defined(_WIN32)
@@ -31,7 +36,6 @@
# define SYSAPI_UNIX 1
# define WINAPI_CARBON 1
# define HAVE_ALLOCA_H 1
# define HAVE_CXX_BOOL 1
# define HAVE_CXX_CASTS 1
# define HAVE_CXX_EXCEPTIONS 1
@@ -48,20 +52,26 @@
# define HAVE_POSIX_SIGWAIT 1
# define HAVE_PTHREAD 1
# define HAVE_PTHREAD_SIGNAL 1
# include <sys/types.h>
# include <sys/socket.h>
# if defined(_SOCKLEN_T)
# define HAVE_SOCKLEN_T 1
# endif
# define HAVE_SSTREAM 1
# define HAVE_STDINT_H 1
# define HAVE_STDLIB_H 1
# define HAVE_STRINGS_H 1
# define HAVE_STRING_H 1
# define HAVE_SYS_SELECT_H 1
# define HAVE_SYS_SOCKET_H 1
# define HAVE_SYS_STAT_H 1
# define HAVE_SYS_TIME_H 1
# define HAVE_SYS_TYPES_H 1
# define HAVE_SYS_UTSNAME_H 1
# define HAVE_UNISTD_H 1
# define HAVE_VSNPRINTF 1
# define HAVE_WCHAR_H 1
# define HAVE_SYS_SOCKET_H 1
/* disable this so we can build with the 10.2.8 SDK */
/*# define HAVE_WCHAR_H 1*/
# define SELECT_TYPE_ARG1 int
# define SELECT_TYPE_ARG234 (fd_set *)

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\io.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\io.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\io.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\io.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\mt.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\mt.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\mt.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\mt.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -59,6 +59,7 @@ CTCPListenSocket::bind(const CNetworkAddress& addr)
{
try {
CLock lock(m_mutex);
ARCH->setReuseAddrOnSocket(m_socket, true);
ARCH->bindSocket(m_socket, addr.getAddress());
ARCH->listenOnSocket(m_socket);
CSocketMultiplexer::getInstance()->addSocket(this,

View File

@@ -485,8 +485,9 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
sendEvent(getDisconnectedEvent());
needNewJob = true;
}
catch (XArchNetwork&) {
catch (XArchNetwork& e) {
// other write error
LOG((CLOG_WARN "error writing socket: %s", e.what().c_str()));
onDisconnected();
sendEvent(getOutputErrorEvent());
sendEvent(getDisconnectedEvent());
@@ -531,8 +532,9 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
onDisconnected();
needNewJob = true;
}
catch (XArchNetwork&) {
catch (XArchNetwork& e) {
// ignore other read error
LOG((CLOG_WARN "error reading socket: %s", e.what().c_str()));
}
}

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\net.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\net.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\net.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\io" /I "..\mt" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\net.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -14,6 +14,7 @@
#include "CMSWindowsDesks.h"
#include "CMSWindowsScreen.h"
#include "CSynergyHook.h"
#include "IScreenSaver.h"
#include "XScreen.h"
#include "CLock.h"
@@ -45,8 +46,8 @@
#define WM_NCXBUTTONDOWN 0x00AB
#define WM_NCXBUTTONUP 0x00AC
#define WM_NCXBUTTONDBLCLK 0x00AD
#define MOUSEEVENTF_XDOWN 0x0100
#define MOUSEEVENTF_XUP 0x0200
#define MOUSEEVENTF_XDOWN 0x0080
#define MOUSEEVENTF_XUP 0x0100
#define XBUTTON1 0x0001
#define XBUTTON2 0x0002
#endif
@@ -67,7 +68,7 @@
#define SYNERGY_MSG_FAKE_BUTTON SYNERGY_HOOK_LAST_MSG + 5
// x; y
#define SYNERGY_MSG_FAKE_MOVE SYNERGY_HOOK_LAST_MSG + 6
// delta; <unused>
// xDelta; yDelta
#define SYNERGY_MSG_FAKE_WHEEL SYNERGY_HOOK_LAST_MSG + 7
// POINT*; <unused>
#define SYNERGY_MSG_CURSOR_POS SYNERGY_HOOK_LAST_MSG + 8
@@ -77,6 +78,8 @@
#define SYNERGY_MSG_SCREENSAVER SYNERGY_HOOK_LAST_MSG + 10
// dx; dy
#define SYNERGY_MSG_FAKE_REL_MOVE SYNERGY_HOOK_LAST_MSG + 11
// enable; <unused>
#define SYNERGY_MSG_FAKE_INPUT SYNERGY_HOOK_LAST_MSG + 12
//
// CMSWindowsDesks
@@ -106,6 +109,7 @@ CMSWindowsDesks::CMSWindowsDesks(
m_cursor = createBlankCursor();
m_deskClass = createDeskWindowClass(m_isPrimary);
m_keyLayout = GetKeyboardLayout(GetCurrentThreadId());
resetOptions();
}
CMSWindowsDesks::~CMSWindowsDesks()
@@ -164,6 +168,23 @@ CMSWindowsDesks::leave(HKL keyLayout)
sendMessage(SYNERGY_MSG_LEAVE, (WPARAM)keyLayout, 0);
}
void
CMSWindowsDesks::resetOptions()
{
m_leaveForegroundOption = false;
}
void
CMSWindowsDesks::setOptions(const COptionsList& options)
{
for (UInt32 i = 0, n = options.size(); i < n; i += 2) {
if (options[i] == kOptionWin32KeepForeground) {
m_leaveForegroundOption = (options[i + 1] != 0);
LOG((CLOG_DEBUG1 "%s the foreground window", m_leaveForegroundOption ? "Don\'t grab" : "Grab"));
}
}
}
void
CMSWindowsDesks::updateKeys()
{
@@ -193,6 +214,18 @@ CMSWindowsDesks::installScreensaverHooks(bool install)
}
}
void
CMSWindowsDesks::fakeInputBegin()
{
sendMessage(SYNERGY_MSG_FAKE_INPUT, 1, 0);
}
void
CMSWindowsDesks::fakeInputEnd()
{
sendMessage(SYNERGY_MSG_FAKE_INPUT, 0, 0);
}
void
CMSWindowsDesks::getCursorPos(SInt32& x, SInt32& y) const
{
@@ -310,9 +343,9 @@ CMSWindowsDesks::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
}
void
CMSWindowsDesks::fakeMouseWheel(SInt32 delta) const
CMSWindowsDesks::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
{
sendMessage(SYNERGY_MSG_FAKE_WHEEL, delta, 0);
sendMessage(SYNERGY_MSG_FAKE_WHEEL, xDelta, yDelta);
}
void
@@ -565,9 +598,21 @@ CMSWindowsDesks::deskEnter(CDesk* desk)
SWP_NOMOVE | SWP_NOSIZE |
SWP_NOACTIVATE | SWP_HIDEWINDOW);
// this is here only because of the "ConsoleWindowClass" stuff in
// deskLeave.
// restore the foreground window
// XXX -- this raises the window to the top of the Z-order. we
// want it to stay wherever it was to properly support X-mouse
// (mouse over activation) but i've no idea how to do that.
// the obvious workaround of using SetWindowPos() to move it back
// after being raised doesn't work.
DWORD thisThread =
GetWindowThreadProcessId(desk->m_window, NULL);
DWORD thatThread =
GetWindowThreadProcessId(desk->m_foregroundWindow, NULL);
AttachThreadInput(thatThread, thisThread, TRUE);
SetForegroundWindow(desk->m_foregroundWindow);
AttachThreadInput(thatThread, thisThread, FALSE);
EnableWindow(desk->m_window, desk->m_lowLevel ? FALSE : TRUE);
desk->m_foregroundWindow = NULL;
}
void
@@ -575,9 +620,6 @@ CMSWindowsDesks::deskLeave(CDesk* desk, HKL keyLayout)
{
ShowCursor(FALSE);
if (m_isPrimary) {
// update key state
m_updateKeys->run();
// map a window to hide the cursor and to use whatever keyboard
// layout we choose rather than the keyboard layout of the last
// active window.
@@ -610,38 +652,26 @@ CMSWindowsDesks::deskLeave(CDesk* desk, HKL keyLayout)
SetActiveWindow(desk->m_window);
}
// if the active window is a console then activate our window.
// we do this because for some reason our hook reports unshifted
// characters when the shift is down and a console window is
// active. interestingly we do see the shift key go down and up.
// if using low-level hooks then disable the foreground window
// so it can't mess up any of our keyboard events. the console
// program, for example, will cause characters to be reported as
// unshifted, regardless of the shift key state. interestingly
// we do see the shift key go down and up.
//
// note that we must enable the window to activate it and we
// need to disable the window on deskEnter.
// FIXME -- figure out the real problem here and solve it.
else {
HWND foreground = GetForegroundWindow();
if (foreground != NULL) {
char className[40];
if (GetClassName(foreground, className,
sizeof(className) / sizeof(className[0])) &&
strcmp(className, "ConsoleWindowClass") == 0) {
EnableWindow(desk->m_window, TRUE);
SetActiveWindow(desk->m_window);
// force our window to the foreground. we can't
// simply call SetForegroundWindow() because that
// will only alert the user that the window wants
// to be the foreground as of windows 98/2000. we
// have to attach to the thread of the current
// foreground window then call it on our window
// and finally detach the threads.
DWORD thisThread =
GetWindowThreadProcessId(desk->m_window, NULL);
DWORD thatThread =
GetWindowThreadProcessId(foreground, NULL);
AttachThreadInput(thatThread, thisThread, TRUE);
SetForegroundWindow(desk->m_window);
AttachThreadInput(thatThread, thisThread, FALSE);
}
desk->m_foregroundWindow = getForegroundWindow();
if (desk->m_foregroundWindow != NULL) {
EnableWindow(desk->m_window, TRUE);
SetActiveWindow(desk->m_window);
DWORD thisThread =
GetWindowThreadProcessId(desk->m_window, NULL);
DWORD thatThread =
GetWindowThreadProcessId(desk->m_foregroundWindow, NULL);
AttachThreadInput(thatThread, thisThread, TRUE);
SetForegroundWindow(desk->m_window);
AttachThreadInput(thatThread, thisThread, FALSE);
}
}
@@ -671,9 +701,10 @@ CMSWindowsDesks::deskThread(void* vdesk)
MSG msg;
// use given desktop for this thread
CDesk* desk = reinterpret_cast<CDesk*>(vdesk);
desk->m_threadID = GetCurrentThreadId();
desk->m_window = NULL;
CDesk* desk = reinterpret_cast<CDesk*>(vdesk);
desk->m_threadID = GetCurrentThreadId();
desk->m_window = NULL;
desk->m_foregroundWindow = NULL;
if (desk->m_desk != NULL && SetThreadDesktop(desk->m_desk) != 0) {
// create a message queue
PeekMessage(&msg, NULL, 0,0, PM_NOREMOVE);
@@ -763,7 +794,10 @@ CMSWindowsDesks::deskThread(void* vdesk)
break;
case SYNERGY_MSG_FAKE_WHEEL:
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, msg.wParam, 0);
// XXX -- add support for x-axis scrolling
if (msg.lParam != 0) {
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, msg.lParam, 0);
}
break;
case SYNERGY_MSG_CURSOR_POS: {
@@ -787,6 +821,12 @@ CMSWindowsDesks::deskThread(void* vdesk)
m_uninstallScreensaver();
}
break;
case SYNERGY_MSG_FAKE_INPUT:
keybd_event(SYNERGY_HOOK_FAKE_INPUT_VIRTUAL_KEY,
SYNERGY_HOOK_FAKE_INPUT_SCANCODE,
msg.wParam ? 0 : KEYEVENTF_KEYUP, 0);
break;
}
// notify that message was processed
@@ -870,11 +910,12 @@ CMSWindowsDesks::checkDesk()
// inaccessible desktop to an accessible one we have to
// update the keyboard state.
LOG((CLOG_DEBUG "switched to desk \"%s\"", name.c_str()));
bool syncKeys = false;
bool isAccessible = isDeskAccessible(desk);
if (isDeskAccessible(m_activeDesk) != isAccessible) {
if (isAccessible) {
LOG((CLOG_DEBUG "desktop is now accessible"));
sendMessage(SYNERGY_MSG_SYNC_KEYS, 0, 0);
syncKeys = true;
}
else {
LOG((CLOG_DEBUG "desktop is now inaccessible"));
@@ -890,6 +931,11 @@ CMSWindowsDesks::checkDesk()
if (!wasOnScreen) {
sendMessage(SYNERGY_MSG_LEAVE, (WPARAM)m_keyLayout, 0);
}
// update keys if necessary
if (syncKeys) {
updateKeys();
}
}
else if (name != m_activeDeskName) {
// screen saver might have started
@@ -972,3 +1018,16 @@ CMSWindowsDesks::getDesktopName(HDESK desk)
return result;
}
}
HWND
CMSWindowsDesks::getForegroundWindow() const
{
// Ideally we'd return NULL as much as possible, only returning
// the actual foreground window when we know it's going to mess
// up our keyboard input. For now we'll just let the user
// decide.
if (m_leaveForegroundOption) {
return NULL;
}
return GetForegroundWindow();
}

View File

@@ -18,6 +18,7 @@
#include "CSynergyHook.h"
#include "KeyTypes.h"
#include "MouseTypes.h"
#include "OptionTypes.h"
#include "CCondVar.h"
#include "CMutex.h"
#include "CString.h"
@@ -92,6 +93,19 @@ public:
*/
void leave(HKL keyLayout);
//! Notify of options changes
/*!
Resets all options to their default values.
*/
void resetOptions();
//! Notify of options changes
/*!
Set options to given values. Ignores unknown options and doesn't
modify options that aren't given in \c options.
*/
void setOptions(const COptionsList& options);
//! Update the key state
/*!
Causes the key state to get updated to reflect the physical keyboard
@@ -115,6 +129,18 @@ public:
*/
void installScreensaverHooks(bool install);
//! Start ignoring user input
/*!
Starts ignoring user input so we don't pick up our own synthesized events.
*/
void fakeInputBegin();
//! Stop ignoring user input
/*!
Undoes whatever \c fakeInputBegin() did.
*/
void fakeInputEnd();
//@}
//! @name accessors
//@{
@@ -152,9 +178,9 @@ public:
//! Fake mouse wheel
/*!
Synthesize a mouse wheel event of amount \c delta.
Synthesize a mouse wheel event of amount \c delta in direction \c axis.
*/
void fakeMouseWheel(SInt32 delta) const;
void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
//@}
@@ -167,6 +193,7 @@ private:
DWORD m_targetID;
HDESK m_desk;
HWND m_window;
HWND m_foregroundWindow;
bool m_lowLevel;
};
typedef std::map<CString, CDesk*> CDesks;
@@ -198,6 +225,9 @@ private:
void waitForDesk() const;
void sendMessage(UINT, WPARAM, LPARAM) const;
// work around for messed up keyboard events from low-level hooks
HWND getForegroundWindow() const;
// desk API wrappers
HDESK openInputDesktop();
void closeDesktop(HDESK);
@@ -258,6 +288,9 @@ private:
// keyboard stuff
IJob* m_updateKeys;
HKL m_keyLayout;
// options
bool m_leaveForegroundOption;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -17,9 +17,12 @@
#include "CKeyState.h"
#include "CString.h"
#include "stdvector.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
class CEvent;
class CEventQueueTimer;
class CMSWindowsDesks;
//! Microsoft Windows key mapper
@@ -28,24 +31,62 @@ This class maps KeyIDs to keystrokes.
*/
class CMSWindowsKeyState : public CKeyState {
public:
CMSWindowsKeyState(CMSWindowsDesks* desks);
CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget);
virtual ~CMSWindowsKeyState();
//! @name accessors
//! @name manipulators
//@{
//! Handle screen disabling
/*!
Called when screen is disabled. This is needed to deal with platform
brokenness.
*/
void disable();
//! Set the active keyboard layout
/*!
Uses \p keyLayout when querying the keyboard.
*/
void setKeyLayout(HKL keyLayout);
//! Check the named virtual key for release
//! Test and set autorepeat state
/*!
If \p virtualKey isn't really pressed but we think it is then
update our state and post a key release event to \p eventTarget.
Returns true if the given button is autorepeating and updates internal
state.
*/
void fixKey(void* eventTarget, UINT virtualKey);
bool testAutoRepeat(bool press, bool isRepeat, KeyButton);
//! Remember modifier state
/*!
Records the current non-toggle modifier state.
*/
void saveModifiers();
//! Set effective modifier state
/*!
Temporarily sets the non-toggle modifier state to those saved by the
last call to \c saveModifiers if \p enable is \c true. Restores the
modifier state to the current modifier state if \p enable is \c false.
This is for synthesizing keystrokes on the primary screen when the
cursor is on a secondary screen. When on a secondary screen we capture
all non-toggle modifier state, track the state internally and do not
pass it on. So if Alt+F1 synthesizes Alt+X we need to synthesize
not just X but also Alt, despite the fact that our internal modifier
state indicates Alt is down, because local apps never saw the Alt down
event.
*/
void useSavedModifiers(bool enable);
//@}
//! @name accessors
//@{
//! Map a virtual key to a button
/*!
Returns the button for the \p virtualKey.
*/
KeyButton virtualKeyToButton(UINT virtualKey) const;
//! Map key event to a key
/*!
@@ -55,84 +96,121 @@ public:
KeyID mapKeyFromEvent(WPARAM charAndVirtKey,
LPARAM info, KeyModifierMask* maskOut) const;
//! Map a virtual key to a button
//! Check if keyboard groups have changed
/*!
Returns the button for the \p virtualKey.
Returns true iff the number or order of the keyboard groups have
changed since the last call to updateKeys().
*/
KeyButton virtualKeyToButton(UINT virtualKey) const;
bool didGroupsChange() const;
//! Map key to virtual key
/*!
Returns the virtual key for key \p key or 0 if there's no such virtual
key.
*/
UINT mapKeyToVirtualKey(KeyID key) const;
//! Map virtual key and button to KeyID
/*!
Returns the KeyID for virtual key \p virtualKey and button \p button
(button should include the extended key bit), or kKeyNone if there is
no such key.
*/
static KeyID getKeyID(UINT virtualKey, KeyButton button);
//@}
// IKeyState overrides
virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
KeyButton button);
virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
SInt32 count, KeyButton button);
virtual bool fakeCtrlAltDel();
virtual KeyModifierMask
pollActiveModifiers() const;
virtual SInt32 pollActiveGroup() const;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
// CKeyState overrides
virtual void onKey(KeyButton button, bool down,
KeyModifierMask newState);
virtual void sendKeyEvent(void* target,
bool press, bool isAutoRepeat,
KeyID key, KeyModifierMask mask,
SInt32 count, KeyButton button);
virtual bool fakeCtrlAltDel();
virtual const char* getKeyName(KeyButton) const;
protected:
// IKeyState overrides
virtual void doUpdateKeys();
virtual void doFakeKeyEvent(KeyButton button,
bool press, bool isAutoRepeat);
virtual KeyButton mapKey(Keystrokes& keys, KeyID id,
KeyModifierMask desiredMask,
bool isAutoRepeat) const;
// CKeyState overrides
virtual void getKeyMap(CKeyMap& keyMap);
virtual void fakeKey(const Keystroke& keystroke);
virtual KeyModifierMask&
getActiveModifiersRValue();
private:
typedef std::vector<HKL> GroupList;
// send ctrl+alt+del hotkey event on NT family
static void ctrlAltDelThread(void*);
// convert a language ID to a code page
UINT getCodePageFromLangID(LANGID langid) const;
bool getGroups(GroupList&) const;
void setWindowGroup(SInt32 group);
// map a virtual key to a button. this tries to deal with the
// broken win32 API as best it can.
KeyButton mapVirtKeyToButton(UINT virtualKey,
KeyButton& extended) const;
void fixKeys();
void handleFixKeys(const CEvent&, void*);
// same as above and discard extended
KeyButton mapVirtKeyToButton(UINT virtualKey) const;
KeyID getIDForKey(CKeyMap::KeyItem& item,
KeyButton button, UINT virtualKey,
PBYTE keyState, HKL hkl) const;
// map character \c c given keyboard layout \c hkl to the keystrokes
// to generate it.
KeyButton mapCharacter(Keystrokes& keys,
char c, HKL hkl, bool isAutoRepeat) const;
// map \c virtualKey to the keystrokes to generate it, along with
// keystrokes to update and restore the modifier state.
KeyButton mapToKeystrokes(Keystrokes& keys, KeyButton button,
KeyModifierMask desiredMask,
KeyModifierMask requiredMask,
bool isAutoRepeat) const;
// get keystrokes to get modifiers in a desired state
bool adjustModifiers(Keystrokes& keys,
Keystrokes& undo,
KeyModifierMask desiredMask,
KeyModifierMask requiredMask) const;
// pass character to ToAsciiEx(), returning what it returns
int toAscii(TCHAR c, HKL hkl, bool menu, WORD* chars) const;
// return true iff \c c is a dead character
bool isDeadChar(TCHAR c, HKL hkl, bool menu) const;
void addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item);
private:
// not implemented
CMSWindowsKeyState(const CMSWindowsKeyState&);
CMSWindowsKeyState& operator=(const CMSWindowsKeyState&);
private:
typedef std::map<HKL, SInt32> GroupMap;
typedef std::map<KeyID, UINT> KeyToVKMap;
bool m_is95Family;
void* m_eventTarget;
CMSWindowsDesks* m_desks;
HKL m_keyLayout;
CString m_keyName;
UINT m_scanCodeToVirtKey[512];
UINT m_scanCodeToVirtKeyNumLock[512];
KeyButton m_virtKeyToScanCode[256];
UINT m_buttonToVK[512];
UINT m_buttonToNumpadVK[512];
KeyButton m_virtualKeyToButton[256];
KeyToVKMap m_keyToVKMap;
static const char* s_vkToName[];
static const KeyID s_virtualKey[][2];
static const UINT s_mapE000[];
static const UINT s_mapEE00[];
static const UINT s_mapEF00[];
// the timer used to check for fixing key state
CEventQueueTimer* m_fixTimer;
// the groups (keyboard layouts)
GroupList m_groups;
GroupMap m_groupMap;
// the last button that we generated a key down event for. this
// is zero if the last key event was a key up. we use this to
// synthesize key repeats since the low level keyboard hook can't
// tell us if an event is a key repeat.
KeyButton m_lastDown;
// modifier tracking
bool m_useSavedModifiers;
KeyModifierMask m_savedModifiers;
KeyModifierMask m_originalSavedModifiers;
// pointer to ToUnicodeEx. on win95 family this will be NULL.
typedef int (WINAPI *ToUnicodeEx_t)(UINT wVirtKey,
UINT wScanCode,
PBYTE lpKeyState,
LPWSTR pwszBuff,
int cchBuff,
UINT wFlags,
HKL dwhkl);
ToUnicodeEx_t m_ToUnicodeEx;
static const KeyID s_virtualKey[];
};
#endif

View File

@@ -19,6 +19,7 @@
#include "CMSWindowsKeyState.h"
#include "CMSWindowsScreenSaver.h"
#include "CClipboard.h"
#include "CKeyMap.h"
#include "XScreen.h"
#include "CLock.h"
#include "CThread.h"
@@ -54,8 +55,8 @@
#define WM_NCXBUTTONDOWN 0x00AB
#define WM_NCXBUTTONUP 0x00AC
#define WM_NCXBUTTONDBLCLK 0x00AD
#define MOUSEEVENTF_XDOWN 0x0100
#define MOUSEEVENTF_XUP 0x0200
#define MOUSEEVENTF_XDOWN 0x0080
#define MOUSEEVENTF_XUP 0x0100
#define XBUTTON1 0x0001
#define XBUTTON2 0x0002
#endif
@@ -76,8 +77,7 @@
HINSTANCE CMSWindowsScreen::s_instance = NULL;
CMSWindowsScreen* CMSWindowsScreen::s_screen = NULL;
CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
IJob* suspend, IJob* resume) :
CMSWindowsScreen::CMSWindowsScreen(bool isPrimary) :
m_isPrimary(isPrimary),
m_is95Family(CArchMiscWindows::isWindows95Family()),
m_isOnScreen(m_isPrimary),
@@ -90,8 +90,8 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
m_sequenceNumber(0),
m_mark(0),
m_markReceived(0),
m_keyLayout(NULL),
m_fixTimer(NULL),
m_keyLayout(NULL),
m_screensaver(NULL),
m_screensaverNotify(false),
m_screensaverActive(false),
@@ -106,8 +106,6 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
m_setZone(NULL),
m_setMode(NULL),
m_keyState(NULL),
m_suspend(suspend),
m_resume(resume),
m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0),
m_showingMouse(false)
{
@@ -124,7 +122,7 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
m_hookLibrary, m_screensaver,
new TMethodJob<CMSWindowsScreen>(this,
&CMSWindowsScreen::updateKeysCB));
m_keyState = new CMSWindowsKeyState(m_desks);
m_keyState = new CMSWindowsKeyState(m_desks, getEventTarget());
updateScreenShape();
m_class = createWindowClass();
m_window = createWindow(m_class, "Synergy");
@@ -139,8 +137,6 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
destroyWindow(m_window);
destroyClass(m_class);
closeHookLibrary(m_hookLibrary);
delete m_suspend;
delete m_resume;
s_screen = NULL;
throw;
}
@@ -167,8 +163,6 @@ CMSWindowsScreen::~CMSWindowsScreen()
destroyWindow(m_window);
destroyClass(m_class);
closeHookLibrary(m_hookLibrary);
delete m_suspend;
delete m_resume;
s_screen = NULL;
}
@@ -192,6 +186,12 @@ CMSWindowsScreen::enable()
{
assert(m_isOnScreen == m_isPrimary);
// we need to poll some things to fix them
m_fixTimer = EVENTQUEUE->newTimer(1.0, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
new TMethodEventJob<CMSWindowsScreen>(this,
&CMSWindowsScreen::handleFixes));
// install our clipboard snooper
m_nextClipboardWindow = SetClipboardViewer(m_window);
@@ -232,17 +232,20 @@ CMSWindowsScreen::disable()
CArchMiscWindows::kDISPLAY);
}
// uninstall fix key timer
// tell key state
m_keyState->disable();
// stop snooping the clipboard
ChangeClipboardChain(m_window, m_nextClipboardWindow);
m_nextClipboardWindow = NULL;
// uninstall fix timer
if (m_fixTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
EVENTQUEUE->deleteTimer(m_fixTimer);
m_fixTimer = NULL;
}
// stop snooping the clipboard
ChangeClipboardChain(m_window, m_nextClipboardWindow);
m_nextClipboardWindow = NULL;
m_isOnScreen = m_isPrimary;
forceShowCursor();
}
@@ -292,6 +295,10 @@ CMSWindowsScreen::leave()
// all messages prior to now are invalid
nextMark();
// remember the modifier state. this is the modifier state
// reflected in the internal keyboard state.
m_keyState->saveModifiers();
// capture events
m_setMode(kHOOK_RELAY_EVENTS);
}
@@ -388,13 +395,13 @@ CMSWindowsScreen::screensaver(bool activate)
void
CMSWindowsScreen::resetOptions()
{
// no options
m_desks->resetOptions();
}
void
CMSWindowsScreen::setOptions(const COptionsList&)
CMSWindowsScreen::setOptions(const COptionsList& options)
{
// no options
m_desks->setOptions(options);
}
void
@@ -467,6 +474,130 @@ CMSWindowsScreen::warpCursor(SInt32 x, SInt32 y)
m_yCursor = y;
}
UInt32
CMSWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
{
// only allow certain modifiers
if ((mask & ~(KeyModifierShift | KeyModifierControl |
KeyModifierAlt | KeyModifierSuper)) != 0) {
LOG((CLOG_WARN "could not map hotkey id=%04x mask=%04x", key, mask));
return 0;
}
// fail if no keys
if (key == kKeyNone && mask == 0) {
return 0;
}
// convert to win32
UINT modifiers = 0;
if ((mask & KeyModifierShift) != 0) {
modifiers |= MOD_SHIFT;
}
if ((mask & KeyModifierControl) != 0) {
modifiers |= MOD_CONTROL;
}
if ((mask & KeyModifierAlt) != 0) {
modifiers |= MOD_ALT;
}
if ((mask & KeyModifierSuper) != 0) {
modifiers |= MOD_WIN;
}
UINT vk = m_keyState->mapKeyToVirtualKey(key);
if (key != kKeyNone && vk == 0) {
// can't map key
LOG((CLOG_WARN "could not map hotkey id=%04x mask=%04x", key, mask));
return 0;
}
// choose hotkey id
UInt32 id;
if (!m_oldHotKeyIDs.empty()) {
id = m_oldHotKeyIDs.back();
m_oldHotKeyIDs.pop_back();
}
else {
id = m_hotKeys.size() + 1;
}
// if this hot key has modifiers only then we'll handle it specially
bool err;
if (key == kKeyNone) {
// check if already registered
err = (m_hotKeyToIDMap.count(CHotKeyItem(vk, modifiers)) > 0);
}
else {
// register with OS
err = (RegisterHotKey(NULL, id, modifiers, vk) == 0);
}
if (!err) {
m_hotKeys.insert(std::make_pair(id, CHotKeyItem(vk, modifiers)));
m_hotKeyToIDMap[CHotKeyItem(vk, modifiers)] = id;
}
else {
m_oldHotKeyIDs.push_back(id);
m_hotKeys.erase(id);
LOG((CLOG_WARN "failed to register hotkey %s (id=%04x mask=%04x)", CKeyMap::formatKey(key, mask).c_str(), key, mask));
return 0;
}
LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", CKeyMap::formatKey(key, mask).c_str(), key, mask, id));
return id;
}
void
CMSWindowsScreen::unregisterHotKey(UInt32 id)
{
// look up hotkey
HotKeyMap::iterator i = m_hotKeys.find(id);
if (i == m_hotKeys.end()) {
return;
}
// unregister with OS
bool err;
if (i->second.getVirtualKey() != 0) {
err = !UnregisterHotKey(NULL, id);
}
else {
err = false;
}
if (err) {
LOG((CLOG_WARN "failed to unregister hotkey id=%d", id));
}
else {
LOG((CLOG_DEBUG "unregistered hotkey id=%d", id));
}
// discard hot key from map and record old id for reuse
m_hotKeyToIDMap.erase(i->second);
m_hotKeys.erase(i);
m_oldHotKeyIDs.push_back(id);
}
void
CMSWindowsScreen::fakeInputBegin()
{
assert(m_isPrimary);
if (!m_isOnScreen) {
m_keyState->useSavedModifiers(true);
}
m_desks->fakeInputBegin();
}
void
CMSWindowsScreen::fakeInputEnd()
{
assert(m_isPrimary);
m_desks->fakeInputEnd();
if (!m_isOnScreen) {
m_keyState->useSavedModifiers(false);
}
}
SInt32
CMSWindowsScreen::getJumpZoneSize() const
{
@@ -521,9 +652,9 @@ CMSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
}
void
CMSWindowsScreen::fakeMouseWheel(SInt32 delta) const
CMSWindowsScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
{
m_desks->fakeMouseWheel(delta);
m_desks->fakeMouseWheel(xDelta, yDelta);
}
void
@@ -556,9 +687,9 @@ CMSWindowsScreen::fakeKeyUp(KeyButton button)
}
void
CMSWindowsScreen::fakeToggle(KeyModifierMask modifier)
CMSWindowsScreen::fakeAllKeysUp()
{
CPlatformScreen::fakeToggle(modifier);
CPlatformScreen::fakeAllKeysUp();
updateForceShowCursor();
}
@@ -776,7 +907,8 @@ CMSWindowsScreen::onPreDispatchPrimary(HWND,
static_cast<SInt32>(lParam));
case SYNERGY_MSG_MOUSE_WHEEL:
return onMouseWheel(static_cast<SInt32>(wParam));
// XXX -- support x-axis scrolling
return onMouseWheel(0, static_cast<SInt32>(wParam));
case SYNERGY_MSG_PRE_WARP:
{
@@ -800,6 +932,13 @@ CMSWindowsScreen::onPreDispatchPrimary(HWND,
case SYNERGY_MSG_POST_WARP:
LOG((CLOG_WARN "unmatched post warp"));
return true;
case WM_HOTKEY:
// we discard these messages. we'll catch the hot key in the
// regular key event handling, where we can detect both key
// press and release. we only register the hot key so no other
// app will act on the key combination.
break;
}
return false;
@@ -827,8 +966,6 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
break;
case WM_DRAWCLIPBOARD:
LOG((CLOG_DEBUG "clipboard was taken"));
// first pass on the message
if (m_nextClipboardWindow != NULL) {
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
@@ -843,7 +980,6 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
LOG((CLOG_DEBUG "clipboard chain: new next: 0x%08x", m_nextClipboardWindow));
}
else if (m_nextClipboardWindow != NULL) {
LOG((CLOG_DEBUG "clipboard chain: forward: %d 0x%08x 0x%08x", msg, wParam, lParam));
SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
}
return true;
@@ -856,15 +992,15 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
case PBT_APMRESUMEAUTOMATIC:
case PBT_APMRESUMECRITICAL:
case PBT_APMRESUMESUSPEND:
if (m_resume != NULL) {
m_resume->run();
}
EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(),
getEventTarget(), NULL,
CEvent::kDeliverImmediately));
break;
case PBT_APMSUSPEND:
if (m_suspend != NULL) {
m_suspend->run();
}
EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(),
getEventTarget(), NULL,
CEvent::kDeliverImmediately));
break;
}
*result = TRUE;
@@ -894,62 +1030,70 @@ CMSWindowsScreen::onMark(UInt32 mark)
bool
CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
{
LOG((CLOG_DEBUG1 "event: Key char=%d, vk=0x%02x, lParam=0x%08x", (wParam & 0xff00u) >> 8, wParam & 0xffu, lParam));
static const KeyModifierMask s_ctrlAlt =
KeyModifierControl | KeyModifierAlt;
// fix up key state
fixKeys();
LOG((CLOG_DEBUG1 "event: Key char=%d, vk=0x%02x, nagr=%d, lParam=0x%08x", (wParam & 0xff00u) >> 8, wParam & 0xffu, (wParam & 0x10000u) ? 1 : 0, lParam));
// get key info
KeyButton button = (KeyButton)((lParam & 0x01ff0000) >> 16);
bool down = ((lParam & 0xc0000000u) == 0x00000000u);
bool up = ((lParam & 0x80000000u) == 0x80000000u);
bool wasDown = isKeyDown(button);
// get event info
KeyButton button = (KeyButton)((lParam & 0x01ff0000) >> 16);
bool down = ((lParam & 0x80000000u) == 0x00000000u);
bool wasDown = isKeyDown(button);
KeyModifierMask oldState = pollActiveModifiers();
// the windows keys are a royal pain on the windows 95 family.
// the system eats the key up events if and only if the windows
// key wasn't combined with another key, i.e. it was tapped.
// fixKeys() and scheduleFixKeys() are all about synthesizing
// the missing key up. but even windows itself gets a little
// confused and sets bit 30 in lParam if you tap the windows
// key twice. that bit means the key was previously down and
// that makes some sense since the up event was missing.
// anyway, on the windows 95 family we forget about windows
// key repeats and treat anything that's not a key down as a
// key up.
if (m_is95Family &&
((wParam & 0xffu) == VK_LWIN || (wParam & 0xffu) == VK_RWIN)) {
down = !up;
// check for autorepeat
if (m_keyState->testAutoRepeat(down, (lParam & 0x40000000u) == 1, button)) {
lParam |= 0x40000000u;
}
// update key state. ignore key repeats.
if (down) {
m_keyState->setKeyDown(button, true);
}
else if (up) {
m_keyState->setKeyDown(button, false);
// if the button is zero then guess what the button should be.
// these are badly synthesized key events and logitech software
// that maps mouse buttons to keys is known to do this.
// alternatively, we could just throw these events out.
if (button == 0) {
button = m_keyState->virtualKeyToButton(wParam & 0xffu);
if (button == 0) {
return true;
}
wasDown = isKeyDown(button);
}
// schedule a timer if we need to fix keys later
scheduleFixKeys();
// record keyboard state
m_keyState->onKey(button, down, oldState);
// special case: we detect ctrl+alt+del being pressed on some
// systems but we don't detect the release of those keys. so
// if ctrl, alt, and del are down then mark them up.
KeyModifierMask mask = getActiveModifiers();
bool ctrlAlt = ((mask & (KeyModifierControl | KeyModifierAlt)) ==
(KeyModifierControl | KeyModifierAlt));
if (down && ctrlAlt &&
isKeyDown(m_keyState->virtualKeyToButton(VK_DELETE))) {
m_keyState->setKeyDown(
m_keyState->virtualKeyToButton(VK_LCONTROL), false);
m_keyState->setKeyDown(
m_keyState->virtualKeyToButton(VK_RCONTROL), false);
m_keyState->setKeyDown(
m_keyState->virtualKeyToButton(VK_LMENU), false);
m_keyState->setKeyDown(
m_keyState->virtualKeyToButton(VK_RMENU), false);
m_keyState->setKeyDown(
m_keyState->virtualKeyToButton(VK_DELETE), false);
// windows doesn't tell us the modifier key state on mouse or key
// events so we have to figure it out. most apps would use
// GetKeyState() or even GetAsyncKeyState() for that but we can't
// because our hook doesn't pass on key events for several modifiers.
// it can't otherwise the system would interpret them normally on
// the primary screen even when on a secondary screen. so tapping
// alt would activate menus and tapping the windows key would open
// the start menu. if you don't pass those events on in the hook
// then GetKeyState() understandably doesn't reflect the effect of
// the event. curiously, neither does GetAsyncKeyState(), which is
// surprising.
//
// so anyway, we have to track the modifier state ourselves for
// at least those modifiers we don't pass on. pollActiveModifiers()
// does that but we have to update the keyboard state before calling
// pollActiveModifiers() to get the right answer. but the only way
// to set the modifier state or to set the up/down state of a key
// is via onKey(). so we have to call onKey() twice.
KeyModifierMask state = pollActiveModifiers();
m_keyState->onKey(button, down, state);
// check for hot keys
if (oldState != state) {
// modifier key was pressed/released
if (onHotKey(0, lParam)) {
return true;
}
}
else {
// non-modifier was pressed/released
if (onHotKey(wParam, lParam)) {
return true;
}
}
// ignore message if posted prior to last mark change
@@ -957,20 +1101,23 @@ CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
// check for ctrl+alt+del. we do not want to pass that to the
// client. the user can use ctrl+alt+pause to emulate it.
UINT virtKey = (wParam & 0xffu);
if (virtKey == VK_DELETE && ctrlAlt) {
if (virtKey == VK_DELETE && (state & s_ctrlAlt) == s_ctrlAlt) {
LOG((CLOG_DEBUG "discard ctrl+alt+del"));
return true;
}
// check for ctrl+alt+del emulation
if ((virtKey == VK_PAUSE || virtKey == VK_CANCEL) && ctrlAlt) {
if ((virtKey == VK_PAUSE || virtKey == VK_CANCEL) &&
(state & s_ctrlAlt) == s_ctrlAlt) {
LOG((CLOG_DEBUG "emulate ctrl+alt+del"));
// switch wParam and lParam to be as if VK_DELETE was
// pressed or released
wParam = VK_DELETE;
// pressed or released. when mapping the key we require that
// we not use AltGr (the 0x10000 flag in wParam) and we not
// use the keypad delete key (the 0x01000000 flag in lParam).
wParam = VK_DELETE | 0x00010000u;
lParam &= 0xfe000000;
lParam |= m_keyState->virtualKeyToButton(wParam) << 16;
lParam |= 0x00000001;
lParam |= m_keyState->virtualKeyToButton(wParam & 0xffu) << 16;
lParam |= 0x01000001;
}
// process key
@@ -978,28 +1125,28 @@ CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
KeyID key = m_keyState->mapKeyFromEvent(wParam, lParam, &mask);
button = static_cast<KeyButton>((lParam & 0x01ff0000u) >> 16);
if (key != kKeyNone) {
// fix up key. if the key isn't down according to
// fix key up. if the key isn't down according to
// our table then we never got the key press event
// for it. if it's not a modifier key then we'll
// synthesize the press first. only do this on
// the windows 95 family, which eats certain special
// keys like alt+tab, ctrl+esc, etc.
if (m_is95Family && !wasDown && up) {
if (m_is95Family && !wasDown && !down) {
switch (virtKey) {
case VK_SHIFT:
case VK_LSHIFT:
case VK_RSHIFT:
case VK_SHIFT:
case VK_CONTROL:
case VK_LCONTROL:
case VK_RCONTROL:
case VK_CONTROL:
case VK_MENU:
case VK_LMENU:
case VK_RMENU:
case VK_MENU:
case VK_LWIN:
case VK_RWIN:
case VK_CAPITAL:
case VK_NUMLOCK:
case VK_SCROLL:
case VK_LWIN:
case VK_RWIN:
break;
default:
@@ -1012,17 +1159,64 @@ CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
// do it
m_keyState->sendKeyEvent(getEventTarget(),
((lParam & 0x80000000u) == 0),
((lParam & 0x40000000u) == 1),
((lParam & 0x40000000u) != 0),
key, mask, (SInt32)(lParam & 0xffff), button);
}
else {
LOG((CLOG_DEBUG2 "event: cannot map key"));
LOG((CLOG_DEBUG1 "cannot map key"));
}
}
return true;
}
bool
CMSWindowsScreen::onHotKey(WPARAM wParam, LPARAM lParam)
{
// get the key info
KeyModifierMask state = getActiveModifiers();
UINT virtKey = (wParam & 0xffu);
UINT modifiers = 0;
if ((state & KeyModifierShift) != 0) {
modifiers |= MOD_SHIFT;
}
if ((state & KeyModifierControl) != 0) {
modifiers |= MOD_CONTROL;
}
if ((state & KeyModifierAlt) != 0) {
modifiers |= MOD_ALT;
}
if ((state & KeyModifierSuper) != 0) {
modifiers |= MOD_WIN;
}
// find the hot key id
HotKeyToIDMap::const_iterator i =
m_hotKeyToIDMap.find(CHotKeyItem(virtKey, modifiers));
if (i == m_hotKeyToIDMap.end()) {
return false;
}
// find what kind of event
CEvent::Type type;
if ((lParam & 0x80000000u) == 0u) {
if ((lParam & 0x40000000u) != 0u) {
// ignore key repeats but it counts as a hot key
return true;
}
type = getHotKeyDownEvent();
}
else {
type = getHotKeyUpEvent();
}
// generate event
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(i->second)));
return true;
}
bool
CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
{
@@ -1042,16 +1236,19 @@ CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
// ignore message if posted prior to last mark change
if (!ignore()) {
KeyModifierMask mask = m_keyState->getActiveModifiers();
if (pressed) {
LOG((CLOG_DEBUG1 "event: button press button=%d", button));
if (button != kButtonNone) {
sendEvent(getButtonDownEvent(), CButtonInfo::alloc(button));
sendEvent(getButtonDownEvent(),
CButtonInfo::alloc(button, mask));
}
}
else {
LOG((CLOG_DEBUG1 "event: button release button=%d", button));
if (button != kButtonNone) {
sendEvent(getButtonUpEvent(), CButtonInfo::alloc(button));
sendEvent(getButtonUpEvent(),
CButtonInfo::alloc(button, mask));
}
}
}
@@ -1109,12 +1306,12 @@ CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
}
bool
CMSWindowsScreen::onMouseWheel(SInt32 delta)
CMSWindowsScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
{
// ignore message if posted prior to last mark change
if (!ignore()) {
LOG((CLOG_DEBUG1 "event: button wheel delta=%d", delta));
sendEvent(getWheelEvent(), CWheelInfo::alloc(delta));
LOG((CLOG_DEBUG1 "event: button wheel delta=%+d,%+d", xDelta, yDelta));
sendEvent(getWheelEvent(), CWheelInfo::alloc(xDelta, yDelta));
}
return true;
}
@@ -1197,7 +1394,6 @@ CMSWindowsScreen::onClipboardChange()
// now notify client that somebody changed the clipboard (unless
// we're the owner).
if (!CMSWindowsClipboard::isOwnedBySynergy()) {
LOG((CLOG_DEBUG "clipboard changed: foreign owned"));
if (m_ownClipboard) {
LOG((CLOG_DEBUG "clipboard changed: lost ownership"));
m_ownClipboard = false;
@@ -1205,7 +1401,7 @@ CMSWindowsScreen::onClipboardChange()
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardSelection);
}
}
else {
else if (!m_ownClipboard) {
LOG((CLOG_DEBUG "clipboard changed: synergy owned"));
m_ownClipboard = true;
}
@@ -1282,6 +1478,34 @@ CMSWindowsScreen::updateScreenShape()
m_desks->setShape(m_x, m_y, m_w, m_h, m_xCenter, m_yCenter, m_multimon);
}
void
CMSWindowsScreen::handleFixes(const CEvent&, void*)
{
// fix clipboard chain
fixClipboardViewer();
// update keys if keyboard layouts have changed
if (m_keyState->didGroupsChange()) {
updateKeys();
}
}
void
CMSWindowsScreen::fixClipboardViewer()
{
// XXX -- disable this code for now. somehow it can cause an infinite
// recursion in the WM_DRAWCLIPBOARD handler. either we're sending
// the message to our own window or some window farther down the chain
// forwards the message to our window or a window farther up the chain.
// i'm not sure how that could happen. the m_nextClipboardWindow = NULL
// was not in the code that infinite loops and may fix the bug but i
// doubt it.
return;
ChangeClipboardChain(m_window, m_nextClipboardWindow);
m_nextClipboardWindow = NULL;
m_nextClipboardWindow = SetClipboardViewer(m_window);
}
void
CMSWindowsScreen::enableSpecialKeys(bool enable) const
{
@@ -1387,63 +1611,37 @@ CMSWindowsScreen::mapPressFromEvent(WPARAM msg, LPARAM) const
}
}
void
CMSWindowsScreen::fixKeys()
{
// fake key releases for the windows keys if we think they're
// down but they're really up. we have to do this because if the
// user presses and releases a windows key without pressing any
// other key while it's down then the system will eat the key
// release. if we don't detect that and synthesize the release
// then the client won't take the usual windows key release action
// (which on windows is to show the start menu).
//
// only check on the windows 95 family since the NT family reports
// the key releases as usual.
if (m_is95Family) {
m_keyState->fixKey(getEventTarget(), VK_LWIN);
m_keyState->fixKey(getEventTarget(), VK_RWIN);
// check if we need the fix timer anymore
scheduleFixKeys();
}
}
void
CMSWindowsScreen::scheduleFixKeys()
{
if (m_is95Family) {
// see if any keys that need fixing are down
bool fix =
(m_keyState->isKeyDown(m_keyState->virtualKeyToButton(VK_LWIN)) ||
m_keyState->isKeyDown(m_keyState->virtualKeyToButton(VK_RWIN)));
// start or stop fix timer
if (fix && m_fixTimer == NULL) {
m_fixTimer = EVENTQUEUE->newTimer(0.1, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
new TMethodEventJob<CMSWindowsScreen>(
this, &CMSWindowsScreen::handleFixKeys));
}
else if (!fix && m_fixTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
EVENTQUEUE->deleteTimer(m_fixTimer);
m_fixTimer = NULL;
}
}
}
void
CMSWindowsScreen::handleFixKeys(const CEvent&, void*)
{
fixKeys();
}
void
CMSWindowsScreen::updateKeysCB(void*)
{
m_keyState->updateKeys();
updateButtons();
// record which keys we think are down
bool down[IKeyState::kNumButtons];
bool sendFixes = (isPrimary() && !m_isOnScreen);
if (sendFixes) {
for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) {
down[i] = m_keyState->isKeyDown(i);
}
}
// update layouts if necessary
if (m_keyState->didGroupsChange()) {
CPlatformScreen::updateKeyMap();
}
// now update the keyboard state
CPlatformScreen::updateKeyState();
// now see which keys we thought were down but now think are up.
// send key releases for these keys to the active client.
if (sendFixes) {
KeyModifierMask mask = pollActiveModifiers();
for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) {
if (down[i] && !m_keyState->isKeyDown(i)) {
m_keyState->sendKeyEvent(getEventTarget(),
false, false, kKeyNone, mask, 1, i);
}
}
}
}
void
@@ -1512,3 +1710,28 @@ CMSWindowsScreen::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return result;
}
//
// CMSWindowsScreen::CHotKeyItem
//
CMSWindowsScreen::CHotKeyItem::CHotKeyItem(UINT keycode, UINT mask) :
m_keycode(keycode),
m_mask(mask)
{
// do nothing
}
UINT
CMSWindowsScreen::CHotKeyItem::getVirtualKey() const
{
return m_keycode;
}
bool
CMSWindowsScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
{
return (m_keycode < x.m_keycode ||
(m_keycode == x.m_keycode && m_mask < x.m_mask));
}

View File

@@ -28,12 +28,11 @@ class CMSWindowsDesks;
class CMSWindowsKeyState;
class CMSWindowsScreenSaver;
class CThread;
class IJob;
//! Implementation of IPlatformScreen for Microsoft Windows
class CMSWindowsScreen : public CPlatformScreen {
public:
CMSWindowsScreen(bool isPrimary, IJob* suspend, IJob* resume);
CMSWindowsScreen(bool isPrimary);
virtual ~CMSWindowsScreen();
//! @name manipulators
@@ -68,6 +67,11 @@ public:
// IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y);
virtual UInt32 registerHotKey(KeyID key,
KeyModifierMask mask);
virtual void unregisterHotKey(UInt32 id);
virtual void fakeInputBegin();
virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
@@ -76,7 +80,7 @@ public:
virtual void fakeMouseButton(ButtonID id, bool press) const;
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
virtual void fakeMouseWheel(SInt32 delta) const;
virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
// IKeyState overrides
virtual void updateKeys();
@@ -85,7 +89,7 @@ public:
virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
SInt32 count, KeyButton button);
virtual void fakeKeyUp(KeyButton button);
virtual void fakeToggle(KeyModifierMask modifier);
virtual void fakeAllKeysUp();
// IPlatformScreen overrides
virtual void enable();
@@ -139,9 +143,10 @@ private:
// message handlers
bool onMark(UInt32 mark);
bool onKey(WPARAM, LPARAM);
bool onHotKey(WPARAM, LPARAM);
bool onMouseButton(WPARAM, LPARAM);
bool onMouseMove(SInt32 x, SInt32 y);
bool onMouseWheel(SInt32 delta);
bool onMouseWheel(SInt32 xDelta, SInt32 yDelta);
bool onScreensaver(bool activated);
bool onDisplayChange();
bool onClipboardChange();
@@ -158,6 +163,12 @@ private:
// update screen size cache
void updateScreenShape();
// fix timer callback
void handleFixes(const CEvent&, void*);
// fix the clipboard viewer chain
void fixClipboardViewer();
// enable/disable special key combinations so we can catch/pass them
void enableSpecialKeys(bool) const;
@@ -167,16 +178,6 @@ private:
// map a button event to a press (true) or release (false)
bool mapPressFromEvent(WPARAM msg, LPARAM button) const;
// fix the key state, synthesizing fake key releases for keys
// that aren't down anymore.
void fixKeys();
// (un)schedule a later call to fixKeys
void scheduleFixKeys();
// event handler to fix the key state
void handleFixKeys(const CEvent&, void*);
// job to update the key state
void updateKeysCB(void*);
@@ -194,6 +195,22 @@ private:
static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
private:
struct CHotKeyItem {
public:
CHotKeyItem(UINT vk, UINT modifiers);
UINT getVirtualKey() const;
bool operator<(const CHotKeyItem&) const;
private:
UINT m_keycode;
UINT m_mask;
};
typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
typedef std::vector<UInt32> HotKeyIDList;
typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
static HINSTANCE s_instance;
// true if screen is being used as a primary screen, false otherwise
@@ -229,12 +246,12 @@ private:
// the main loop's thread id
DWORD m_threadID;
// timer for periodically checking stuff that requires polling
CEventQueueTimer* m_fixTimer;
// the keyboard layout to use when off primary screen
HKL m_keyLayout;
// the timer used to check for fixing key state
CEventQueueTimer* m_fixTimer;
// screen saver stuff
CMSWindowsScreenSaver* m_screensaver;
bool m_screensaverNotify;
@@ -260,13 +277,14 @@ private:
// keyboard stuff
CMSWindowsKeyState* m_keyState;
// hot key stuff
HotKeyMap m_hotKeys;
HotKeyIDList m_oldHotKeyIDs;
HotKeyToIDMap m_hotKeyToIDMap;
// map of button state
bool m_buttons[1 + kButtonExtra0 + 1];
// suspend/resume callbacks
IJob* m_suspend;
IJob* m_resume;
// the system shows the mouse cursor when an internal display count
// is >= 0. this count is maintained per application but there's
// apparently a system wide count added to the application's count.

View File

@@ -107,7 +107,7 @@ CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam)
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, processID);
if (process == NULL) {
// didn't start
LOG((CLOG_DEBUG "can't open screen saver process"));
LOG((CLOG_DEBUG2 "can't open screen saver process"));
return false;
}
@@ -123,7 +123,7 @@ CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam)
// we first check that the screen saver is indeed active
// before watching for it to stop.
if (!isActive()) {
LOG((CLOG_DEBUG "can't open screen saver desktop"));
LOG((CLOG_DEBUG2 "can't open screen saver desktop"));
return false;
}
@@ -441,7 +441,7 @@ void
CMSWindowsScreenSaver::setSecure(bool secure, bool saveSecureAsInt)
{
HKEY hkey =
CArchMiscWindows::openKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure);
CArchMiscWindows::addKey(HKEY_CURRENT_USER, g_pathScreenSaverIsSecure);
if (hkey == NULL) {
return;
}

View File

@@ -42,15 +42,18 @@ COSXClipboard::empty()
assert(m_scrap != NULL);
OSStatus err = ClearScrap(&m_scrap);
// XXX -- check err?
if (err != noErr) {
LOG((CLOG_DEBUG "failed to grab clipboard"));
return false;
}
// we own the clipboard
err = PutScrapFlavor(
m_scrap,
getOwnershipFlavor(),
kScrapFlavorMaskNone,
0,
0);
0);
if (err != noErr) {
LOG((CLOG_DEBUG "failed to grab clipboard"));
return false;

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,28 @@ public:
COSXKeyState();
virtual ~COSXKeyState();
//! @name modifiers
//@{
//! Handle modifier key change
/*!
Determines which modifier keys have changed and updates the modifier
state and sends key events as appropriate.
*/
void handleModifierKeys(void* target,
KeyModifierMask oldMask, KeyModifierMask newMask);
//@}
//! @name accessors
//@{
//! Convert OS X modifier mask to synergy mask
/*!
Returns the synergy modifier mask corresponding to the OS X modifier
mask in \p mask.
*/
KeyModifierMask mapModifiersFromOSX(UInt32 mask) const;
//! Map key event to keys
/*!
Converts a key event into a sequence of KeyIDs and the shadow modifier
@@ -43,80 +65,64 @@ public:
KeyButton mapKeyFromEvent(CKeyIDs& ids,
KeyModifierMask* maskOut, EventRef event) const;
//! Handle modifier key change
//! Map key and mask to native values
/*!
Determines which modifier keys have changed and updates the modifier
state and sends key events as appropriate.
Calculates mac virtual key and mask for a key \p key and modifiers
\p mask. Returns \c true if the key can be mapped, \c false otherwise.
*/
void handleModifierKeys(void* target,
KeyModifierMask oldMask, KeyModifierMask newMask);
bool mapSynergyHotKeyToMac(KeyID key, KeyModifierMask mask,
UInt32& macVirtualKey,
UInt32& macModifierMask) const;
//@}
// IKeyState overrides
virtual void setHalfDuplexMask(KeyModifierMask);
virtual bool fakeCtrlAltDel();
virtual const char* getKeyName(KeyButton) const;
virtual void sendKeyEvent(void* target,
bool press, bool isAutoRepeat,
KeyID key, KeyModifierMask mask,
SInt32 count, KeyButton button);
virtual KeyModifierMask
pollActiveModifiers() const;
virtual SInt32 pollActiveGroup() const;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
protected:
// IKeyState overrides
virtual void doUpdateKeys();
virtual void doFakeKeyEvent(KeyButton button,
bool press, bool isAutoRepeat);
virtual KeyButton mapKey(Keystrokes& keys, KeyID id,
KeyModifierMask desiredMask,
bool isAutoRepeat) const;
// CKeyState overrides
virtual void getKeyMap(CKeyMap& keyMap);
virtual void fakeKey(const Keystroke& keystroke);
private:
struct CKeyEventInfo {
public:
KeyButton m_button;
KeyModifierMask m_requiredMask;
KeyModifierMask m_requiredState;
};
typedef std::vector<CKeyEventInfo> CKeySequence;
typedef std::map<KeyID, CKeySequence> CKeyIDMap;
typedef std::map<UInt32, KeyID> CVirtualKeyMap;
typedef std::map<UInt16, std::pair<SInt32, KeyModifierMask> > CDeadKeyMap;
class CKeyResource;
typedef std::vector<KeyboardLayoutRef> GroupList;
KeyButton addKeystrokes(Keystrokes& keys,
KeyButton keyButton,
KeyModifierMask desiredMask,
KeyModifierMask requiredMask,
bool isAutoRepeat) const;
bool adjustModifiers(Keystrokes& keys,
Keystrokes& undo,
KeyModifierMask desiredMask,
KeyModifierMask requiredMask) const;
void addKeyButton(KeyButtons& keys, KeyID id) const;
void handleModifierKey(void* target, KeyID id, bool down);
// Add hard coded special keys to a CKeyMap.
void getKeyMapForSpecialKeys(
CKeyMap& keyMap, SInt32 group) const;
// Check if the keyboard layout has changed and call doUpdateKeys
// Convert keyboard resource to a key map
bool getKeyMap(CKeyMap& keyMap,
SInt32 group, const CKeyResource& r) const;
// Get the available keyboard groups
bool getGroups(GroupList&) const;
// Change active keyboard group to group
void setGroup(SInt32 group);
// Check if the keyboard layout has changed and update keyboard state
// if so.
void checkKeyboardLayout();
// Switch to a new keyboard layout.
void setKeyboardLayout(SInt16 keyboardLayoutID);
// Send an event for the given modifier key
void handleModifierKey(void* target,
UInt32 virtualKey, KeyID id,
bool down, KeyModifierMask newMask);
// Insert KeyID to key sequences for non-printing characters, like
// delete, home, up arrow, etc. and the virtual key to KeyID mapping.
void fillSpecialKeys(CKeyIDMap& keyMap,
CVirtualKeyMap& virtualKeyMap) const;
// Convert the KCHR resource to a KeyID to key sequence map. the
// map maps each KeyID to the sequence of keys (with modifiers)
// that would have to be synthesized to generate the KeyID character.
// Returns false iff no KCHR resource was found.
bool fillKCHRKeysMap(CKeyIDMap& keyMap) const;
// Convert the uchr resource to a KeyID to key sequence map. the
// map maps each KeyID to the sequence of keys (with modifiers)
// that would have to be synthesized to generate the KeyID character.
// Returns false iff no uchr resource was found or it couldn't be
// mapped.
bool filluchrKeysMap(CKeyIDMap& keyMap) const;
// Checks if any in \p ids is a glyph key and if \p isCommand is false.
// If so it adds the AltGr modifier to \p mask. This allows OS X
// servers to use the option key both as AltGr and as a modifier. If
// option is acting as AltGr (i.e. it generates a glyph and there are
// no command modifiers active) then we don't send the super modifier
// to clients because they'd try to match it as a command modifier.
void adjustAltGrModifier(const CKeyIDs& ids,
KeyModifierMask* mask, bool isCommand) const;
// Maps an OS X virtual key id to a KeyButton. This simply remaps
// the ids so we don't use KeyButton 0.
@@ -126,28 +132,89 @@ private:
// mapVirtualKeyToKeyButton.
static UInt32 mapKeyButtonToVirtualKey(KeyButton keyButton);
// Convert a character in the current script to the equivalent KeyID.
static KeyID charToKeyID(UInt8);
// Convert a unicode character to the equivalent KeyID.
static KeyID unicharToKeyID(UniChar);
// Choose the modifier mask with the fewest modifiers for character
// mapping table i. The tableSelectors table has numEntries. If
// no mapping is found for i, try mapping defaultIndex.
static KeyModifierMask
maskForTable(UInt8 i, UInt8* tableSelectors,
UInt32 numEntries, UInt8 defaultIndex);
// Save characters built from dead key sequences.
static void mapDeadKeySequence(CKeyIDMap& keyMap,
CKeySequence& sequence,
UInt16 state, const UInt8* base,
const UCKeyStateRecordsIndex* sri,
const UCKeyStateTerminators* st,
CDeadKeyMap& dkMap);
private:
class CKeyResource : public IInterface {
public:
virtual bool isValid() const = 0;
virtual UInt32 getNumModifierCombinations() const = 0;
virtual UInt32 getNumTables() const = 0;
virtual UInt32 getNumButtons() const = 0;
virtual UInt32 getTableForModifier(UInt32 mask) const = 0;
virtual KeyID getKey(UInt32 table, UInt32 button) const = 0;
// Convert a character in the current script to the equivalent KeyID
static KeyID getKeyID(UInt8);
// Convert a unicode character to the equivalent KeyID.
static KeyID unicharToKeyID(UniChar);
};
class CKCHRKeyResource : public CKeyResource {
public:
CKCHRKeyResource(const void*);
// CKeyResource overrides
virtual bool isValid() const;
virtual UInt32 getNumModifierCombinations() const;
virtual UInt32 getNumTables() const;
virtual UInt32 getNumButtons() const;
virtual UInt32 getTableForModifier(UInt32 mask) const;
virtual KeyID getKey(UInt32 table, UInt32 button) const;
private:
struct KCHRResource {
public:
SInt16 m_version;
UInt8 m_tableSelectionIndex[256];
SInt16 m_numTables;
UInt8 m_characterTables[1][128];
};
struct CKCHRDeadKeyRecord {
public:
UInt8 m_tableIndex;
UInt8 m_virtualKey;
SInt16 m_numCompletions;
UInt8 m_completion[1][2];
};
struct CKCHRDeadKeys {
public:
SInt16 m_numRecords;
CKCHRDeadKeyRecord m_records[1];
};
const KCHRResource* m_resource;
};
class CUCHRKeyResource : public CKeyResource {
public:
CUCHRKeyResource(const void*, UInt32 keyboardType);
// CKeyResource overrides
virtual bool isValid() const;
virtual UInt32 getNumModifierCombinations() const;
virtual UInt32 getNumTables() const;
virtual UInt32 getNumButtons() const;
virtual UInt32 getTableForModifier(UInt32 mask) const;
virtual KeyID getKey(UInt32 table, UInt32 button) const;
private:
typedef std::vector<KeyID> KeySequence;
bool getDeadKey(KeySequence& keys, UInt16 index) const;
bool getKeyRecord(KeySequence& keys,
UInt16 index, UInt16& state) const;
bool addSequence(KeySequence& keys, UCKeyCharSeq c) const;
private:
const UCKeyboardLayout* m_resource;
const UCKeyModifiersToTableNum* m_m;
const UCKeyToCharTableIndex* m_cti;
const UCKeySequenceDataIndex* m_sdi;
const UCKeyStateRecordsIndex* m_sri;
const UCKeyStateTerminators* m_st;
UInt16 m_spaceOutput;
};
// OS X uses a physical key if 0 for the 'A' key. synergy reserves
// KeyButton 0 so we offset all OS X physical key ids by this much
// when used as a KeyButton and by minus this much to map a KeyButton
@@ -156,25 +223,13 @@ private:
KeyButtonOffset = 1
};
// KCHR resource header
struct CKCHRResource {
public:
SInt16 m_version;
UInt8 m_tableSelectionIndex[256];
SInt16 m_numTables;
UInt8 m_characterTables[1][128];
};
typedef std::map<KeyboardLayoutRef, SInt32> GroupMap;
typedef std::map<UInt32, KeyID> CVirtualKeyMap;
SInt16 m_keyboardLayoutID;
UInt32 m_keyboardType;
mutable UInt32 m_deadKeyState;
Handle m_KCHRHandle;
Handle m_uchrHandle;
CKCHRResource* m_KCHRResource;
UCKeyboardLayout* m_uchrResource;
CKeyIDMap m_keyMap;
CVirtualKeyMap m_virtualKeyMap;
bool m_uchrFound;
mutable UInt32 m_deadKeyState;
GroupList m_groups;
GroupMap m_groupMap;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -16,9 +16,21 @@
#define COSXSCREEN_H
#include "CPlatformScreen.h"
#include "stdmap.h"
#include "stdvector.h"
#include <Carbon/Carbon.h>
#include <mach/mach_port.h>
#include <mach/mach_interface.h>
#include <mach/mach_init.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
template <class T>
class CCondVar;
class CEventQueueTimer;
class CMutex;
class CThread;
class COSXKeyState;
class COSXScreenSaver;
@@ -38,6 +50,10 @@ public:
// IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y);
virtual UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
virtual void unregisterHotKey(UInt32 id);
virtual void fakeInputBegin();
virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
@@ -46,7 +62,7 @@ public:
virtual void fakeMouseButton(ButtonID id, bool press) const;
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
virtual void fakeMouseWheel(SInt32 delta) const;
virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
// IPlatformScreen overrides
virtual void enable();
@@ -71,7 +87,7 @@ protected:
private:
void updateScreenShape();
void postMouseEvent(const CGPoint &) const;
void postMouseEvent(CGPoint&) const;
// convenience function to send events
void sendEvent(CEvent::Type type, void* = NULL) const;
@@ -82,25 +98,83 @@ private:
// mouse button handler. pressed is true if this is a mousedown
// event, false if it is a mouseup event. macButton is the index
// of the button pressed using the mac button mapping.
bool onMouseButton(bool pressed, UInt16 macButton) const;
bool onMouseWheel(SInt32 delta) const;
bool onMouseButton(bool pressed, UInt16 macButton);
bool onMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
bool onDisplayChange();
bool onKey(EventRef event) const;
bool onKey(EventRef event);
bool onHotKey(EventRef event) const;
// map mac mouse button to synergy buttons
ButtonID mapMacButtonToSynergy(UInt16) const;
// map mac modifier mask to synergy modifier mask
KeyModifierMask mapMacModifiersToSynergy(EventRef event) const;
/// Resolution switch callback
// map mac scroll wheel value to a synergy scroll wheel value
SInt32 mapScrollWheelToSynergy(SInt32) const;
// map synergy scroll wheel value to a mac scroll wheel value
SInt32 mapScrollWheelFromSynergy(SInt32) const;
// get the current scroll wheel speed
double getScrollSpeed() const;
// get the current scroll wheel speed
double getScrollSpeedFactor() const;
// enable/disable drag handling for buttons 3 and up
void enableDragTimer(bool enable);
// drag timer handler
void handleDrag(const CEvent&, void*);
// clipboard check timer handler
void handleClipboardCheck(const CEvent&, void*);
// Resolution switch callback
static pascal void displayManagerCallback(void* inUserData,
SInt16 inMessage, void* inNotifyData);
// fast user switch callback
static pascal OSStatus
userSwitchCallback(EventHandlerCallRef nextHandler,
EventRef theEvent, void* inUserData);
// sleep / wakeup support
void watchSystemPowerThread(void*);
static void testCanceled(CFRunLoopTimerRef timer, void*info);
static void powerChangeCallback(void* refcon, io_service_t service,
natural_t messageType, void* messageArgument);
void handlePowerChangeRequest(natural_t messageType,
void* messageArgument);
static CEvent::Type getConfirmSleepEvent();
void handleConfirmSleep(const CEvent& event, void*);
// global hotkey operating mode
static bool isGlobalHotKeyOperatingModeAvailable();
static void setGlobalHotKeysEnabled(bool enabled);
static bool getGlobalHotKeysEnabled();
private:
struct CHotKeyItem {
public:
CHotKeyItem(UInt32, UInt32);
CHotKeyItem(EventHotKeyRef, UInt32, UInt32);
EventHotKeyRef getRef() const;
bool operator<(const CHotKeyItem&) const;
private:
EventHotKeyRef m_ref;
UInt32 m_keycode;
UInt32 m_mask;
};
typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
typedef std::vector<UInt32> HotKeyIDList;
typedef std::map<KeyModifierMask, UInt32> ModifierHotKeyMap;
typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
// true if screen is being used as a primary screen, false otherwise
bool m_isPrimary;
@@ -120,6 +194,9 @@ private:
mutable bool m_cursorPosValid;
mutable boolean_t m_buttons[5];
bool m_cursorHidden;
SInt32 m_dragNumButtonsDown;
Point m_dragLastPoint;
CEventQueueTimer* m_dragTimer;
// keyboard stuff
COSXKeyState* m_keyState;
@@ -133,17 +210,43 @@ private:
// clipboard stuff
bool m_ownClipboard;
CEventQueueTimer* m_clipboardTimer;
// window object that gets user input events when the server
// has focus.
WindowRef m_hiddenWindow;
// window object that gets user input events when the server
// does not have focus.
WindowRef m_userInputWindow;
// display manager stuff (to get screen resolution switches).
DMExtendedNotificationUPP m_displayManagerNotificationUPP;
ProcessSerialNumber m_PSN;
// fast user switching
EventHandlerRef m_switchEventHandlerRef;
// sleep / wakeup
CMutex* m_pmMutex;
CThread* m_pmWatchThread;
CCondVar<bool>* m_pmThreadReady;
CFRunLoopRef m_pmRunloop;
io_connect_t m_pmRootPort;
// hot key stuff
HotKeyMap m_hotKeys;
HotKeyIDList m_oldHotKeyIDs;
ModifierHotKeyMap m_modifierHotKeys;
UInt32 m_activeModifierHotKey;
KeyModifierMask m_activeModifierHotKeyMask;
HotKeyToIDMap m_hotKeyToIDMap;
// global hotkey operating mode
static bool s_testedForGHOM;
static bool s_hasGHOM;
// events
static CEvent::Type s_confirmSleepEvent;
};
#endif

View File

@@ -12,45 +12,164 @@
* GNU General Public License for more details.
*/
#include "COSXScreenSaver.h"
#include <Carbon/Carbon.h>
// FIXME -- implement this
#import "COSXScreenSaver.h"
#import "COSXScreenSaverUtil.h"
#import "CLog.h"
#import "IEventQueue.h"
#import "IPrimaryScreen.h"
#import <string.h>
//
// COSXScreenSaver
//
COSXScreenSaver::COSXScreenSaver()
COSXScreenSaver::COSXScreenSaver(void* eventTarget) :
m_eventTarget(eventTarget),
m_enabled(true)
{
m_autoReleasePool = screenSaverUtilCreatePool();
m_screenSaverController = screenSaverUtilCreateController();
// install launch/termination event handlers
EventTypeSpec launchEventTypes[2];
launchEventTypes[0].eventClass = kEventClassApplication;
launchEventTypes[0].eventKind = kEventAppLaunched;
launchEventTypes[1].eventClass = kEventClassApplication;
launchEventTypes[1].eventKind = kEventAppTerminated;
EventHandlerUPP launchTerminationEventHandler =
NewEventHandlerUPP(launchTerminationCallback);
InstallApplicationEventHandler(launchTerminationEventHandler, 2,
launchEventTypes, this,
&m_launchTerminationEventHandlerRef);
DisposeEventHandlerUPP(launchTerminationEventHandler);
m_screenSaverPSN.highLongOfPSN = 0;
m_screenSaverPSN.lowLongOfPSN = 0;
// test if screensaver is running and find process number
if (isActive()) {
ProcessInfoRec procInfo;
Str31 procName; // pascal string. first byte holds length.
memset(&procInfo, 0, sizeof(procInfo));
procInfo.processName = procName;
procInfo.processInfoLength = sizeof(ProcessInfoRec);
ProcessSerialNumber psn;
OSErr err = GetNextProcess(&psn);
while (err == 0) {
memset(procName, 0, sizeof(procName));
err = GetProcessInformation(&psn, &procInfo);
if (err != 0) {
break;
}
if (strcmp("ScreenSaverEngine", (const char*)&procName[1]) == 0) {
m_screenSaverPSN = psn;
break;
}
err = GetNextProcess(&psn);
}
}
}
COSXScreenSaver::~COSXScreenSaver()
{
RemoveEventHandler(m_launchTerminationEventHandlerRef);
// screenSaverUtilReleaseController(m_screenSaverController);
screenSaverUtilReleasePool(m_autoReleasePool);
}
void
COSXScreenSaver::enable()
{
m_enabled = true;
screenSaverUtilEnable(m_screenSaverController);
}
void
COSXScreenSaver::disable()
{
m_enabled = false;
screenSaverUtilDisable(m_screenSaverController);
}
void
COSXScreenSaver::activate()
{
screenSaverUtilActivate(m_screenSaverController);
}
void
COSXScreenSaver::deactivate()
{
screenSaverUtilDeactivate(m_screenSaverController, m_enabled);
}
bool
COSXScreenSaver::isActive() const
{
return false;
return (screenSaverUtilIsActive(m_screenSaverController) != 0);
}
void
COSXScreenSaver::processLaunched(ProcessSerialNumber psn)
{
CFStringRef processName;
OSStatus err = CopyProcessName(&psn, &processName);
if (err == 0 && CFEqual(CFSTR("ScreenSaverEngine"), processName)) {
m_screenSaverPSN = psn;
LOG((CLOG_DEBUG1 "ScreenSaverEngine launched. Enabled=%d", m_enabled));
if (m_enabled) {
EVENTQUEUE->addEvent(
CEvent(IPrimaryScreen::getScreensaverActivatedEvent(),
m_eventTarget));
}
}
}
void
COSXScreenSaver::processTerminated(ProcessSerialNumber psn)
{
if (m_screenSaverPSN.highLongOfPSN == psn.highLongOfPSN &&
m_screenSaverPSN.lowLongOfPSN == psn.lowLongOfPSN) {
LOG((CLOG_DEBUG1 "ScreenSaverEngine terminated. Enabled=%d", m_enabled));
if (m_enabled) {
EVENTQUEUE->addEvent(
CEvent(IPrimaryScreen::getScreensaverDeactivatedEvent(),
m_eventTarget));
}
m_screenSaverPSN.highLongOfPSN = 0;
m_screenSaverPSN.lowLongOfPSN = 0;
}
}
pascal OSStatus
COSXScreenSaver::launchTerminationCallback(
EventHandlerCallRef nextHandler,
EventRef theEvent, void* userData)
{
OSStatus result;
ProcessSerialNumber psn;
EventParamType actualType;
UInt32 actualSize;
result = GetEventParameter(theEvent, kEventParamProcessID,
typeProcessSerialNumber, &actualType,
sizeof(psn), &actualSize, &psn);
if ((result == noErr) &&
(actualSize > 0) &&
(actualType == typeProcessSerialNumber)) {
COSXScreenSaver* screenSaver = (COSXScreenSaver*)userData;
UInt32 eventKind = GetEventKind(theEvent);
if (eventKind == kEventAppLaunched) {
screenSaver->processLaunched(psn);
}
else if (eventKind == kEventAppTerminated) {
screenSaver->processTerminated(psn);
}
}
return (CallNextEventHandler(nextHandler, theEvent));
}

View File

@@ -16,11 +16,12 @@
#define COSXSCREENSAVER_H
#include "IScreenSaver.h"
#include <Carbon/Carbon.h>
//! OSX screen saver implementation
class COSXScreenSaver : public IScreenSaver {
public:
COSXScreenSaver();
COSXScreenSaver(void* eventTarget);
virtual ~COSXScreenSaver();
// IScreenSaver overrides
@@ -29,6 +30,25 @@ public:
virtual void activate();
virtual void deactivate();
virtual bool isActive() const;
private:
void processLaunched(ProcessSerialNumber psn);
void processTerminated(ProcessSerialNumber psn);
static pascal OSStatus
launchTerminationCallback(
EventHandlerCallRef nextHandler,
EventRef theEvent, void* userData);
private:
// the target for the events we generate
void* m_eventTarget;
bool m_enabled;
void* m_screenSaverController;
void* m_autoReleasePool;
EventHandlerRef m_launchTerminationEventHandlerRef;
ProcessSerialNumber m_screenSaverPSN;
};
#endif

View File

@@ -0,0 +1,39 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef COSXSCREENSAVERUTIL_H
#define COSXSCREENSAVERUTIL_H
#include "common.h"
#if defined(__cplusplus)
extern "C" {
#endif
void* screenSaverUtilCreatePool();
void screenSaverUtilReleasePool(void*);
void* screenSaverUtilCreateController();
void screenSaverUtilReleaseController(void*);
void screenSaverUtilEnable(void*);
void screenSaverUtilDisable(void*);
void screenSaverUtilActivate(void*);
void screenSaverUtilDeactivate(void*, int isEnabled);
int screenSaverUtilIsActive(void*);
#if defined(__cplusplus)
}
#endif
#endif

View File

@@ -0,0 +1,81 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2004 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#import "COSXScreenSaverUtil.h"
#import "OSXScreenSaverControl.h"
#import <Foundation/NSAutoreleasePool.h>
//
// screenSaverUtil functions
//
// Note: these helper functions exist only so we can avoid using ObjC++.
// autoconf/automake don't know about ObjC++ and I don't know how to
// teach them about it.
//
void*
screenSaverUtilCreatePool()
{
return [[NSAutoreleasePool alloc] init];
}
void
screenSaverUtilReleasePool(void* pool)
{
[(NSAutoreleasePool*)pool release];
}
void*
screenSaverUtilCreateController()
{
return [[ScreenSaverController controller] retain];
}
void
screenSaverUtilReleaseController(void* controller)
{
[(ScreenSaverController*)controller release];
}
void
screenSaverUtilEnable(void* controller)
{
[(ScreenSaverController*)controller setScreenSaverCanRun:YES];
}
void
screenSaverUtilDisable(void* controller)
{
[(ScreenSaverController*)controller setScreenSaverCanRun:NO];
}
void
screenSaverUtilActivate(void* controller)
{
[(ScreenSaverController*)controller setScreenSaverCanRun:YES];
[(ScreenSaverController*)controller screenSaverStartNow];
}
void
screenSaverUtilDeactivate(void* controller, int isEnabled)
{
[(ScreenSaverController*)controller screenSaverStopNow];
[(ScreenSaverController*)controller setScreenSaverCanRun:isEnabled];
}
int
screenSaverUtilIsActive(void* controller)
{
return [(ScreenSaverController*)controller screenSaverIsRunning];
}

View File

@@ -59,8 +59,8 @@ typedef struct tagMOUSEHOOKSTRUCTWin2000 {
#define WM_NCXBUTTONDOWN 0x00AB
#define WM_NCXBUTTONUP 0x00AC
#define WM_NCXBUTTONDBLCLK 0x00AD
#define MOUSEEVENTF_XDOWN 0x0100
#define MOUSEEVENTF_XUP 0x0200
#define MOUSEEVENTF_XDOWN 0x0080
#define MOUSEEVENTF_XUP 0x0100
#define XBUTTON1 0x0001
#define XBUTTON2 0x0002
#endif
@@ -96,10 +96,10 @@ static SInt32 g_wScreen = 0;
static SInt32 g_hScreen = 0;
static WPARAM g_deadVirtKey = 0;
static LPARAM g_deadLParam = 0;
static WPARAM g_oldDeadVirtKey = 0;
static BYTE g_deadKeyState[256] = { 0 };
static DWORD g_hookThread = 0;
static DWORD g_attachedThread = 0;
static bool g_fakeInput = false;
#if defined(_MSC_VER)
#pragma data_seg()
@@ -161,192 +161,213 @@ attachThreadToForeground()
#if !NO_GRAB_KEYBOARD
static
WPARAM
makeKeyMsg(UINT virtKey, char c)
makeKeyMsg(UINT virtKey, char c, bool noAltGr)
{
return MAKEWPARAM(MAKEWORD(virtKey & 0xff, (BYTE)c), 0);
return MAKEWPARAM(MAKEWORD(virtKey & 0xff, (BYTE)c), noAltGr ? 1 : 0);
}
static
void
keyboardGetState(BYTE keys[256])
{
if (g_hookThread != 0) {
GetKeyboardState(keys);
}
else {
SHORT key;
for (int i = 0; i < 256; ++i) {
key = GetAsyncKeyState(i);
keys[i] = (BYTE)((key < 0) ? 0x80u : 0);
}
key = GetKeyState(VK_CAPITAL);
keys[VK_CAPITAL] = (BYTE)(((key < 0) ? 0x80 : 0) | (key & 1));
// we have to use GetAsyncKeyState() rather than GetKeyState() because
// we don't pass through most keys so the event synchronous state
// doesn't get updated. we do that because certain modifier keys have
// side effects, like alt and the windows key.
SHORT key;
for (int i = 0; i < 256; ++i) {
key = GetAsyncKeyState(i);
keys[i] = (BYTE)((key < 0) ? 0x80u : 0);
}
key = GetKeyState(VK_CAPITAL);
keys[VK_CAPITAL] = (BYTE)(((key < 0) ? 0x80 : 0) | (key & 1));
}
static
bool
doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
{
// check for dead keys. we don't forward those to our window.
// instead we'll leave the key in the keyboard layout (a buffer
// internal to the system) for translation when the next key is
// pressed. note that some systems set bit 31 to indicate a
// dead key and others bit 15. nice.
UINT c = MapVirtualKey(wParam, 2);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x00000000, c);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | (c << 8) | 0x01000000, lParam);
if ((c & 0x80008000u) != 0) {
if ((lParam & 0x80000000u) == 0) {
if (g_deadVirtKey == 0) {
// dead key press, no dead key in the buffer
g_deadVirtKey = wParam;
g_deadLParam = lParam;
keyboardGetState(g_deadKeyState);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x02000000, lParam);
return false;
}
// second dead key press in a row so let it pass
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x03000000, lParam);
}
else if (wParam == g_oldDeadVirtKey) {
// dead key release for second dead key in a row. discard
// because we've already handled it. also take it out of
// the keyboard buffer.
g_oldDeadVirtKey = 0;
WORD c;
UINT scanCode = ((lParam & 0x00ff0000u) >> 16);
ToAscii(wParam, scanCode, g_deadKeyState, &c, 0);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x09000000, lParam);
return true;
}
else {
// dead key release
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x04000000, lParam);
// check for special events indicating if we should start or stop
// passing events through and not report them to the server. this
// is used to allow the server to synthesize events locally but
// not pick them up as user events.
if (wParam == SYNERGY_HOOK_FAKE_INPUT_VIRTUAL_KEY &&
((lParam >> 16) & 0xffu) == SYNERGY_HOOK_FAKE_INPUT_SCANCODE) {
// update flag
g_fakeInput = ((lParam & 0x80000000u) == 0);
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
0xff000000u | wParam, lParam);
// discard event
return true;
}
// if we're expecting fake input then just pass the event through
// and do not forward to the server
if (g_fakeInput) {
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
0xfe000000u | wParam, lParam);
return false;
}
// VK_RSHIFT may be sent with an extended scan code but right shift
// is not an extended key so we reset that bit.
if (wParam == VK_RSHIFT) {
lParam &= ~0x01000000u;
}
// tell server about event
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG, wParam, lParam);
// ignore dead key release
if (g_deadVirtKey == wParam &&
(lParam & 0x80000000u) != 0) {
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x04000000, lParam);
return false;
}
// we need the keyboard state for ToAscii()
BYTE keys[256];
keyboardGetState(keys);
// ToAscii() maps ctrl+letter to the corresponding control code
// and ctrl+backspace to delete. we don't want those translations
// so clear the control modifier state. however, if we want to
// simulate AltGr (which is ctrl+alt) then we must not clear it.
UINT control = keys[VK_CONTROL] | keys[VK_LCONTROL] | keys[VK_RCONTROL];
UINT menu = keys[VK_MENU] | keys[VK_LMENU] | keys[VK_RMENU];
if ((control & 0x80) == 0 || (menu & 0x80) == 0) {
keys[VK_LCONTROL] = 0;
keys[VK_RCONTROL] = 0;
keys[VK_CONTROL] = 0;
}
else {
keys[VK_LCONTROL] = 0x80;
keys[VK_RCONTROL] = 0x80;
keys[VK_CONTROL] = 0x80;
keys[VK_LMENU] = 0x80;
keys[VK_RMENU] = 0x80;
keys[VK_MENU] = 0x80;
}
// ToAscii() needs to know if a menu is active for some reason.
// we don't know and there doesn't appear to be any way to find
// out. so we'll just assume a menu is active if the menu key
// is down.
// FIXME -- figure out some way to check if a menu is active
UINT flags = 0;
if ((menu & 0x80) != 0)
flags |= 1;
// if we're on the server screen then just pass numpad keys with alt
// key down as-is. we won't pick up the resulting character but the
// local app will. if on a client screen then grab keys as usual;
// if the client is a windows system it'll synthesize the expected
// character. if not then it'll probably just do nothing.
if (g_mode != kHOOK_RELAY_EVENTS) {
// we don't use virtual keys because we don't know what the
// state of the numlock key is. we'll hard code the scan codes
// instead. hopefully this works across all keyboards.
UINT sc = (lParam & 0x01ff0000u) >> 16;
if (menu &&
(sc >= 0x47u && sc <= 0x52u && sc != 0x4au && sc != 0x4eu)) {
return false;
}
}
// convert key to a character. this combines a saved dead key,
// if any, with this key. however, the dead key must remain in
// the keyboard layout for the application receiving this event
// so it can also convert the key to a character. we only do
// this on a key press.
WPARAM charAndVirtKey = (wParam & 0xffu);
if (c != 0) {
// we need the keyboard state for ToAscii()
BYTE keys[256];
keyboardGetState(keys);
// ToAscii() maps ctrl+letter to the corresponding control code
// and ctrl+backspace to delete. we don't want those translations
// so clear the control modifier state. however, if we want to
// simulate AltGr (which is ctrl+alt) then we must not clear it.
UINT control = keys[VK_CONTROL] | keys[VK_LCONTROL] | keys[VK_RCONTROL];
UINT menu = keys[VK_MENU] | keys[VK_LMENU] | keys[VK_RMENU];
if ((control & 0x80) == 0 || (menu & 0x80) == 0) {
keys[VK_LCONTROL] = 0;
keys[VK_RCONTROL] = 0;
keys[VK_CONTROL] = 0;
}
else {
keys[VK_LCONTROL] = 0x80;
keys[VK_RCONTROL] = 0x80;
keys[VK_CONTROL] = 0x80;
keys[VK_LMENU] = 0x80;
keys[VK_RMENU] = 0x80;
keys[VK_MENU] = 0x80;
}
// ToAscii() needs to know if a menu is active for some reason.
// we don't know and there doesn't appear to be any way to find
// out. so we'll just assume a menu is active if the menu key
// is down.
// FIXME -- figure out some way to check if a menu is active
UINT flags = 0;
if ((menu & 0x80) != 0)
flags |= 1;
// map the key event to a character. this has the side
// effect of removing the dead key from the system's keyboard
// layout buffer.
WORD c = 0;
UINT scanCode = ((lParam & 0x00ff0000u) >> 16);
int n = ToAscii(wParam, scanCode, keys, &c, flags);
// if mapping failed and ctrl and alt are pressed then try again
// with both not pressed. this handles the case where ctrl and
// alt are being used as individual modifiers rather than AltGr.
// we have to put the dead key back first, if there was one.
if (n == 0 && (control & 0x80) != 0 && (menu & 0x80) != 0) {
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x05000000, lParam);
if (g_deadVirtKey != 0) {
ToAscii(g_deadVirtKey, (g_deadLParam & 0x00ff0000u) >> 16,
g_deadKeyState, &c, flags);
}
keys[VK_LCONTROL] = 0;
keys[VK_RCONTROL] = 0;
keys[VK_CONTROL] = 0;
keys[VK_LMENU] = 0;
keys[VK_RMENU] = 0;
keys[VK_MENU] = 0;
n = ToAscii(wParam, scanCode, keys, &c, flags);
}
// map the key event to a character. we have to put the dead
// key back first and this has the side effect of removing it.
if (g_deadVirtKey != 0) {
WORD c = 0;
ToAscii(g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
g_deadKeyState, &c, flags);
}
WORD c = 0;
UINT scanCode = ((lParam & 0x10ff0000u) >> 16);
int n = ToAscii(wParam, scanCode, keys, &c, flags);
// if mapping failed and ctrl and alt are pressed then try again
// with both not pressed. this handles the case where ctrl and
// alt are being used as individual modifiers rather than AltGr.
// we note that's the case in the message sent back to synergy
// because there's no simple way to deduce it after the fact.
// we have to put the dead key back first, if there was one.
bool noAltGr = false;
if (n == 0 && (control & 0x80) != 0 && (menu & 0x80) != 0) {
noAltGr = true;
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | (c << 8) | ((n & 0xff) << 16) | 0x06000000,
wParam | 0x05000000, lParam);
if (g_deadVirtKey != 0) {
ToAscii(g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
g_deadKeyState, &c, flags);
}
BYTE keys2[256];
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) {
keys2[i] = keys[i];
}
keys2[VK_LCONTROL] = 0;
keys2[VK_RCONTROL] = 0;
keys2[VK_CONTROL] = 0;
keys2[VK_LMENU] = 0;
keys2[VK_RMENU] = 0;
keys2[VK_MENU] = 0;
n = ToAscii(wParam, scanCode, keys2, &c, flags);
}
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | ((c & 0xff) << 8) |
((n & 0xff) << 16) | 0x06000000,
lParam);
switch (n) {
default:
// key is a dead key; we're not expecting this since we
// bailed out above for any dead key.
g_deadVirtKey = wParam;
g_deadLParam = lParam;
break;
WPARAM charAndVirtKey = 0;
bool clearDeadKey = false;
switch (n) {
default:
// key is a dead key
g_deadVirtKey = wParam;
g_deadLParam = lParam;
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) {
g_deadKeyState[i] = keys[i];
}
break;
case 0:
// key doesn't map to a character. this can happen if
// non-character keys are pressed after a dead key.
break;
case 0:
// key doesn't map to a character. this can happen if
// non-character keys are pressed after a dead key.
charAndVirtKey = makeKeyMsg(wParam, (char)0, noAltGr);
break;
case 1:
// key maps to a character composed with dead key
charAndVirtKey = makeKeyMsg(wParam, (char)LOBYTE(c));
break;
case 1:
// key maps to a character composed with dead key
charAndVirtKey = makeKeyMsg(wParam, (char)LOBYTE(c), noAltGr);
clearDeadKey = true;
break;
case 2: {
// previous dead key not composed. send a fake key press
// and release for the dead key to our window.
WPARAM deadCharAndVirtKey =
makeKeyMsg(g_deadVirtKey, (char)LOBYTE(c));
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY,
case 2: {
// previous dead key not composed. send a fake key press
// and release for the dead key to our window.
WPARAM deadCharAndVirtKey =
makeKeyMsg(g_deadVirtKey, (char)LOBYTE(c), noAltGr);
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY,
deadCharAndVirtKey, g_deadLParam & 0x7fffffffu);
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY,
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY,
deadCharAndVirtKey, g_deadLParam | 0x80000000u);
// use uncomposed character
charAndVirtKey = makeKeyMsg(wParam, (char)HIBYTE(c));
break;
}
}
// use uncomposed character
charAndVirtKey = makeKeyMsg(wParam, (char)HIBYTE(c), noAltGr);
clearDeadKey = true;
break;
}
}
// put back the dead key, if any, for the application to use
if (g_deadVirtKey != 0) {
ToAscii(g_deadVirtKey, (g_deadLParam & 0x00ff0000u) >> 16,
// put back the dead key, if any, for the application to use
if (g_deadVirtKey != 0) {
ToAscii(g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
g_deadKeyState, &c, flags);
for (int i = 0; i < 256; ++i) {
g_deadKeyState[i] = 0;
}
}
}
// clear out old dead key state
// clear out old dead key state
if (clearDeadKey) {
g_deadVirtKey = 0;
g_deadLParam = 0;
}
@@ -355,19 +376,12 @@ doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
// forwarding events to clients because this'll keep our thread's
// key state table up to date. that's important for querying
// the scroll lock toggle state.
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
charAndVirtKey | 0x07000000, lParam);
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY, charAndVirtKey, lParam);
// send fake key release if the user just pressed two dead keys
// in a row, otherwise we'll lose the release because we always
// return from the top of this function for all dead key releases.
if ((c & 0x80008000u) != 0) {
g_oldDeadVirtKey = wParam;
// XXX -- with hot keys for actions we may only need to do this when
// forwarding.
if (charAndVirtKey != 0) {
PostThreadMessage(g_threadID, SYNERGY_MSG_DEBUG,
wParam | 0x08000000, lParam);
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY,
charAndVirtKey, lParam | 0x80000000u);
charAndVirtKey | 0x07000000, lParam);
PostThreadMessage(g_threadID, SYNERGY_MSG_KEY, charAndVirtKey, lParam);
}
if (g_mode == kHOOK_RELAY_EVENTS) {
@@ -381,32 +395,14 @@ doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
// lights may not stay synchronized.
break;
case VK_SHIFT:
case VK_LSHIFT:
case VK_RSHIFT:
// pass the shift modifiers. if we don't do this
// we may not get the right dead key when caps lock
// is on. for example, on the french layout (with
// english keycaps) on caps lock then press shift + [
// and q. instead of an A with ^ above it you get an
// A with dots above it.
break;
case VK_CONTROL:
case VK_LCONTROL:
case VK_RCONTROL:
case VK_MENU:
case VK_LMENU:
case VK_RMENU:
case VK_HANGUL:
// pass the control and alt modifiers if using a low
// level hook, discard them if not.
// pass these modifiers if using a low level hook, discard
// them if not.
if (g_hookThread == 0) {
return true;
}
break;
default:
// discard
return true;
@@ -531,7 +527,7 @@ static
bool
mouseHookHandler(WPARAM wParam, SInt32 x, SInt32 y, SInt32 data)
{
attachThreadToForeground();
// attachThreadToForeground();
return doMouseHookHandler(wParam, x, y, data);
}
@@ -804,7 +800,7 @@ init(DWORD threadID)
// save thread id. we'll post messages to this thread's
// message queue.
g_threadID = threadID;
g_threadID = threadID;
// set defaults
g_mode = kHOOK_DISABLE;
@@ -847,6 +843,9 @@ install()
g_deadVirtKey = 0;
g_deadLParam = 0;
// reset fake input flag
g_fakeInput = false;
// check for mouse wheel support
g_wheelSupport = getWheelSupport();

View File

@@ -38,6 +38,9 @@
#define SYNERGY_MSG_INPUT_LAST SYNERGY_MSG_PRE_WARP
#define SYNERGY_HOOK_LAST_MSG SYNERGY_MSG_DEBUG
#define SYNERGY_HOOK_FAKE_INPUT_VIRTUAL_KEY VK_CANCEL
#define SYNERGY_HOOK_FAKE_INPUT_SCANCODE 0
extern "C" {
enum EHookResult {

View File

@@ -503,11 +503,10 @@ CXWindowsClipboard::icccmFillCache()
(target != m_atomAtom && target != m_atomTargets)) {
LOG((CLOG_DEBUG1 "selection doesn't support TARGETS"));
data = "";
target = XA_STRING;
data.append(reinterpret_cast<char*>(&target), sizeof(target));
CXWindowsUtil::appendAtomData(data, XA_STRING);
}
CXWindowsUtil::convertAtomProperty(data);
const Atom* targets = reinterpret_cast<const Atom*>(data.data());
const UInt32 numTargets = data.size() / sizeof(Atom);
LOG((CLOG_DEBUG " available targets: %s", CXWindowsUtil::atomsToString(m_display, targets, numTargets).c_str()));
@@ -525,12 +524,18 @@ CXWindowsClipboard::icccmFillCache()
// see if atom is in target list
Atom target = None;
// XXX -- just ask for the converter's target to see if it's
// available rather than checking TARGETS. i've seen clipboard
// owners that don't report all the targets they support.
target = converter->getAtom();
/*
for (UInt32 i = 0; i < numTargets; ++i) {
if (converter->getAtom() == targets[i]) {
target = targets[i];
break;
}
}
*/
if (target == None) {
continue;
}
@@ -661,7 +666,7 @@ CXWindowsClipboard::motifOwnsClipboard() const
reinterpret_cast<const CMotifClipHeader*>(data.data());
if (data.size() >= sizeof(CMotifClipHeader) &&
header->m_id == kMotifClipHeader) {
if (header->m_selectionOwner == owner) {
if (static_cast<Window>(header->m_selectionOwner) == owner) {
return true;
}
}
@@ -835,12 +840,12 @@ CXWindowsClipboard::insertMultipleReply(Window requestor,
}
// fail if the requested targets isn't of the correct form
if (format != 32 ||
target != m_atomAtomPair) {
if (format != 32 || target != m_atomAtomPair) {
return false;
}
// data is a list of atom pairs: target, property
CXWindowsUtil::convertAtomProperty(data);
const Atom* targets = reinterpret_cast<const Atom*>(data.data());
const UInt32 numTargets = data.size() / sizeof(Atom);
@@ -851,10 +856,7 @@ CXWindowsClipboard::insertMultipleReply(Window requestor,
const Atom property = targets[i + 1];
if (!addSimpleRequest(requestor, target, time, property)) {
// note that we can't perform the requested conversion
static const Atom none = None;
data.replace(i * sizeof(Atom), sizeof(Atom),
reinterpret_cast<const char*>(&none),
sizeof(Atom));
CXWindowsUtil::replaceAtomData(data, i, None);
changed = true;
}
}
@@ -900,16 +902,18 @@ CXWindowsClipboard::insertReply(CReply* reply)
if (newWindow) {
// note errors while we adjust event masks
bool error = false;
CXWindowsUtil::CErrorLock lock(m_display, &error);
{
CXWindowsUtil::CErrorLock lock(m_display, &error);
// get and save the current event mask
XWindowAttributes attr;
XGetWindowAttributes(m_display, reply->m_requestor, &attr);
m_eventMasks[reply->m_requestor] = attr.your_event_mask;
// get and save the current event mask
XWindowAttributes attr;
XGetWindowAttributes(m_display, reply->m_requestor, &attr);
m_eventMasks[reply->m_requestor] = attr.your_event_mask;
// add the events we want
XSelectInput(m_display, reply->m_requestor, attr.your_event_mask |
StructureNotifyMask | PropertyChangeMask);
// add the events we want
XSelectInput(m_display, reply->m_requestor, attr.your_event_mask |
StructureNotifyMask | PropertyChangeMask);
}
// if we failed then the window has already been destroyed
if (error) {
@@ -1193,13 +1197,9 @@ CXWindowsClipboard::getTargetsData(CString& data, int* format) const
assert(format != NULL);
// add standard targets
Atom atom;
atom = m_atomTargets;
data.append(reinterpret_cast<char*>(&atom), sizeof(Atom));
atom = m_atomMultiple;
data.append(reinterpret_cast<char*>(&atom), sizeof(Atom));
atom = m_atomTimestamp;
data.append(reinterpret_cast<char*>(&atom), sizeof(Atom));
CXWindowsUtil::appendAtomData(data, m_atomTargets);
CXWindowsUtil::appendAtomData(data, m_atomMultiple);
CXWindowsUtil::appendAtomData(data, m_atomTimestamp);
// add targets we can convert to
for (ConverterList::const_iterator index = m_converters.begin();
@@ -1208,8 +1208,7 @@ CXWindowsClipboard::getTargetsData(CString& data, int* format) const
// skip formats we don't have
if (m_added[converter->getFormat()]) {
atom = converter->getAtom();
data.append(reinterpret_cast<char*>(&atom), sizeof(Atom));
CXWindowsUtil::appendAtomData(data, converter->getAtom());
}
}
@@ -1222,9 +1221,8 @@ CXWindowsClipboard::getTimestampData(CString& data, int* format) const
{
assert(format != NULL);
assert(sizeof(m_timeOwned) == 4);
checkCache();
data.append(reinterpret_cast<const char*>(&m_timeOwned), 4);
CXWindowsUtil::appendTimeData(data, m_timeOwned);
*format = 32;
return m_atomInteger;
}
@@ -1264,6 +1262,9 @@ CXWindowsClipboard::CICCCMGetClipboard::readClipboard(Display* display,
LOG((CLOG_DEBUG1 "request selection=%s, target=%s, window=%x", CXWindowsUtil::atomToString(display, selection).c_str(), CXWindowsUtil::atomToString(display, target).c_str(), m_requestor));
m_atomNone = XInternAtom(display, "NONE", False);
m_atomIncr = XInternAtom(display, "INCR", False);
// save output pointers
m_actualTarget = actualTarget;
m_data = data;
@@ -1361,7 +1362,8 @@ CXWindowsClipboard::CICCCMGetClipboard::processEvent(
case SelectionNotify:
if (xevent->xselection.requestor == m_requestor) {
// done if we can't convert
if (xevent->xselection.property == None) {
if (xevent->xselection.property == None ||
xevent->xselection.property == m_atomNone) {
m_done = true;
return true;
}
@@ -1409,7 +1411,7 @@ CXWindowsClipboard::CICCCMGetClipboard::processEvent(
// note if incremental. if we're already incremental then the
// selection owner is busted. if the INCR property has no size
// then the selection owner is busted.
if (target == XInternAtom(display, "INCR", False)) {
if (target == m_atomIncr) {
if (m_incr) {
m_failed = true;
m_error = true;

View File

@@ -155,6 +155,10 @@ private:
bool m_failed;
bool m_done;
// atoms needed for the protocol
Atom m_atomNone; // NONE, not None
Atom m_atomIncr;
// true iff we've received the selection notify
bool m_reading;
@@ -182,7 +186,7 @@ private:
SInt32 m_pad2[4];
SInt32 m_numItems;
SInt32 m_pad3[3];
Window m_selectionOwner;
SInt32 m_selectionOwner; // a Window
SInt32 m_pad4[2];
};
@@ -204,9 +208,9 @@ private:
SInt32 m_pad1[6];
SInt32 m_length;
SInt32 m_data;
Atom m_type;
SInt32 m_type; // an Atom
SInt32 m_pad2[1];
int m_deleted;
SInt32 m_deleted;
SInt32 m_pad3[4];
};

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,7 @@
#include "CKeyState.h"
#include "stdmap.h"
#include "stdvector.h"
#if X_DISPLAY_MISSING
# error X11 is required to build synergy
#else
@@ -26,6 +27,9 @@
# else
# error The XTest extension is required to build synergy
# endif
# if HAVE_XKB_EXTENSION
# include <X11/extensions/XKBstr.h>
# endif
#endif
//! X Windows key state
@@ -34,9 +38,35 @@ A key state for X Windows.
*/
class CXWindowsKeyState : public CKeyState {
public:
CXWindowsKeyState(Display*);
typedef std::vector<int> CKeycodeList;
enum {
kGroupPoll = -1,
kGroupPollAndSet = -2
};
CXWindowsKeyState(Display*, bool useXKB);
~CXWindowsKeyState();
//! @name modifiers
//@{
//! Set active group
/*!
Sets the active group to \p group. This is the group returned by
\c pollActiveGroup(). If \p group is \c kGroupPoll then
\c pollActiveGroup() will really poll, but that's a slow operation
on X11. If \p group is \c kGroupPollAndSet then this will poll the
active group now and use it for future calls to \c pollActiveGroup().
*/
void setActiveGroup(SInt32 group);
//! Set the auto-repeat state
/*!
Sets the auto-repeat state.
*/
void setAutoRepeat(const XKeyboardState&);
//@}
//! @name accessors
//@{
@@ -47,106 +77,79 @@ public:
*/
KeyModifierMask mapModifiersFromX(unsigned int state) const;
//! Convert synergy modifier mask to X mask
/*!
Converts the synergy modifier mask to the corresponding X modifier
mask. Returns \c true if successful and \c false if any modifier
could not be converted.
*/
bool mapModifiersToX(KeyModifierMask, unsigned int&) const;
//! Convert synergy key to all corresponding X keycodes
/*!
Converts the synergy key \p key to all of the keycodes that map to
that key.
*/
void mapKeyToKeycodes(KeyID key,
CKeycodeList& keycodes) const;
//@}
// IKeyState overrides
virtual bool fakeCtrlAltDel();
virtual const char* getKeyName(KeyButton) const;
virtual KeyModifierMask
pollActiveModifiers() const;
virtual SInt32 pollActiveGroup() const;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
protected:
// IKeyState overrides
virtual void doUpdateKeys();
virtual void doFakeKeyEvent(KeyButton button,
bool press, bool isAutoRepeat);
virtual KeyButton mapKey(Keystrokes& keys, KeyID id,
KeyModifierMask desiredMask,
bool isAutoRepeat) const;
// CKeyState overrides
virtual void getKeyMap(CKeyMap& keyMap);
virtual void fakeKey(const Keystroke& keystroke);
private:
class KeyMapping {
void updateKeysymMap(CKeyMap&);
void updateKeysymMapXKB(CKeyMap&);
bool hasModifiersXKB() const;
int getEffectiveGroup(KeyCode, int group) const;
UInt32 getGroupFromState(unsigned int state) const;
static void remapKeyModifiers(KeyID, SInt32,
CKeyMap::KeyItem&, void*);
private:
struct XKBModifierInfo {
public:
KeyMapping();
public:
// KeyCode to generate keysym and whether keycode[i] is
// sensitive to shift and mode switch.
KeyCode m_keycode[4];
bool m_shiftSensitive[4];
bool m_modeSwitchSensitive[4];
// the modifier mask of keysym or 0 if not a modifier
KeyModifierMask m_modifierMask;
// whether keysym is sensitive to caps and num lock
bool m_numLockSensitive;
bool m_capsLockSensitive;
unsigned char m_level;
UInt32 m_mask;
bool m_lock;
};
typedef std::map<KeySym, KeyMapping> KeySymMap;
typedef KeySymMap::const_iterator KeySymIndex;
// save the current keyboard mapping and note the modifiers
void updateKeysymMap();
typedef std::vector<KeyModifierMask> KeyModifierMaskList;
typedef std::map<KeyModifierMask, unsigned int> KeyModifierToXMask;
typedef std::multimap<KeyID, KeyCode> KeyToKeyCodeMap;
typedef std::map<KeyCode, unsigned int> NonXKBModifierMap;
typedef std::map<UInt32, XKBModifierInfo> XKBModifierMap;
// note interesting modifier KeySyms
void updateModifiers();
// map a modifier index and its KeySym to a modifier mask. also
// save the modifier mask in one of m_*Mask.
KeyModifierMask mapToModifierMask(unsigned int, KeySym);
// convert a KeyID to a KeySym
KeySym keyIDToKeySym(KeyID id, KeyModifierMask mask) const;
// map a KeySym into the keystrokes to produce it
KeyButton mapToKeystrokes(Keystrokes& keys,
KeySymIndex keyIndex,
bool isAutoRepeat,
bool pressAndRelease) const;
// map a decomposition into keystrokes to produce it. returns the
// last key added to keys iff successful and 0 otherwise.
KeyButton mapDecompositionToKeystrokes(Keystrokes& keys,
KeySym keysym, bool usingDeadKeys) const;
// choose the best set of modifiers to generate the KeySym
unsigned int findBestKeyIndex(KeySymIndex keyIndex,
KeyModifierMask currentMask) const;
// returns true if the sense of shift is inverted for KeySym
bool isShiftInverted(KeySymIndex keyIndex,
KeyModifierMask currentMask) const;
// returns the keystrokes to adjust the modifiers into the desired
// state the keystrokes to get back to the current state.
bool adjustModifiers(Keystrokes& keys,
Keystrokes& undo,
KeyModifierMask desiredMask) const;
// returns true if keysym is sensitive to the NumLock state
bool isNumLockSensitive(KeySym keysym) const;
// returns true if keysym is sensitive to the CapsLock state
bool isCapsLockSensitive(KeySym keysym) const;
private:
Display* m_display;
#if HAVE_XKB_EXTENSION
XkbDescPtr m_xkb;
#endif
SInt32 m_group;
XKBModifierMap m_lastGoodXKBModifiers;
NonXKBModifierMap m_lastGoodNonXKBModifiers;
// keysym to keycode mapping
KeySymMap m_keysymMap;
// X modifier (bit number) to synergy modifier (mask) mapping
KeyModifierMaskList m_modifierFromX;
// the keyboard control state the last time this screen was entered
XKeyboardState m_keyControl;
// synergy modifier (mask) to X modifier (mask)
KeyModifierToXMask m_modifierToX;
// modifier keysyms
KeySym m_modeSwitchKeysym;
// map KeyID to all keycodes that can synthesize that KeyID
KeyToKeyCodeMap m_keyCodeFromKey;
// modifier masks
unsigned int m_altMask;
unsigned int m_metaMask;
unsigned int m_superMask;
unsigned int m_modeSwitchMask;
unsigned int m_numLockMask;
unsigned int m_scrollLockMask;
// autorepeat state
XKeyboardState m_keyboardState;
};
#endif

View File

@@ -19,6 +19,7 @@
#include "CXWindowsScreenSaver.h"
#include "CXWindowsUtil.h"
#include "CClipboard.h"
#include "CKeyMap.h"
#include "XScreen.h"
#include "CLog.h"
#include "CStopwatch.h"
@@ -45,47 +46,12 @@
# include <X11/extensions/Xinerama.h>
}
# endif
# if HAVE_XKB_EXTENSION
# include <X11/XKBlib.h>
# endif
#endif
#include "CArch.h"
// map "Internet" keys to KeyIDs
static const KeySym g_map1008FF[] =
{
/* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x08 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x10 */ 0, kKeyAudioDown, kKeyAudioMute, kKeyAudioUp,
/* 0x14 */ kKeyAudioPlay, kKeyAudioStop, kKeyAudioPrev, kKeyAudioNext,
/* 0x18 */ kKeyWWWHome, kKeyAppMail, 0, kKeyWWWSearch, 0, 0, 0, 0,
/* 0x20 */ 0, 0, 0, 0, 0, 0, kKeyWWWBack, kKeyWWWForward,
/* 0x28 */ kKeyWWWStop, kKeyWWWRefresh, 0, 0, kKeyEject, 0, 0, 0,
/* 0x30 */ kKeyWWWFavorites, 0, kKeyAppMedia, 0, 0, 0, 0, 0,
/* 0x38 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x40 */ kKeyAppUser1, kKeyAppUser2, 0, 0, 0, 0, 0, 0,
/* 0x48 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x50 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x58 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x60 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x68 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x70 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x78 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x88 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0x98 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xa0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xa8 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xb0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xb8 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xc0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xc8 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xd0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xd8 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xe0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xe8 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xf0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 0xf8 */ 0, 0, 0, 0, 0, 0, 0, 0
};
//
// CXWindowsScreen
@@ -123,7 +89,8 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary) :
m_sequenceNumber(0),
m_screensaver(NULL),
m_screensaverNotify(false),
m_xtestIsXineramaUnaware(true)
m_xtestIsXineramaUnaware(true),
m_xkb(false)
{
assert(s_screen == NULL);
@@ -139,7 +106,7 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary) :
m_window = openWindow();
m_screensaver = new CXWindowsScreenSaver(m_display,
m_window, getEventTarget());
m_keyState = new CXWindowsKeyState(m_display);
m_keyState = new CXWindowsKeyState(m_display, m_xkb);
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : ""));
LOG((CLOG_DEBUG "window is 0x%08x", m_window));
}
@@ -215,6 +182,7 @@ CXWindowsScreen::enable()
XKeyboardState keyControl;
XGetKeyboardControl(m_display, &keyControl);
m_autoRepeat = (keyControl.global_auto_repeat == AutoRepeatModeOn);
m_keyState->setAutoRepeat(keyControl);
// move hider window under the cursor center
XMoveWindow(m_display, m_window, m_xCenter, m_yCenter);
@@ -226,8 +194,6 @@ CXWindowsScreen::enable()
// warp the mouse to the cursor center
fakeMouseMove(m_xCenter, m_yCenter);
}
updateKeys();
}
void
@@ -256,10 +222,6 @@ CXWindowsScreen::enter()
XUnsetICFocus(m_ic);
}
// unmap the hider/grab window. this also ungrabs the mouse and
// keyboard if they're grabbed.
XUnmapWindow(m_display, m_window);
// set the input focus to what it had been when we took it
if (m_lastFocus != None) {
// the window may not exist anymore so ignore errors
@@ -267,6 +229,10 @@ CXWindowsScreen::enter()
XSetInputFocus(m_display, m_lastFocus, m_lastFocusRevert, CurrentTime);
}
// unmap the hider/grab window. this also ungrabs the mouse and
// keyboard if they're grabbed.
XUnmapWindow(m_display, m_window);
/* maybe call this if entering for the screensaver
// set keyboard focus to root window. the screensaver should then
// pick up key events for when the user enters a password to unlock.
@@ -278,6 +244,7 @@ CXWindowsScreen::enter()
XKeyboardState keyControl;
XGetKeyboardControl(m_display, &keyControl);
m_autoRepeat = (keyControl.global_auto_repeat == AutoRepeatModeOn);
m_keyState->setAutoRepeat(keyControl);
// turn off auto-repeat. we do this so fake key press events don't
// cause the local server to generate their own auto-repeats of
@@ -511,6 +478,245 @@ CXWindowsScreen::warpCursor(SInt32 x, SInt32 y)
m_yCursor = y;
}
UInt32
CXWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
{
// only allow certain modifiers
if ((mask & ~(KeyModifierShift | KeyModifierControl |
KeyModifierAlt | KeyModifierSuper)) != 0) {
LOG((CLOG_WARN "could not map hotkey id=%04x mask=%04x", key, mask));
return 0;
}
// fail if no keys
if (key == kKeyNone && mask == 0) {
return 0;
}
// convert to X
unsigned int modifiers;
if (!m_keyState->mapModifiersToX(mask, modifiers)) {
// can't map all modifiers
LOG((CLOG_WARN "could not map hotkey id=%04x mask=%04x", key, mask));
return 0;
}
CXWindowsKeyState::CKeycodeList keycodes;
m_keyState->mapKeyToKeycodes(key, keycodes);
if (key != kKeyNone && keycodes.empty()) {
// can't map key
LOG((CLOG_WARN "could not map hotkey id=%04x mask=%04x", key, mask));
return 0;
}
// choose hotkey id
UInt32 id;
if (!m_oldHotKeyIDs.empty()) {
id = m_oldHotKeyIDs.back();
m_oldHotKeyIDs.pop_back();
}
else {
id = m_hotKeys.size() + 1;
}
HotKeyList& hotKeys = m_hotKeys[id];
// all modifier hotkey must be treated specially. for each modifier
// we need to grab the modifier key in combination with all the other
// requested modifiers.
bool err = false;
{
CXWindowsUtil::CErrorLock lock(m_display, &err);
if (key == kKeyNone) {
static const KeyModifierMask s_hotKeyModifiers[] = {
KeyModifierShift,
KeyModifierControl,
KeyModifierAlt,
KeyModifierMeta,
KeyModifierSuper
};
XModifierKeymap* modKeymap = XGetModifierMapping(m_display);
for (size_t j = 0; j < sizeof(s_hotKeyModifiers) /
sizeof(s_hotKeyModifiers[0]) && !err; ++j) {
// skip modifier if not in mask
if ((mask & s_hotKeyModifiers[j]) == 0) {
continue;
}
// skip with error if we can't map remaining modifiers
unsigned int modifiers2;
KeyModifierMask mask2 = (mask & ~s_hotKeyModifiers[j]);
if (!m_keyState->mapModifiersToX(mask2, modifiers2)) {
err = true;
continue;
}
// compute modifier index for modifier. there should be
// exactly one X modifier missing
int index;
switch (modifiers ^ modifiers2) {
case ShiftMask:
index = ShiftMapIndex;
break;
case LockMask:
index = LockMapIndex;
break;
case ControlMask:
index = ControlMapIndex;
break;
case Mod1Mask:
index = Mod1MapIndex;
break;
case Mod2Mask:
index = Mod2MapIndex;
break;
case Mod3Mask:
index = Mod3MapIndex;
break;
case Mod4Mask:
index = Mod4MapIndex;
break;
case Mod5Mask:
index = Mod5MapIndex;
break;
default:
err = true;
continue;
}
// grab each key for the modifier
const KeyCode* modifiermap =
modKeymap->modifiermap + index * modKeymap->max_keypermod;
for (int k = 0; k < modKeymap->max_keypermod && !err; ++k) {
KeyCode code = modifiermap[k];
if (modifiermap[k] != 0) {
XGrabKey(m_display, code, modifiers2, m_root,
False, GrabModeAsync, GrabModeAsync);
if (!err) {
hotKeys.push_back(std::make_pair(code, modifiers2));
m_hotKeyToIDMap[CHotKeyItem(code, modifiers2)] = id;
}
}
}
}
XFreeModifiermap(modKeymap);
}
// a non-modifier key must be insensitive to CapsLock, NumLock and
// ScrollLock, so we have to grab the key with every combination of
// those.
else {
// collect available toggle modifiers
unsigned int modifier;
unsigned int toggleModifiers[3];
size_t numToggleModifiers = 0;
if (m_keyState->mapModifiersToX(KeyModifierCapsLock, modifier)) {
toggleModifiers[numToggleModifiers++] = modifier;
}
if (m_keyState->mapModifiersToX(KeyModifierNumLock, modifier)) {
toggleModifiers[numToggleModifiers++] = modifier;
}
if (m_keyState->mapModifiersToX(KeyModifierScrollLock, modifier)) {
toggleModifiers[numToggleModifiers++] = modifier;
}
for (CXWindowsKeyState::CKeycodeList::iterator j = keycodes.begin();
j != keycodes.end() && !err; ++j) {
for (size_t i = 0; i < (1u << numToggleModifiers); ++i) {
// add toggle modifiers for index i
unsigned int tmpModifiers = modifiers;
if ((i & 1) != 0) {
tmpModifiers |= toggleModifiers[0];
}
if ((i & 2) != 0) {
tmpModifiers |= toggleModifiers[1];
}
if ((i & 4) != 0) {
tmpModifiers |= toggleModifiers[2];
}
// add grab
XGrabKey(m_display, *j, tmpModifiers, m_root,
False, GrabModeAsync, GrabModeAsync);
if (!err) {
hotKeys.push_back(std::make_pair(*j, tmpModifiers));
m_hotKeyToIDMap[CHotKeyItem(*j, tmpModifiers)] = id;
}
}
}
}
}
if (err) {
// if any failed then unregister any we did get
for (HotKeyList::iterator j = hotKeys.begin();
j != hotKeys.end(); ++j) {
XUngrabKey(m_display, j->first, j->second, m_root);
m_hotKeyToIDMap.erase(CHotKeyItem(j->first, j->second));
}
m_oldHotKeyIDs.push_back(id);
m_hotKeys.erase(id);
LOG((CLOG_WARN "failed to register hotkey %s (id=%04x mask=%04x)", CKeyMap::formatKey(key, mask).c_str(), key, mask));
return 0;
}
LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", CKeyMap::formatKey(key, mask).c_str(), key, mask, id));
return id;
}
void
CXWindowsScreen::unregisterHotKey(UInt32 id)
{
// look up hotkey
HotKeyMap::iterator i = m_hotKeys.find(id);
if (i == m_hotKeys.end()) {
return;
}
// unregister with OS
bool err = false;
{
CXWindowsUtil::CErrorLock lock(m_display, &err);
HotKeyList& hotKeys = i->second;
for (HotKeyList::iterator j = hotKeys.begin();
j != hotKeys.end(); ++j) {
XUngrabKey(m_display, j->first, j->second, m_root);
m_hotKeyToIDMap.erase(CHotKeyItem(j->first, j->second));
}
}
if (err) {
LOG((CLOG_WARN "failed to unregister hotkey id=%d", id));
}
else {
LOG((CLOG_DEBUG "unregistered hotkey id=%d", id));
}
// discard hot key from map and record old id for reuse
m_hotKeys.erase(i);
m_oldHotKeyIDs.push_back(id);
}
void
CXWindowsScreen::fakeInputBegin()
{
// FIXME -- not implemented
}
void
CXWindowsScreen::fakeInputEnd()
{
// FIXME -- not implemented
}
SInt32
CXWindowsScreen::getJumpZoneSize() const
{
@@ -578,17 +784,22 @@ CXWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
}
void
CXWindowsScreen::fakeMouseWheel(SInt32 delta) const
CXWindowsScreen::fakeMouseWheel(SInt32, SInt32 yDelta) const
{
// XXX -- support x-axis scrolling
if (yDelta == 0) {
return;
}
// choose button depending on rotation direction
const unsigned int xButton = mapButtonToX(static_cast<ButtonID>(
(delta >= 0) ? -1 : -2));
(yDelta >= 0) ? -1 : -2));
if (xButton == 0) {
// If we get here, then the XServer does not support the scroll
// wheel buttons, so send PageUp/PageDown keystrokes instead.
// Patch by Tom Chadwick.
KeyCode keycode = 0;
if (delta >= 0) {
if (yDelta >= 0) {
keycode = XKeysymToKeycode(m_display, XK_Page_Up);
}
else {
@@ -602,12 +813,12 @@ CXWindowsScreen::fakeMouseWheel(SInt32 delta) const
}
// now use absolute value of delta
if (delta < 0) {
delta = -delta;
if (yDelta < 0) {
yDelta = -yDelta;
}
// send as many clicks as necessary
for (; delta >= 120; delta -= 120) {
for (; yDelta >= 120; yDelta -= 120) {
XTestFakeButtonEvent(m_display, xButton, True, CurrentTime);
XTestFakeButtonEvent(m_display, xButton, False, CurrentTime);
}
@@ -615,7 +826,7 @@ CXWindowsScreen::fakeMouseWheel(SInt32 delta) const
}
Display*
CXWindowsScreen::openDisplay(const char* displayName) const
CXWindowsScreen::openDisplay(const char* displayName)
{
// get the DISPLAY
if (displayName == NULL) {
@@ -643,6 +854,25 @@ CXWindowsScreen::openDisplay(const char* displayName) const
}
}
#if HAVE_XKB_EXTENSION
{
m_xkb = false;
int major = XkbMajorVersion, minor = XkbMinorVersion;
if (XkbLibraryVersion(&major, &minor)) {
int opcode, firstError;
if (XkbQueryExtension(display, &opcode, &m_xkbEventBase,
&firstError, &major, &minor)) {
m_xkb = true;
XkbSelectEvents(display, XkbUseCoreKbd,
XkbMapNotifyMask, XkbMapNotifyMask);
XkbSelectEventDetails(display, XkbUseCoreKbd,
XkbStateNotifyMask,
XkbGroupStateMask, XkbGroupStateMask);
}
}
}
#endif
return display;
}
@@ -864,10 +1094,22 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
}
if (xevent->type == KeyPress || xevent->type == KeyRelease) {
if (!isRepeat) {
m_keyState->setKeyDown(xevent->xkey.keycode,
xevent->type == KeyPress);
if (xevent->xkey.window == m_root) {
// this is a hot key
onHotKey(xevent->xkey, isRepeat);
return;
}
else if (!m_isOnScreen) {
// this might be a hot key
if (onHotKey(xevent->xkey, isRepeat)) {
return;
}
}
bool down = (isRepeat || xevent->type == KeyPress);
KeyModifierMask state =
m_keyState->mapModifiersFromX(xevent->xkey.state);
m_keyState->onKey(xevent->xkey.keycode, down, state);
}
}
@@ -924,19 +1166,7 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
break;
case MappingNotify:
if (XPending(m_display) > 0) {
XEvent tmpEvent;
XPeekEvent(m_display, &tmpEvent);
if (tmpEvent.type == MappingNotify) {
// discard this MappingNotify since another follows.
// we tend to get a bunch of these in a row.
return;
}
}
// keyboard mapping changed
XRefreshKeyboardMapping(&xevent->xmapping);
m_keyState->updateKeys();
refreshKeyboard(xevent);
break;
case LeaveNotify:
@@ -1036,6 +1266,21 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
return;
default:
#if HAVE_XKB_EXTENSION
if (m_xkb && xevent->type == m_xkbEventBase) {
XkbEvent* xkbEvent = reinterpret_cast<XkbEvent*>(xevent);
switch (xkbEvent->any.xkb_type) {
case XkbMapNotify:
refreshKeyboard(xevent);
return;
case XkbStateNotify:
LOG((CLOG_INFO "group change: %d", xkbEvent->state.group));
m_keyState->setActiveGroup((SInt32)xkbEvent->state.group);
return;
}
}
#endif
break;
}
}
@@ -1116,13 +1361,44 @@ CXWindowsScreen::onKeyRelease(XKeyEvent& xkey, bool isRepeat)
}
}
bool
CXWindowsScreen::onHotKey(XKeyEvent& xkey, bool isRepeat)
{
// find the hot key id
HotKeyToIDMap::const_iterator i =
m_hotKeyToIDMap.find(CHotKeyItem(xkey.keycode, xkey.state));
if (i == m_hotKeyToIDMap.end()) {
return false;
}
// find what kind of event
CEvent::Type type;
if (xkey.type == KeyPress) {
type = getHotKeyDownEvent();
}
else if (xkey.type == KeyRelease) {
type = getHotKeyUpEvent();
}
else {
return false;
}
// generate event (ignore key repeats)
if (!isRepeat) {
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(i->second)));
}
return true;
}
void
CXWindowsScreen::onMousePress(const XButtonEvent& xbutton)
{
LOG((CLOG_DEBUG1 "event: ButtonPress button=%d", xbutton.button));
const ButtonID button = mapButtonFromX(&xbutton);
ButtonID button = mapButtonFromX(&xbutton);
KeyModifierMask mask = m_keyState->mapModifiersFromX(xbutton.state);
if (button != kButtonNone) {
sendEvent(getButtonDownEvent(), CButtonInfo::alloc(button));
sendEvent(getButtonDownEvent(), CButtonInfo::alloc(button, mask));
}
}
@@ -1130,18 +1406,20 @@ void
CXWindowsScreen::onMouseRelease(const XButtonEvent& xbutton)
{
LOG((CLOG_DEBUG1 "event: ButtonRelease button=%d", xbutton.button));
const ButtonID button = mapButtonFromX(&xbutton);
ButtonID button = mapButtonFromX(&xbutton);
KeyModifierMask mask = m_keyState->mapModifiersFromX(xbutton.state);
if (button != kButtonNone) {
sendEvent(getButtonUpEvent(), CButtonInfo::alloc(button));
sendEvent(getButtonUpEvent(), CButtonInfo::alloc(button, mask));
}
else if (xbutton.button == 4) {
// wheel forward (away from user)
sendEvent(getWheelEvent(), CWheelInfo::alloc(120));
sendEvent(getWheelEvent(), CWheelInfo::alloc(0, 120));
}
else if (xbutton.button == 5) {
// wheel backward (toward user)
sendEvent(getWheelEvent(), CWheelInfo::alloc(-120));
sendEvent(getWheelEvent(), CWheelInfo::alloc(0, -120));
}
// XXX -- support x-axis scrolling
}
void
@@ -1409,41 +1687,7 @@ CXWindowsScreen::mapKeyFromX(XKeyEvent* event) const
}
// convert key
switch (keysym & 0xffffff00) {
case 0x0000:
// Latin-1
return static_cast<KeyID>(keysym);
case 0xfe00:
// ISO 9995 Function and Modifier Keys
if (keysym == XK_ISO_Left_Tab) {
return kKeyLeftTab;
}
if (keysym == XK_ISO_Level3_Shift) {
// treat ISO_Level3_Shift as ModeSwitch
return kKeyModeSwitch;
}
return kKeyNone;
case 0xff00:
// MISCELLANY
return static_cast<KeyID>(keysym - 0xff00 + 0xef00);
case 0x1008ff00:
// "Internet" keys
return g_map1008FF[keysym & 0xff];
default: {
// lookup character in table
UInt32 key = CXWindowsUtil::mapKeySymToUCS4(keysym);
if (key != 0x0000ffff) {
return static_cast<KeyID>(key);
}
// unknown character
return kKeyNone;
}
}
return CXWindowsUtil::mapKeySymToKeyID(keysym);
}
ButtonID
@@ -1608,3 +1852,50 @@ CXWindowsScreen::grabMouseAndKeyboard()
LOG((CLOG_DEBUG1 "grabbed pointer and keyboard"));
return true;
}
void
CXWindowsScreen::refreshKeyboard(XEvent* event)
{
if (XPending(m_display) > 0) {
XEvent tmpEvent;
XPeekEvent(m_display, &tmpEvent);
if (tmpEvent.type == MappingNotify) {
// discard this event since another follows.
// we tend to get a bunch of these in a row.
return;
}
}
// keyboard mapping changed
#if HAVE_XKB_EXTENSION
if (m_xkb && event->type == m_xkbEventBase) {
XkbRefreshKeyboardMapping((XkbMapNotifyEvent*)event);
}
else
#else
{
XRefreshKeyboardMapping(&event->xmapping);
}
#endif
m_keyState->updateKeyMap();
m_keyState->updateKeyState();
}
//
// CXWindowsScreen::CHotKeyItem
//
CXWindowsScreen::CHotKeyItem::CHotKeyItem(int keycode, unsigned int mask) :
m_keycode(keycode),
m_mask(mask)
{
// do nothing
}
bool
CXWindowsScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
{
return (m_keycode < x.m_keycode ||
(m_keycode == x.m_keycode && m_mask < x.m_mask));
}

View File

@@ -49,6 +49,10 @@ public:
// IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y);
virtual UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
virtual void unregisterHotKey(UInt32 id);
virtual void fakeInputBegin();
virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
@@ -57,7 +61,7 @@ public:
virtual void fakeMouseButton(ButtonID id, bool press) const;
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
virtual void fakeMouseWheel(SInt32 delta) const;
virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
// IPlatformScreen overrides
virtual void enable();
@@ -112,7 +116,7 @@ private:
KeyCode m_keycode;
};
Display* openDisplay(const char* displayName) const;
Display* openDisplay(const char* displayName);
void saveShape();
Window openWindow() const;
void openIM();
@@ -120,6 +124,7 @@ private:
bool grabMouseAndKeyboard();
void onKeyPress(XKeyEvent&);
void onKeyRelease(XKeyEvent&, bool isRepeat);
bool onHotKey(XKeyEvent&, bool isRepeat);
void onMousePress(const XButtonEvent&);
void onMouseRelease(const XButtonEvent&);
void onMouseMove(const XMotionEvent&);
@@ -133,10 +138,27 @@ private:
void warpCursorNoFlush(SInt32 x, SInt32 y);
void refreshKeyboard(XEvent*);
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
private:
struct CHotKeyItem {
public:
CHotKeyItem(int, unsigned int);
bool operator<(const CHotKeyItem&) const;
private:
int m_keycode;
unsigned int m_mask;
};
typedef std::set<bool> CFilteredKeycodes;
typedef std::vector<std::pair<int, unsigned int> > HotKeyList;
typedef std::map<UInt32, HotKeyList> HotKeyMap;
typedef std::vector<UInt32> HotKeyIDList;
typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
// true if screen is being used as a primary screen, false otherwise
bool m_isPrimary;
@@ -158,6 +180,11 @@ private:
// keyboard stuff
CXWindowsKeyState* m_keyState;
// hot key stuff
HotKeyMap m_hotKeys;
HotKeyIDList m_oldHotKeyIDs;
HotKeyToIDMap m_hotKeyToIDMap;
// input focus stuff
Window m_lastFocus;
int m_lastFocusRevert;
@@ -190,6 +217,10 @@ private:
bool m_xtestIsXineramaUnaware;
bool m_xinerama;
// XKB extension stuff
bool m_xkb;
int m_xkbEventBase;
// pointer to (singleton) screen. this is only needed by
// ioErrorHandler().
static CXWindowsScreen* s_screen;

View File

@@ -62,7 +62,8 @@ CXWindowsScreenSaver::CXWindowsScreenSaver(
m_dpms(false),
m_disabled(false),
m_suppressDisable(false),
m_disableTimer(NULL)
m_disableTimer(NULL),
m_disablePos(0)
{
// get atoms
m_atomScreenSaver = XInternAtom(m_display,
@@ -87,18 +88,18 @@ CXWindowsScreenSaver::CXWindowsScreenSaver(
#endif
// watch top-level windows for changes
bool error = false;
{
bool error = false;
CXWindowsUtil::CErrorLock lock(m_display, &error);
Window root = DefaultRootWindow(m_display);
XWindowAttributes attr;
XGetWindowAttributes(m_display, root, &attr);
m_rootEventMask = attr.your_event_mask;
XSelectInput(m_display, root, m_rootEventMask | SubstructureNotifyMask);
if (error) {
LOG((CLOG_DEBUG "didn't set root event mask"));
m_rootEventMask = 0;
}
}
if (error) {
LOG((CLOG_DEBUG "didn't set root event mask"));
m_rootEventMask = 0;
}
// get the built-in settings
@@ -346,9 +347,11 @@ CXWindowsScreenSaver::setXScreenSaver(Window window)
// see if xscreensaver is active
bool error = false;
CXWindowsUtil::CErrorLock lock(m_display, &error);
XWindowAttributes attr;
XGetWindowAttributes(m_display, m_xscreensaver, &attr);
{
CXWindowsUtil::CErrorLock lock(m_display, &error);
XGetWindowAttributes(m_display, m_xscreensaver, &attr);
}
setXScreenSaverActive(!error && attr.map_state != IsUnmapped);
// save current DPMS state; xscreensaver may have changed it.
@@ -418,8 +421,10 @@ CXWindowsScreenSaver::sendXScreenSaverCommand(Atom cmd, long arg1, long arg2)
LOG((CLOG_DEBUG "send xscreensaver command: %d %d %d", (long)cmd, arg1, arg2));
bool error = false;
CXWindowsUtil::CErrorLock lock(m_display, &error);
XSendEvent(m_display, m_xscreensaver, False, 0, &event);
{
CXWindowsUtil::CErrorLock lock(m_display, &error);
XSendEvent(m_display, m_xscreensaver, False, 0, &event);
}
if (error) {
findXScreenSaver();
}
@@ -465,18 +470,23 @@ CXWindowsScreenSaver::clearWatchForXScreenSaver()
void
CXWindowsScreenSaver::addWatchXScreenSaver(Window window)
{
bool error = false;
CXWindowsUtil::CErrorLock lock(m_display, &error);
// get window attributes
bool error = false;
XWindowAttributes attr;
XGetWindowAttributes(m_display, window, &attr);
{
CXWindowsUtil::CErrorLock lock(m_display, &error);
XGetWindowAttributes(m_display, window, &attr);
}
// if successful and window uses override_redirect (like xscreensaver
// does) then watch it for property changes.
if (!error && attr.override_redirect == True) {
XSelectInput(m_display, window,
error = false;
{
CXWindowsUtil::CErrorLock lock(m_display, &error);
XSelectInput(m_display, window,
attr.your_event_mask | PropertyChangeMask);
}
if (!error) {
// if successful then add the window to our list
m_watchWindows.insert(std::make_pair(window, attr.your_event_mask));
@@ -509,9 +519,9 @@ CXWindowsScreenSaver::handleDisableTimer(const CEvent&, void*)
event.xmotion.root = DefaultRootWindow(m_display);
event.xmotion.subwindow = None;
event.xmotion.time = CurrentTime;
event.xmotion.x = 0;
event.xmotion.x = m_disablePos;
event.xmotion.y = 0;
event.xmotion.x_root = 0;
event.xmotion.x_root = m_disablePos;
event.xmotion.y_root = 0;
event.xmotion.state = 0;
event.xmotion.is_hint = NotifyNormal;
@@ -519,6 +529,8 @@ CXWindowsScreenSaver::handleDisableTimer(const CEvent&, void*)
CXWindowsUtil::CErrorLock lock(m_display);
XSendEvent(m_display, m_xscreensaver, False, 0, &event);
m_disablePos = 20 - m_disablePos;
}
}

View File

@@ -154,6 +154,11 @@ private:
// the disable timer (NULL if not installed)
CEventQueueTimer* m_disableTimer;
// fake mouse motion position for suppressing the screen saver.
// xscreensaver since 2.21 requires the mouse to move more than 10
// pixels to be considered significant.
SInt32 m_disablePos;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -59,37 +59,19 @@ public:
*/
static Time getCurrentTime(Display*, Window);
//! Convert KeySym to UCS-4
//! Convert KeySym to KeyID
/*!
Converts a KeySym to the equivalent UCS-4 character. Returns
0x0000ffff if the KeySym cannot be mapped.
Converts a KeySym to the equivalent KeyID. Returns kKeyNone if the
KeySym cannot be mapped.
*/
static UInt32 mapKeySymToUCS4(KeySym);
static UInt32 mapKeySymToKeyID(KeySym);
//! Convert UCS-4 to KeySym
//! Convert KeySym to corresponding KeyModifierMask
/*!
Converts a UCS-4 character to the equivalent KeySym. Returns
NoSymbol (0) if the character cannot be mapped.
Converts a KeySym to the corresponding KeyModifierMask, or 0 if the
KeySym is not a modifier.
*/
static KeySym mapUCS4ToKeySym(UInt32);
//! Decompose a KeySym using dead keys
/*!
Decomposes \c keysym into its component keysyms. All but the last
decomposed KeySym are dead keys. Returns true iff the decomposition
was successful.
*/
static bool decomposeKeySymWithDeadKeys(KeySym keysym,
KeySyms& decomposed);
//! Decompose a KeySym using the compose key
/*!
Decomposes \c keysym into its component keysyms. The first key is
Multi_key and the rest are normal (i.e. not dead) keys. Returns
true iff the decomposition was successful.
*/
static bool decomposeKeySymWithCompose(KeySym keysym,
KeySyms& decomposed);
static UInt32 getModifierBitForKeySym(KeySym keysym);
//! Convert Atom to its string
/*!
@@ -105,6 +87,35 @@ public:
static CString atomsToString(Display* display,
const Atom* atom, UInt32 num);
//! Prepare a property of atoms for use
/*!
64-bit systems may need to modify a property's data if it's a
list of Atoms before using it.
*/
static void convertAtomProperty(CString& data);
//! Append an Atom to property data
/*!
Converts \p atom to a 32-bit on-the-wire format and appends it to
\p data.
*/
static void appendAtomData(CString& data, Atom atom);
//! Replace an Atom in property data
/*!
Converts \p atom to a 32-bit on-the-wire format and replaces the atom
at index \p index in \p data.
*/
static void replaceAtomData(CString& data,
UInt32 index, Atom atom);
//! Append an Time to property data
/*!
Converts \p time to a 32-bit on-the-wire format and appends it to
\p data.
*/
static void appendTimeData(CString& data, Time time);
//! X11 error handler
/*!
This class sets an X error handler in the c'tor and restores the
@@ -167,13 +178,8 @@ private:
private:
typedef std::map<KeySym, UInt32> CKeySymMap;
typedef std::map<UInt32, KeySym> CUCS4Map;
typedef std::map<KeySym, KeySyms> CKeySymsMap;
static CKeySymMap s_keySymToUCS4;
static CUCS4Map s_UCS4ToKeySym;
static CKeySymsMap s_deadKeyDecomposedKeySyms;
static CKeySymsMap s_composeDecomposedKeySyms;
};
#endif

View File

@@ -78,6 +78,7 @@ CARBON_SOURCE_FILES = \
COSXKeyState.cpp \
COSXScreen.cpp \
COSXScreenSaver.cpp \
COSXScreenSaverUtil.m \
COSXClipboard.h \
COSXClipboardAnyTextConverter.h \
COSXClipboardTextConverter.h \
@@ -86,6 +87,8 @@ CARBON_SOURCE_FILES = \
COSXKeyState.h \
COSXScreen.h \
COSXScreenSaver.h \
COSXScreenSaverUtil.h \
OSXScreenSaverControl.h \
$(NULL)
EXTRA_DIST = \

View File

@@ -0,0 +1,36 @@
// ScreenSaver.framework private API
// Class dumping by Alex Harper http://www.ragingmenace.com/
#import <Foundation/NSObject.h>
@protocol ScreenSaverControl
- (double)screenSaverTimeRemaining;
- (void)restartForUser:fp12;
- (void)screenSaverStopNow;
- (void)screenSaverStartNow;
- (void)setScreenSaverCanRun:(char)fp12;
- (BOOL)screenSaverCanRun;
- (BOOL)screenSaverIsRunning;
@end
@interface ScreenSaverController:NSObject <ScreenSaverControl>
+ controller;
+ monitor;
+ daemonConnectionName;
+ daemonPath;
+ enginePath;
- init;
- (void)dealloc;
- (void)_connectionClosed:fp12;
- (BOOL)screenSaverIsRunning;
- (BOOL)screenSaverCanRun;
- (void)setScreenSaverCanRun:(char)fp12;
- (void)screenSaverStartNow;
- (void)screenSaverStopNow;
- (void)restartForUser:fp12;
- (double)screenSaverTimeRemaining;
@end

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\synergy" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\platform.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\synergy" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\platform.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\synergy" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\platform.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\synergy" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\platform.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"

View File

@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O1 /I "..\common" /I "..\arch" /I "..\base" /I "..\net" /I "..\synergy" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /c /Fd..\..\gen\build\synrgyhk.pdb
# ADD CPP /nologo /MT /W4 /GR /GX /O1 /I "..\common" /I "..\arch" /I "..\base" /I "..\net" /I "..\synergy" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /Fd"..\..\gen\build\synrgyhk.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
@@ -71,7 +71,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\net" /I "..\synergy" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /FD /GZ /c /Fd..\..\gen\debug\synrgyhk.pdb
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\net" /I "..\synergy" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SYNRGYHK_EXPORTS" /Fd"..\..\gen\debug\synrgyhk.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32

View File

@@ -0,0 +1,52 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2006 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "CBaseClientProxy.h"
//
// CBaseClientProxy
//
CBaseClientProxy::CBaseClientProxy(const CString& name) :
m_name(name),
m_x(0),
m_y(0)
{
// do nothing
}
CBaseClientProxy::~CBaseClientProxy()
{
// do nothing
}
void
CBaseClientProxy::setJumpCursorPos(SInt32 x, SInt32 y)
{
m_x = x;
m_y = y;
}
void
CBaseClientProxy::getJumpCursorPos(SInt32& x, SInt32& y) const
{
x = m_x;
y = m_y;
}
CString
CBaseClientProxy::getName() const
{
return m_name;
}

View File

@@ -0,0 +1,85 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef CBASECLIENTPROXY_H
#define CBASECLIENTPROXY_H
#include "IClient.h"
#include "CString.h"
//! Generic proxy for client or primary
class CBaseClientProxy : public IClient {
public:
/*!
\c name is the name of the client.
*/
CBaseClientProxy(const CString& name);
~CBaseClientProxy();
//! @name manipulators
//@{
//! Save cursor position
/*!
Save the position of the cursor when jumping from client.
*/
void setJumpCursorPos(SInt32 x, SInt32 y);
//@}
//! @name accessors
//@{
//! Get cursor position
/*!
Get the position of the cursor when last jumping from client.
*/
void getJumpCursorPos(SInt32& x, SInt32& y) const;
//@}
// IScreen
virtual void* getEventTarget() const = 0;
virtual bool getClipboard(ClipboardID id, IClipboard*) const = 0;
virtual void getShape(SInt32& x, SInt32& y,
SInt32& width, SInt32& height) const = 0;
virtual void getCursorPos(SInt32& x, SInt32& y) const = 0;
// IClient overrides
virtual void enter(SInt32 xAbs, SInt32 yAbs,
UInt32 seqNum, KeyModifierMask mask,
bool forScreensaver) = 0;
virtual bool leave() = 0;
virtual void setClipboard(ClipboardID, const IClipboard*) = 0;
virtual void grabClipboard(ClipboardID) = 0;
virtual void setClipboardDirty(ClipboardID, bool) = 0;
virtual void keyDown(KeyID, KeyModifierMask, KeyButton) = 0;
virtual void keyRepeat(KeyID, KeyModifierMask,
SInt32 count, KeyButton) = 0;
virtual void keyUp(KeyID, KeyModifierMask, KeyButton) = 0;
virtual void mouseDown(ButtonID) = 0;
virtual void mouseUp(ButtonID) = 0;
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs) = 0;
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel) = 0;
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta) = 0;
virtual void screensaver(bool activate) = 0;
virtual void resetOptions() = 0;
virtual void setOptions(const COptionsList& options) = 0;
virtual CString getName() const;
private:
CString m_name;
SInt32 m_x, m_y;
};
#endif

View File

@@ -26,7 +26,7 @@ CEvent::Type CClientProxy::s_disconnectedEvent = CEvent::kUnknown;
CEvent::Type CClientProxy::s_clipboardChangedEvent= CEvent::kUnknown;
CClientProxy::CClientProxy(const CString& name, IStream* stream) :
m_name(name),
CBaseClientProxy(name),
m_stream(stream)
{
// do nothing
@@ -53,12 +53,6 @@ CClientProxy::getStream() const
return m_stream;
}
CString
CClientProxy::getName() const
{
return m_name;
}
CEvent::Type
CClientProxy::getReadyEvent()
{

View File

@@ -15,14 +15,14 @@
#ifndef CCLIENTPROXY_H
#define CCLIENTPROXY_H
#include "IClient.h"
#include "CBaseClientProxy.h"
#include "CEvent.h"
#include "CString.h"
class IStream;
//! Generic proxy for client
class CClientProxy : public IClient {
class CClientProxy : public CBaseClientProxy {
public:
/*!
\c name is the name of the client.
@@ -97,14 +97,12 @@ public:
virtual void mouseUp(ButtonID) = 0;
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs) = 0;
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel) = 0;
virtual void mouseWheel(SInt32 delta) = 0;
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta) = 0;
virtual void screensaver(bool activate) = 0;
virtual void resetOptions() = 0;
virtual void setOptions(const COptionsList& options) = 0;
virtual CString getName() const;
private:
CString m_name;
IStream* m_stream;
static CEvent::Type s_readyEvent;

View File

@@ -27,7 +27,6 @@
CClientProxy1_0::CClientProxy1_0(const CString& name, IStream* stream) :
CClientProxy(name, stream),
m_heartbeatAlarm(kHeartRate * kHeartBeatsUntilDeath),
m_heartbeatTimer(NULL),
m_parser(&CClientProxy1_0::parseHandshakeMessage)
{
@@ -52,6 +51,8 @@ CClientProxy1_0::CClientProxy1_0(const CString& name, IStream* stream) :
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleFlatline, NULL));
setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath);
LOG((CLOG_DEBUG1 "querying client \"%s\" info", getName().c_str()));
CProtocolUtil::writef(getStream(), kMsgQInfo);
}
@@ -104,6 +105,26 @@ CClientProxy1_0::removeHeartbeatTimer()
}
}
void
CClientProxy1_0::resetHeartbeatTimer()
{
// reset the alarm
removeHeartbeatTimer();
addHeartbeatTimer();
}
void
CClientProxy1_0::resetHeartbeatRate()
{
setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath);
}
void
CClientProxy1_0::setHeartbeatRate(double, double alarm)
{
m_heartbeatAlarm = alarm;
}
void
CClientProxy1_0::handleData(const CEvent&, void*)
{
@@ -121,7 +142,7 @@ CClientProxy1_0::handleData(const CEvent&, void*)
// parse message
LOG((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
if (!(this->*m_parser)(code)) {
LOG((CLOG_ERR "invalid message from client \"%s\"", getName().c_str()));
LOG((CLOG_ERR "invalid message from client \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
disconnect();
return;
}
@@ -131,8 +152,7 @@ CClientProxy1_0::handleData(const CEvent&, void*)
}
// restart heartbeat timer
removeHeartbeatTimer();
addHeartbeatTimer();
resetHeartbeatTimer();
}
bool
@@ -148,6 +168,7 @@ CClientProxy1_0::parseHandshakeMessage(const UInt8* code)
m_parser = &CClientProxy1_0::parseMessage;
if (recvInfo()) {
EVENTQUEUE->addEvent(CEvent(getReadyEvent(), getEventTarget()));
addHeartbeatTimer();
return true;
}
}
@@ -325,10 +346,11 @@ CClientProxy1_0::mouseRelativeMove(SInt32, SInt32)
}
void
CClientProxy1_0::mouseWheel(SInt32 delta)
CClientProxy1_0::mouseWheel(SInt32, SInt32 yDelta)
{
LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getName().c_str(), delta));
CProtocolUtil::writef(getStream(), kMsgDMouseWheel, delta);
// clients prior to 1.3 only support the y axis
LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getName().c_str(), yDelta));
CProtocolUtil::writef(getStream(), kMsgDMouseWheel1_0, yDelta);
}
void
@@ -345,7 +367,7 @@ CClientProxy1_0::resetOptions()
CProtocolUtil::writef(getStream(), kMsgCResetOptions);
// reset heart rate and death
m_heartbeatAlarm = kHeartRate * kHeartBeatsUntilDeath;
resetHeartbeatRate();
removeHeartbeatTimer();
addHeartbeatTimer();
}
@@ -363,7 +385,7 @@ CClientProxy1_0::setOptions(const COptionsList& options)
if (rate <= 0.0) {
rate = -1.0;
}
m_heartbeatAlarm = rate * kHeartBeatsUntilDeath;
setHeartbeatRate(rate, rate * kHeartBeatsUntilDeath);
removeHeartbeatTimer();
addHeartbeatTimer();
}

View File

@@ -50,7 +50,7 @@ public:
virtual void mouseUp(ButtonID);
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
virtual void mouseWheel(SInt32 delta);
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
virtual void screensaver(bool activate);
virtual void resetOptions();
virtual void setOptions(const COptionsList& options);
@@ -59,11 +59,15 @@ protected:
virtual bool parseHandshakeMessage(const UInt8* code);
virtual bool parseMessage(const UInt8* code);
virtual void resetHeartbeatRate();
virtual void setHeartbeatRate(double rate, double alarm);
virtual void resetHeartbeatTimer();
virtual void addHeartbeatTimer();
virtual void removeHeartbeatTimer();
private:
void disconnect();
void removeHandlers();
void addHeartbeatTimer();
void removeHeartbeatTimer();
void handleData(const CEvent&, void*);
void handleDisconnect(const CEvent&, void*);

View File

@@ -0,0 +1,114 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2006 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "CClientProxy1_3.h"
#include "CProtocolUtil.h"
#include "CLog.h"
#include "IEventQueue.h"
#include "TMethodEventJob.h"
//
// CClientProxy1_3
//
CClientProxy1_3::CClientProxy1_3(const CString& name, IStream* stream) :
CClientProxy1_2(name, stream),
m_keepAliveRate(kKeepAliveRate),
m_keepAliveTimer(NULL)
{
setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
}
CClientProxy1_3::~CClientProxy1_3()
{
// cannot do this in superclass or our override wouldn't get called
removeHeartbeatTimer();
}
void
CClientProxy1_3::mouseWheel(SInt32 xDelta, SInt32 yDelta)
{
LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d,%+d", getName().c_str(), xDelta, yDelta));
CProtocolUtil::writef(getStream(), kMsgDMouseWheel, xDelta, yDelta);
}
bool
CClientProxy1_3::parseMessage(const UInt8* code)
{
// process message
if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
// reset alarm
resetHeartbeatTimer();
return true;
}
else {
return CClientProxy1_2::parseMessage(code);
}
}
void
CClientProxy1_3::resetHeartbeatRate()
{
setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
}
void
CClientProxy1_3::setHeartbeatRate(double rate, double)
{
m_keepAliveRate = rate;
CClientProxy1_2::setHeartbeatRate(rate, rate * kKeepAlivesUntilDeath);
}
void
CClientProxy1_3::resetHeartbeatTimer()
{
// reset the alarm but not the keep alive timer
CClientProxy1_2::removeHeartbeatTimer();
CClientProxy1_2::addHeartbeatTimer();
}
void
CClientProxy1_3::addHeartbeatTimer()
{
// create and install a timer to periodically send keep alives
if (m_keepAliveRate > 0.0) {
m_keepAliveTimer = EVENTQUEUE->newTimer(m_keepAliveRate, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
new TMethodEventJob<CClientProxy1_3>(this,
&CClientProxy1_3::handleKeepAlive, NULL));
}
// superclass does the alarm
CClientProxy1_2::addHeartbeatTimer();
}
void
CClientProxy1_3::removeHeartbeatTimer()
{
// remove the timer that sends keep alives periodically
if (m_keepAliveTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_keepAliveTimer);
EVENTQUEUE->deleteTimer(m_keepAliveTimer);
m_keepAliveTimer = NULL;
}
// superclass does the alarm
CClientProxy1_2::removeHeartbeatTimer();
}
void
CClientProxy1_3::handleKeepAlive(const CEvent&, void*)
{
CProtocolUtil::writef(getStream(), kMsgCKeepAlive);
}

View File

@@ -0,0 +1,47 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2006 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef CCLIENTPROXY1_3_H
#define CCLIENTPROXY1_3_H
#include "CClientProxy1_2.h"
//! Proxy for client implementing protocol version 1.3
class CClientProxy1_3 : public CClientProxy1_2 {
public:
CClientProxy1_3(const CString& name, IStream* adoptedStream);
~CClientProxy1_3();
// IClient overrides
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
protected:
// CClientProxy overrides
virtual bool parseMessage(const UInt8* code);
virtual void resetHeartbeatRate();
virtual void setHeartbeatRate(double rate, double alarm);
virtual void resetHeartbeatTimer();
virtual void addHeartbeatTimer();
virtual void removeHeartbeatTimer();
private:
void handleKeepAlive(const CEvent&, void*);
private:
double m_keepAliveRate;
CEventQueueTimer* m_keepAliveTimer;
};
#endif

View File

@@ -16,6 +16,7 @@
#include "CClientProxy1_0.h"
#include "CClientProxy1_1.h"
#include "CClientProxy1_2.h"
#include "CClientProxy1_3.h"
#include "ProtocolTypes.h"
#include "CProtocolUtil.h"
#include "XSynergy.h"
@@ -219,6 +220,10 @@ CClientProxyUnknown::handleData(const CEvent&, void*)
case 2:
m_proxy = new CClientProxy1_2(name, m_stream);
break;
case 3:
m_proxy = new CClientProxy1_3(name, m_stream);
break;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,12 +19,15 @@
#include "ProtocolTypes.h"
#include "CNetworkAddress.h"
#include "CStringUtil.h"
#include "CInputFilter.h"
#include "XBase.h"
#include "stdmap.h"
#include "stdset.h"
#include "IPlatformScreen.h"
#include <iosfwd>
class CConfig;
class CConfigReadContext;
namespace std {
template <>
@@ -50,17 +53,93 @@ namespace and must be unique.
class CConfig {
public:
typedef std::map<OptionID, OptionValue> CScreenOptions;
typedef std::pair<float, float> CInterval;
class CCellEdge {
public:
CCellEdge(EDirection side, float position);
CCellEdge(EDirection side, const CInterval&);
CCellEdge(const CString& name, EDirection side, const CInterval&);
~CCellEdge();
CInterval getInterval() const;
void setName(const CString& newName);
CString getName() const;
EDirection getSide() const;
bool overlaps(const CCellEdge&) const;
bool isInside(float x) const;
// transform position to [0,1]
float transform(float x) const;
// transform [0,1] to position
float inverseTransform(float x) const;
// compares side and start of interval
bool operator<(const CCellEdge&) const;
// compares side and interval
bool operator==(const CCellEdge&) const;
bool operator!=(const CCellEdge&) const;
private:
void init(const CString& name, EDirection side,
const CInterval&);
private:
CString m_name;
EDirection m_side;
CInterval m_interval;
};
private:
class CCell {
class CName {
public:
CName(CConfig*, const CString& name);
bool operator==(const CString& name) const;
private:
CConfig* m_config;
CString m_name;
};
class CCell {
private:
typedef std::map<CCellEdge, CCellEdge> CEdgeLinks;
public:
typedef CEdgeLinks::const_iterator const_iterator;
bool add(const CCellEdge& src, const CCellEdge& dst);
void remove(EDirection side);
void remove(EDirection side, float position);
void remove(const CName& destinationName);
void rename(const CName& oldName, const CString& newName);
bool hasEdge(const CCellEdge&) const;
bool overlaps(const CCellEdge&) const;
bool getLink(EDirection side, float position,
const CCellEdge*& src, const CCellEdge*& dst) const;
bool operator==(const CCell&) const;
bool operator!=(const CCell&) const;
const_iterator begin() const;
const_iterator end() const;
private:
CEdgeLinks m_neighbors;
public:
CString m_neighbor[kLastDirection - kFirstDirection + 1];
CScreenOptions m_options;
};
typedef std::map<CString, CCell, CStringUtil::CaselessCmp> CCellMap;
typedef std::map<CString, CString, CStringUtil::CaselessCmp> CNameMap;
public:
typedef CCell::const_iterator link_const_iterator;
typedef CCellMap::const_iterator internal_const_iterator;
typedef CNameMap::const_iterator all_const_iterator;
class const_iterator : std::iterator_traits<CConfig> {
@@ -141,6 +220,13 @@ public:
*/
bool removeAlias(const CString& alias);
//! Remove aliases
/*!
Removes all aliases for a canonical screen name. It returns false
if the canonical name is unknown, otherwise returns true.
*/
bool removeAliases(const CString& canonical);
//! Remove all aliases
/*!
This removes all aliases but not the screens.
@@ -149,25 +235,43 @@ public:
//! Connect screens
/*!
Establishes a one-way connection between opposite edges of two
screens. The user will be able to jump from the \c srcSide of
screen \c srcName to the opposite side of screen \c dstName
when both screens are connected to the server and the user
isn't locked to a screen. Returns false if \c srcName is
unknown.
Establishes a one-way connection between portions of opposite edges
of two screens. Each portion is described by an interval defined
by two numbers, the start and end of the interval half-open on the
end. The numbers range from 0 to 1, inclusive, for the left/top
to the right/bottom. The user will be able to jump from the
\c srcStart to \c srcSend interval of \c srcSide of screen
\c srcName to the opposite side of screen \c dstName in the interval
\c dstStart and \c dstEnd when both screens are connected to the
server and the user isn't locked to a screen. Returns false if
\c srcName is unknown. \c srcStart must be less than or equal to
\c srcEnd and \c dstStart must be less then or equal to \c dstEnd
and all of \c srcStart, \c srcEnd, \c dstStart, or \c dstEnd must
be inside the range [0,1].
*/
bool connect(const CString& srcName,
EDirection srcSide,
const CString& dstName);
float srcStart, float srcEnd,
const CString& dstName,
float dstStart, float dstEnd);
//! Disconnect screens
/*!
Removes a connection created by connect(). Returns false if
\c srcName is unknown.
Removes all connections created by connect() on side \c srcSide.
Returns false if \c srcName is unknown.
*/
bool disconnect(const CString& srcName,
EDirection srcSide);
//! Disconnect screens
/*!
Removes the connections created by connect() on side \c srcSide
covering position \c position. Returns false if \c srcName is
unknown.
*/
bool disconnect(const CString& srcName,
EDirection srcSide, float position);
//! Set server address
/*!
Set the synergy listen addresses. There is no default address so
@@ -199,6 +303,13 @@ public:
*/
bool removeOptions(const CString& name);
//! Get the hot key input filter
/*!
Returns the hot key input filter. Clients can modify hotkeys using
that object.
*/
CInputFilter* getInputFilter();
//@}
//! @name accessors
//@{
@@ -241,10 +352,33 @@ public:
//! Get neighbor
/*!
Returns the canonical screen name of the neighbor in the given
direction (set through connect()). Returns the empty string
if there is no neighbor in that direction.
direction (set through connect()) at position \c position. Returns
the empty string if there is no neighbor in that direction, otherwise
saves the position on the neighbor in \c positionOut if it's not
\c NULL.
*/
CString getNeighbor(const CString&, EDirection) const;
CString getNeighbor(const CString&, EDirection,
float position, float* positionOut) const;
//! Check for neighbor
/*!
Returns \c true if the screen has a neighbor anywhere along the edge
given by the direction.
*/
bool hasNeighbor(const CString&, EDirection) const;
//! Check for neighbor
/*!
Returns \c true if the screen has a neighbor in the given range along
the edge given by the direction.
*/
bool hasNeighbor(const CString&, EDirection,
float start, float end) const;
//! Get beginning neighbor iterator
link_const_iterator beginNeighbor(const CString&) const;
//! Get ending neighbor iterator
link_const_iterator endNeighbor(const CString&) const;
//! Get the server address
const CNetworkAddress& getSynergyAddress() const;
@@ -257,11 +391,25 @@ public:
*/
const CScreenOptions* getOptions(const CString& name) const;
//! Check for lock to screen action
/*!
Returns \c true if this configuration has a lock to screen action.
This is for backwards compatible support of ScrollLock locking.
*/
bool hasLockToScreenAction() const;
//! Compare configurations
bool operator==(const CConfig&) const;
//! Compare configurations
bool operator!=(const CConfig&) const;
//! Read configuration
/*!
Reads a configuration from a context. Throws XConfigRead on error
and context is unchanged.
*/
void read(CConfigReadContext& context);
//! Read configuration
/*!
Reads a configuration from a stream. Throws XConfigRead on error.
@@ -280,26 +428,90 @@ public:
*/
static const char* dirName(EDirection);
//! Get interval as string
/*!
Returns an interval as a parseable string.
*/
static CString formatInterval(const CInterval&);
//@}
private:
static bool readLine(std::istream&, CString&);
static OptionValue parseBoolean(const CString&);
static OptionValue parseInt(const CString&);
static OptionValue parseModifierKey(const CString&);
void readSection(CConfigReadContext&);
void readSectionOptions(CConfigReadContext&);
void readSectionScreens(CConfigReadContext&);
void readSectionLinks(CConfigReadContext&);
void readSectionAliases(CConfigReadContext&);
CInputFilter::CCondition*
parseCondition(CConfigReadContext&,
const CString& condition,
const std::vector<CString>& args);
void parseAction(CConfigReadContext&,
const CString& action,
const std::vector<CString>& args,
CInputFilter::CRule&, bool activate);
void parseScreens(CConfigReadContext&, const CString&,
std::set<CString>& screens) const;
static const char* getOptionName(OptionID);
static CString getOptionValue(OptionID, OptionValue);
void readSection(std::istream&);
void readSectionOptions(std::istream&);
void readSectionScreens(std::istream&);
void readSectionLinks(std::istream&);
void readSectionAliases(std::istream&);
private:
CCellMap m_map;
CNameMap m_nameToCanonicalName;
CNetworkAddress m_synergyAddress;
CScreenOptions m_globalOptions;
CInputFilter m_inputFilter;
bool m_hasLockToScreenAction;
};
//! Configuration read context
/*!
Maintains a context when reading a configuration from a stream.
*/
class CConfigReadContext {
public:
typedef std::vector<CString> ArgList;
CConfigReadContext(std::istream&, SInt32 firstLine = 1);
~CConfigReadContext();
bool readLine(CString&);
UInt32 getLineNumber() const;
operator void*() const;
bool operator!() const;
OptionValue parseBoolean(const CString&) const;
OptionValue parseInt(const CString&) const;
OptionValue parseModifierKey(const CString&) const;
OptionValue parseCorner(const CString&) const;
OptionValue parseCorners(const CString&) const;
CConfig::CInterval
parseInterval(const ArgList& args) const;
void parseNameWithArgs(
const CString& type, const CString& line,
const CString& delim, CString::size_type& index,
CString& name, ArgList& args) const;
IPlatformScreen::CKeyInfo*
parseKeystroke(const CString& keystroke) const;
IPlatformScreen::CKeyInfo*
parseKeystroke(const CString& keystroke,
const std::set<CString>& screens) const;
IPlatformScreen::CButtonInfo*
parseMouse(const CString& mouse) const;
KeyModifierMask parseModifier(const CString& modifiers) const;
private:
// not implemented
CConfigReadContext& operator=(const CConfigReadContext&);
static CString concatArgs(const ArgList& args);
private:
std::istream& m_stream;
SInt32 m_line;
};
//! Configuration stream read exception
@@ -308,7 +520,9 @@ Thrown when a configuration stream cannot be parsed.
*/
class XConfigRead : public XBase {
public:
XConfigRead(const CString&);
XConfigRead(const CConfigReadContext& context, const CString&);
XConfigRead(const CConfigReadContext& context,
const char* errorFmt, const CString& arg);
~XConfigRead();
protected:

999
lib/server/CInputFilter.cpp Normal file
View File

@@ -0,0 +1,999 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2005 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "CInputFilter.h"
#include "CServer.h"
#include "CPrimaryClient.h"
#include "CKeyMap.h"
#include "CEventQueue.h"
#include "CLog.h"
#include "TMethodEventJob.h"
#include <stdlib.h>
#include <string.h>
// -----------------------------------------------------------------------------
// Input Filter Condition Classes
// -----------------------------------------------------------------------------
CInputFilter::CCondition::CCondition()
{
// do nothing
}
CInputFilter::CCondition::~CCondition()
{
// do nothing
}
void
CInputFilter::CCondition::enablePrimary(CPrimaryClient*)
{
// do nothing
}
void
CInputFilter::CCondition::disablePrimary(CPrimaryClient*)
{
// do nothing
}
CInputFilter::CKeystrokeCondition::CKeystrokeCondition(
IPlatformScreen::CKeyInfo* info) :
m_id(0),
m_key(info->m_key),
m_mask(info->m_mask)
{
free(info);
}
CInputFilter::CKeystrokeCondition::CKeystrokeCondition(
KeyID key, KeyModifierMask mask) :
m_id(0),
m_key(key),
m_mask(mask)
{
// do nothing
}
CInputFilter::CKeystrokeCondition::~CKeystrokeCondition()
{
// do nothing
}
KeyID
CInputFilter::CKeystrokeCondition::getKey() const
{
return m_key;
}
KeyModifierMask
CInputFilter::CKeystrokeCondition::getMask() const
{
return m_mask;
}
CInputFilter::CCondition*
CInputFilter::CKeystrokeCondition::clone() const
{
return new CKeystrokeCondition(m_key, m_mask);
}
CString
CInputFilter::CKeystrokeCondition::format() const
{
return CStringUtil::print("keystroke(%s)",
CKeyMap::formatKey(m_key, m_mask).c_str());
}
CInputFilter::EFilterStatus
CInputFilter::CKeystrokeCondition::match(const CEvent& event)
{
EFilterStatus status;
// check for hotkey events
CEvent::Type type = event.getType();
if (type == IPrimaryScreen::getHotKeyDownEvent()) {
status = kActivate;
}
else if (type == IPrimaryScreen::getHotKeyUpEvent()) {
status = kDeactivate;
}
else {
return kNoMatch;
}
// check if it's our hotkey
IPrimaryScreen::CHotKeyInfo* kinfo =
reinterpret_cast<IPlatformScreen::CHotKeyInfo*>(event.getData());
if (kinfo->m_id != m_id) {
return kNoMatch;
}
return status;
}
void
CInputFilter::CKeystrokeCondition::enablePrimary(CPrimaryClient* primary)
{
m_id = primary->registerHotKey(m_key, m_mask);
}
void
CInputFilter::CKeystrokeCondition::disablePrimary(CPrimaryClient* primary)
{
primary->unregisterHotKey(m_id);
m_id = 0;
}
CInputFilter::CMouseButtonCondition::CMouseButtonCondition(
IPlatformScreen::CButtonInfo* info) :
m_button(info->m_button),
m_mask(info->m_mask)
{
free(info);
}
CInputFilter::CMouseButtonCondition::CMouseButtonCondition(
ButtonID button, KeyModifierMask mask) :
m_button(button),
m_mask(mask)
{
// do nothing
}
CInputFilter::CMouseButtonCondition::~CMouseButtonCondition()
{
// do nothing
}
ButtonID
CInputFilter::CMouseButtonCondition::getButton() const
{
return m_button;
}
KeyModifierMask
CInputFilter::CMouseButtonCondition::getMask() const
{
return m_mask;
}
CInputFilter::CCondition*
CInputFilter::CMouseButtonCondition::clone() const
{
return new CMouseButtonCondition(m_button, m_mask);
}
CString
CInputFilter::CMouseButtonCondition::format() const
{
CString key = CKeyMap::formatKey(kKeyNone, m_mask);
if (!key.empty()) {
key += "+";
}
return CStringUtil::print("mousebutton(%s%d)", key.c_str(), m_button);
}
CInputFilter::EFilterStatus
CInputFilter::CMouseButtonCondition::match(const CEvent& event)
{
static const KeyModifierMask s_ignoreMask =
KeyModifierAltGr | KeyModifierCapsLock |
KeyModifierNumLock | KeyModifierScrollLock;
EFilterStatus status;
// check for hotkey events
CEvent::Type type = event.getType();
if (type == IPrimaryScreen::getButtonDownEvent()) {
status = kActivate;
}
else if (type == IPrimaryScreen::getButtonUpEvent()) {
status = kDeactivate;
}
else {
return kNoMatch;
}
// check if it's the right button and modifiers. ignore modifiers
// that cannot be combined with a mouse button.
IPlatformScreen::CButtonInfo* minfo =
reinterpret_cast<IPlatformScreen::CButtonInfo*>(event.getData());
if (minfo->m_button != m_button ||
(minfo->m_mask & ~s_ignoreMask) != m_mask) {
return kNoMatch;
}
return status;
}
CInputFilter::CScreenConnectedCondition::CScreenConnectedCondition(
const CString& screen) :
m_screen(screen)
{
// do nothing
}
CInputFilter::CScreenConnectedCondition::~CScreenConnectedCondition()
{
// do nothing
}
CInputFilter::CCondition*
CInputFilter::CScreenConnectedCondition::clone() const
{
return new CScreenConnectedCondition(m_screen);
}
CString
CInputFilter::CScreenConnectedCondition::format() const
{
return CStringUtil::print("connect(%s)", m_screen.c_str());
}
CInputFilter::EFilterStatus
CInputFilter::CScreenConnectedCondition::match(const CEvent& event)
{
if (event.getType() == CServer::getConnectedEvent()) {
CServer::CScreenConnectedInfo* info =
reinterpret_cast<CServer::CScreenConnectedInfo*>(event.getData());
if (m_screen == info->m_screen || m_screen.empty()) {
return kActivate;
}
}
return kNoMatch;
}
// -----------------------------------------------------------------------------
// Input Filter Action Classes
// -----------------------------------------------------------------------------
CInputFilter::CAction::CAction()
{
// do nothing
}
CInputFilter::CAction::~CAction()
{
// do nothing
}
CInputFilter::CLockCursorToScreenAction::CLockCursorToScreenAction(Mode mode):
m_mode(mode)
{
// do nothing
}
CInputFilter::CLockCursorToScreenAction::Mode
CInputFilter::CLockCursorToScreenAction::getMode() const
{
return m_mode;
}
CInputFilter::CAction*
CInputFilter::CLockCursorToScreenAction::clone() const
{
return new CLockCursorToScreenAction(*this);
}
CString
CInputFilter::CLockCursorToScreenAction::format() const
{
static const char* s_mode[] = { "off", "on", "toggle" };
return CStringUtil::print("lockCursorToScreen(%s)", s_mode[m_mode]);
}
void
CInputFilter::CLockCursorToScreenAction::perform(const CEvent& event)
{
static const CServer::CLockCursorToScreenInfo::State s_state[] = {
CServer::CLockCursorToScreenInfo::kOff,
CServer::CLockCursorToScreenInfo::kOn,
CServer::CLockCursorToScreenInfo::kToggle
};
// send event
CServer::CLockCursorToScreenInfo* info =
CServer::CLockCursorToScreenInfo::alloc(s_state[m_mode]);
EVENTQUEUE->addEvent(CEvent(CServer::getLockCursorToScreenEvent(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CSwitchToScreenAction::CSwitchToScreenAction(
const CString& screen) :
m_screen(screen)
{
// do nothing
}
CString
CInputFilter::CSwitchToScreenAction::getScreen() const
{
return m_screen;
}
CInputFilter::CAction*
CInputFilter::CSwitchToScreenAction::clone() const
{
return new CSwitchToScreenAction(*this);
}
CString
CInputFilter::CSwitchToScreenAction::format() const
{
return CStringUtil::print("switchToScreen(%s)", m_screen.c_str());
}
void
CInputFilter::CSwitchToScreenAction::perform(const CEvent& event)
{
// pick screen name. if m_screen is empty then use the screen from
// event if it has one.
CString screen = m_screen;
if (screen.empty() && event.getType() == CServer::getConnectedEvent()) {
CServer::CScreenConnectedInfo* info =
reinterpret_cast<CServer::CScreenConnectedInfo*>(event.getData());
screen = info->m_screen;
}
// send event
CServer::CSwitchToScreenInfo* info =
CServer::CSwitchToScreenInfo::alloc(screen);
EVENTQUEUE->addEvent(CEvent(CServer::getSwitchToScreenEvent(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CSwitchInDirectionAction::CSwitchInDirectionAction(
EDirection direction) :
m_direction(direction)
{
// do nothing
}
EDirection
CInputFilter::CSwitchInDirectionAction::getDirection() const
{
return m_direction;
}
CInputFilter::CAction*
CInputFilter::CSwitchInDirectionAction::clone() const
{
return new CSwitchInDirectionAction(*this);
}
CString
CInputFilter::CSwitchInDirectionAction::format() const
{
static const char* s_names[] = {
"",
"left",
"right",
"up",
"down"
};
return CStringUtil::print("switchInDirection(%s)", s_names[m_direction]);
}
void
CInputFilter::CSwitchInDirectionAction::perform(const CEvent& event)
{
CServer::CSwitchInDirectionInfo* info =
CServer::CSwitchInDirectionInfo::alloc(m_direction);
EVENTQUEUE->addEvent(CEvent(CServer::getSwitchInDirectionEvent(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CKeystrokeAction::CKeystrokeAction(
IPlatformScreen::CKeyInfo* info, bool press) :
m_keyInfo(info),
m_press(press)
{
// do nothing
}
CInputFilter::CKeystrokeAction::~CKeystrokeAction()
{
free(m_keyInfo);
}
void
CInputFilter::CKeystrokeAction::adoptInfo(IPlatformScreen::CKeyInfo* info)
{
free(m_keyInfo);
m_keyInfo = info;
}
const IPlatformScreen::CKeyInfo*
CInputFilter::CKeystrokeAction::getInfo() const
{
return m_keyInfo;
}
bool
CInputFilter::CKeystrokeAction::isOnPress() const
{
return m_press;
}
CInputFilter::CAction*
CInputFilter::CKeystrokeAction::clone() const
{
IKeyState::CKeyInfo* info = IKeyState::CKeyInfo::alloc(*m_keyInfo);
return new CKeystrokeAction(info, m_press);
}
CString
CInputFilter::CKeystrokeAction::format() const
{
const char* type = formatName();
if (m_keyInfo->m_screens[0] == '\0') {
return CStringUtil::print("%s(%s)", type,
CKeyMap::formatKey(m_keyInfo->m_key,
m_keyInfo->m_mask).c_str());
}
else if (m_keyInfo->m_screens[0] == '*') {
return CStringUtil::print("%s(%s,*)", type,
CKeyMap::formatKey(m_keyInfo->m_key,
m_keyInfo->m_mask).c_str());
}
else {
return CStringUtil::print("%s(%s,%.*s)", type,
CKeyMap::formatKey(m_keyInfo->m_key,
m_keyInfo->m_mask).c_str(),
strlen(m_keyInfo->m_screens + 1) - 1,
m_keyInfo->m_screens + 1);
}
}
void
CInputFilter::CKeystrokeAction::perform(const CEvent& event)
{
CEvent::Type type = m_press ? IPlatformScreen::getKeyDownEvent() :
IPlatformScreen::getKeyUpEvent();
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getFakeInputBeginEvent(),
event.getTarget(), NULL,
CEvent::kDeliverImmediately));
EVENTQUEUE->addEvent(CEvent(type, event.getTarget(), m_keyInfo,
CEvent::kDeliverImmediately |
CEvent::kDontFreeData));
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getFakeInputEndEvent(),
event.getTarget(), NULL,
CEvent::kDeliverImmediately));
}
const char*
CInputFilter::CKeystrokeAction::formatName() const
{
return (m_press ? "keyDown" : "keyUp");
}
CInputFilter::CMouseButtonAction::CMouseButtonAction(
IPlatformScreen::CButtonInfo* info, bool press) :
m_buttonInfo(info),
m_press(press)
{
// do nothing
}
CInputFilter::CMouseButtonAction::~CMouseButtonAction()
{
free(m_buttonInfo);
}
const IPlatformScreen::CButtonInfo*
CInputFilter::CMouseButtonAction::getInfo() const
{
return m_buttonInfo;
}
bool
CInputFilter::CMouseButtonAction::isOnPress() const
{
return m_press;
}
CInputFilter::CAction*
CInputFilter::CMouseButtonAction::clone() const
{
IPlatformScreen::CButtonInfo* info =
IPrimaryScreen::CButtonInfo::alloc(*m_buttonInfo);
return new CMouseButtonAction(info, m_press);
}
CString
CInputFilter::CMouseButtonAction::format() const
{
const char* type = formatName();
CString key = CKeyMap::formatKey(kKeyNone, m_buttonInfo->m_mask);
return CStringUtil::print("%s(%s%s%d)", type,
key.c_str(), key.empty() ? "" : "+",
m_buttonInfo->m_button);
}
void
CInputFilter::CMouseButtonAction::perform(const CEvent& event)
{
// send modifiers
IPlatformScreen::CKeyInfo* modifierInfo = NULL;
if (m_buttonInfo->m_mask != 0) {
KeyID key = m_press ? kKeySetModifiers : kKeyClearModifiers;
modifierInfo =
IKeyState::CKeyInfo::alloc(key, m_buttonInfo->m_mask, 0, 1);
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getKeyDownEvent(),
event.getTarget(), modifierInfo,
CEvent::kDeliverImmediately));
}
// send button
CEvent::Type type = m_press ? IPlatformScreen::getButtonDownEvent() :
IPlatformScreen::getButtonUpEvent();
EVENTQUEUE->addEvent(CEvent(type, event.getTarget(), m_buttonInfo,
CEvent::kDeliverImmediately |
CEvent::kDontFreeData));
}
const char*
CInputFilter::CMouseButtonAction::formatName() const
{
return (m_press ? "mouseDown" : "mouseUp");
}
//
// CInputFilter::CRule
//
CInputFilter::CRule::CRule() :
m_condition(NULL)
{
// do nothing
}
CInputFilter::CRule::CRule(CCondition* adoptedCondition) :
m_condition(adoptedCondition)
{
// do nothing
}
CInputFilter::CRule::CRule(const CRule& rule) :
m_condition(NULL)
{
copy(rule);
}
CInputFilter::CRule::~CRule()
{
clear();
}
CInputFilter::CRule&
CInputFilter::CRule::operator=(const CRule& rule)
{
if (&rule != this) {
copy(rule);
}
return *this;
}
void
CInputFilter::CRule::clear()
{
delete m_condition;
for (CActionList::iterator i = m_activateActions.begin();
i != m_activateActions.end(); ++i) {
delete *i;
}
for (CActionList::iterator i = m_deactivateActions.begin();
i != m_deactivateActions.end(); ++i) {
delete *i;
}
m_condition = NULL;
m_activateActions.clear();
m_deactivateActions.clear();
}
void
CInputFilter::CRule::copy(const CRule& rule)
{
clear();
if (rule.m_condition != NULL) {
m_condition = rule.m_condition->clone();
}
for (CActionList::const_iterator i = rule.m_activateActions.begin();
i != rule.m_activateActions.end(); ++i) {
m_activateActions.push_back((*i)->clone());
}
for (CActionList::const_iterator i = rule.m_deactivateActions.begin();
i != rule.m_deactivateActions.end(); ++i) {
m_deactivateActions.push_back((*i)->clone());
}
}
void
CInputFilter::CRule::setCondition(CCondition* adopted)
{
delete m_condition;
m_condition = adopted;
}
void
CInputFilter::CRule::adoptAction(CAction* action, bool onActivation)
{
if (action != NULL) {
if (onActivation) {
m_activateActions.push_back(action);
}
else {
m_deactivateActions.push_back(action);
}
}
}
void
CInputFilter::CRule::removeAction(bool onActivation, UInt32 index)
{
if (onActivation) {
delete m_activateActions[index];
m_activateActions.erase(m_activateActions.begin() + index);
}
else {
delete m_deactivateActions[index];
m_deactivateActions.erase(m_deactivateActions.begin() + index);
}
}
void
CInputFilter::CRule::replaceAction(CAction* adopted,
bool onActivation, UInt32 index)
{
if (adopted == NULL) {
removeAction(onActivation, index);
}
else if (onActivation) {
delete m_activateActions[index];
m_activateActions[index] = adopted;
}
else {
delete m_deactivateActions[index];
m_deactivateActions[index] = adopted;
}
}
void
CInputFilter::CRule::enable(CPrimaryClient* primaryClient)
{
if (m_condition != NULL) {
m_condition->enablePrimary(primaryClient);
}
}
void
CInputFilter::CRule::disable(CPrimaryClient* primaryClient)
{
if (m_condition != NULL) {
m_condition->disablePrimary(primaryClient);
}
}
bool
CInputFilter::CRule::handleEvent(const CEvent& event)
{
// NULL condition never matches
if (m_condition == NULL) {
return false;
}
// match
const CActionList* actions;
switch (m_condition->match(event)) {
default:
// not handled
return false;
case kActivate:
actions = &m_activateActions;
LOG((CLOG_DEBUG1 "activate actions"));
break;
case kDeactivate:
actions = &m_deactivateActions;
LOG((CLOG_DEBUG1 "deactivate actions"));
break;
}
// perform actions
for (CActionList::const_iterator i = actions->begin();
i != actions->end(); ++i) {
LOG((CLOG_DEBUG1 "hotkey: %s", (*i)->format().c_str()));
(*i)->perform(event);
}
return true;
}
CString
CInputFilter::CRule::format() const
{
CString s;
if (m_condition != NULL) {
// condition
s += m_condition->format();
s += " = ";
// activate actions
CActionList::const_iterator i = m_activateActions.begin();
if (i != m_activateActions.end()) {
s += (*i)->format();
while (++i != m_activateActions.end()) {
s += ", ";
s += (*i)->format();
}
}
// deactivate actions
if (!m_deactivateActions.empty()) {
s += "; ";
i = m_deactivateActions.begin();
if (i != m_deactivateActions.end()) {
s += (*i)->format();
while (++i != m_deactivateActions.end()) {
s += ", ";
s += (*i)->format();
}
}
}
}
return s;
}
const CInputFilter::CCondition*
CInputFilter::CRule::getCondition() const
{
return m_condition;
}
UInt32
CInputFilter::CRule::getNumActions(bool onActivation) const
{
if (onActivation) {
return static_cast<UInt32>(m_activateActions.size());
}
else {
return static_cast<UInt32>(m_deactivateActions.size());
}
}
const CInputFilter::CAction&
CInputFilter::CRule::getAction(bool onActivation, UInt32 index) const
{
if (onActivation) {
return *m_activateActions[index];
}
else {
return *m_deactivateActions[index];
}
}
// -----------------------------------------------------------------------------
// Input Filter Class
// -----------------------------------------------------------------------------
CInputFilter::CInputFilter() :
m_primaryClient(NULL)
{
// do nothing
}
CInputFilter::CInputFilter(const CInputFilter& x) :
m_ruleList(x.m_ruleList),
m_primaryClient(NULL)
{
setPrimaryClient(x.m_primaryClient);
}
CInputFilter::~CInputFilter()
{
setPrimaryClient(NULL);
}
CInputFilter&
CInputFilter::operator=(const CInputFilter& x)
{
if (&x != this) {
CPrimaryClient* oldClient = m_primaryClient;
setPrimaryClient(NULL);
m_ruleList = x.m_ruleList;
setPrimaryClient(oldClient);
}
return *this;
}
void
CInputFilter::addFilterRule(const CRule& rule)
{
m_ruleList.push_back(rule);
if (m_primaryClient != NULL) {
m_ruleList.back().enable(m_primaryClient);
}
}
void
CInputFilter::removeFilterRule(UInt32 index)
{
if (m_primaryClient != NULL) {
m_ruleList[index].disable(m_primaryClient);
}
m_ruleList.erase(m_ruleList.begin() + index);
}
CInputFilter::CRule&
CInputFilter::getRule(UInt32 index)
{
return m_ruleList[index];
}
void
CInputFilter::setPrimaryClient(CPrimaryClient* client)
{
if (m_primaryClient == client) {
return;
}
if (m_primaryClient != NULL) {
for (CRuleList::iterator rule = m_ruleList.begin();
rule != m_ruleList.end(); ++rule) {
rule->disable(m_primaryClient);
}
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyDownEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyUpEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyRepeatEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonDownEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonUpEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getHotKeyDownEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getHotKeyUpEvent(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(CServer::getConnectedEvent(),
m_primaryClient->getEventTarget());
}
m_primaryClient = client;
if (m_primaryClient != NULL) {
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyDownEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyUpEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(CServer::getConnectedEvent(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
for (CRuleList::iterator rule = m_ruleList.begin();
rule != m_ruleList.end(); ++rule) {
rule->enable(m_primaryClient);
}
}
}
CString
CInputFilter::format(const CString& linePrefix) const
{
CString s;
for (CRuleList::const_iterator i = m_ruleList.begin();
i != m_ruleList.end(); ++i) {
s += linePrefix;
s += i->format();
s += "\n";
}
return s;
}
UInt32
CInputFilter::getNumRules() const
{
return static_cast<UInt32>(m_ruleList.size());
}
bool
CInputFilter::operator==(const CInputFilter& x) const
{
// if there are different numbers of rules then we can't be equal
if (m_ruleList.size() != x.m_ruleList.size()) {
return false;
}
// compare rule lists. the easiest way to do that is to format each
// rule into a string, sort the strings, then compare the results.
std::vector<CString> aList, bList;
for (CRuleList::const_iterator i = m_ruleList.begin();
i != m_ruleList.end(); ++i) {
aList.push_back(i->format());
}
for (CRuleList::const_iterator i = x.m_ruleList.begin();
i != x.m_ruleList.end(); ++i) {
bList.push_back(i->format());
}
std::partial_sort(aList.begin(), aList.end(), aList.end());
std::partial_sort(bList.begin(), bList.end(), bList.end());
return (aList == bList);
}
bool
CInputFilter::operator!=(const CInputFilter& x) const
{
return !operator==(x);
}
void
CInputFilter::handleEvent(const CEvent& event, void*)
{
// copy event and adjust target
CEvent myEvent(event.getType(), this, event.getData(),
event.getFlags() | CEvent::kDontFreeData |
CEvent::kDeliverImmediately);
// let each rule try to match the event until one does
for (CRuleList::iterator rule = m_ruleList.begin();
rule != m_ruleList.end(); ++rule) {
if (rule->handleEvent(myEvent)) {
// handled
return;
}
}
// not handled so pass through
EVENTQUEUE->addEvent(myEvent);
}

322
lib/server/CInputFilter.h Normal file
View File

@@ -0,0 +1,322 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2005 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef CINPUTFILTER_H
#define CINPUTFILTER_H
#include "KeyTypes.h"
#include "MouseTypes.h"
#include "ProtocolTypes.h"
#include "IPlatformScreen.h"
#include "CString.h"
#include "stdmap.h"
class CPrimaryClient;
class CEvent;
class CInputFilter {
public:
// -------------------------------------------------------------------------
// Input Filter Condition Classes
// -------------------------------------------------------------------------
enum EFilterStatus {
kNoMatch,
kActivate,
kDeactivate
};
class CCondition {
public:
CCondition();
virtual ~CCondition();
virtual CCondition* clone() const = 0;
virtual CString format() const = 0;
virtual EFilterStatus match(const CEvent&) = 0;
virtual void enablePrimary(CPrimaryClient*);
virtual void disablePrimary(CPrimaryClient*);
};
// CKeystrokeCondition
class CKeystrokeCondition : public CCondition {
public:
CKeystrokeCondition(IPlatformScreen::CKeyInfo*);
CKeystrokeCondition(KeyID key, KeyModifierMask mask);
virtual ~CKeystrokeCondition();
KeyID getKey() const;
KeyModifierMask getMask() const;
// CCondition overrides
virtual CCondition* clone() const;
virtual CString format() const;
virtual EFilterStatus match(const CEvent&);
virtual void enablePrimary(CPrimaryClient*);
virtual void disablePrimary(CPrimaryClient*);
private:
UInt32 m_id;
KeyID m_key;
KeyModifierMask m_mask;
};
// CMouseButtonCondition
class CMouseButtonCondition : public CCondition {
public:
CMouseButtonCondition(IPlatformScreen::CButtonInfo*);
CMouseButtonCondition(ButtonID, KeyModifierMask mask);
virtual ~CMouseButtonCondition();
ButtonID getButton() const;
KeyModifierMask getMask() const;
// CCondition overrides
virtual CCondition* clone() const;
virtual CString format() const;
virtual EFilterStatus match(const CEvent&);
private:
ButtonID m_button;
KeyModifierMask m_mask;
};
// CScreenConnectedCondition
class CScreenConnectedCondition : public CCondition {
public:
CScreenConnectedCondition(const CString& screen);
virtual ~CScreenConnectedCondition();
// CCondition overrides
virtual CCondition* clone() const;
virtual CString format() const;
virtual EFilterStatus match(const CEvent&);
private:
CString m_screen;
};
// -------------------------------------------------------------------------
// Input Filter Action Classes
// -------------------------------------------------------------------------
class CAction {
public:
CAction();
virtual ~CAction();
virtual CAction* clone() const = 0;
virtual CString format() const = 0;
virtual void perform(const CEvent&) = 0;
};
// CLockCursorToScreenAction
class CLockCursorToScreenAction : public CAction {
public:
enum Mode { kOff, kOn, kToggle };
CLockCursorToScreenAction(Mode = kToggle);
Mode getMode() const;
// CAction overrides
virtual CAction* clone() const;
virtual CString format() const;
virtual void perform(const CEvent&);
private:
Mode m_mode;
};
// CSwitchToScreenAction
class CSwitchToScreenAction : public CAction {
public:
CSwitchToScreenAction(const CString& screen);
CString getScreen() const;
// CAction overrides
virtual CAction* clone() const;
virtual CString format() const;
virtual void perform(const CEvent&);
private:
CString m_screen;
};
// CSwitchInDirectionAction
class CSwitchInDirectionAction : public CAction {
public:
CSwitchInDirectionAction(EDirection);
EDirection getDirection() const;
// CAction overrides
virtual CAction* clone() const;
virtual CString format() const;
virtual void perform(const CEvent&);
private:
EDirection m_direction;
};
// CKeystrokeAction
class CKeystrokeAction : public CAction {
public:
CKeystrokeAction(IPlatformScreen::CKeyInfo* adoptedInfo, bool press);
~CKeystrokeAction();
void adoptInfo(IPlatformScreen::CKeyInfo*);
const IPlatformScreen::CKeyInfo*
getInfo() const;
bool isOnPress() const;
// CAction overrides
virtual CAction* clone() const;
virtual CString format() const;
virtual void perform(const CEvent&);
protected:
virtual const char* formatName() const;
private:
IPlatformScreen::CKeyInfo* m_keyInfo;
bool m_press;
};
// CMouseButtonAction -- modifier combinations not implemented yet
class CMouseButtonAction : public CAction {
public:
CMouseButtonAction(IPlatformScreen::CButtonInfo* adoptedInfo,
bool press);
~CMouseButtonAction();
const IPlatformScreen::CButtonInfo*
getInfo() const;
bool isOnPress() const;
// CAction overrides
virtual CAction* clone() const;
virtual CString format() const;
virtual void perform(const CEvent&);
protected:
virtual const char* formatName() const;
private:
IPlatformScreen::CButtonInfo* m_buttonInfo;
bool m_press;
};
class CRule {
public:
CRule();
CRule(CCondition* adopted);
CRule(const CRule&);
~CRule();
CRule& operator=(const CRule&);
// replace the condition
void setCondition(CCondition* adopted);
// add an action to the rule
void adoptAction(CAction*, bool onActivation);
// remove an action from the rule
void removeAction(bool onActivation, UInt32 index);
// replace an action in the rule
void replaceAction(CAction* adopted,
bool onActivation, UInt32 index);
// enable/disable
void enable(CPrimaryClient*);
void disable(CPrimaryClient*);
// event handling
bool handleEvent(const CEvent&);
// convert rule to a string
CString format() const;
// get the rule's condition
const CCondition*
getCondition() const;
// get number of actions
UInt32 getNumActions(bool onActivation) const;
// get action by index
const CAction& getAction(bool onActivation, UInt32 index) const;
private:
void clear();
void copy(const CRule&);
private:
typedef std::vector<CAction*> CActionList;
CCondition* m_condition;
CActionList m_activateActions;
CActionList m_deactivateActions;
};
// -------------------------------------------------------------------------
// Input Filter Class
// -------------------------------------------------------------------------
typedef std::vector<CRule> CRuleList;
CInputFilter();
CInputFilter(const CInputFilter&);
virtual ~CInputFilter();
CInputFilter& operator=(const CInputFilter&);
// add rule, adopting the condition and the actions
void addFilterRule(const CRule& rule);
// remove a rule
void removeFilterRule(UInt32 index);
// get rule by index
CRule& getRule(UInt32 index);
// enable event filtering using the given primary client. disable
// if client is NULL.
void setPrimaryClient(CPrimaryClient* client);
// convert rules to a string
CString format(const CString& linePrefix) const;
// get number of rules
UInt32 getNumRules() const;
//! Compare filters
bool operator==(const CInputFilter&) const;
//! Compare filters
bool operator!=(const CInputFilter&) const;
private:
// event handling
void handleEvent(const CEvent&, void*);
private:
CRuleList m_ruleList;
CPrimaryClient* m_primaryClient;
};
#endif

View File

@@ -22,8 +22,9 @@
//
CPrimaryClient::CPrimaryClient(const CString& name, CScreen* screen) :
m_name(name),
m_screen(screen)
CBaseClientProxy(name),
m_screen(screen),
m_fakeInputCount(0)
{
// all clipboards are clean
for (UInt32 i = 0; i < kClipboardEnd; ++i) {
@@ -42,6 +43,34 @@ CPrimaryClient::reconfigure(UInt32 activeSides)
m_screen->reconfigure(activeSides);
}
UInt32
CPrimaryClient::registerHotKey(KeyID key, KeyModifierMask mask)
{
return m_screen->registerHotKey(key, mask);
}
void
CPrimaryClient::unregisterHotKey(UInt32 id)
{
m_screen->unregisterHotKey(id);
}
void
CPrimaryClient::fakeInputBegin()
{
if (++m_fakeInputCount == 1) {
m_screen->fakeInputBegin();
}
}
void
CPrimaryClient::fakeInputEnd()
{
if (--m_fakeInputCount == 0) {
m_screen->fakeInputEnd();
}
}
SInt32
CPrimaryClient::getJumpZoneSize() const
{
@@ -57,7 +86,7 @@ CPrimaryClient::getCursorCenter(SInt32& x, SInt32& y) const
KeyModifierMask
CPrimaryClient::getToggleMask() const
{
return m_screen->getActiveModifiers();
return m_screen->pollActiveModifiers();
}
bool
@@ -150,9 +179,15 @@ CPrimaryClient::setClipboardDirty(ClipboardID id, bool dirty)
}
void
CPrimaryClient::keyDown(KeyID, KeyModifierMask, KeyButton)
CPrimaryClient::keyDown(KeyID key, KeyModifierMask mask, KeyButton button)
{
// ignore
if (m_fakeInputCount > 0) {
// XXX -- don't forward keystrokes to primary screen for now
(void)key;
(void)mask;
(void)button;
// m_screen->keyDown(key, mask, button);
}
}
void
@@ -162,9 +197,15 @@ CPrimaryClient::keyRepeat(KeyID, KeyModifierMask, SInt32, KeyButton)
}
void
CPrimaryClient::keyUp(KeyID, KeyModifierMask, KeyButton)
CPrimaryClient::keyUp(KeyID key, KeyModifierMask mask, KeyButton button)
{
// ignore
if (m_fakeInputCount > 0) {
// XXX -- don't forward keystrokes to primary screen for now
(void)key;
(void)mask;
(void)button;
// m_screen->keyUp(key, mask, button);
}
}
void
@@ -192,7 +233,7 @@ CPrimaryClient::mouseRelativeMove(SInt32, SInt32)
}
void
CPrimaryClient::mouseWheel(SInt32)
CPrimaryClient::mouseWheel(SInt32, SInt32)
{
// ignore
}
@@ -214,9 +255,3 @@ CPrimaryClient::setOptions(const COptionsList& options)
{
m_screen->setOptions(options);
}
CString
CPrimaryClient::getName() const
{
return m_name;
}

View File

@@ -15,7 +15,7 @@
#ifndef CPRIMARYCLIENT_H
#define CPRIMARYCLIENT_H
#include "IClient.h"
#include "CBaseClientProxy.h"
#include "ProtocolTypes.h"
class CScreen;
@@ -26,7 +26,7 @@ The primary screen does not have a client associated with it. This
class provides a pseudo-client to allow the primary screen to be
treated as if it was a client.
*/
class CPrimaryClient : public IClient {
class CPrimaryClient : public CBaseClientProxy {
public:
/*!
\c name is the name of the server and \p screen is primary screen.
@@ -43,6 +43,34 @@ public:
*/
void reconfigure(UInt32 activeSides);
//! Register a system hotkey
/*!
Registers a system-wide hotkey for key \p key with modifiers \p mask.
Returns an id used to unregister the hotkey.
*/
UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
//! Unregister a system hotkey
/*!
Unregisters a previously registered hot key.
*/
void unregisterHotKey(UInt32 id);
//! Prepare to synthesize input on primary screen
/*!
Prepares the primary screen to receive synthesized input. We do not
want to receive this synthesized input as user input so this method
ensures that we ignore it. Calls to \c fakeInputBegin() and
\c fakeInputEnd() may be nested; only the outermost have an effect.
*/
void fakeInputBegin();
//! Done synthesizing input on primary screen
/*!
Undoes whatever \c fakeInputBegin() did.
*/
void fakeInputEnd();
//@}
//! @name accessors
//@{
@@ -61,7 +89,7 @@ public:
the edges of the screen, typically the center.
*/
void getCursorCenter(SInt32& x, SInt32& y) const;
//! Get toggle key state
/*!
Returns the primary screen's current toggle modifier key state.
@@ -103,16 +131,15 @@ public:
virtual void mouseUp(ButtonID);
virtual void mouseMove(SInt32 xAbs, SInt32 yAbs);
virtual void mouseRelativeMove(SInt32 xRel, SInt32 yRel);
virtual void mouseWheel(SInt32 delta);
virtual void mouseWheel(SInt32 xDelta, SInt32 yDelta);
virtual void screensaver(bool activate);
virtual void resetOptions();
virtual void setOptions(const COptionsList& options);
virtual CString getName() const;
private:
CString m_name;
CScreen* m_screen;
bool m_clipboardDirty[kClipboardEnd];
SInt32 m_fakeInputCount;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -26,9 +26,10 @@
#include "stdset.h"
#include "stdvector.h"
class CBaseClientProxy;
class CEventQueueTimer;
class CPrimaryClient;
class IClient;
class CInputFilter;
//! Synergy server
/*!
@@ -36,6 +37,46 @@ This class implements the top-level server algorithms for synergy.
*/
class CServer {
public:
//! Lock cursor to screen data
class CLockCursorToScreenInfo {
public:
enum State { kOff, kOn, kToggle };
static CLockCursorToScreenInfo* alloc(State state = kToggle);
public:
State m_state;
};
//! Switch to screen data
class CSwitchToScreenInfo {
public:
static CSwitchToScreenInfo* alloc(const CString& screen);
public:
// this is a C-string; this type is a variable size structure
char m_screen[1];
};
//! Switch in direction data
class CSwitchInDirectionInfo {
public:
static CSwitchInDirectionInfo* alloc(EDirection direction);
public:
EDirection m_direction;
};
//! Screen connected data
class CScreenConnectedInfo {
public:
static CScreenConnectedInfo* alloc(const CString& screen);
public:
// this is a C-string; this type is a variable size structure
char m_screen[1];
};
/*!
Start the server with the configuration \p config and the primary
client (local screen) \p primaryClient. The client retains
@@ -60,7 +101,7 @@ public:
Adds \p client to the server. The client is adopted and will be
destroyed when the client disconnects or is disconnected.
*/
void adoptClient(IClient* client);
void adoptClient(CBaseClientProxy* client);
//! Disconnect clients
/*!
@@ -94,6 +135,14 @@ public:
*/
static CEvent::Type getErrorEvent();
//! Get connected event type
/*!
Returns the connected event type. This is sent when a client screen
has connected. The event data is a \c CScreenConnectedInfo* that
indicates the connected screen.
*/
static CEvent::Type getConnectedEvent();
//! Get disconnected event type
/*!
Returns the disconnected event type. This is sent when all the
@@ -101,18 +150,35 @@ public:
*/
static CEvent::Type getDisconnectedEvent();
//@}
protected:
//! Handle special keys
//! Get switch to screen event type
/*!
Handles keys with special meaning.
Returns the switch to screen event type. The server responds to this
by switching screens. The event data is a \c CSwitchToScreenInfo*
that indicates the target screen.
*/
bool onCommandKey(KeyID, KeyModifierMask, bool down);
static CEvent::Type getSwitchToScreenEvent();
//! Get switch in direction event type
/*!
Returns the switch in direction event type. The server responds to this
by switching screens. The event data is a \c CSwitchInDirectionInfo*
that indicates the target direction.
*/
static CEvent::Type getSwitchInDirectionEvent();
//! Get lock cursor event type
/*!
Returns the lock cursor event type. The server responds to this
by locking the cursor to the active screen or unlocking it. The
event data is a \c CLockCursorToScreenInfo*.
*/
static CEvent::Type getLockCursorToScreenEvent();
//@}
private:
// get canonical name of client
CString getName(const IClient*) const;
CString getName(const CBaseClientProxy*) const;
// get the sides of the primary screen that have neighbors
UInt32 getActivePrimarySides() const;
@@ -127,28 +193,52 @@ private:
bool isLockedToScreen() const;
// returns the jump zone of the client
SInt32 getJumpZoneSize(IClient*) const;
SInt32 getJumpZoneSize(CBaseClientProxy*) const;
// change the active screen
void switchScreen(IClient*,
void switchScreen(CBaseClientProxy*,
SInt32 x, SInt32 y, bool forScreenSaver);
// lookup neighboring screen
IClient* getNeighbor(IClient*, EDirection) const;
// jump to screen
void jumpToScreen(CBaseClientProxy*);
// convert pixel position to fraction, using x or y depending on the
// direction.
float mapToFraction(CBaseClientProxy*, EDirection,
SInt32 x, SInt32 y) const;
// convert fraction to pixel position, writing only x or y depending
// on the direction.
void mapToPixel(CBaseClientProxy*, EDirection, float f,
SInt32& x, SInt32& y) const;
// returns true if the client has a neighbor anywhere along the edge
// indicated by the direction.
bool hasAnyNeighbor(CBaseClientProxy*, EDirection) const;
// lookup neighboring screen, mapping the coordinate independent of
// the direction to the neighbor's coordinate space.
CBaseClientProxy* getNeighbor(CBaseClientProxy*, EDirection,
SInt32& x, SInt32& y) const;
// lookup neighboring screen. given a position relative to the
// source screen, find the screen we should move onto and where.
// if the position is sufficiently far from the source then we
// cross multiple screens. if there is no suitable screen then
// return NULL and x,y are not modified.
IClient* getNeighbor(IClient*, EDirection,
CBaseClientProxy* mapToNeighbor(CBaseClientProxy*, EDirection,
SInt32& x, SInt32& y) const;
// adjusts x and y or neither to avoid ending up in a jump zone
// after entering the client in the given direction.
void avoidJumpZone(CBaseClientProxy*, EDirection,
SInt32& x, SInt32& y) const;
// test if a switch is permitted. this includes testing user
// options like switch delay and tracking any state required to
// implement them. returns true iff a switch is permitted.
bool isSwitchOkay(IClient* dst, EDirection,
SInt32 x, SInt32 y);
bool isSwitchOkay(CBaseClientProxy* dst, EDirection,
SInt32 x, SInt32 y, SInt32 xActive, SInt32 yActive);
// update switch state due to a mouse move at \p x, \p y that
// doesn't switch screens.
@@ -181,11 +271,16 @@ private:
// returns true iff the delay switch timer is started
bool isSwitchWaitStarted() const;
// returns the corner (EScreenSwitchCornerMasks) where x,y is on the
// given client. corners have the given size.
UInt32 getCorner(CBaseClientProxy*,
SInt32 x, SInt32 y, SInt32 size) const;
// stop relative mouse moves
void stopRelativeMoves();
// send screen options to \c client
void sendOptions(IClient* client) const;
void sendOptions(CBaseClientProxy* client) const;
// process options from configuration
void processOptions();
@@ -207,28 +302,35 @@ private:
void handleSwitchWaitTimeout(const CEvent&, void*);
void handleClientDisconnected(const CEvent&, void*);
void handleClientCloseTimeout(const CEvent&, void*);
void handleSwitchToScreenEvent(const CEvent&, void*);
void handleSwitchInDirectionEvent(const CEvent&, void*);
void handleLockCursorToScreenEvent(const CEvent&, void*);
void handleFakeInputBeginEvent(const CEvent&, void*);
void handleFakeInputEndEvent(const CEvent&, void*);
// event processing
void onClipboardChanged(IClient* sender,
void onClipboardChanged(CBaseClientProxy* sender,
ClipboardID id, UInt32 seqNum);
void onScreensaver(bool activated);
void onKeyDown(KeyID, KeyModifierMask, KeyButton);
void onKeyUp(KeyID, KeyModifierMask, KeyButton);
void onKeyDown(KeyID, KeyModifierMask, KeyButton,
const char* screens);
void onKeyUp(KeyID, KeyModifierMask, KeyButton,
const char* screens);
void onKeyRepeat(KeyID, KeyModifierMask, SInt32, KeyButton);
void onMouseDown(ButtonID);
void onMouseUp(ButtonID);
bool onMouseMovePrimary(SInt32 x, SInt32 y);
void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
void onMouseWheel(SInt32 delta);
void onMouseWheel(SInt32 xDelta, SInt32 yDelta);
// add client to list and attach event handlers for client
bool addClient(IClient*);
bool addClient(CBaseClientProxy*);
// remove client from list and detach event handlers for client
bool removeClient(IClient*);
bool removeClient(CBaseClientProxy*);
// close a client
void closeClient(IClient*, const char* msg);
void closeClient(CBaseClientProxy*, const char* msg);
// close clients not in \p config
void closeClients(const CConfig& config);
@@ -238,11 +340,11 @@ private:
void closeAllClients();
// remove clients from internal state
void removeActiveClient(IClient*);
void removeOldClient(IClient*);
void removeActiveClient(CBaseClientProxy*);
void removeOldClient(CBaseClientProxy*);
// force the cursor off of \p client
void forceLeaveClient(IClient* client);
void forceLeaveClient(CBaseClientProxy* client);
private:
class CClipboardInfo {
@@ -260,17 +362,17 @@ private:
CPrimaryClient* m_primaryClient;
// all clients (including the primary client) indexed by name
typedef std::map<CString, IClient*> CClientList;
typedef std::set<IClient*> CClientSet;
typedef std::map<CString, CBaseClientProxy*> CClientList;
typedef std::set<CBaseClientProxy*> CClientSet;
CClientList m_clients;
CClientSet m_clientSet;
// all old connections that we're waiting to hangup
typedef std::map<IClient*, CEventQueueTimer*> COldClients;
typedef std::map<CBaseClientProxy*, CEventQueueTimer*> COldClients;
COldClients m_oldClients;
// the client with focus
IClient* m_active;
CBaseClientProxy* m_active;
// the sequence number of enter messages
UInt32 m_seqNum;
@@ -289,17 +391,20 @@ private:
// current configuration
CConfig m_config;
// input filter (from m_config);
CInputFilter* m_inputFilter;
// clipboard cache
CClipboardInfo m_clipboards[kClipboardEnd];
// state saved when screen saver activates
IClient* m_activeSaver;
CBaseClientProxy* m_activeSaver;
SInt32 m_xSaver, m_ySaver;
// common state for screen switch tests. all tests are always
// trying to reach the same screen in the same direction.
EDirection m_switchDir;
IClient* m_switchScreen;
CBaseClientProxy* m_switchScreen;
// state for delayed screen switching
double m_switchWaitDelay;
@@ -316,8 +421,15 @@ private:
// relative mouse move option
bool m_relativeMoves;
// screen locking (former scroll lock)
bool m_lockedToScreen;
static CEvent::Type s_errorEvent;
static CEvent::Type s_connectedEvent;
static CEvent::Type s_disconnectedEvent;
static CEvent::Type s_switchToScreen;
static CEvent::Type s_switchInDirection;
static CEvent::Type s_lockCursorToScreen;
};
#endif

View File

@@ -23,22 +23,28 @@ MAINTAINERCLEANFILES = \
noinst_LIBRARIES = libserver.a
libserver_a_SOURCES = \
CBaseClientProxy.cpp \
CClientListener.cpp \
CClientProxy.cpp \
CClientProxy1_0.cpp \
CClientProxy1_1.cpp \
CClientProxy1_2.cpp \
CClientProxy1_3.cpp \
CClientProxyUnknown.cpp \
CConfig.cpp \
CInputFilter.cpp \
CPrimaryClient.cpp \
CServer.cpp \
CBaseClientProxy.h \
CClientListener.h \
CClientProxy.h \
CClientProxy1_0.h \
CClientProxy1_1.h \
CClientProxy1_2.h \
CClientProxy1_3.h \
CClientProxyUnknown.h \
CConfig.h \
CInputFilter.h \
CPrimaryClient.h \
CServer.h \
$(NULL)

View File

@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "..\..\gen\build"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\server.pdb" /FD /c
# ADD CPP /nologo /MT /W4 /GR /GX /O2 /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\build\server.pdb" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -65,7 +65,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "..\..\gen\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\server.pdb" /FD /GZ /c
# ADD CPP /nologo /MTd /W4 /Gm /GR /GX /ZI /Od /I "..\common" /I "..\arch" /I "..\base" /I "..\mt" /I "..\io" /I "..\net" /I "..\synergy" /I "..\platform" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fd"..\..\gen\debug\server.pdb" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
@@ -87,6 +87,10 @@ LIB32=link.exe -lib
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CBaseClientProxy.cpp
# End Source File
# Begin Source File
SOURCE=.\CClientListener.cpp
# End Source File
# Begin Source File
@@ -107,6 +111,10 @@ SOURCE=.\CClientProxy1_2.cpp
# End Source File
# Begin Source File
SOURCE=.\CClientProxy1_3.cpp
# End Source File
# Begin Source File
SOURCE=.\CClientProxyUnknown.cpp
# End Source File
# Begin Source File
@@ -115,6 +123,10 @@ SOURCE=.\CConfig.cpp
# End Source File
# Begin Source File
SOURCE=.\CInputFilter.cpp
# End Source File
# Begin Source File
SOURCE=.\CPrimaryClient.cpp
# End Source File
# Begin Source File
@@ -127,6 +139,10 @@ SOURCE=.\CServer.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\CBaseClientProxy.h
# End Source File
# Begin Source File
SOURCE=.\CClientListener.h
# End Source File
# Begin Source File
@@ -147,6 +163,10 @@ SOURCE=.\CClientProxy1_2.h
# End Source File
# Begin Source File
SOURCE=.\CClientProxy1_3.h
# End Source File
# Begin Source File
SOURCE=.\CClientProxyUnknown.h
# End Source File
# Begin Source File
@@ -155,6 +175,10 @@ SOURCE=.\CConfig.h
# End Source File
# Begin Source File
SOURCE=.\CInputFilter.h
# End Source File
# Begin Source File
SOURCE=.\CPrimaryClient.h
# End Source File
# Begin Source File

Some files were not shown because too many files have changed in this diff Show More