From 1f00cd502ff3b3aef1eb1fac67d20e69fa4e4bad Mon Sep 17 00:00:00 2001 From: marc_culler Date: Wed, 2 Sep 2020 16:09:53 +0000 Subject: Better fix for [d72abe6b54] using NSEvents. --- macosx/tkMacOSXMouseEvent.c | 9 ++++++--- macosx/tkMacOSXPrivate.h | 7 +++++++ macosx/tkMacOSXWm.c | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index f2d7e32..be08a29 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -69,8 +69,13 @@ enum { case NSRightMouseDragged: case NSOtherMouseDragged: button = [theEvent buttonNumber] + Button1; + break; case NSMouseEntered: + [(TKWindow *)eventWindow setMouseInResizeArea:YES]; + break; case NSMouseExited: + [(TKWindow *)eventWindow setMouseInResizeArea:NO]; + break; case NSCursorUpdate: case NSLeftMouseUp: case NSRightMouseUp: @@ -100,12 +105,10 @@ enum { */ if (eventType == NSLeftMouseDown && + [(TKWindow *)eventWindow mouseInResizeArea] && ([eventWindow styleMask] & NSResizableWindowMask) && [NSApp macOSVersion] > 100600) { - NSRect frame = [eventWindow frame]; - if (local.x < 3 || local.x > frame.size.width - 3 || local.y < 3) { return theEvent; - } } global = [eventWindow tkConvertPointToScreen: local]; tkwin = TkMacOSXGetCapture(); diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index 5ac834c..ef753e5 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -436,6 +436,13 @@ VISIBILITY_HIDDEN VISIBILITY_HIDDEN @interface TKWindow : NSWindow +{ +#ifdef __i386__ + /* The Objective C runtime used on i386 requires this. */ + Bool _mouseInResizeArea; +#endif +} +@property Bool mouseInResizeArea; @end @interface TKWindow(TKWm) diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 453f277..12ce7b2 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -363,6 +363,7 @@ static void RemoveTransient(TkWindow *winPtr); #pragma mark TKWindow(TKWm) @implementation TKWindow: NSWindow +@synthesize mouseInResizeArea = _mouseInResizeArea; @end @implementation TKWindow(TKWm) -- cgit v0.12 From 3b22ceb0af03432acd3eef120a2e085358c48328 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 4 Sep 2020 18:00:32 +0000 Subject: Straighten out a lot of convoluted code in tkMacOSXMouseEvent.c --- macosx/tkMacOSXMouseEvent.c | 195 +++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 110 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index be08a29..81fc841 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -42,9 +42,9 @@ enum { * window attribute pointing to the active window. As of 10.8 this behavior * had changed. The new behavior was that if the mouse were ever moved outside * of a window, all subsequent NSMouseMoved NSEvents would have a Nil window - * attribute. To work around this the TKApplication remembers the last non-Nil - * window that it received in a mouse event. If it receives an NSEvent with a - * Nil window attribute then the saved window is used. + * attribute until the mouse returned to the window. In 11.1 it changed again. + * The window attribute can be non-nil, but referencing a window which does not + * belong to the application. */ @implementation TKApplication(TKMouseEvent) @@ -53,10 +53,10 @@ enum { NSWindow *eventWindow = [theEvent window]; NSEventType eventType = [theEvent type]; TkWindow *winPtr = NULL, *grabWinPtr; - Tk_Window tkwin; + Tk_Window tkwin = None, capture, target; NSPoint local, global; NSInteger button = -1; - [NSEvent stopPeriodicEvents]; + int win_x, win_y; #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); @@ -76,11 +76,11 @@ enum { case NSMouseExited: [(TKWindow *)eventWindow setMouseInResizeArea:NO]; break; + case NSMouseMoved: case NSCursorUpdate: case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: - case NSMouseMoved: case NSTabletPoint: case NSTabletProximity: case NSScrollWheel: @@ -90,112 +90,64 @@ enum { } /* - * Compute the mouse position in Tk screen coordinates (global) and in the - * Tk coordinates of its containing Tk Window (local). If a grab is in effect, - * the local coordinates should be relative to the grab window. + * Do not send ButtonPress XEvents for MouseDown NSEvents that start a + * resize. (The MouseUp will be handled during LiveResize.) See + * ticket [d72abe6b54]. */ - if (eventWindow) { - local = [theEvent locationInWindow]; + if (eventType == NSLeftMouseDown && + [(TKWindow *)eventWindow mouseInResizeArea] && + ([eventWindow styleMask] & NSResizableWindowMask)) { + return theEvent; + } - /* - * Do not send ButtonPress XEvents for MouseDown NSEvents that start a - * resize. (The MouseUp will be handled during LiveResize.) See - * ticket [d72abe6b54]. - */ + /* + * Find an appropriate NSWindow to attach to this event, and its + * associated Tk window. + */ - if (eventType == NSLeftMouseDown && - [(TKWindow *)eventWindow mouseInResizeArea] && - ([eventWindow styleMask] & NSResizableWindowMask) && - [NSApp macOSVersion] > 100600) { - return theEvent; - } - global = [eventWindow tkConvertPointToScreen: local]; - tkwin = TkMacOSXGetCapture(); - if (tkwin) { - winPtr = (TkWindow *) tkwin; - eventWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window); - if (eventWindow) { - local = [eventWindow tkConvertPointFromScreen: global]; - } else { - return theEvent; - } + capture = TkMacOSXGetCapture(); + if (capture) { + winPtr = (TkWindow *) capture; + eventWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window); + if (!eventWindow) { + return theEvent; } - local.y = [eventWindow frame].size.height - local.y; - global.y = TkMacOSXZeroScreenHeight() - global.y; } else { - - /* - * If the event has no NSWindow, the location is in screen coordinates. - */ - - global = [theEvent locationInWindow]; - tkwin = TkMacOSXGetCapture(); - if (tkwin) { - winPtr = (TkWindow *) tkwin; - eventWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window); - } else { - eventWindow = [NSApp mainWindow]; + if (eventWindow) { + winPtr = TkMacOSXGetTkWindow(eventWindow); } - if (!eventWindow) { - return theEvent; + if (!winPtr) { + eventWindow = [NSApp mainWindow]; + winPtr = TkMacOSXGetTkWindow(eventWindow); } - local = [eventWindow tkConvertPointFromScreen: global]; - local.y = [eventWindow frame].size.height - local.y; - global.y = TkMacOSXZeroScreenHeight() - global.y; - } - - /* - * If we still don't have a window, try using the toplevel that - * manages the NSWindow. - */ - - if (!tkwin) { - winPtr = TkMacOSXGetTkWindow(eventWindow); - tkwin = (Tk_Window)winPtr; } - if (!tkwin) { + if (!winPtr) { /* - * We can't find a window for this event. We have to ignore it. + * We couldn't find a Tk window for this event. We have to ignore it. */ #ifdef TK_MAC_DEBUG_EVENTS - TkMacOSXDbgMsg("tkwin == NULL"); + TkMacOSXDbgMsg("Event received with no Tk window."); #endif return theEvent; } + tkwin = (Tk_Window) winPtr; /* - * Ignore the event if a local grab is in effect and the Tk event window is - * not in the grabber's subtree. - */ - - grabWinPtr = winPtr->dispPtr->grabWinPtr; - if (grabWinPtr && /* There is a grab in effect ... */ - !winPtr->dispPtr->grabFlags && /* and it is a local grab ... */ - grabWinPtr->mainPtr == winPtr->mainPtr){ /* in the same application. */ - Tk_Window tkwin2, tkEventWindow = Tk_CoordsToWindow(global.x, global.y, tkwin); - if (!tkEventWindow) { - return theEvent; - } - for (tkwin2 = tkEventWindow; - !Tk_IsTopLevel(tkwin2); - tkwin2 = Tk_Parent(tkwin2)) { - if (tkwin2 == (Tk_Window)grabWinPtr) { - break; - } - } - if (tkwin2 != (Tk_Window)grabWinPtr) { - return theEvent; - } - } - - /* - * Convert local from NSWindow flipped coordinates to the toplevel's - * coordinates. + * Compute the mouse position in local (window) and global (screen) + * coordinates. These are Tk coordinates, meaning that the local origin is + * at the top left corner of the containing toplevel and the global origin + * is at top left corner of the primary screen. */ + global = [NSEvent mouseLocation]; + local = [eventWindow convertPointFromScreen: global]; + global.x = floor(global.x); + global.y = floor(TkMacOSXZeroScreenHeight() - global.y); + local.x = floor(local.x); + local.y = floor([eventWindow frame].size.height - local.y); if (Tk_IsEmbedded(winPtr)) { TkWindow *contPtr = TkpGetOtherWindow(winPtr); if (Tk_IsTopLevel(contPtr)) { @@ -212,15 +164,38 @@ enum { } /* - * Use the toplevel coordinates to find the containing Tk window. Then - * convert local into the coordinates of that window. (The converted - * local coordinates are only needed for scrollwheel events.) + * Use the local coordinates to find the Tk window which should receive + * this event. Also convert local into the coordinates of that window. + * (The converted local coordinates are only needed for scrollwheel + * events.) */ - int win_x, win_y; - tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y); - local.x = win_x; - local.y = win_y; + target = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y); + + /* + * Ignore the event if a local grab is in effect and the Tk window is + * not in the grabber's subtree. + */ + + grabWinPtr = winPtr->dispPtr->grabWinPtr; + if (grabWinPtr && /* There is a grab in effect ... */ + !winPtr->dispPtr->grabFlags && /* and it is a local grab ... */ + grabWinPtr->mainPtr == winPtr->mainPtr){ /* in the same application. */ + Tk_Window tkwin2; + if (!target) { + return theEvent; + } + for (tkwin2 = target; + !Tk_IsTopLevel(tkwin2); + tkwin2 = Tk_Parent(tkwin2)) { + if (tkwin2 == (Tk_Window)grabWinPtr) { + break; + } + } + if (tkwin2 != (Tk_Window)grabWinPtr) { + return theEvent; + } + } /* * Generate an XEvent for this mouse event. @@ -259,31 +234,32 @@ enum { /* * For normal mouse events, Tk_UpdatePointer will send the XEvent. + * Unfortunately, it will also recompute the local coordinates. */ #ifdef TK_MAC_DEBUG_EVENTS - TKLog(@"UpdatePointer %p x %f.0 y %f.0 %d", - tkwin, global.x, global.y, state); + TKLog(@"UpdatePointer %p x %.1f y %.1f %d", + target, global.x, global.y, state); #endif - Tk_UpdatePointer(tkwin, global.x, global.y, state); + + Tk_UpdatePointer(target, global.x, global.y, state); } else { + CGFloat delta; + int coarseDelta; + XEvent xEvent; /* * For scroll wheel events we need to send the XEvent here. */ - CGFloat delta; - int coarseDelta; - XEvent xEvent; - xEvent.type = MouseWheelEvent; - xEvent.xbutton.x = local.x; - xEvent.xbutton.y = local.y; + xEvent.xbutton.x = win_x; + xEvent.xbutton.y = win_y; xEvent.xbutton.x_root = global.x; xEvent.xbutton.y_root = global.y; xEvent.xany.send_event = false; - xEvent.xany.display = Tk_Display(tkwin); - xEvent.xany.window = Tk_WindowId(tkwin); + xEvent.xany.display = Tk_Display(target); + xEvent.xany.window = Tk_WindowId(target); delta = [theEvent deltaY]; if (delta != 0.0) { @@ -650,7 +626,6 @@ TkpSetCapture( while (winPtr && !Tk_IsTopLevel(winPtr)) { winPtr = winPtr->parentPtr; } - [NSEvent stopPeriodicEvents]; captureWinPtr = (Tk_Window)winPtr; } -- cgit v0.12 From 0879001fd49dfc052a3012652070d0e51095de84 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 4 Sep 2020 21:11:15 +0000 Subject: Remove a hash table that was not needed --- generic/tkInt.decls | 14 +++-- generic/tkIntPlatDecls.h | 17 ++---- generic/tkStubInit.c | 4 +- macosx/tkMacOSXPrivate.h | 19 +++++- macosx/tkMacOSXWm.c | 146 ++++++++++++----------------------------------- 5 files changed, 72 insertions(+), 128 deletions(-) diff --git a/generic/tkInt.decls b/generic/tkInt.decls index a160541..6cb33d3 100644 --- a/generic/tkInt.decls +++ b/generic/tkInt.decls @@ -956,9 +956,10 @@ declare 24 aqua { declare 25 aqua { void TkMacOSXMenuClick(void) } -declare 26 aqua { - void TkMacOSXRegisterOffScreenWindow(Window window, void *portPtr) -} +# The corresponding Unregister was not a stub, and this should be static. +#declare 26 aqua { +# void TkMacOSXRegisterOffScreenWindow(Window window, void *portPtr) +#} declare 27 aqua { int TkMacOSXResizable(TkWindow *winPtr) } @@ -977,9 +978,10 @@ declare 31 aqua { declare 32 aqua { void TkMacOSXUpdateClipRgn(TkWindow *winPtr) } -declare 33 aqua { - void TkMacOSXUnregisterMacWindow(void *portPtr) -} +# This was not implemented. Perhaps meant to be OffScreen ? +#declare 33 aqua { +# void TkMacOSXUnregisterMacWindow(void *portPtr) +#} declare 34 aqua { int TkMacOSXUseMenuID(short macID) } diff --git a/generic/tkIntPlatDecls.h b/generic/tkIntPlatDecls.h index 8221d7a..2f15ae7 100644 --- a/generic/tkIntPlatDecls.h +++ b/generic/tkIntPlatDecls.h @@ -199,9 +199,7 @@ EXTERN void TkMacOSXMakeRealWindowExist(TkWindow *winPtr); EXTERN void * TkMacOSXMakeStippleMap(Drawable d1, Drawable d2); /* 25 */ EXTERN void TkMacOSXMenuClick(void); -/* 26 */ -EXTERN void TkMacOSXRegisterOffScreenWindow(Window window, - void *portPtr); +/* Slot 26 is reserved */ /* 27 */ EXTERN int TkMacOSXResizable(TkWindow *winPtr); /* 28 */ @@ -214,8 +212,7 @@ EXTERN void TkMacOSXSetUpClippingRgn(Drawable drawable); EXTERN void TkMacOSXSetUpGraphicsPort(GC gc, void *destPort); /* 32 */ EXTERN void TkMacOSXUpdateClipRgn(TkWindow *winPtr); -/* 33 */ -EXTERN void TkMacOSXUnregisterMacWindow(void *portPtr); +/* Slot 33 is reserved */ /* 34 */ EXTERN int TkMacOSXUseMenuID(short macID); /* 35 */ @@ -420,14 +417,14 @@ typedef struct TkIntPlatStubs { void (*tkMacOSXMakeRealWindowExist) (TkWindow *winPtr); /* 23 */ void * (*tkMacOSXMakeStippleMap) (Drawable d1, Drawable d2); /* 24 */ void (*tkMacOSXMenuClick) (void); /* 25 */ - void (*tkMacOSXRegisterOffScreenWindow) (Window window, void *portPtr); /* 26 */ + void (*reserved26)(void); int (*tkMacOSXResizable) (TkWindow *winPtr); /* 27 */ void (*tkMacOSXSetHelpMenuItemCount) (void); /* 28 */ void (*tkMacOSXSetScrollbarGrow) (TkWindow *winPtr, int flag); /* 29 */ void (*tkMacOSXSetUpClippingRgn) (Drawable drawable); /* 30 */ void (*tkMacOSXSetUpGraphicsPort) (GC gc, void *destPort); /* 31 */ void (*tkMacOSXUpdateClipRgn) (TkWindow *winPtr); /* 32 */ - void (*tkMacOSXUnregisterMacWindow) (void *portPtr); /* 33 */ + void (*reserved33)(void); int (*tkMacOSXUseMenuID) (short macID); /* 34 */ TkRegion (*tkMacOSXVisableClipRgn) (TkWindow *winPtr); /* 35 */ void (*tkMacOSXWinBounds) (TkWindow *winPtr, void *geometry); /* 36 */ @@ -657,8 +654,7 @@ extern const TkIntPlatStubs *tkIntPlatStubsPtr; (tkIntPlatStubsPtr->tkMacOSXMakeStippleMap) /* 24 */ #define TkMacOSXMenuClick \ (tkIntPlatStubsPtr->tkMacOSXMenuClick) /* 25 */ -#define TkMacOSXRegisterOffScreenWindow \ - (tkIntPlatStubsPtr->tkMacOSXRegisterOffScreenWindow) /* 26 */ +/* Slot 26 is reserved */ #define TkMacOSXResizable \ (tkIntPlatStubsPtr->tkMacOSXResizable) /* 27 */ #define TkMacOSXSetHelpMenuItemCount \ @@ -671,8 +667,7 @@ extern const TkIntPlatStubs *tkIntPlatStubsPtr; (tkIntPlatStubsPtr->tkMacOSXSetUpGraphicsPort) /* 31 */ #define TkMacOSXUpdateClipRgn \ (tkIntPlatStubsPtr->tkMacOSXUpdateClipRgn) /* 32 */ -#define TkMacOSXUnregisterMacWindow \ - (tkIntPlatStubsPtr->tkMacOSXUnregisterMacWindow) /* 33 */ +/* Slot 33 is reserved */ #define TkMacOSXUseMenuID \ (tkIntPlatStubsPtr->tkMacOSXUseMenuID) /* 34 */ #define TkMacOSXVisableClipRgn \ diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index c69ecac..546b2e4 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -582,14 +582,14 @@ static const TkIntPlatStubs tkIntPlatStubs = { TkMacOSXMakeRealWindowExist, /* 23 */ TkMacOSXMakeStippleMap, /* 24 */ TkMacOSXMenuClick, /* 25 */ - TkMacOSXRegisterOffScreenWindow, /* 26 */ + 0, /* 26 */ TkMacOSXResizable, /* 27 */ TkMacOSXSetHelpMenuItemCount, /* 28 */ TkMacOSXSetScrollbarGrow, /* 29 */ TkMacOSXSetUpClippingRgn, /* 30 */ TkMacOSXSetUpGraphicsPort, /* 31 */ TkMacOSXUpdateClipRgn, /* 32 */ - TkMacOSXUnregisterMacWindow, /* 33 */ + 0, /* 33 */ TkMacOSXUseMenuID, /* 34 */ TkMacOSXVisableClipRgn, /* 35 */ TkMacOSXWinBounds, /* 36 */ diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index ef753e5..fc221b0 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -440,19 +440,36 @@ VISIBILITY_HIDDEN #ifdef __i386__ /* The Objective C runtime used on i386 requires this. */ Bool _mouseInResizeArea; + Window _tkWindow; #endif } @property Bool mouseInResizeArea; +@property Window tkWindow; @end @interface TKWindow(TKWm) - (void) tkLayoutChanged; @end -@interface NSDrawerWindow : NSWindow +@interface TKDrawerWindow : NSWindow { id _i1, _i2; +#ifdef __i386__ + /* The Objective C runtime used on i386 requires this. */ + Window _tkWindow; +#endif +} +@property Window tkWindow; +@end + +@interface TKPanel : NSPanel +{ +#ifdef __i386__ + /* The Objective C runtime used on i386 requires this. */ + Window _tkWindow; +#endif } +@property Window tkWindow; @end #pragma mark NSMenu & NSMenuItem Utilities diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 12ce7b2..41e2894 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -193,13 +193,6 @@ static const Tk_GeomMgr wmMgrType = { static int tkMacOSXWmAttrNotifyVal = 0; /* - * Hash table for Mac Window -> TkWindow mapping. - */ - -static Tcl_HashTable windowTable; -static int windowHashInit = false; - -/* * Forward declarations for procedures defined in this file: */ @@ -360,12 +353,21 @@ static void RemoveTransient(TkWindow *winPtr); #pragma mark - -#pragma mark TKWindow(TKWm) +@implementation TKPanel: NSPanel +@synthesize tkWindow = _tkWindow; +@end + +@implementation TKDrawerWindow: NSWindow +@synthesize tkWindow = _tkWindow; +@end @implementation TKWindow: NSWindow @synthesize mouseInResizeArea = _mouseInResizeArea; +@synthesize tkWindow = _tkWindow; @end +#pragma mark TKWindow(TKWm) + @implementation TKWindow(TKWm) /* @@ -886,7 +888,7 @@ TkWmDeadWindow( TkWindow *winPtr) /* Top-level window that's being deleted. */ { WmInfo *wmPtr = winPtr->wmInfoPtr, *wmPtr2; - NSWindow *ourNSWindow; + TKWindow *deadNSWindow; if (wmPtr == NULL) { return; @@ -965,27 +967,27 @@ TkWmDeadWindow( * the parent. Then close and release the NSWindow. */ - ourNSWindow = wmPtr->window; - if (ourNSWindow && !Tk_IsEmbedded(winPtr)) { - NSWindow *parent = [ourNSWindow parentWindow]; - TkMacOSXUnregisterMacWindow(ourNSWindow); + deadNSWindow = (TKWindow *)wmPtr->window; + if (deadNSWindow && !Tk_IsEmbedded(winPtr)) { + NSWindow *parent = [deadNSWindow parentWindow]; + [deadNSWindow setTkWindow:None]; if (winPtr->window) { ((MacDrawable *) winPtr->window)->view = nil; } wmPtr->window = NULL; if (parent) { - [parent removeChildWindow:ourNSWindow]; + [parent removeChildWindow:deadNSWindow]; } #if DEBUG_ZOMBIES > 1 { - const char *title = [[ourNSWindow title] UTF8String]; + const char *title = [[deadNSWindow title] UTF8String]; if (title == nil) { title = "unnamed window"; } fprintf(stderr, ">>>> Closing <%s>. Count is: %lu\n", title, - [ourNSWindow retainCount]); + [deadNSWindow retainCount]); } #endif @@ -1012,7 +1014,7 @@ TkWmDeadWindow( wmPtr2 = winPtr2->wmInfoPtr; isOnScreen = (wmPtr2->hints.initial_state != IconicState && wmPtr2->hints.initial_state != WithdrawnState); - if (w != ourNSWindow && isOnScreen && [w canBecomeKeyWindow]) { + if (w != deadNSWindow && isOnScreen && [w canBecomeKeyWindow]) { [w makeKeyAndOrderFront:NSApp]; break; } @@ -1022,12 +1024,12 @@ TkWmDeadWindow( * Prevent zombies on systems with a TouchBar. */ - if (ourNSWindow == [NSApp keyWindow]) { + if (deadNSWindow == [NSApp keyWindow]) { [NSApp _setKeyWindow:nil]; [NSApp _setMainWindow:nil]; } - [ourNSWindow close]; - [ourNSWindow release]; + [deadNSWindow close]; + [deadNSWindow release]; [NSApp _resetAutoreleasePool]; #if DEBUG_ZOMBIES > 1 @@ -5383,7 +5385,8 @@ TkGetTransientMaster( * * TkMacOSXGetXWindow -- * - * Returns the X window Id associated with the given NSWindow*. + * Stub function that returns the X window Id associated with the + * given NSWindow*. * * Results: * The window id is returned. None is returned if not a Tk window. @@ -5398,16 +5401,9 @@ Window TkMacOSXGetXWindow( void *macWinPtr) { - Tcl_HashEntry *hPtr; - - if (!macWinPtr || !windowHashInit) { - return None; - } - hPtr = Tcl_FindHashEntry(&windowTable, macWinPtr); - if (hPtr == NULL) { - return None; - } - return (Window) Tcl_GetHashValue(hPtr); + TKWindow *w = (TKWindow *)macWinPtr; + Window window = (Window) TkMacOSXGetTkWindow(w); + return window ? window : None; } /* @@ -5430,11 +5426,14 @@ TkWindow* TkMacOSXGetTkWindow( NSWindow *w) { - Window window = TkMacOSXGetXWindow(w); + Window window = None; TkDisplay *dispPtr = TkGetDisplayList(); - + if ([w respondsToSelector: @selector (tkWindow)]) { + window = [(TKWindow *)w tkWindow]; + } return (window != None ? (TkWindow *)Tk_IdToWindow(dispPtr->display, window) : NULL); + } /* @@ -6110,16 +6109,16 @@ TkMacOSXMakeRealWindowExist( NSUnifiedTitleAndToolbarWindowMask : 0) | ((attributes & kWindowSideTitlebarAttribute) ? 1 << 9 : 0) | (attributes >> WM_NSMASK_SHIFT); - Class winClass = (macClass == kDrawerWindowClass ? [NSDrawerWindow class] : + Class winClass = (macClass == kDrawerWindowClass ? [TKDrawerWindow class] : (styleMask & (NSUtilityWindowMask|NSDocModalWindowMask| - NSNonactivatingPanelMask|NSHUDWindowMask)) ? [NSPanel class] : + NSNonactivatingPanelMask|NSHUDWindowMask)) ? [TKPanel class] : [TKWindow class]); NSRect structureRect = [winClass frameRectForContentRect:NSZeroRect styleMask:styleMask]; NSRect contentRect = NSMakeRect(5 - structureRect.origin.x, TkMacOSXZeroScreenHeight() - (TkMacOSXZeroScreenTop() + 5 + structureRect.origin.y + structureRect.size.height + 200), 200, 200); - NSWindow *window = [[winClass alloc] initWithContentRect:contentRect + TKWindow *window = [[winClass alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; if (!window) { Tcl_Panic("couldn't allocate new Mac window"); @@ -6132,7 +6131,7 @@ TkMacOSXMakeRealWindowExist( [window setAcceptsMouseMovedEvents:YES]; [window setReleasedWhenClosed:NO]; if (styleMask & NSUtilityWindowMask) { - [(NSPanel*)window setFloatingPanel:YES]; + [(TKPanel*)window setFloatingPanel:YES]; } if ((styleMask & (NSTexturedBackgroundWindowMask|NSHUDWindowMask)) && !(styleMask & NSDocModalWindowMask)) { @@ -6152,7 +6151,7 @@ TkMacOSXMakeRealWindowExist( geometry.origin.y = TkMacOSXZeroScreenHeight() - (geometry.origin.y + geometry.size.height); [window setFrame:geometry display:YES]; - TkMacOSXRegisterOffScreenWindow((Window) macWin, window); + [window setTkWindow: (Window) macWin]; macWin->flags |= TK_HOST_EXISTS; if (overrideRedirect) { @@ -6205,75 +6204,6 @@ TkpRedrawWidget(Tk_Window tkwin) { } } -/* - *---------------------------------------------------------------------- - * - * TkMacOSXRegisterOffScreenWindow -- - * - * This function adds the passed in Off Screen Port to the hash table that - * maps Mac windows to root X windows. - * - * Results: - * None. - * - * Side effects: - * An entry is added to the windowTable hash table. - * - *---------------------------------------------------------------------- - */ - -void -TkMacOSXRegisterOffScreenWindow( - Window window, /* Window structure. */ - void *portPtr) /* Pointer to a Mac Window. */ -{ - Tcl_HashEntry *valueHashPtr; - int isNew; - - if (!windowHashInit) { - Tcl_InitHashTable(&windowTable, TCL_ONE_WORD_KEYS); - windowHashInit = true; - } - valueHashPtr = Tcl_CreateHashEntry(&windowTable, (char *) portPtr, &isNew); - if (!isNew) { - Tcl_Panic("Same macintosh window allocated twice!"); - } - Tcl_SetHashValue(valueHashPtr, window); -} - -/* - *---------------------------------------------------------------------- - * - * TkMacOSXUnregisterMacWindow -- - * - * Given a macintosh port window, this function removes the association - * between this window and the root X window that Tk cares about. - * - * Results: - * None. - * - * Side effects: - * An entry is removed from the windowTable hash table. - * - *---------------------------------------------------------------------- - */ - -void -TkMacOSXUnregisterMacWindow( - void *macWinPtr) /* Reference to a Mac Window */ -{ - Tcl_HashEntry *entryPtr; - - if (!windowHashInit) { - Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited"); - } - entryPtr = Tcl_FindHashEntry(&windowTable, macWinPtr); - if (!entryPtr) { - TkMacOSXDbgMsg("Failed to find window %p", macWinPtr); - } else { - Tcl_DeleteHashEntry(entryPtr); - } -} /* *---------------------------------------------------------------------- @@ -6884,7 +6814,7 @@ ApplyWindowAttributeFlagChanges( if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) { [macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ? kCGUtilityWindowLevel : ([macWindow isKindOfClass: - [NSPanel class]] && [macWindow isFloatingPanel] ? + [TKPanel class]] && [macWindow isFloatingPanel] ? kCGFloatingWindowLevel : kCGNormalWindowLevel)]; } -- cgit v0.12 From 5efe561d378b27a0a98a3b99ea7de2e38a6da3e1 Mon Sep 17 00:00:00 2001 From: culler Date: Sat, 5 Sep 2020 17:02:04 +0000 Subject: Deal with coordinate conversion on older macs. Edit comments. --- macosx/tkMacOSXMouseEvent.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 81fc841..4bdf455 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -76,11 +76,11 @@ enum { case NSMouseExited: [(TKWindow *)eventWindow setMouseInResizeArea:NO]; break; - case NSMouseMoved: - case NSCursorUpdate: case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: + case NSMouseMoved: + case NSCursorUpdate: case NSTabletPoint: case NSTabletProximity: case NSScrollWheel: @@ -95,7 +95,7 @@ enum { * ticket [d72abe6b54]. */ - if (eventType == NSLeftMouseDown && + if ((eventType == NSLeftMouseDown) && [(TKWindow *)eventWindow mouseInResizeArea] && ([eventWindow styleMask] & NSResizableWindowMask)) { return theEvent; @@ -143,7 +143,7 @@ enum { */ global = [NSEvent mouseLocation]; - local = [eventWindow convertPointFromScreen: global]; + local = [eventWindow tkConvertPointFromScreen: global]; global.x = floor(global.x); global.y = floor(TkMacOSXZeroScreenHeight() - global.y); local.x = floor(local.x); @@ -202,6 +202,13 @@ enum { */ unsigned int state = 0; + + /* + * For mouseDown events we set the single bit for that button in the state. + * Otherwise the button state is 0. Hopefully this allows TkUpdatePointer + * to maintain its button state correctly. + */ + if (button > 0) { state |= TkGetButtonMask(button); } @@ -233,8 +240,9 @@ enum { if (eventType != NSScrollWheel) { /* - * For normal mouse events, Tk_UpdatePointer will send the XEvent. - * Unfortunately, it will also recompute the local coordinates. + * For normal mouse events, Tk_UpdatePointer will send the appropriate + * XEvents using its cached state information. Unfortunately, it will + * also recompute the local coordinates. */ #ifdef TK_MAC_DEBUG_EVENTS -- cgit v0.12 From deb22dbee2982870a5144c9e5ceaa5cd2b8cc32e Mon Sep 17 00:00:00 2001 From: culler Date: Sat, 5 Sep 2020 20:06:27 +0000 Subject: Deal with the nested tracking areas in the title bar. --- macosx/tkMacOSXMouseEvent.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 4bdf455..3121c87 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -57,10 +57,17 @@ enum { NSPoint local, global; NSInteger button = -1; int win_x, win_y; + Bool inTitleBar = NO; #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif + + if (eventWindow) { + NSRect viewFrame = [[eventWindow contentView] frame]; + NSPoint location = [theEvent locationInWindow]; + inTitleBar = viewFrame.size.height < location.y; + } switch (eventType) { case NSLeftMouseDown: case NSRightMouseDown: @@ -71,10 +78,15 @@ enum { button = [theEvent buttonNumber] + Button1; break; case NSMouseEntered: - [(TKWindow *)eventWindow setMouseInResizeArea:YES]; - break; + if (!inTitleBar) { + [(TKWindow *)eventWindow setMouseInResizeArea:YES]; + break; + } case NSMouseExited: - [(TKWindow *)eventWindow setMouseInResizeArea:NO]; + if (! inTitleBar) { + [(TKWindow *)eventWindow setMouseInResizeArea:NO]; + break; + } break; case NSLeftMouseUp: case NSRightMouseUp: @@ -90,9 +102,8 @@ enum { } /* - * Do not send ButtonPress XEvents for MouseDown NSEvents that start a - * resize. (The MouseUp will be handled during LiveResize.) See - * ticket [d72abe6b54]. + * Ignore button presses that start a resize. (The release will be handled + * during LiveResize.) See ticket [d72abe6b54]. */ if ((eventType == NSLeftMouseDown) && @@ -102,6 +113,15 @@ enum { } /* + * Ignore button presses and releases that occur in the title bar. + */ + + if ((eventType == NSLeftMouseDown || eventType == NSLeftMouseUp) && + inTitleBar) { + return theEvent; + } + + /* * Find an appropriate NSWindow to attach to this event, and its * associated Tk window. */ -- cgit v0.12 From d10c9fecddbfd053dbabca48b2c47785a1204b2f Mon Sep 17 00:00:00 2001 From: culler Date: Sat, 5 Sep 2020 20:33:03 +0000 Subject: One more trick. --- macosx/tkMacOSXMouseEvent.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 3121c87..a12848f 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -62,7 +62,7 @@ enum { #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif - + if (eventWindow) { NSRect viewFrame = [[eventWindow contentView] frame]; NSPoint location = [theEvent locationInWindow]; @@ -80,18 +80,15 @@ enum { case NSMouseEntered: if (!inTitleBar) { [(TKWindow *)eventWindow setMouseInResizeArea:YES]; - break; } + break; case NSMouseExited: - if (! inTitleBar) { - [(TKWindow *)eventWindow setMouseInResizeArea:NO]; - break; - } + [(TKWindow *)eventWindow setMouseInResizeArea:NO]; break; case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: - case NSMouseMoved: + case NSMouseMoved: case NSCursorUpdate: case NSTabletPoint: case NSTabletProximity: @@ -115,7 +112,7 @@ enum { /* * Ignore button presses and releases that occur in the title bar. */ - + if ((eventType == NSLeftMouseDown || eventType == NSLeftMouseUp) && inTitleBar) { return theEvent; -- cgit v0.12 From a3727ee19e1dd52c7fb30f53f67bc24a853f8458 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sat, 5 Sep 2020 22:00:16 +0000 Subject: Supply the missing description of TkpWarpPointer. --- macosx/tkMacOSXMouseEvent.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index a12848f..30ba1bf 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -607,6 +607,23 @@ GenerateButtonEvent( return true; } +/* + *---------------------------------------------------------------------- + * + * TkpWarpPointer -- + * + * Move the mouse cursor to the screen location specified by the warpX and + * warpY fields of a TkDisplay. + * + * Results: + * None + * + * Side effects: + * The mouse cursor is moved. + * + *---------------------------------------------------------------------- + */ + void TkpWarpPointer( TkDisplay *dispPtr) -- cgit v0.12 From 57cb5d1b7215c1c676e7213748bcd65096f52af3 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 6 Sep 2020 16:23:06 +0000 Subject: Split long line --- macosx/tkMacOSXWm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index d97ef64..b1998bc 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -5846,7 +5846,8 @@ WmWinTabbingId( result = Tcl_NewStringObj(idString.UTF8String, [idString length]); } if (result == NULL) { - NSLog(@"Failed to read tabbing identifier; try calling update idletasks before getting/setting the tabbing identifier of the window."); + NSLog(@"Failed to read tabbing identifier; try calling update idletasks" + " before getting/setting the tabbing identifier of the window."); return TCL_OK; } Tcl_SetObjResult(interp, result); -- cgit v0.12 From c7622ae4dc2d427140072764e7b49861d0ed9627 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sun, 6 Sep 2020 16:36:00 +0000 Subject: Maintain our own button state so we can provide Tk_UpdatePointer with the data that it expects. --- macosx/tkMacOSXMouseEvent.c | 72 ++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 30ba1bf..40e6332 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -24,6 +24,7 @@ typedef struct { Point global; Point local; } MouseEventData; + static Tk_Window captureWinPtr = NULL; /* Current capture window; may be * NULL. */ @@ -52,12 +53,14 @@ enum { { NSWindow *eventWindow = [theEvent window]; NSEventType eventType = [theEvent type]; + NSInteger button = [theEvent buttonNumber] + Button1; TkWindow *winPtr = NULL, *grabWinPtr; Tk_Window tkwin = None, capture, target; NSPoint local, global; - NSInteger button = -1; int win_x, win_y; Bool inTitleBar = NO; + static int validPresses = 0, ignoredPresses = 0; + unsigned int buttonState = 0; #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); @@ -69,13 +72,16 @@ enum { inTitleBar = viewFrame.size.height < location.y; } switch (eventType) { - case NSLeftMouseDown: + case NSRightMouseUp: + case NSOtherMouseUp: + buttonState &= ~TkGetButtonMask(button); + break; case NSRightMouseDown: case NSOtherMouseDown: case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: - button = [theEvent buttonNumber] + Button1; + buttonState |= TkGetButtonMask(button); break; case NSMouseEntered: if (!inTitleBar) { @@ -86,8 +92,7 @@ enum { [(TKWindow *)eventWindow setMouseInResizeArea:NO]; break; case NSLeftMouseUp: - case NSRightMouseUp: - case NSOtherMouseUp: + case NSLeftMouseDown: case NSMouseMoved: case NSCursorUpdate: case NSTabletPoint: @@ -99,23 +104,41 @@ enum { } /* - * Ignore button presses that start a resize. (The release will be handled - * during LiveResize.) See ticket [d72abe6b54]. + * Update the button state. We ignore left button presses that start a + * resize or occur in the title bar. See tickets [d72abe6b54] and + * [39cbacb9e8]. */ - if ((eventType == NSLeftMouseDown) && - [(TKWindow *)eventWindow mouseInResizeArea] && - ([eventWindow styleMask] & NSResizableWindowMask)) { - return theEvent; - } + if (eventType == NSLeftMouseDown) { + if ([(TKWindow *)eventWindow mouseInResizeArea] && + ([eventWindow styleMask] & NSResizableWindowMask)) { - /* - * Ignore button presses and releases that occur in the title bar. - */ + /* + * When the left button is pressed in the resize area, we receive + * NSMouseDown, but when it is released we do not receive + * NSMouseUp. So ignore the event and clear the button state but + * do not change the ignoredPresses count. + */ - if ((eventType == NSLeftMouseDown || eventType == NSLeftMouseUp) && - inTitleBar) { - return theEvent; + buttonState &= ~TkGetButtonMask(Button1); + return theEvent; + } + if (inTitleBar) { + ignoredPresses++; + return theEvent; + } + validPresses++; + buttonState |= TkGetButtonMask(Button1); + } + if (eventType == NSLeftMouseUp) { + if (ignoredPresses > 0) { + ignoredPresses--; + } else if (validPresses > 0) { + validPresses--; + } + if (validPresses == 0) { + buttonState &= ~TkGetButtonMask(Button1); + } } /* @@ -218,18 +241,7 @@ enum { * Generate an XEvent for this mouse event. */ - unsigned int state = 0; - - /* - * For mouseDown events we set the single bit for that button in the state. - * Otherwise the button state is 0. Hopefully this allows TkUpdatePointer - * to maintain its button state correctly. - */ - - if (button > 0) { - state |= TkGetButtonMask(button); - } - + unsigned int state = buttonState; NSUInteger modifiers = [theEvent modifierFlags]; if (modifiers & NSAlphaShiftKeyMask) { -- cgit v0.12 From ed3e00f106834b22064086e15e4062321d07b8ca Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 6 Sep 2020 18:52:05 +0000 Subject: Fix [4e1e290760]: [NSColor whiteColor] is yellow without a colorspace. --- macosx/tkMacOSXColor.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 8885792..208fc8b 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -318,19 +318,15 @@ GetRGBA( #if MAC_OS_X_VERSION_MIN_REQUIRED < 101400 color = [[NSColor colorForControlTint: [NSColor currentControlTint]] colorUsingColorSpace:sRGB]; - [color getComponents: rgba]; #endif - break; - } - if (entry->index == selectedTabTextIndex) { + } else if (entry->index == selectedTabTextIndex) { int OSVersion = [NSApp macOSVersion]; if (OSVersion > 100600 && OSVersion < 110000) { - color = [NSColor whiteColor]; - [color getComponents: rgba]; - break; + color = [[NSColor whiteColor] colorUsingColorSpace:sRGB]; } + } else { + color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; } - color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; [color getComponents: rgba]; break; case clearColor: -- cgit v0.12 From 26cc1c7a65e49782d799cd635733bb0a132545eb Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 6 Sep 2020 20:35:28 +0000 Subject: Don't process events which have no meaning to Tk. --- macosx/tkMacOSXMouseEvent.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 40e6332..493e63f 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -78,9 +78,6 @@ enum { break; case NSRightMouseDown: case NSOtherMouseDown: - case NSLeftMouseDragged: - case NSRightMouseDragged: - case NSOtherMouseDragged: buttonState |= TkGetButtonMask(button); break; case NSMouseEntered: @@ -94,12 +91,17 @@ enum { case NSLeftMouseUp: case NSLeftMouseDown: case NSMouseMoved: + case NSScrollWheel: +#if 0 case NSCursorUpdate: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: case NSTabletPoint: case NSTabletProximity: - case NSScrollWheel: +#endif break; - default: /* Unrecognized mouse event. */ + default: /* This type of event is ignored. */ return theEvent; } @@ -113,7 +115,7 @@ enum { if ([(TKWindow *)eventWindow mouseInResizeArea] && ([eventWindow styleMask] & NSResizableWindowMask)) { - /* + /* * When the left button is pressed in the resize area, we receive * NSMouseDown, but when it is released we do not receive * NSMouseUp. So ignore the event and clear the button state but -- cgit v0.12 From aa5d50309de13f1aadf5549364beed42c5092d38 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sun, 6 Sep 2020 21:57:38 +0000 Subject: We do need to process MouseDragged events, though, since they appear in place of MouseMoved events. --- macosx/tkMacOSXMouseEvent.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 493e63f..dceb678 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -76,6 +76,9 @@ enum { case NSOtherMouseUp: buttonState &= ~TkGetButtonMask(button); break; + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: case NSRightMouseDown: case NSOtherMouseDown: buttonState |= TkGetButtonMask(button); @@ -94,9 +97,6 @@ enum { case NSScrollWheel: #if 0 case NSCursorUpdate: - case NSLeftMouseDragged: - case NSRightMouseDragged: - case NSOtherMouseDragged: case NSTabletPoint: case NSTabletProximity: #endif -- cgit v0.12 From 0e5e252c47d4b11c94b2ca25e1f01a4123c85e98 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sun, 6 Sep 2020 22:59:56 +0000 Subject: Don't process events for non-Tk windows. --- macosx/tkMacOSXMouseEvent.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index dceb678..05c4e0f 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -53,24 +53,37 @@ enum { { NSWindow *eventWindow = [theEvent window]; NSEventType eventType = [theEvent type]; - NSInteger button = [theEvent buttonNumber] + Button1; + NSRect viewFrame = [[eventWindow contentView] frame]; TkWindow *winPtr = NULL, *grabWinPtr; Tk_Window tkwin = None, capture, target; NSPoint local, global; - int win_x, win_y; + NSInteger button; Bool inTitleBar = NO; - static int validPresses = 0, ignoredPresses = 0; + int win_x, win_y; unsigned int buttonState = 0; + static int validPresses = 0, ignoredPresses = 0; #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif + /* + * If this event is not for a Tk toplevel, just pass it up the responder + * chain. + */ + + if (![eventWindow isMemberOfClass:[TKWindow class]]) { + return theEvent; + } + + /* + * Check if the event is located in the titlebar. + */ + if (eventWindow) { - NSRect viewFrame = [[eventWindow contentView] frame]; - NSPoint location = [theEvent locationInWindow]; - inTitleBar = viewFrame.size.height < location.y; + inTitleBar = viewFrame.size.height < [theEvent locationInWindow].y; } + button = [theEvent buttonNumber] + Button1; switch (eventType) { case NSRightMouseUp: case NSOtherMouseUp: -- cgit v0.12 From bc231dc106f1dbdad5eb6bf83f1a2ef179fb72ff Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 7 Sep 2020 16:04:07 +0000 Subject: Work around the fact that we do need to process synthesized mouse events for testing --- macosx/tkMacOSXMouseEvent.c | 10 +++++++--- macosx/tkMacOSXTest.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 05c4e0f..15ae5ce 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -68,12 +68,16 @@ enum { #endif /* - * If this event is not for a Tk toplevel, just pass it up the responder - * chain. + * If this event is not for a Tk toplevel, it should just be passed up the + * responder chain. However, there is an exception for synthesized events, + * which are used in testing. Those events are recognized by having their + * (unused) pressure field set to the impossible value -1.0. */ if (![eventWindow isMemberOfClass:[TKWindow class]]) { - return theEvent; + if (eventWindow && [eventWindow pressure] != -1.0) { + return theEvent; + } } /* diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index 434504f..cefcfad 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -229,7 +229,7 @@ PressButtonObjCmd( pt.x = loc.x = x; pt.y = y; loc.y = ScreenHeight - y; - wNum = 0; + wNum = -1; CGWarpMouseCursorPosition(pt); motion = [NSEvent mouseEventWithType:NSMouseMoved location:loc -- cgit v0.12 From 5c986033d8fb50cfcdeb184c2884afa5fa352f42 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 7 Sep 2020 16:08:38 +0000 Subject: Edit a comment. --- macosx/tkMacOSXTest.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index cefcfad..9faeff8 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -175,9 +175,11 @@ TkTestLogDisplay( * PressButtonObjCmd -- * * This Tcl command simulates a button press at a specific screen - * location. It injects NSEvents into the NSApplication event queue, - * as opposed to adding events to the Tcl queue as event generate - * would do. One application is for testing the grab command. + * location. It injects NSEvents into the NSApplication event queue, as + * opposed to adding events to the Tcl queue as event generate would do. + * One application is for testing the grab command. These events have + * pressure = -1.0 as a signal indicating that they should not be ignored + * by [NSApp tkProcessMouseEvent]. * * Results: * A standard Tcl result. @@ -229,7 +231,7 @@ PressButtonObjCmd( pt.x = loc.x = x; pt.y = y; loc.y = ScreenHeight - y; - wNum = -1; + wNum = 0; CGWarpMouseCursorPosition(pt); motion = [NSEvent mouseEventWithType:NSMouseMoved location:loc @@ -239,7 +241,7 @@ PressButtonObjCmd( context:nil eventNumber:0 clickCount:1 - pressure:0.0]; + pressure:-1.0]; [NSApp postEvent:motion atStart:NO]; press = [NSEvent mouseEventWithType:NSLeftMouseDown location:loc @@ -249,7 +251,7 @@ PressButtonObjCmd( context:nil eventNumber:1 clickCount:1 - pressure:0.0]; + pressure:-1.0]; [NSApp postEvent:press atStart:NO]; release = [NSEvent mouseEventWithType:NSLeftMouseUp location:loc @@ -259,7 +261,7 @@ PressButtonObjCmd( context:nil eventNumber:2 clickCount:1 - pressure:0.0]; + pressure:-1.0]; [NSApp postEvent:release atStart:NO]; return TCL_OK; } -- cgit v0.12 From 42fdbf1e581d12fe5d3a33e37b66c2dce3898a17 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 7 Sep 2020 18:35:22 +0000 Subject: fix a typo --- macosx/tkMacOSXMouseEvent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 15ae5ce..a93486f 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -75,7 +75,7 @@ enum { */ if (![eventWindow isMemberOfClass:[TKWindow class]]) { - if (eventWindow && [eventWindow pressure] != -1.0) { + if (eventWindow && [theEvent pressure] != -1.0) { return theEvent; } } -- cgit v0.12