From b64a5a5eac960a2b2d4ac92330811743117ca6cf Mon Sep 17 00:00:00 2001 From: marc_culler Date: Tue, 15 Sep 2020 20:10:01 +0000 Subject: More aqua initialization issues --- macosx/tkMacOSXInit.c | 35 ++++++++++++++++++++--------------- macosx/tkMacOSXSubwindows.c | 1 + macosx/tkMacOSXWindowEvent.c | 1 + 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 2cf4b0c..6d3ac1c 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -278,19 +278,19 @@ TkpInit( static int initialized = 0; /* - * Since it is possible for TkInit to be called multiple times and we - * don't want to do the following initialization multiple times we protect - * against doing it more than once. + * TkpInit can be called multiple times with different interpreters. But + * The application initialization should only be done onece. */ if (!initialized) { struct stat st; - initialized = 1; /* * Initialize/check OS version variable for runtime checks. */ + initialized = 1; + #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 # error Mac OS X 10.6 required #endif @@ -427,6 +427,22 @@ TkpInit( */ TkMacOSXServices_Init(interp); + + /* + * The root window has been created and mapped, but XMapWindow deferred its + * call to makeKeyAndOrderFront because the first call to XMapWindow + * occurs too early in the initialization process for that. Process idle + * tasks now, so the root window is configured, then order it front. + */ + + while(Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}; + for (NSWindow *window in [NSApp windows]) { + TkWindow *winPtr = TkMacOSXGetTkWindow(window); + if (winPtr && Tk_IsMapped(winPtr)) { + [window makeKeyAndOrderFront:NSApp]; + break; + } + } } if (tkLibPath[0] != '\0') { @@ -445,17 +461,6 @@ TkpInit( Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", TkMacOSXGetAppPathCmd, NULL, NULL); - /* - * The root window has been created and mapped, but XMapWindow deferred its - * call to makeKeyAndOrderFront because the first call to XMapWindow - * occurs too early in the initialization process for that. Process idle - * tasks now, so the root window is configured, then order it front. - */ - - while(Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}; - for (NSWindow *window in [NSApp windows]) { - [window makeKeyAndOrderFront:NSApp]; - } return TCL_OK; } diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 682fbb3..6ac766c 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -315,6 +315,7 @@ XUnmapWindow( if (!Tk_IsEmbedded(winPtr) && winPtr->wmInfoPtr->hints.initial_state!=IconicState) { [win orderOut:nil]; + [win setExcludedFromWindowsMenu:YES]; } TkMacOSXInvalClipRgns((Tk_Window)winPtr); diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 9e6c3dd..fcbd134 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -211,6 +211,7 @@ extern NSString *NSWindowDidOrderOffScreenNotification; TkWindow *winPtr = TkMacOSXGetTkWindow(window); if (winPtr) { TKContentView *view = [window contentView]; + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 if (@available(macOS 10.15, *)) { [view viewDidChangeEffectiveAppearance]; -- cgit v0.12 From 0a2028696498075a876a3a507484ef9ebfcf1dd6 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Wed, 16 Sep 2020 01:23:01 +0000 Subject: Deal with the deprecation of the context property of mouse NSEvents. --- macosx/tkMacOSXMouseEvent.c | 4 ++-- macosx/tkMacOSXTest.c | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 00477dd..804531b 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -72,11 +72,11 @@ enum { * 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) context pointer set to 1. + * both the windowNumber and the eventNumber set to -1. */ if (eventWindow && ![eventWindow isMemberOfClass:[TKWindow class]]) { - if ([theEvent context] != (void *) 1) + if ([theEvent windowNumber] != -1 || [theEvent eventNumber] != -1) return theEvent; } diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index 16fe37e..7981f7e 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -197,7 +197,8 @@ PressButtonObjCmd( int objc, Tcl_Obj *const objv[]) { - int x = 0, y = 0, i, value, wNum; + int x = 0, y = 0, i, value; + NSInteger signal = -1; CGPoint pt; NSPoint loc; NSEvent *motion, *press, *release; @@ -231,15 +232,20 @@ PressButtonObjCmd( pt.x = loc.x = x; pt.y = y; loc.y = ScreenHeight - y; - wNum = 0; + + /* + * We set the window number and the eventNumber to -1 as a signal to + * processMouseEvent. + */ + CGWarpMouseCursorPosition(pt); motion = [NSEvent mouseEventWithType:NSMouseMoved location:loc modifierFlags:0 timestamp:GetCurrentEventTime() - windowNumber:wNum - context:(void *) 1 - eventNumber:0 + windowNumber:signal + context:nil + eventNumber:signal clickCount:1 pressure:0.0]; [NSApp postEvent:motion atStart:NO]; @@ -247,19 +253,19 @@ PressButtonObjCmd( location:loc modifierFlags:0 timestamp:GetCurrentEventTime() - windowNumber:wNum - context:(void *)1 - eventNumber:1 + windowNumber:signal + context:nil + eventNumber:signal clickCount:1 - pressure:-1.0]; + pressure:0.0]; [NSApp postEvent:press atStart:NO]; release = [NSEvent mouseEventWithType:NSLeftMouseUp location:loc modifierFlags:0 timestamp:GetCurrentEventTime() - windowNumber:wNum - context:(void*) 1 - eventNumber:2 + windowNumber:signal + context:nil + eventNumber:signal clickCount:1 pressure:-1.0]; [NSApp postEvent:release atStart:NO]; -- cgit v0.12 From c4d109c37eaf3da5573c1cb5196bc4457fe3179e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 17 Sep 2020 12:13:47 +0000 Subject: Extend .fossil-settings/ignore-glob and .gitattributes --- .fossil-settings/ignore-glob | 11 ++++++++++- .gitattributes | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob index ba419e1..c62c87c 100644 --- a/.fossil-settings/ignore-glob +++ b/.fossil-settings/ignore-glob @@ -1,9 +1,12 @@ *.a *.dll *.dylib +*.dylib.E *.exe *.exp +*.la *.lib +*.lo *.o *.obj *.pdb @@ -11,6 +14,7 @@ *.sl *.so */Makefile +*/autom4te.cache */config.cache */config.log */config.status @@ -19,8 +23,13 @@ */tktest* */versions.vc doc/man.macros +html +macosx/configure win/Debug* win/Release* +win/*.manifest win/nmhlp-out.txt +win/nmakehlp.out unix/tk.pc -html/* +unix/Tk-Info.plist +unix/Wish-Info.plist diff --git a/.gitattributes b/.gitattributes index e9a67c8..fe89ab8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -22,15 +22,19 @@ # Declare files that will always have CRLF line endings on checkout. *.bat eol=crlf +*.rc eol=crlf *.sln eol=crlf *.vc eol=crlf # Denote all files that are truly binary and should not be modified. *.a binary +*.bmp binary +*.cur binary *.dll binary *.exe binary *.gif binary *.gz binary +*.ico binary *.jpg binary *.lib binary *.pdf binary -- cgit v0.12 From 31aef8c3ec4eb7586b974773140793a5e0c61ad8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 17 Sep 2020 15:48:52 +0000 Subject: typo in unixEmbed.test testcase. Make install-sh executable --- tests/unixEmbed.test | 2 +- unix/install-sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 unix/install-sh diff --git a/tests/unixEmbed.test b/tests/unixEmbed.test index 2dd32dc..4372253 100644 --- a/tests/unixEmbed.test +++ b/tests/unixEmbed.test @@ -976,7 +976,7 @@ test unixEmbed-7.1 {TkpRedirectKeyEvent procedure, forward keystroke} -constrain update bind .t1 {lappend y {key %A}} set y {} - event generate .t1 -keysym a + event generate .t1 -keysym a set y }] update diff --git a/unix/install-sh b/unix/install-sh old mode 100644 new mode 100755 -- cgit v0.12 From 32168d08399e99c9efa0508a9d12e9a69d0acb4c Mon Sep 17 00:00:00 2001 From: marc_culler Date: Thu, 17 Sep 2020 17:46:19 +0000 Subject: Deal with timing issues for AppleEvents which arrive during the launch process. --- macosx/tkMacOSXHLEvents.c | 45 ++++++++++++++++++++++++++++++++++++++------- macosx/tkMacOSXInit.c | 10 +++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 88036ee..70e3bf2 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -39,6 +39,7 @@ typedef struct AppleEventInfo { const char *procedure; Tcl_DString command; NSAppleEventDescriptor *replyEvent; /* Only used for DoScriptText. */ + int retryCount; } AppleEventInfo; /* @@ -148,6 +149,7 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; AEKeyword keyword; Tcl_DString pathName; + /* * Do nothing if we don't have an interpreter. */ @@ -215,7 +217,13 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; AEInfo->interp = _eventInterp; AEInfo->procedure = openDocumentProc; AEInfo->replyEvent = nil; - Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo); + AEInfo->retryCount = 0; + + if (Tcl_FindCommand(_eventInterp, "::tk::mac::OpenDocuments", NULL, 0)){ + ProcessAppleEvent((ClientData)AEInfo); + } else { + Tcl_CreateTimerHandler(500, ProcessAppleEvent, (ClientData)AEInfo); + } } - (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event @@ -232,7 +240,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; AEInfo->interp = _eventInterp; AEInfo->procedure = printDocProc; AEInfo->replyEvent = nil; - Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo); + AEInfo->retryCount = 0; + ProcessAppleEvent((ClientData)AEInfo); } - (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event @@ -293,7 +302,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; AEInfo->interp = _eventInterp; AEInfo->procedure = scriptFileProc; AEInfo->replyEvent = nil; - Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo); + AEInfo->retryCount = 0; + ProcessAppleEvent((ClientData)AEInfo); } } } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type, @@ -317,12 +327,13 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; Tcl_DStringAppendElement(scriptTextCommand, data); AEInfo->interp = _eventInterp; AEInfo->procedure = scriptTextProc; + AEInfo->retryCount = 0; if (Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) { AEInfo->replyEvent = replyEvent; ProcessAppleEvent((ClientData)AEInfo); } else { AEInfo->replyEvent = nil; - Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo); + ProcessAppleEvent((ClientData)AEInfo); } } } @@ -343,7 +354,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText"; AEInfo->interp = _eventInterp; AEInfo->procedure = launchURLProc; AEInfo->replyEvent = nil; - Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo); + AEInfo->retryCount = 0; + ProcessAppleEvent((ClientData)AEInfo); } @end @@ -378,8 +390,27 @@ static void ProcessAppleEvent( { int code; AppleEventInfo *AEInfo = (AppleEventInfo*) clientData; - if (!AEInfo->interp || - !Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) { + static Bool retry = NO; + + if (!AEInfo->interp) { + return; + } + + /* + * Apple events that are delivered during the app startup can arrive + * before the Tcl procedure for handling the events has been defined. + * If the command is not found we create a timer handler to process + * the event later, hopefully after the command has been created. + * We retry up to 2 times before giving up. + */ + + if (!Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) { + if (AEInfo->retryCount < 2) { + AEInfo->retryCount++; + Tcl_CreateTimerHandler(200, ProcessAppleEvent, clientData); + } else { + ckfree(clientData); + } return; } code = Tcl_EvalEx(AEInfo->interp, Tcl_DStringValue(&AEInfo->command), diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 6d3ac1c..2601d6b 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -145,7 +145,7 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, */ [NSApp _lockAutoreleasePool]; - while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS| TCL_DONT_WAIT)) {} + while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {} [NSApp _unlockAutoreleasePool]; } @@ -336,7 +336,6 @@ TkpInit( nil]]; [TKApplication sharedApplication]; [pool drain]; - [NSApp _setup:interp]; /* * WARNING: The finishLaunching method runs asynchronously. This @@ -345,11 +344,12 @@ TkpInit( * with the root window (see below). If the NSApplication wins then an * AppleEvent created during launch, e.g. by dropping a file icon on * the application icon, will be delivered before the procedure meant - * to to handle the AppleEvent has been defined. This is now handled - * by processing the AppleEvent as an idle task. See - * tkMacOSXHLEvents.c. + * to to handle the AppleEvent has been defined. This is handled in + * tkMacOSXHLEvents.c by scheduling a timer event to handle the + * ApplEvent later, after the required procedure has been defined. */ + [NSApp _setup:interp]; [NSApp finishLaunching]; /* -- cgit v0.12 From 322c529d4842cb7cb068d0cee5164d80e2085574 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 18 Sep 2020 11:00:06 +0000 Subject: Remove unused variable --- macosx/tkMacOSXHLEvents.c | 1 - 1 file changed, 1 deletion(-) diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 70e3bf2..258740b 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -390,7 +390,6 @@ static void ProcessAppleEvent( { int code; AppleEventInfo *AEInfo = (AppleEventInfo*) clientData; - static Bool retry = NO; if (!AEInfo->interp) { return; -- cgit v0.12 From 971e564fd07029199b132900f4390cd8d51fdff1 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 18 Sep 2020 12:35:25 +0000 Subject: Don't depend on lsearch returning -1 any more --- tests/oldpack.test | 4 ++-- tests/text.test | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/oldpack.test b/tests/oldpack.test index e39ae08..35fd0f6 100644 --- a/tests/oldpack.test +++ b/tests/oldpack.test @@ -31,9 +31,9 @@ label .pack.violet.l -text P -bd 2 -relief raised place .pack.violet.l -relwidth 1.0 -relheight 1.0 if {![catch {pack ap .pack .pack.red top}]} { - + # Don't execute any of this file if Tk is compiled with -DTCL_NO_DEPRECATED - + test oldpack-1.1 {basic positioning} -body { #pack ap .pack .pack.red top diff --git a/tests/text.test b/tests/text.test index 3802746..b3e10bc 100644 --- a/tests/text.test +++ b/tests/text.test @@ -7034,12 +7034,12 @@ test text-27.28 {edit undo and edit redo do not leave \ .t edit separator .t insert end "Again hello.\n" .t edit undo - lappend res [lsearch [.t mark names] tk::undoMark*] + lappend res [expr {[lsearch [.t mark names] tk::undoMark*]<0}] .t edit redo - lappend res [lsearch [.t mark names] tk::undoMark*] + lappend res [expr {[lsearch [.t mark names] tk::undoMark*]<0}] } -cleanup { destroy .t -} -result [list -1 -1] +} -result {1 1} test text-28.1 {bug fix - 624372, ControlUtfProc long lines} -body { -- cgit v0.12