Skip to content

Commit 80b21d3

Browse files
committed
Adjust the way dark mode works and its interaction with colorschemes
In particular, we no longer keep a preference that is "the current color scheme". Instead, we keep two preferences with a slightly different meaning: "the name of the preferred dark-mode color scheme" and "the name of the preferred light-mode color scheme". This subtle shift in the meaning of color schemes cleans up a number of things in the code. The "current color scheme" is now an emergent property of what the colors happen to be. We also add a new preference that tells us if we're paying attention to the underlying OS's dark mode setting or not (and, if we're not, do we want to be in dark mode or light mode). Also, the color preferences dialog now has checkboxes saying which color scheme to use in dark mode and which one to use in light mode instead of buttons that set the color scheme. Choosing the chcekboxes might still trigger a change in the colorscheme (if we're in the corresponding mode) As part of this, code should be using color-prefs:white-on-black-color-scheme? to determine if it should draw in dark or light mode now instead of other ways. Also, this points to a future improvement: there is code that shouldn't depend on the framework that might want to pay attention to dark or light mode, so the color schemes should probably move into mrlib/ somewhere, someday. related to racket/drracket#469
1 parent 24aa914 commit 80b21d3

File tree

14 files changed

+357
-124
lines changed

14 files changed

+357
-124
lines changed

gui-doc/scribblings/framework/editor-snip.scrbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
}
3434
@defmethod[(get-color) (or/c string? (is-a?/c color%))]{
3535
Returns @racketblock[
36-
(if (preferences:get 'framework:white-on-black?)
36+
(if (color-prefs:white-on-black-color-scheme?)
3737
"white"
3838
"black")]
3939
}

gui-lib/framework/main.rkt

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
(require (for-doc racket/base scribble/manual framework/private/mapdesc
3333
setup/getinfo racket/pretty string-constants
34-
(for-label string-constants racket/pretty)))
34+
(for-label racket/file string-constants racket/pretty)))
3535

