From f6c1908879a22fd92cbcd008c9b05bcae14aab7c Mon Sep 17 00:00:00 2001 From: culler Date: Thu, 16 Jul 2020 14:32:06 +0000 Subject: Fix stupid error with isDrawing - thanks Christopher, Nicolas and Kevin. --- generic/tkTest.c | 6 +++--- macosx/tkMacOSXDraw.c | 2 +- macosx/tkMacOSXInt.h | 2 +- macosx/tkMacOSXSubwindows.c | 8 ++++---- macosx/tkMacOSXTest.c | 30 ++++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/generic/tkTest.c b/generic/tkTest.c index a8929b9..e80f488 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -31,9 +31,9 @@ #if defined(MAC_OSX_TK) #include "tkMacOSXInt.h" #include "tkScrollbar.h" -#define LOG_DISPLAY TkTestLogDisplay() +#define LOG_DISPLAY(drawable) TkTestLogDisplay(drawable) #else -#define LOG_DISPLAY 1 +#define LOG_DISPLAY(drawable) 1 #endif #ifdef __UNIX__ @@ -1581,7 +1581,7 @@ ImageDisplay( * not just the changed portion. Tests must account for this. */ - if (LOG_DISPLAY) { + if (LOG_DISPLAY(drawable)) { sprintf(buffer, "%s display %d %d %d %d", instPtr->masterPtr->imageName, imageX, imageY, width, height); Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName, diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 4304a3c..7d12a4b 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -1636,7 +1636,7 @@ TkMacOSXSetupDrawingContext( HIShapeGetBounds(dc.clipRgn, &clipBounds); clipBounds = CGRectApplyAffineTransform(clipBounds, t); } - if (![NSApp isDrawing]) { + if (view != [NSView focusView]) { /* * We can only draw into the view when the current CGContext is diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index 58761d5..fbcfffb 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -200,7 +200,7 @@ MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x, MODULE_SCOPE void TkpRetainRegion(TkRegion r); MODULE_SCOPE void TkpReleaseRegion(TkRegion r); MODULE_SCOPE void TkpShiftButton(NSButton *button, NSPoint delta); -MODULE_SCOPE Bool TkTestLogDisplay(void); +MODULE_SCOPE Bool TkTestLogDisplay(Drawable drawable); MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin); /* diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index e6a6e6e..8bae8fd 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -216,8 +216,8 @@ XMapWindow( TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr); } - if (![NSApp isDrawing]) { - TKContentView *view = [win contentView]; + TKContentView *view = [win contentView]; + if (view != [NSView focusView]) { [view addTkDirtyRect:[view bounds]]; } @@ -332,8 +332,8 @@ XUnmapWindow( TkMacOSXUpdateClipRgn(parentPtr); } winPtr->flags &= ~TK_MAPPED; - if (![NSApp isDrawing]) { - TKContentView *view = [win contentView]; + TKContentView *view = [win contentView]; + if (view != [NSView focusView]) { [view addTkDirtyRect:[view bounds]]; } return Success; diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index a5d1d83..39f50e6 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -14,6 +14,8 @@ #include "tkMacOSXPrivate.h" #include "tkMacOSXConstants.h" +#include "tkMacOSXWm.h" + /* * Forward declarations of procedures defined later in this file: @@ -108,7 +110,8 @@ DebuggerObjCmd( * first call will usually not occur inside of drawRect. * * Results: - * On OSX 10.14 and later, returns true if and only if called from + * On OSX 10.14 and later, returns true if and only if the NSView of the + * drawable is the current focusView, which can only be the case when * within [NSView drawRect]. On earlier systems returns false if * and only if called from with [NSView drawRect]. * @@ -118,9 +121,28 @@ DebuggerObjCmd( *---------------------------------------------------------------------- */ MODULE_SCOPE Bool -TkTestLogDisplay(void) { - if ([NSApp macOSVersion] >= 101400) { - return [NSApp isDrawing]; +TkTestLogDisplay( + Drawable drawable) +{ + MacDrawable *macWin = (MacDrawable *) drawable; + NSWindow *win = nil; + if (macWin->toplevel && macWin->toplevel->winPtr && + macWin->toplevel->winPtr->wmInfoPtr && + macWin->toplevel->winPtr->wmInfoPtr->window) { + win = macWin->toplevel->winPtr->wmInfoPtr->window; + } else if (macWin->winPtr && macWin->winPtr->wmInfoPtr && + macWin->winPtr->wmInfoPtr->window) { + win = macWin->winPtr->wmInfoPtr->window; + }/* + else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) { + TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); + if (contWinPtr) { + win = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr); + } + }*/ + if (win && [NSApp macOSVersion] >= 101400) { + TKContentView *view = [win contentView]; + return (view == [NSView focusView]); } else { return ![NSApp isDrawing]; } -- cgit v0.12