Skip to content

Commit a3d78df

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 a313476 commit a3d78df

File tree

14 files changed

+369
-137
lines changed

14 files changed

+369
-137
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: 59 additions & 35 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
@@ -2175,11 +2175,31 @@ the color selection buttons all have the same size.
21752175

21762176
(proc-doc/names
21772177
color-prefs:unmarshall-style-delta
2178-
(-> printable/c (or/c false/c (is-a?/c style-delta%)))
2178+
(-> printable/c (or/c #f (is-a?/c style-delta%)))
21792179
(marshalled-style-delta)
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.
@@ -2254,15 +2274,10 @@ the color selection buttons all have the same size.
22542274
color-scheme is based on an inverted color scheme. If absent, it
22552275
is @racket[#f].}
22562276
@item{@racket['inverted-base-name]: must be a
2257-
symbol or @racket[#f]. If it is a symbol, the symbol
2258-
indicates the name of a color scheme that corresponds to the
2259-
present scheme, but in the inverted color mode. If absent,
2260-
it defaults to @racket[#f]. When a color scheme has an
2261-
inverted color scheme named, that color scheme must have the
2262-
opposite boolean in its @racket['white-on-black-base?] field
2263-
and, under Mac OS, switching to and from dark mode will
2264-
switch between the two color schemes. Note that both schemes
2265-
must name the opposite mode color scheme.}
2277+
symbol or @racket[#f]. This field is no longer used; in the past
2278+
it linked two color schemes and was used when switching between light
2279+
and dark modes. Now, two separate preferences are kept; the user's
2280+
choice for dark mode and their choice for light mode.}
22662281
@item{@racket['example]: must be a string and is used in the preferences dialog
22672282
to show an example of the color scheme. If absent, the string used in
22682283
the ``Classic'' color scheme is used.}
@@ -2315,30 +2330,37 @@ the color selection buttons all have the same size.
23152330
@tt{racket -W info@"@"color-scheme -l drracket} will print out the styles used in your
23162331
version of DrRacket.
23172332

2318-
@history[#:changed "1.68" @list{Added @racket['inverted-base-name].}]
2333+
@history[#:changed "1.68" @list{Added @racket['inverted-base-name].}
2334+
#:changed "1.79" @list{Ignore @racket['inverted-base-name].}]
23192335
})
23202336

23212337
(proc-doc/names
23222338
color-prefs:set-current-color-scheme
23232339
(-> symbol? void?)
23242340
(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.})
2341+
@{
2342+
Set's the user's preferred @tech{color scheme} to
2343+
the one whose name is @racket[name].
2344+
Also, updates the colors in DrRacket's GUI to the colors in
2345+
that color scheme if the named color scheme matches the
2346+
dark/light mode that the GUI is in.
2347+
})
23292348

2330-
(proc-doc
2349+
(proc-doc/names
23312350
color-prefs:get-current-color-scheme-name
2332-
(-> symbol?)
2333-
@{Returns the current color scheme's name.})
2351+
(->* () (#:wob? boolean?) symbol?)
2352+
(() ((wob? (white-on-black-color-scheme?))))
2353+
@{Returns the name of either the user's preferred dark mode or light mode @tech{color scheme},
2354+
based on the @racket[wob?] boolean. If the boolean is @racket[#true], returns the dark mode's name,
2355+
otherwise the light mode's.})
23342356

23352357
(proc-doc/names
23362358
color-prefs:known-color-scheme-name?
23372359
(-> any/c boolean?)
23382360
(name)
23392361
@{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.
2341-
2362+
a color or style that is an entry in the current @tech{color scheme}.
2363+
23422364
In order to return @racket[#t], @racket[name] must have been
23432365
passed as the first argument to @racket[color-prefs:add-color-scheme-entry].})
23442366

@@ -2347,17 +2369,18 @@ the color selection buttons all have the same size.
23472369
(-> symbol? (or/c #f symbol?))
23482370
(name)
23492371
@{
2350-
Returns the inverted-base color scheme name
2372+
Returns the inverted-base @tech{color scheme} name
23512373
of color scheme named @racket[name], if it has one.
23522374

2353-
@history[#:added "1.68"]
2375+
@history[#:added "1.68"
2376+
#:changed "1.79" @list{This function is no longer used.}]
23542377
})
23552378

23562379
(proc-doc/names
23572380
color-prefs:color-scheme-style-name?
23582381
(-> any/c boolean?)
23592382
(name)
2360-
@{Returns @racket[#t] if @racket[name] is a known color scheme name,
2383+
@{Returns @racket[#t] if @racket[name] is a known @tech{color scheme} name,
23612384
and is connected to a style.
23622385

23632386
In order to return @racket[#t], @racket[name] must have been
@@ -2368,21 +2391,22 @@ of color scheme named @racket[name], if it has one.
23682391
color-prefs:color-scheme-color-name?
23692392
(-> any/c boolean?)
23702393
(name)
2371-
@{Returns @racket[#t] if @racket[name] is a known color scheme name,
2394+
@{Returns @racket[#t] if @racket[name] is a known @tech{color scheme} name,
23722395
and is connected to a color.
23732396

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

2378-
(proc-doc
2401+
(proc-doc
23792402
color-prefs:lookup-in-color-scheme
23802403
(->i ([name color-prefs:known-color-scheme-name?])
2381-
()
2404+
(#:wob? [wob boolean?])
23822405
[result (name)
23832406
(if (color-prefs:color-scheme-style-name? name)
23842407
(is-a?/c style-delta%)
23852408
(is-a?/c color%))])
2409+
((white-on-black-color-scheme?))
23862410
@{Returns the current style delta or color associated with @racket[name].})
23872411

23882412
(proc-doc
@@ -2395,7 +2419,7 @@ of color scheme named @racket[name], if it has one.
23952419
()
23962420
[result void?])
23972421
@{Updates the current color or style delta associated with
2398-
@racket[name] in the current color scheme.})
2422+
@racket[name] in the current @tech{color scheme}.})
23992423

24002424
(proc-doc
24012425
color-prefs:register-color-scheme-entry-change-callback
@@ -2431,8 +2455,8 @@ of color scheme named @racket[name], if it has one.
24312455
(proc-doc
24322456
color-prefs:get-color-scheme-names
24332457
(-> (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.
2458+
@{Returns two sets; the first is the known @tech{color scheme} names that are just colors
2459+
and the second is the known @tech{color scheme} names that are styles.
24362460

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

0 commit comments

Comments
 (0)