From 1b1e4cc61c4f9772610d0e1c4c539d2562203ac6 Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 14 Apr 2019 22:21:17 +0000 Subject: Implement "tk::unsupported::MacWindowStyle isdark" to determine whether an Aqua toplevel is currently being displayed in Dark Mode. --- macosx/README | 17 ++++++++++++----- macosx/tkMacOSXWindowEvent.c | 13 ++++--------- macosx/tkMacOSXWm.c | 12 +++++++++--- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/macosx/README b/macosx/README index fd54c2d..37225c8 100644 --- a/macosx/README +++ b/macosx/README @@ -184,12 +184,13 @@ Note that not all attributes are valid for all window classes. Support for the support for some legacy Carbon-specific classes and attributes was removed (they are still accepted by the command but no longer have any effect). -- Another command available in the tk::unsupported::MacWindowStyle namespace is -tk::unsupported::MacWindowStyle tabbingid window ?newId? which can be used to -get or set the tabbingIdentifier for the NSWindow associated with a Tk Window. -See section 3 for details. +- Another command available in the tk::unsupported::MacWindowStyle namespace is: + tk::unsupported::MacWindowStyle tabbingid window ?newId? +which can be used to get or set the tabbingIdentifier for the NSWindow +associated with a Tk Window. See section 3 for details. -- A command tk::unsupported::MacWindowStyle appearance window ?newAappearance? +- The command: + tk::unsupported::MacWindowStyle appearance window ?newAappearance? is available when Tk is built and run on macOS 10.14 (Mojave) or later. In that case the Ttk widgets all support the "Dark Mode" appearance which was introduced in 10.14. The command accepts the following values for the optional @@ -199,6 +200,12 @@ appearance independent of any preferences settings. If it is set to "auto" the appearance will be determined by the preferences. This command can be used to opt out of Dark Mode on a per-window basis. +- To determine the current appearance of a window in macOS 10.14 (Mojave) and +higher, one can use the command: + tk::unsupported::MacWindowStyle isdark +The boolean return value is true if the window is currently displayed with the +dark appearance. + - If you want to use Remote Debugging with Xcode, you need to set the environment variable XCNOSTDIN to 1 in the Executable editor for Wish. That will cause us to force closing stdin & stdout. Otherwise, given how Xcode launches diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 212381e..54e1272 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -1070,7 +1070,6 @@ ConfigureRestrictProc( { XVirtualEvent event; int x, y; - NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; NSWindow *w = [self window]; TkWindow *winPtr = TkMacOSXGetTkWindow(w); Tk_Window tkwin = (Tk_Window) winPtr; @@ -1091,16 +1090,12 @@ ConfigureRestrictProc( &event.x_root, &event.y_root, &x, &y, &event.state); Tk_TopCoordsToWindow(tkwin, x, y, &event.x, &event.y); event.same_screen = true; - if (osxMode == nil) { - event.name = Tk_GetUid("LightAqua"); - Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL); - return; - } - if ([osxMode isEqual:@"Dark"]) { + if (TkMacOSXInDarkMode(tkwin)) { event.name = Tk_GetUid("DarkAqua"); - Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL); - return; + } else { + event.name = Tk_GetUid("LightAqua"); } + Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL); } /* diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index fa2acf7..504c73f 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -1021,7 +1021,6 @@ TkWmDeadWindow( while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} } [NSApp _resetAutoreleasePool]; - #if DEBUG_ZOMBIES > 0 fprintf(stderr, "================= Pool dump ===================\n"); [NSAutoreleasePool showPools]; @@ -5518,10 +5517,10 @@ TkUnsupported1ObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { static const char *const subcmds[] = { - "style", "tabbingid", "appearance", NULL + "style", "tabbingid", "appearance", "isdark", NULL }; enum SubCmds { - TKMWS_STYLE, TKMWS_TABID, TKMWS_APPEARANCE + TKMWS_STYLE, TKMWS_TABID, TKMWS_APPEARANCE, TKMWS_ISDARK }; Tk_Window tkwin = clientData; TkWindow *winPtr; @@ -5587,6 +5586,13 @@ TkUnsupported1ObjCmd( return TCL_ERROR; } return WmWinAppearance(interp, winPtr, objc, objv); + case TKMWS_ISDARK: + if ((objc != 3)) { + Tcl_WrongNumArgs(interp, 2, objv, "isdark window"); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewBooleanObj(TkMacOSXInDarkMode(tkwin))); + return TCL_OK; default: return TCL_ERROR; } -- cgit v0.12