fixed wrong code style around cursor show/hide, made secondary input event handling look more readable, cut down on cursor shown/hidden state usage (to make sure the cursor is shown and hidden when needed), added check after show/hide to make sure that it actually happened

This commit is contained in:
Nick Bolton 2012-10-26 00:21:22 +00:00
parent 0502e3b3d6
commit 240c5a781d
1 changed files with 58 additions and 47 deletions

View File

@ -643,22 +643,51 @@ COSXScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
void
COSXScreen::showCursor()
{
LOG((CLOG_DEBUG "showing cursor"));
LOG((CLOG_DEBUG "showing cursor, display=%d", m_displayID));
CGDisplayShowCursor(m_displayID);
CFStringRef propertyString = CFStringCreateWithCString(NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman);
CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, kCFBooleanFalse);
CFRelease(propertyString);
// interestingly, CGDisplayShowCursor was removed in favor of only using
// the above. this could have caused the intermittent issue:
//
// Bug #2855 - Mouse cursor remains hidden on Mac client.
//
// ... seems like it might be a good idea to add it back in (it's hard
// to prove for or against since the bug is so random).
CGError error = CGDisplayShowCursor(m_displayID);
if (error != kCGErrorSuccess) {
LOG((CLOG_ERR "failed to show cursor, error=%d", error));
}
if (!CGCursorIsVisible()) {
LOG((CLOG_ERR "cursor was not shown"));
}
m_cursorHidden = false;
}
void
COSXScreen::hideCursor()
{
LOG((CLOG_DEBUG "hiding cursor, display=%d", m_displayID));
CFStringRef propertyString = CFStringCreateWithCString(NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman);
CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, kCFBooleanTrue);
CFRelease(propertyString);
LOG((CLOG_DEBUG "hiding cursor"));
CGDisplayHideCursor(m_displayID);
CGError error = CGDisplayHideCursor(m_displayID);
if (error != kCGErrorSuccess) {
LOG((CLOG_ERR "failed to hide cursor, error=%d", error));
}
if (CGCursorIsVisible()) {
LOG((CLOG_ERR "cursor was not hidden"));
}
m_cursorHidden = true;
}
void
@ -682,11 +711,7 @@ COSXScreen::enable()
else {
// FIXME -- prevent system from entering power save mode
// hide cursor
if (!m_cursorHidden) {
hideCursor();
m_cursorHidden = true;
}
// warp the mouse to the cursor center
fakeMouseMove(m_xCenter, m_yCenter);
@ -712,11 +737,7 @@ COSXScreen::enable()
void
COSXScreen::disable()
{
// show cursor if hidden
if (m_cursorHidden) {
showCursor();
m_cursorHidden = false;
}
// FIXME -- stop watching jump zones, stop capturing input
@ -747,11 +768,8 @@ COSXScreen::disable()
void
COSXScreen::enter()
{
// show cursor
if (m_cursorHidden) {
showCursor();
m_cursorHidden = false;
}
if (m_isPrimary) {
CGSetLocalEventsSuppressionInterval(0.0);
@ -780,11 +798,7 @@ COSXScreen::enter()
bool
COSXScreen::leave()
{
// hide cursor
if (!m_cursorHidden) {
hideCursor();
m_cursorHidden = true;
}
if (m_isPrimary) {
// warp to center
@ -1760,28 +1774,25 @@ COSXScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const
(m_keycode == x.m_keycode && m_mask < x.m_mask));
}
// Quartz event tap support for the secondary display. This make sure that we
// will show the cursor if a local event comes in while synergy has the cursor off the screen.
// Quartz event tap support for the secondary display. This makes sure that we
// will show the cursor if a local event comes in while synergy has the cursor
// off the screen.
CGEventRef
COSXScreen::handleCGInputEventSecondary(CGEventTapProxy proxy,
COSXScreen::handleCGInputEventSecondary(
CGEventTapProxy proxy,
CGEventType type,
CGEventRef event,
void* refcon)
{
COSXScreen* screen = (COSXScreen*)refcon;
if (screen->m_cursorHidden) {
CGPoint pos;
bool showCursor = true;
if (type == kCGEventMouseMoved) {
pos = CGEventGetLocation(event);
if (pos.x == screen->m_xCenter && pos.y == screen->m_yCenter) {
showCursor = false;
}
}
if (showCursor) {
LOG((CLOG_DEBUG "show cursor, event type %d", type));
if (screen->m_cursorHidden && type == kCGEventMouseMoved) {
CGPoint pos = CGEventGetLocation(event);
if (pos.x != screen->m_xCenter || pos.y != screen->m_yCenter) {
LOG((CLOG_DEBUG "show cursor on secondary, type=%d pos=%d,%d",
type, pos.x, pos.y));
screen->showCursor();
screen->m_cursorHidden = false;
}
}
return event;