]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.backend.cocoa: set the light/dark theme on startup and when changed.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 31 Dec 2021 04:40:38 +0000 (20:40 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 31 Dec 2021 04:41:45 +0000 (20:41 -0800)
basis/cocoa/cocoa.factor
basis/ui/backend/cocoa/cocoa.factor
basis/ui/backend/cocoa/views/views.factor

index 10f6a93ffc915c281d73d247bbdc773fae5e57d8..708381f633d554d3befb378f9e362859fa4c849c 100644 (file)
@@ -7,7 +7,6 @@ IN: cocoa
 SYMBOL: sent-messages
 
 sent-messages [ H{ } clone ] initialize
-
 : remember-send ( selector -- )
     dup sent-messages get set-at ;
 
@@ -52,6 +51,7 @@ SYNTAX: IMPORT: scan-token [ ] import-objc-class ;
 [
     {
         "NSAlert"
+        "NSAppearance"
         "NSAppleScript"
         "NSApplication"
         "NSArray"
index 6b257e1eb967c1225aa9842b4aff126255759af4..81553f5a5f246ffcc52a65cf2f13760e3f0bfbbc 100644 (file)
@@ -1,15 +1,14 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.data arrays assocs classes
-cocoa cocoa.application cocoa.classes cocoa.messages cocoa.nibs
-cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.types
-cocoa.views cocoa.windows combinators command-line
-core-foundation core-foundation.run-loop core-graphics
-core-graphics.types destructors fry generalizations io.thread
-kernel libc literals locals math math.bitwise math.rectangles
-memory namespaces sequences threads ui colors ui.backend
-ui.backend.cocoa.views ui.clipboards ui.gadgets
-ui.gadgets.worlds ui.pixel-formats ui.private words.symbol ;
+USING: accessors alien.c-types alien.data cocoa
+cocoa.application cocoa.classes cocoa.nibs cocoa.pasteboard
+cocoa.runtime cocoa.subclassing cocoa.views cocoa.windows
+combinators core-foundation.run-loop core-foundation.strings
+core-graphics core-graphics.types io.thread kernel literals math
+math.bitwise math.rectangles namespaces sequences threads ui
+ui.backend ui.backend.cocoa.views ui.clipboards
+ui.gadgets.worlds ui.pixel-formats ui.private ui.theme
+ui.theme.switching ;
 IN: ui.backend.cocoa
 
 TUPLE: window-handle view window ;
@@ -208,6 +207,11 @@ M: cocoa-ui-backend system-alert
 : install-app-delegate ( -- )
     NSApp FactorApplicationDelegate install-delegate ;
 
+: set-theme ( -- )
+    NSAppearance -> currentAppearance -> name CF>string
+    "NSAppearanceNameDarkAqua" = dark-theme light-theme ?
+    switch-theme ;
+
 SYMBOL: cocoa-startup-hook
 
 cocoa-startup-hook [
@@ -218,6 +222,7 @@ M: cocoa-ui-backend (with-ui)
     "UI" assert.app [
         init-clipboard
         cocoa-startup-hook get call( -- )
+        set-theme
         start-ui
         stop-io-thread
         init-thread-timer
index 48d20387ad39ae3de0604df4719b86596691d193..3373d80407ec920020538ad98aa3775561bdfb72 100644 (file)
@@ -334,10 +334,8 @@ PRIVATE>
 
     METHOD: void viewDidChangeEffectiveAppearance [
         self -> effectiveAppearance -> name [
-            CF>string {
-                { "NSAppearanceNameAqua" [ light-theme ] }
-                { "NSAppearanceNameDarkAqua" [ dark-theme ] }
-            } case switch-theme
+            CF>string "NSAppearanceNameDarkAqua" =
+            dark-theme light-theme ? switch-theme
         ] when*
     ] ;