Skip to content

Commit

Permalink
tk: Backport fix for ttk::ThemeChanged error
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstphrchvz authored and MarcusCalhoun-Lopez committed May 14, 2023
1 parent 17b1c4f commit db4f8f7
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
5 changes: 4 additions & 1 deletion x11/tk/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PortGroup muniversal 1.1

name tk
version 8.6.13
revision 0
revision 1
categories x11
license Tcl/Tk
maintainers {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
Expand Down Expand Up @@ -39,6 +39,9 @@ build.dir ${configure.dir}
# for upstream report, see https://core.tcl-lang.org/tcl/tktview?name=ad393071c2
patchfiles-append patch-dyld_fallback_library_path.diff

# Fix for https://core.tcl-lang.org/tk/info/310c74ecf4
patchfiles-append fix-themechanged-error.patch

# https://github.com/tcltk/tk/commit/b0cb1a48cb0c4a0118d45e8804476a6b4ab502c8
# this is the only code that fails on OSX 10.6, so enable it for 10.7 or newer only; see also
# https://developer.apple.com/documentation/quartzcore/calayer/1410746-contentsscale
Expand Down
120 changes: 120 additions & 0 deletions x11/tk/files/fix-themechanged-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
From https://core.tcl-lang.org/tk/info/b1876b9ebc4b

Index: generic/tkInt.h
==================================================================
--- generic/tkInt.h
+++ generic/tkInt.h
@@ -1090,14 +1090,15 @@
#ifdef __cplusplus
extern "C" {
#endif

/*
- * Themed widget set init function:
+ * Themed widget set init function, and handler called when Tk is destroyed.
*/

MODULE_SCOPE int Ttk_Init(Tcl_Interp *interp);
+MODULE_SCOPE void Ttk_TkDestroyedHandler(Tcl_Interp *interp);

/*
* Internal functions shared among Tk modules but not exported to the outside
* world:
*/

Index: generic/tkWindow.c
==================================================================
--- generic/tkWindow.c
+++ generic/tkWindow.c
@@ -1619,10 +1619,11 @@
TkBindFree(winPtr->mainPtr);
TkDeleteAllImages(winPtr->mainPtr);
TkFontPkgFree(winPtr->mainPtr);
TkFocusFree(winPtr->mainPtr);
TkStylePkgFree(winPtr->mainPtr);
+ Ttk_TkDestroyedHandler(winPtr->mainPtr->interp);

/*
* When embedding Tk into other applications, make sure that all
* destroy events reach the server. Otherwise the embedding
* application may also attempt to destroy the windows, resulting

Index: generic/ttk/ttkTheme.c
==================================================================
--- generic/ttk/ttkTheme.c
+++ generic/ttk/ttkTheme.c
@@ -401,12 +401,10 @@
Cleanup *cleanupList; /* Cleanup records */
Ttk_ResourceCache cache; /* Resource cache */
int themeChangePending; /* scheduled ThemeChangedProc call? */
} StylePackageData;

-static void ThemeChangedProc(void *); /* Forward */
-
/* Ttk_StylePkgFree --
* Cleanup procedure for StylePackageData.
*/
static void Ttk_StylePkgFree(
ClientData clientData,
@@ -415,17 +413,10 @@
StylePackageData *pkgPtr = (StylePackageData *)clientData;
Tcl_HashSearch search;
Tcl_HashEntry *entryPtr;
Cleanup *cleanup;

- /*
- * Cancel any pending ThemeChanged calls:
- */
- if (pkgPtr->themeChangePending) {
- Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
- }
-
/*
* Free themes.
*/
entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
while (entryPtr != NULL) {
@@ -484,11 +475,11 @@
*
*/
void Ttk_RegisterCleanup(
Tcl_Interp *interp, ClientData clientData, Ttk_CleanupProc *cleanupProc)
{
- StylePackageData *pkgPtr = (StylePackageData *)GetStylePackageData(interp);
+ StylePackageData *pkgPtr = GetStylePackageData(interp);
Cleanup *cleanup = (Cleanup *)ckalloc(sizeof(*cleanup));

cleanup->clientData = clientData;
cleanup->cleanupProc = cleanupProc;
cleanup->next = pkgPtr->cleanupList;
@@ -528,10 +519,29 @@
if (!pkgPtr->themeChangePending) {
Tcl_DoWhenIdle(ThemeChangedProc, pkgPtr);
pkgPtr->themeChangePending = 1;
}
}
+
+/* Ttk_TkDestroyedHandler --
+ * See bug [310c74ecf440]: idle calls to ThemeChangedProc()
+ * need to be canceled when Tk is destroyed, since the interp
+ * may still be active afterward; canceling them from
+ * Ttk_StylePkgFree() would be too late.
+ */
+void Ttk_TkDestroyedHandler(
+ Tcl_Interp* interp)
+{
+ StylePackageData* pkgPtr = GetStylePackageData(interp);
+
+ /*
+ * Cancel any pending ThemeChanged calls:
+ */
+ if (pkgPtr->themeChangePending) {
+ Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
+ }
+}

/*
* Ttk_CreateTheme --
* Create a new theme and register it in the global theme table.
*

0 comments on commit db4f8f7

Please sign in to comment.