diff options
Diffstat (limited to 'macosx/tkMacOSXMouseEvent.c')
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index f57c184..90d2d00 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -9,8 +9,6 @@ * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * RCS: @(#) $Id$ */ #include "tkMacOSXPrivate.h" @@ -37,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 @@ -89,6 +88,7 @@ enum { } NSPoint global, local = [theEvent locationInWindow]; + if (win) { global = [win convertBaseToScreen:local]; local.y = [win frame].size.height - local.y; @@ -128,23 +128,23 @@ enum { UInt32 buttons; OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord, 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; - } + } 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) { @@ -535,9 +535,43 @@ 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: c + * mode: objc * c-basic-offset: 4 * fill-column: 79 * coding: utf-8 |