diff options
Diffstat (limited to 'macosx/tkMacOSXMouseEvent.c')
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 10a615e..8c0a2e6 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -35,7 +35,8 @@ enum { }; @implementation TKApplication(TKMouseEvent) -- (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent { +- (NSEvent *) tkProcessMouseEvent: (NSEvent *) theEvent +{ #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif @@ -70,6 +71,7 @@ enum { clickCount = [theEvent clickCount]; buttonNumber = [theEvent buttonNumber]; } + /* fall through */ #endif case NSTabletPoint: case NSTabletProximity: @@ -115,24 +117,24 @@ enum { EventRef eventRef = (EventRef)[theEvent eventRef]; UInt32 buttons; OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord, - typeUInt32, NULL, sizeof(UInt32), NULL, &buttons); + typeUInt32, NULL, sizeof(UInt32), NULL, &buttons); + if (err == noErr) { - state |= (buttons & ((1<<5) - 1)) << 8; - } else { - if (button < 5) { - switch (type) { - case NSLeftMouseDown: - case NSRightMouseDown: - case NSLeftMouseDragged: - case NSRightMouseDragged: - case NSOtherMouseDown: - state |= 1 << (button + 8); - break; - default: - break; - } + state |= (buttons & ((1<<5) - 1)) << 8; + } else if (button < 5) { + switch (type) { + case NSLeftMouseDown: + case NSRightMouseDown: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDown: + state |= 1 << (button + 8); + break; + default: + break; } } + NSUInteger modifiers = [theEvent modifierFlags]; if (modifiers & NSAlphaShiftKeyMask) { @@ -522,6 +524,40 @@ GenerateButtonEvent( return true; } +void +TkpWarpPointer( + TkDisplay *dispPtr) +{ + CGPoint pt; + UInt32 buttonState; + + if (dispPtr->warpWindow) { + int x, y; + + Tk_GetRootCoords(dispPtr->warpWindow, &x, &y); + pt.x = x + dispPtr->warpX; + pt.y = y + dispPtr->warpY; + } else { + pt.x = dispPtr->warpX; + pt.y = dispPtr->warpY; + } + + /* + * Tell the OSX core to generate the events to make it happen. This is + * fairly ugly, but means that under most circumstances we'll register all + * the events that would normally be generated correctly. If we use + * CGWarpMouseCursorPosition instead, strange things happen. + */ + + buttonState = (GetCurrentEvent() && Tk_MacOSXIsAppInFront()) + ? GetCurrentEventButtonState() : GetCurrentButtonState(); + + CGPostMouseEvent(pt, 1 /* generate motion events */, 5, + buttonState&1 ? 1 : 0, buttonState&2 ? 1 : 0, + buttonState&4 ? 1 : 0, buttonState&8 ? 1 : 0, + buttonState&16 ? 1 : 0); +} + /* * Local Variables: * mode: objc |