Tk Source Code

Changes On Branch json_info_plist>.
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch json_info_plist Excluding Merge-Ins

This is equivalent to a diff from e82ce250 to 22418666

2025-07-13
12:20
Merge json_info_plist (TIP #725) check-in: 27680edd user: culler tags: trunk, main
2025-06-13
14:40
Change capitalization; add man page. Closed-Leaf check-in: 22418666 user: culler tags: json_info_plist
2025-06-10
11:38
Addendum to project "Collect utility procs for the Tk test suite", correcting two proc names in comments in entry.test. check-in: 7c346303 user: erikleunissen tags: trunk, main
2025-06-06
12:20
Merge trunk check-in: 7ea63eb0 user: erikleunissen tags: tk_collect_test_utils, addendum3
2025-06-04
18:43
Fix cut-paste error. check-in: 53b369f8 user: culler tags: json_info_plist
18:31
Add a command ::tk::mac::getInfoAsJSON which returns the JSON-encoded Info.plist file. check-in: d6d7263e user: culler tags: json_info_plist
2025-06-02
15:46
Merge mark check-in: e82ce250 user: apnadkarni tags: trunk, main
15:40
Update changes.md for TIP 716 check-in: 829bfc18 user: apnadkarni tags: core-9-0-branch
12:48
Merge core-9-0-branch: TIP 716 accepted check-in: ddcbd331 user: apnadkarni tags: trunk, main

Changes to doc/tk_mac.n.
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







+









+







\fB::tk::mac::Quit\fR
\fB::tk::mac::OnHide\fR
\fB::tk::mac::OnShow\fR
\fB::tk::mac::ShowHelp\fR
\fB::tk::mac::PerformService\fR
\fB::tk::mac::LaunchURL \fIURL...\fR
\fB::tk::mac::GetAppPath\fR
\fB::tk::mac::GetInfoAsJSON

\fB::tk::mac::standardAboutPanel\fR

\fB::tk::mac::useCompatibilityMetrics \fIboolean\fR
\fB::tk::mac::CGAntialiasLimit \fIlimit\fR
\fB::tk::mac::antialiasedtext \fInumber\fR
\fB::tk::mac::useThemedToplevel \fIboolean\fR

\fB::tk::mac::iconBitmap \fIname width height \-kind value\fR

.fi
.BE
.SH "EVENT HANDLER CALLBACKS"
.PP
The Aqua/macOS application environment defines a number of additional
events that applications should respond to. These events are mapped by Tk to
calls to commands in the \fB::tk::mac\fR namespace; unless otherwise noted, if
216
217
218
219
220
221
222





223
224
225
226
227
228
229
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236







+
+
+
+
+







.QW foo://
in the CFBundleURLSchemes key of its Info.plist file; this should be
customized for the specific URL scheme the developer wants to support.
.TP
\fB::tk::mac::GetAppPath\fR
.
Returns the current applications's file path.
.TP
\fB::tk::mac::GetInfoAsJSON\fR
.
Returns a JSON-encoded Tcl string which serializes the application's
\fBmainBundle.infoDictionary\fR (defined by its \fIInfo.plist\fR file).
.PP
.SH "ADDITIONAL DIALOGS"
.PP
Aqua/macOS defines additional dialogs that applications should
support.
.\" COMMAND: standardAboutPanel
.TP
Changes to macosx/tkMacOSXInit.c.
38
39
40
41
42
43
44


45
46
47
48
49
50
51
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53







+
+








/*
 * Forward declarations...
 */

static Tcl_ObjCmdProc2 TkMacOSXGetAppPathObjCmd;
static Tcl_ObjCmdProc2 TkMacOSVersionObjCmd;
static Tcl_ObjCmdProc2 TkMacOSXGetInfoAsJSONObjCmd;


#pragma mark TKApplication(TKInit)

@implementation TKApplication
@synthesize poolLock = _poolLock;
@synthesize macOSVersion = _macOSVersion;
@synthesize tkLiveResizeEnded = _tkLiveResizeEnded;
697
698
699
700
701
702
703


704
705
706
707
708
709
710
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714







+
+







	    TkMacOSXNSImageObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "::tk::mac::standardAboutPanel",
	    TkMacOSXStandardAboutPanelObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "::tk::mac::iconBitmap",
	    TkMacOSXIconBitmapObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "::tk::mac::GetAppPath",
	    TkMacOSXGetAppPathObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "::tk::mac::GetInfoAsJSON",
	    TkMacOSXGetInfoAsJSONObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "::tk::mac::macOSVersion",
	    TkMacOSVersionObjCmd, NULL, NULL);
    MacSystrayInit(interp);
    MacPrint_Init(interp);

    return TCL_OK;
}
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXGetAppPathObjCmd(
    TCL_UNUSED(void *),
    TCL_UNUSED(void *), /* clientData */
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
{
    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832
833




















































834
835
836
837
838
839
840
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896







-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSVersionObjCmd(
    TCL_UNUSED(void *),
    TCL_UNUSED(void *), /* clientData */
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
{
    static char version[16] = "";
    if (objc > 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
    if (version[0] == '\0') {
	snprintf(version, 16, "%d", [NSApp macOSVersion]);
    }
    Tcl_SetResult(interp, version, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetInfoAsJSONObjCmd --
 *
 *	Returns the contents of the Info.plist file in the application
 *      bundle as a JSON-encoded Tcl string.
 *
 * Results:
 *	Returns the JSON encoding of the Info.plist file..
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXGetInfoAsJSONObjCmd(
    TCL_UNUSED(void *), /* clientData */
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
{
    static char *bytes = NULL;

    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    if (bytes == NULL) {
	NSJSONWritingOptions opt = NSJSONWritingPrettyPrinted;
	NSDictionary<NSString *, id> *infoDict = [[NSBundle mainBundle]
						     infoDictionary];
	NSData *infoAsJSON = [NSJSONSerialization
				 dataWithJSONObject: infoDict
					    options:opt
					      error:nil];
	if (infoAsJSON.length) {
	    int buffer_size = (int) infoAsJSON.length + 1;
	    bytes = malloc(buffer_size);
	    strlcpy(bytes, infoAsJSON.bytes, buffer_size);
	}
    }
    if (bytes) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(bytes, TCL_INDEX_NONE));
	return TCL_OK;
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayWarning --
 *
 *	This routines is called from Tk_Main to display warning messages that