3636
(provide-signature-elements
3737
(prefix application: framework:application-class^)
@@ -2069,7 +2069,7 @@ are currently open in tabs.
20692069
void?)
20702070
(pref-sym black-on-white-color white-on-black-color)
20712071
@{Registers a preference whose value will be updated when the user clicks on
2072-
one of the color scheme default settings in the preferences dialog, but
2072+
one of the @tech{color scheme} default settings in the preferences dialog, but
20732073
does not give it a name that can be configured by a color scheme; consider using
20742074
@racket[color-prefs:add-color-scheme-entry] instead.
20752075

@@ -2087,7 +2087,7 @@ are currently open in tabs.
20872087
((white-on-black-color #f)
20882088
(background #f)))
20892089
@{This function registers a color preference but does not give it
2090-
a name that can be configured by a color scheme; consider using
2090+
a name that can be configured by a @tech{color scheme}; consider using
20912091
@racket[color-prefs:add-color-scheme-entry] instead.
20922092

20932093
This function calls @racket[preferences:set-default] and
@@ -2180,6 +2180,26 @@ the color selection buttons all have the same size.
21802180
@{Builds a style delta from its printed representation. Returns @racket[#f]
21812181
if the printed form cannot be parsed.})
21822182

2183+
(proc-doc/names
2184+
color-prefs:white-on-black-color-scheme?
2185+
(-> boolean?)
2186+
()
2187+
@{
2188+
2189+
Returns @racket[#true] if the current @tech{color scheme} is in dark mode
2190+
(i.e. has a light foreground with a dark background) and
2191+
@racket[#false] if it is in light mode (i.e. a dark foreground with
2192+
a light background).
2193+
2194+
This function uses the @racket['framework:white-on-black-mode?] preference;
2195+
returning its value if it is a boolean and using @racket[white-on-black-panel-scheme?] if
2196+
it is set to @racket['platform]. This function is intended
2197+
to be used in place of @racket[white-on-black-panel-scheme?]
2198+
for code that supports @tech{color scheme}s.
2199+
2200+
@history[#:added "1.79"]
2201+
})
2202+
21832203
(proc-doc/names
21842204
color-prefs:white-on-black
21852205
(-> any)
@@ -2211,7 +2231,7 @@ the color selection buttons all have the same size.
22112231
#f)])
22122232
[result void?])
22132233
(#f #f #f #f #f)
2214-
@{Registers a new color or style named @racket[name] for use in the color schemes.
2234+
@{Registers a new color or style named @racket[name] for use in the @tech{color schemes}.
22152235
If @racket[style] is not @racket[#f], a new style is registered; if not a color is
22162236
registered.
22172237

@@ -2229,7 +2249,7 @@ the color selection buttons all have the same size.
22292249
(() ((extras void)))
22302250
@{Adds a panel for choosing a color-scheme to the preferences dialog.
22312251

2232-
The @racket[extras] argument is called after the color schemes have been added
2252+
The @racket[extras] argument is called after the @tech{color schemes} have been added
22332253
to the preferences panel. It is passed the panel containing the color schemes
22342254
and can add items to it.})
22352255

@@ -2241,7 +2261,7 @@ the color selection buttons all have the same size.
22412261
@index{framework:color-schemes}
22422262
@racket['framework:color-schemes]. Each definition must bind
22432263
a list of hash tables, each of which introduces a new
2244-
color scheme. Each hash table should have keys that specify
2264+
@deftech{color scheme}. Each hash table should have keys that specify
22452265
details of the color scheme, as follows:
22462266
@itemlist[@item{@racket['name]: must be either a string or a symbol;
22472267
it names the entire color scheme.
@@ -2322,22 +2342,26 @@ the color selection buttons all have the same size.
23222342
color-prefs:set-current-color-scheme
23232343
(-> symbol? void?)
23242344
(name)
2325-
@{Sets
2326-
the current color scheme to the scheme named @racket[name],
2327-
if @racket[name] is one of the color schemes.
2328-
Otherwise, sets the color scheme to the default color scheme.})
2345+
@{
2346+
Set's the user's preferred @tech{color scheme} to
2347+
the one whose name is @racket[name].
2348+
Also, updates the colors in DrRacket's GUI to the colors in
2349+
that color scheme if the named color scheme matches the
2350+
dark/light mode that the GUI is in.
2351+
})
23292352

2330-
(proc-doc
2353+
(proc-doc/names
23312354
color-prefs:get-current-color-scheme-name
2332-
(-> symbol?)
2333-
@{Returns the current color scheme's name.})
2355+
(->* () (#:wob? boolean?) symbol?)
2356+
(() ((wob? (white-on-black-color-scheme?))))
2357+
@{Returns the name of either the user's preferred dark mode or light mode @tech{color scheme}.})
23342358

23352359
(proc-doc/names
23362360
color-prefs:known-color-scheme-name?
23372361
(-> any/c boolean?)
23382362
(name)
23392363
@{Returns @racket[#t] if the input is a @racket[symbol?] that names
2340-
a color or style that is an entry in the current color scheme.
2364+
a color or style that is an entry in the current @tech{color scheme}.
23412365

23422366
In order to return @racket[#t], @racket[name] must have been
23432367
passed as the first argument to @racket[color-prefs:add-color-scheme-entry].})
@@ -2347,7 +2371,7 @@ the color selection buttons all have the same size.
23472371
(-> symbol? (or/c #f symbol?))
23482372
(name)
23492373
@{
2350-
Returns the inverted-base color scheme name
2374+
Returns the inverted-base @tech{color scheme} name
23512375
of color scheme named @racket[name], if it has one.
23522376

23532377
@history[#:added "1.68"]
@@ -2357,7 +2381,7 @@ of color scheme named @racket[name], if it has one.
23572381
color-prefs:color-scheme-style-name?
23582382
(-> any/c boolean?)
23592383
(name)
2360-
@{Returns @racket[#t] if @racket[name] is a known color scheme name,
2384+
@{Returns @racket[#t] if @racket[name] is a known @tech{color scheme} name,
23612385
and is connected to a style.
23622386

23632387
In order to return @racket[#t], @racket[name] must have been
@@ -2368,21 +2392,22 @@ of color scheme named @racket[name], if it has one.
23682392
color-prefs:color-scheme-color-name?
23692393
(-> any/c boolean?)
23702394
(name)
2371-
@{Returns @racket[#t] if @racket[name] is a known color scheme name,
2395+
@{Returns @racket[#t] if @racket[name] is a known @tech{color scheme} name,
23722396
and is connected to a color.
23732397

23742398
In order to return @racket[#t], @racket[name] must have been
23752399
passed as the first argument to @racket[color-prefs:add-color-scheme-entry]
23762400
and the @racket[#:style] argument must have also been omitted or be @racket[#f].})
23772401

2378-
(proc-doc
2402+
(proc-doc
23792403
color-prefs:lookup-in-color-scheme
23802404
(->i ([name color-prefs:known-color-scheme-name?])
2381-
()
2405+
(#:wob? [wob boolean?])
23822406
[result (name)
23832407
(if (color-prefs:color-scheme-style-name? name)
23842408
(is-a?/c style-delta%)
23852409
(is-a?/c color%))])
2410+
((white-on-black-color-scheme?))
23862411
@{Returns the current style delta or color associated with @racket[name].})
23872412

23882413
(proc-doc
@@ -2395,7 +2420,7 @@ of color scheme named @racket[name], if it has one.
23952420
()
23962421
[result void?])
23972422
@{Updates the current color or style delta associated with
2398-
@racket[name] in the current color scheme.})
2423+
@racket[name] in the current @tech{color scheme}.})
23992424

24002425
(proc-doc
24012426
color-prefs:register-color-scheme-entry-change-callback
@@ -2431,8 +2456,8 @@ of color scheme named @racket[name], if it has one.
24312456
(proc-doc
24322457
color-prefs:get-color-scheme-names
24332458
(-> (values set? set?))
2434-
@{Returns two sets; the first is the known color scheme names that are just colors
2435-
and the second is the known color scheme names that are styles.
2459+
@{Returns two sets; the first is the known @tech{color scheme} names that are just colors
2460+
and the second is the known @tech{color scheme} names that are styles.
24362461

24372462
These are all of the names that have been passed to @racket[color-prefs:add-color-scheme-entry].})
24382463
)

0 commit comments

Comments
 (0)