Bool rfbShouldSendNewPosition(rfbClientPtr cl) { if (!cl->enableCursorPosUpdates) return FALSE; else { return (!CGPointEqualToPoint(cl->clientCursorLocation,currentCursorLoc())); } }
CGPoint CGLineIntersectsRectAtPoint(CGRect rect, CGLine line) { CGLine top = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMinY(rect) ) ); CGLine right = CGLineMake( CGPointMake( CGRectGetMaxX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMaxY(rect) ) ); CGLine bottom = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMaxY(rect) ), CGPointMake( CGRectGetMaxX(rect), CGRectGetMaxY(rect) ) ); CGLine left = CGLineMake( CGPointMake( CGRectGetMinX(rect), CGRectGetMinY(rect) ), CGPointMake( CGRectGetMinX(rect), CGRectGetMaxY(rect) ) ); // ensure the line extends beyond outside the rectangle CGFloat topLeftToBottomRight = CGPointDistance(CGRectTopLeftPoint(rect), CGRectBottomRightPoint(rect)); CGFloat bottomLeftToTopRight = CGPointDistance(CGRectBottomLeftPoint(rect), CGRectTopRightPoint(rect)); CGFloat maxDimension = MT_MAX(topLeftToBottomRight, bottomLeftToTopRight); CGFloat scaleFactor = maxDimension / MT_MIN(CGLineLength(line), maxDimension); CGLine extendedLine = CGLineScale(line, scaleFactor + 3); CGPoint points[4] = { CGLinesIntersectAtPoint(top, extendedLine), CGLinesIntersectAtPoint(right, extendedLine), CGLinesIntersectAtPoint(bottom, extendedLine), CGLinesIntersectAtPoint(left, extendedLine) }; for (int i = 0; i < 4; i++) { CGPoint p = points[i]; if (!CGPointEqualToPoint(p, NULL_POINT)) { return p; } } return NULL_POINT; }
// We call this to see if we have a new cursor and should notify clients to do an update // Or if cursor has moved void rfbCheckForCursorChange() { CGPoint cursorLoc = currentCursorLoc(); //rfbLog("Check For Cursor Change"); // First Let's see if we have new info on the pasteboard - if so we'll send an update to each client if (lastCursorSeed != CGSCurrentCursorSeed() || !CGPointEqualToPoint(lastCursorPosition, cursorLoc)) { rfbClientIteratorPtr iterator = rfbGetClientIterator(); rfbClientPtr cl; // Record first in case another change occurs after notifying clients lastCursorSeed = CGSCurrentCursorSeed(); lastCursorPosition = cursorLoc; // Notify each client while ((cl = rfbClientIteratorNext(iterator)) != NULL) { if (rfbShouldSendNewCursor(cl) || (rfbShouldSendNewPosition(cl))) pthread_cond_signal(&cl->updateCond); } rfbReleaseClientIterator(iterator); } }
bool CGLineEqualToLine(CGLine line1, CGLine line2) { return CGPointEqualToPoint(line1.point1, line2.point1) && CGPointEqualToPoint(line1.point2, line2.point2); }
bool CGCircleEqualToCircle(CGCircle circle1, CGCircle circle2) { return circle1.radius == circle2.radius && CGPointEqualToPoint(circle1.center, circle2.center); }