appears to fix mouse cursor randomly not showing/hiding bug -- not sure though

This commit is contained in:
Nick Bolton 2012-10-30 18:42:58 +00:00
parent 21b02d708f
commit c34918fca1
1 changed files with 17 additions and 32 deletions

View File

@ -653,27 +653,23 @@ COSXScreen::showCursor()
CFStringRef propertyString = CFStringCreateWithCString( CFStringRef propertyString = CFStringCreateWithCString(
NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman); NULL, "SetsCursorInBackground", kCFStringEncodingMacRoman);
// it looks like from around 2010 (os x 10.6 or 10.7) the behavior of
// CGDisplayHideCursor changed so that the cursor could only be hidden by
// the program which owned it. ed's solution in r820 was to send the
// cursor to the background before trying to hide it. however, this
// intermittently caused the cursor to remain hidden when we try to
// show it again. to solve this bug, we return the cursor to the
// background.
CGSSetConnectionProperty( CGSSetConnectionProperty(
_CGSDefaultConnection(), _CGSDefaultConnection(), _CGSDefaultConnection(), _CGSDefaultConnection(),
propertyString, kCFBooleanTrue); propertyString, kCFBooleanTrue);
CFRelease(propertyString);
CGError error = CGDisplayShowCursor(m_displayID); CGError error = CGDisplayShowCursor(m_displayID);
if (error != kCGErrorSuccess) { if (error != kCGErrorSuccess) {
LOG((CLOG_ERR "failed to show cursor, error=%d", error)); LOG((CLOG_ERR "failed to show cursor, error=%d", error));
} }
CGSSetConnectionProperty( // appears to fix "mouse randomly not showing" bug
_CGSDefaultConnection(), _CGSDefaultConnection(), CGAssociateMouseAndMouseCursorPosition(true);
propertyString, kCFBooleanFalse);
CFRelease(propertyString); if (!CGCursorIsVisible()) {
LOG((CLOG_WARN "cursor may not be visible"));
}
m_cursorHidden = false; m_cursorHidden = false;
} }
@ -690,34 +686,19 @@ COSXScreen::hideCursor()
_CGSDefaultConnection(), _CGSDefaultConnection(), _CGSDefaultConnection(), _CGSDefaultConnection(),
propertyString, kCFBooleanTrue); propertyString, kCFBooleanTrue);
CFRelease(propertyString);
CGError error = CGDisplayHideCursor(m_displayID); CGError error = CGDisplayHideCursor(m_displayID);
if (error != kCGErrorSuccess) { if (error != kCGErrorSuccess) {
LOG((CLOG_ERR "failed to hide cursor, error=%d", error)); LOG((CLOG_ERR "failed to hide cursor, error=%d", error));
} }
// ed's solution to send the cursor to the background before hiding // appears to fix "mouse randomly not hiding" bug
// fixed the bug caused by the new behavior of CGDisplayHideCursor, CGAssociateMouseAndMouseCursorPosition(true);
// which is to only allow cursor to be shown/hidden by the program
// that has focus.
// however, this does not always work, and the cursor remains hidden,
// often when leaving the screen immediately after using the dock.
// to work around this, we send the mouse to the corner of the screen
// when the cursor is still visible, where it is less noticeable than
// at the center.
if (CGCursorIsVisible()) { if (CGCursorIsVisible()) {
LOG((CLOG_WARN "cursor is still visible (warping to corner)")); LOG((CLOG_WARN "cursor may be still visible"));
warpCursor(0, m_h);
} }
else {
LOG((CLOG_DEBUG "cursor is hidden, warping to center"));
warpCursor(m_xCenter, m_yCenter);
}
CGSSetConnectionProperty(
_CGSDefaultConnection(), _CGSDefaultConnection(),
propertyString, kCFBooleanFalse);
CFRelease(propertyString);
m_cursorHidden = true; m_cursorHidden = true;
} }
@ -1824,6 +1805,10 @@ COSXScreen::handleCGInputEventSecondary(
CGEventRef event, CGEventRef event,
void* refcon) void* refcon)
{ {
// this fix is really screwing with the correct show/hide behavior. it
// should be tested better before reintroducing.
return event;
COSXScreen* screen = (COSXScreen*)refcon; COSXScreen* screen = (COSXScreen*)refcon;
if (screen->m_cursorHidden && type == kCGEventMouseMoved) { if (screen->m_cursorHidden && type == kCGEventMouseMoved) {