changes to add command line arguments. also added automatic

restarting and daemonizing on unix.  daemon sends log messages
to syslog.  unix now reads config file from file named on
command line;  if no command line arg then uses effective
user's config file and if that's not there it finally tries
/etc/synergy.conf.  if there are no screens configured then
one is added for the primary screen.  broke some startup
stuff on win32.

also now timing out if X primary screen can't grab the mouse
and keyboard.  the server will just give up trying to switch
screens.  the grabs will fail is some other app has a grab
and won't release it.  note that kdm grabs the keyboard for
the duration that the login window is displayed, effectively
disabling synergy.
This commit is contained in:
crs
2002-06-03 18:53:18 +00:00
parent 10f4e94557
commit beda89fd53
11 changed files with 503 additions and 69 deletions

View File

@@ -2,6 +2,7 @@
#include "CXWindowsClipboard.h"
#include "CXWindowsUtil.h"
#include "CServer.h"
#include "CStopwatch.h"
#include "CThread.h"
#include "CLog.h"
#include <assert.h>
@@ -253,7 +254,7 @@ void CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
m_active = false;
}
void CXWindowsPrimaryScreen::leave()
bool CXWindowsPrimaryScreen::leave()
{
log((CLOG_INFO "leaving primary"));
assert(m_active == false);
@@ -266,31 +267,43 @@ void CXWindowsPrimaryScreen::leave()
// grab the mouse and keyboard. keep trying until we get them.
// if we can't grab one after grabbing the other then ungrab
// and wait before retrying.
// and wait before retrying. give up after s_timeout seconds.
static const double s_timeout = 1.0;
int result;
CStopwatch timer;
do {
// mouse first
// keyboard first
do {
result = XGrabPointer(display, m_window, True, 0,
GrabModeAsync, GrabModeAsync,
m_window, None, CurrentTime);
assert(result != GrabNotViewable);
if (result != GrabSuccess) {
log((CLOG_DEBUG2 "waiting to grab pointer"));
CThread::sleep(0.1);
}
} while (result != GrabSuccess);
log((CLOG_DEBUG2 "grabbed pointer"));
// now the keyboard
result = XGrabKeyboard(display, m_window, True,
GrabModeAsync, GrabModeAsync, CurrentTime);
assert(result != GrabNotViewable);
if (result != GrabSuccess) {
log((CLOG_DEBUG2 "waiting to grab keyboard"));
CThread::sleep(0.05);
if (timer.getTime() >= s_timeout) {
log((CLOG_DEBUG2 "grab keyboard timed out"));
XUnmapWindow(display, m_window);
return false;
}
}
} while (result != GrabSuccess);
log((CLOG_DEBUG2 "grabbed keyboard"));
// now the mouse
result = XGrabPointer(display, m_window, True, 0,
GrabModeAsync, GrabModeAsync,
m_window, None, CurrentTime);
assert(result != GrabNotViewable);
if (result != GrabSuccess) {
// back off to avoid grab deadlock
XUngrabPointer(display, CurrentTime);
log((CLOG_DEBUG2 "ungrabbed pointer, waiting to grab keyboard"));
CThread::sleep(0.1);
XUngrabKeyboard(display, CurrentTime);
log((CLOG_DEBUG2 "ungrabbed keyboard, waiting to grab pointer"));
CThread::sleep(0.05);
if (timer.getTime() >= s_timeout) {
log((CLOG_DEBUG2 "grab pointer timed out"));
XUnmapWindow(display, m_window);
return false;
}
}
} while (result != GrabSuccess);
log((CLOG_DEBUG1 "grabbed pointer and keyboard"));
@@ -302,6 +315,8 @@ void CXWindowsPrimaryScreen::leave()
// local client now active
m_active = true;
return true;
}
void CXWindowsPrimaryScreen::onConfigure()