chore: import official kitty sources from upstream

Bring the kovidgoyal/kitty codebase in as the base of FWS-Kitty, vendored at upstream commit 91fb38a without its git history.
This commit is contained in:
BlackAngelTV committed 2026-11-04 11:35:59 +01:00
commit 3d174c45a4
1134 files changed
+433629

No files matched your search

View File
Whitespace-only changes.
+206
View File
@@ -0,0 +1,206 @@
package desktop_ui
import (
"fmt"
"strings"
"github.com/kovidgoyal/dbus"
"github.com/kovidgoyal/kitty"
"github.com/kovidgoyal/kitty/tools/cli"
"github.com/kovidgoyal/kitty/tools/config"
"github.com/kovidgoyal/kitty/tools/utils"
)
var _ = fmt.Print
type ServerOptions struct {
Config []string
Override []string
}
const server_conf_name = "desktop-ui-portal"
func load_server_config(opts *ServerOptions) (ans *Config, err error) {
ans = NewConfig()
p := config.ConfigParser{LineHandler: ans.Parse}
err = p.LoadConfig(server_conf_name+".conf", opts.Config, opts.Override)
return
}
func run_server(opts *ServerOptions) (err error) {
config, err := load_server_config(opts)
if err == nil {
portal, err := NewPortal(config, opts)
if err == nil {
err = portal.Start()
if err == nil {
defer portal.Cleanup()
}
}
}
if err != nil {
return
}
c := make(chan string)
<-c
return
}
func specialize_command(parent *cli.Command) {
parent.Run = func(cmd *cli.Command, args []string) (int, error) {
cmd.ShowHelp()
return 1, nil
}
parent.ShortDescription = "Implement various desktop components for use with lightweight compositors/window managers on Linux"
rs := parent.AddSubCommand(&cli.Command{
Name: "run-server",
ShortDescription: "Start the various servers used to integrate with the Linux desktop",
HelpText: "This should be run very early in the startup sequence of your window manager, before any other programs are run.",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
opts := ServerOptions{}
err = cmd.GetOptionValues(&opts)
if err == nil {
err = run_server(&opts)
}
return utils.IfElse(err == nil, 0, 1), err
},
})
rs.Add(cli.OptionSpec{
Name: `--override -o`, Type: "list", Dest: `Override`,
Help: "Override individual configuration options, can be specified multiple times. Syntax: :italic:`name=value`. For example: :italic:`-o color_scheme=dark`",
})
rs.Add(cli.OptionSpec{
Name: `--config -c`, Type: "list", Dest: `Config`,
Help: strings.ReplaceAll(strings.ReplaceAll(kitty.ConfigHelp, "{appname}", "kitty"), "{conf_name}", server_conf_name),
})
parent.AddSubCommand(&cli.Command{
Name: "enable-portal",
ShortDescription: "This will create or edit the various files needed so that the portal from this kitten is used by xdg-desktop-portal",
HelpText: "Once you run this command, add :code:`kitten desktop-ui run-server` to your window manager startup sequence and reboot your computer (or logout and restart your session) and hopefully xdg-desktop-portal should now delegate to kitty for the portals implemented here. If it doesn't try running :code:`/usr/lib/xdg-desktop-portal -r -v` it will provide a lot of logging about why it is choosing different portal backends. That combined with a careful reading of :code:`man portals.conf` should be enough to learn how to convince xdg-desktop-portal to use kitty.\n\nYou can change the system color-scheme dynamically by running::\n\n:code:`kitten desktop-ui set-color-scheme dark`",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
err = enable_portal()
return utils.IfElse(err == nil, 0, 1), err
},
})
parent.AddSubCommand(&cli.Command{
Name: "set-color-scheme",
ShortDescription: "Change the color scheme",
ArgCompleter: cli.NamesCompleter("Choices for color-scheme", "no-preference", "light", "dark", "toggle"),
Usage: " light|dark|no-preference|toggle",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
if len(args) != 1 {
cmd.ShowHelp()
return 1, fmt.Errorf("must specify the new color scheme value")
}
err = set_color_scheme(args[0])
return utils.IfElse(err == nil, 0, 1), err
},
})
parent.AddSubCommand(&cli.Command{
Name: "set-accent-color",
ShortDescription: "Change the accent color",
Usage: " color_as_hex_or_name",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
if len(args) != 1 {
cmd.ShowHelp()
return 1, fmt.Errorf("must specify the new accent color value")
}
var v dbus.Variant
if v, err = to_color(args[0]); err == nil {
err = set_variant_setting(PORTAL_APPEARANCE_NAMESPACE, PORTAL_ACCENT_COLOR_KEY, v, false)
}
return utils.IfElse(err == nil, 0, 1), err
},
})
parent.AddSubCommand(&cli.Command{
Name: "set-contrast",
ShortDescription: "Change the contrast. Can be high or normal.",
Usage: " high|normal",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
if len(args) != 1 {
cmd.ShowHelp()
return 1, fmt.Errorf("must specify the new contrast value")
}
var v dbus.Variant
switch args[0] {
case "normal":
v = dbus.MakeVariant(uint32(0))
case "high":
v = dbus.MakeVariant(uint32(1))
default:
return 1, fmt.Errorf("%s is not a valid contrast value", args[0])
}
err = set_variant_setting(PORTAL_APPEARANCE_NAMESPACE, PORTAL_CONTRAST_KEY, v, false)
return utils.IfElse(err == nil, 0, 1), err
},
})
st := parent.AddSubCommand(&cli.Command{
Name: "set-setting",
ShortDescription: "Change an arbitrary setting",
Usage: " key [value]",
HelpText: "Set an arbitrary setting. If you want to set the color-scheme use the dedicated command for it. Use this command with care as it does no validation for the type of value. The syntax for specifying values is described at: :link:`the glib docs <https://docs.gtk.org/glib/gvariant-text-format.html>`. Leaving out the value or specifying an empty value, will delete the setting.",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
val := ""
if len(args) < 1 {
cmd.ShowHelp()
return 1, fmt.Errorf("must specify the key")
}
if len(args) > 1 {
val = args[1]
}
opts := SetOptions{}
if err = cmd.GetOptionValues(&opts); err == nil {
err = set_setting(args[0], val, &opts)
}
return utils.IfElse(err == nil, 0, 1), err
},
})
st.Add(cli.OptionSpec{
Name: "--namespace -n",
Help: "The namespace in which to change the setting.",
Default: PORTAL_APPEARANCE_NAMESPACE,
})
st.Add(cli.OptionSpec{
Name: "--data-type",
Help: "The DBUS data type signature of the value. The default is to guess from the textual representation, see :link:`the glib docs <https://docs.gtk.org/glib/gvariant-text-format.html>` for details.",
})
ss := parent.AddSubCommand(&cli.Command{
Name: "show-settings",
ShortDescription: "Print the current values of the desktop settings",
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
if len(args) != 0 {
cmd.ShowHelp()
return 1, fmt.Errorf("no arguments allowed")
}
opts := ShowSettingsOptions{}
err = cmd.GetOptionValues(&opts)
if err == nil {
err = show_settings(&opts)
}
return utils.IfElse(err == nil, 0, 1), err
},
})
ss.Add(cli.OptionSpec{
Name: "--as-json",
Help: "Show the settings as JSON for machine consumption",
Type: "bool-set",
})
ss.Add(cli.OptionSpec{
Name: "--in-namespace",
Help: "Show only settings in the specified names. Can be specified multiple times. When unspecified all namespaces are returned.",
Type: "list",
})
ss.Add(cli.OptionSpec{
Name: "--allow-other-backends",
Help: "Normally, after printing the settings, if the settings did not come from the desktop-ui kitten the command prints an error and exits. This prevents that.",
Type: "bool-set",
})
}
func EntryPoint(root *cli.Command) {
create_cmd(root, nil)
}
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
import sys
from kitty.conf.types import Definition
definition = Definition(
'!kittens.choose_files',
)
agr = definition.add_group
egr = definition.end_group
opt = definition.add_option
map = definition.add_map
mma = definition.add_mouse_map
agr('Appearance')
opt(
'color_scheme',
'no-preference',
choices=('no-preference', 'dark', 'light'),
long_text="""\
The color scheme for your system. This sets the initial value of the color scheme. It can be changed subsequently
by using :code:`kitten desktop-ui color-scheme`.
""",
)
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',
'',
long_text="""
The size in lines and columns of the file chooser popup window. By default it is full screen. For example:
:code:`file_chooser_size 25 80` will cause the popup to be of size 25 lines and 80 columns. Note that if you
use this option, depending on the compositor you are running, the popup window may not be properly modal.
""",
)
opt(
'+file_chooser_kitty_conf',
'',
long_text='Path to config file to use for kitty when drawing the file chooser window. Can be specified multiple times. By default, the'
' normal kitty.conf is used. Relative paths are resolved with respect to the kitty config directory.',
)
opt(
'+file_chooser_kitty_override',
'',
long_text='Override individual kitty configuration options, for the file chooser window.'
' Can be specified multiple times. Syntax: :italic:`name=value`. For example: :code:`font_size=20`.',
)
egr()
def main(args: list[str]) -> None:
raise SystemExit('This must be run as kitten desktop-ui')
if __name__ == '__main__':
main(sys.argv)
elif __name__ == '__conf__':
sys.options_definition = definition # type: ignore
File diff suppressed because it is too large. Load diff
+47
View File
@@ -0,0 +1,47 @@
// 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)
}
}
func TestDBusServiceExecLine(t *testing.T) {
for _, tc := range []struct{ exe, want string }{
{"/opt/kitty/kitten", `/opt/kitty/kitten a`},
{"/opt/kitty app/kitten", `'/opt/kitty app/kitten' a`},
{"/opt/kitty'app/kitten", `'/opt/kitty'"'"'app/kitten' a`},
{`/opt/kitty"app/kitten`, `'/opt/kitty"app/kitten' a`},
{`/opt/kitty\app/kitten`, `'/opt/kitty\\app/kitten' a`},
{"/opt/kitty$app/kitten", `'/opt/kitty$app/kitten' a`},
{"/opt/kitty\tapp/kitten", `'/opt/kitty\tapp/kitten' a`},
{"/opt/kitty\napp/kitten", `'/opt/kitty\napp/kitten' a`},
} {
got, err := dbus_service_exec_line(tc.exe, "a")
if err != nil {
t.Fatalf("Unexpected error for %#v: %s", tc.exe, err)
}
if got != tc.want {
t.Fatalf("Exec line for %#v: got %#v want %#v", tc.exe, got, tc.want)
}
}
if _, err := dbus_service_exec_line("/opt/kitty\rapp/kitten"); err == nil {
t.Fatalf("No error for path containing a carriage return")
}
}