mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-20 15:12:37 +00:00
desktop-ui: Fix an invalid accent_color breaking the appearance settings
This commit is contained in:
parent
a2086eb6a4
commit
2519974e84
3 changed files with 37 additions and 4 deletions
|
|
@ -26,7 +26,12 @@ The color scheme for your system. This sets the initial value of the color schem
|
|||
by using :code:`kitten desktop-ui color-scheme`.
|
||||
""",
|
||||
)
|
||||
opt('accent_color', 'cyan', long_text='The RGB accent color for your system, can be specified as a color name or in hex a decimal format.')
|
||||
opt(
|
||||
'accent_color',
|
||||
'cyan',
|
||||
option_type='to_color',
|
||||
long_text='The RGB accent color for your system, can be specified as a color name or in hex a decimal format.',
|
||||
)
|
||||
opt('contrast', 'normal', choices=('normal', 'high'), long_text='The preferred contrast level.')
|
||||
opt(
|
||||
'file_chooser_size',
|
||||
|
|
|
|||
|
|
@ -71,9 +71,14 @@ type Portal struct {
|
|||
file_chooser_first_instance_exited chan struct{}
|
||||
}
|
||||
|
||||
func color_variant(col style.RGBA) dbus.Variant {
|
||||
return dbus.MakeVariant([]float64{float64(col.Red) / 255., float64(col.Green) / 255., float64(col.Blue) / 255.})
|
||||
}
|
||||
|
||||
func to_color(spec string) (v dbus.Variant, err error) {
|
||||
if col, err := style.ParseColor(spec); err == nil {
|
||||
return dbus.MakeVariant([]float64{float64(col.Red) / 255., float64(col.Green) / 255., float64(col.Blue) / 255.}), nil
|
||||
col, err := style.ParseColor(spec)
|
||||
if err == nil {
|
||||
v = color_variant(col)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -94,7 +99,7 @@ func NewPortal(opts *Config, server_options *ServerOptions) (p *Portal, err erro
|
|||
default:
|
||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(NO_PREFERENCE))
|
||||
}
|
||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_ACCENT_COLOR_KEY], err = to_color(opts.Accent_color)
|
||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_ACCENT_COLOR_KEY] = color_variant(opts.Accent_color)
|
||||
var contrast uint32
|
||||
if opts.Contrast == Contrast_high {
|
||||
contrast = 1
|
||||
|
|
|
|||
23
kittens/desktop_ui/portal_test.go
Normal file
23
kittens/desktop_ui/portal_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// License: GPLv3 Copyright: 2026, kitty contributors
|
||||
|
||||
package desktop_ui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInvalidAccentColor(t *testing.T) {
|
||||
if _, err := to_color("cyan"); err != nil {
|
||||
t.Fatalf("Valid accent color rejected: %s", err)
|
||||
}
|
||||
if v, err := to_color("not-a-color"); err == nil {
|
||||
t.Fatalf("Invalid accent color accepted as: %#v", v)
|
||||
}
|
||||
c := NewConfig()
|
||||
if err := c.Parse("accent_color", "not-a-color"); err == nil {
|
||||
t.Fatalf("Invalid accent_color accepted in config as: %#v", c.Accent_color)
|
||||
}
|
||||
if c.Accent_color != NewConfig().Accent_color {
|
||||
t.Fatalf("Invalid accent_color in config changed the default to: %#v", c.Accent_color)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue