mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Add conf file for desktop-ui kitten
This commit is contained in:
@@ -615,6 +615,7 @@ def generate_constants() -> str:
|
|||||||
from kitty.config import option_names_for_completion
|
from kitty.config import option_names_for_completion
|
||||||
from kitty.fast_data_types import FILE_TRANSFER_CODE
|
from kitty.fast_data_types import FILE_TRANSFER_CODE
|
||||||
from kitty.options.utils import allowed_shell_integration_values, url_style_map
|
from kitty.options.utils import allowed_shell_integration_values, url_style_map
|
||||||
|
from kitty.simple_cli_definitions import CONFIG_HELP
|
||||||
del sys.modules['kittens.hints.main']
|
del sys.modules['kittens.hints.main']
|
||||||
del sys.modules['kittens.query_terminal.main']
|
del sys.modules['kittens.query_terminal.main']
|
||||||
ref_map = load_ref_map()
|
ref_map = load_ref_map()
|
||||||
@@ -647,6 +648,7 @@ const HintsDefaultRegex = `{DEFAULT_REGEX}`
|
|||||||
const DefaultTermName = `{Options.term}`
|
const DefaultTermName = `{Options.term}`
|
||||||
const DefaultUrlStyle = `{url_style}`
|
const DefaultUrlStyle = `{url_style}`
|
||||||
const DefaultUrlColor = `{Options.url_color.as_sharp}`
|
const DefaultUrlColor = `{Options.url_color.as_sharp}`
|
||||||
|
const ConfigHelp = "{serialize_as_go_string(CONFIG_HELP)}"
|
||||||
var Version VersionType = VersionType{{Major: {kc.version.major}, Minor: {kc.version.minor}, Patch: {kc.version.patch},}}
|
var Version VersionType = VersionType{{Major: {kc.version.major}, Minor: {kc.version.minor}, Patch: {kc.version.patch},}}
|
||||||
var DefaultPager []string = []string{{ {dp} }}
|
var DefaultPager []string = []string{{ {dp} }}
|
||||||
var FunctionalKeyNameAliases = map[string]string{serialize_go_dict(functional_key_name_aliases)}
|
var FunctionalKeyNameAliases = map[string]string{serialize_go_dict(functional_key_name_aliases)}
|
||||||
|
|||||||
@@ -2,22 +2,38 @@ package desktop_ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/kovidgoyal/dbus"
|
"github.com/kovidgoyal/dbus"
|
||||||
|
"github.com/kovidgoyal/kitty"
|
||||||
"github.com/kovidgoyal/kitty/tools/cli"
|
"github.com/kovidgoyal/kitty/tools/cli"
|
||||||
|
"github.com/kovidgoyal/kitty/tools/config"
|
||||||
"github.com/kovidgoyal/kitty/tools/utils"
|
"github.com/kovidgoyal/kitty/tools/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
type Options struct {
|
type ServerOptions struct {
|
||||||
Color_scheme, AccentColor, Contrast string
|
Config []string
|
||||||
|
Override []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func run_server(opts *Options) (err error) {
|
const server_conf_name = "desktop-ui-portal"
|
||||||
portal, err := NewPortal(opts)
|
|
||||||
|
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 {
|
if err == nil {
|
||||||
err = portal.Start()
|
portal, err := NewPortal(config)
|
||||||
|
if err == nil {
|
||||||
|
err = portal.Start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -27,21 +43,19 @@ func run_server(opts *Options) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func EntryPoint(root *cli.Command) {
|
func specialize_command(parent *cli.Command) {
|
||||||
parent := root.AddSubCommand(&cli.Command{
|
parent.Run = func(cmd *cli.Command, args []string) (int, error) {
|
||||||
Name: "desktop-ui",
|
cmd.ShowHelp()
|
||||||
ShortDescription: "Implement various desktop components for use with lightweight compositors/window managers on Linux",
|
return 1, nil
|
||||||
Run: func(cmd *cli.Command, args []string) (int, error) {
|
}
|
||||||
cmd.ShowHelp()
|
parent.ShortDescription = "Implement various desktop components for use with lightweight compositors/window managers on Linux"
|
||||||
return 1, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
rs := parent.AddSubCommand(&cli.Command{
|
rs := parent.AddSubCommand(&cli.Command{
|
||||||
Name: "run-server",
|
Name: "run-server",
|
||||||
ShortDescription: "Start the various servers used to integrate with the Linux desktop",
|
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.",
|
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) {
|
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
|
||||||
opts := Options{}
|
opts := ServerOptions{}
|
||||||
err = cmd.GetOptionValues(&opts)
|
err = cmd.GetOptionValues(&opts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = run_server(&opts)
|
err = run_server(&opts)
|
||||||
@@ -50,25 +64,18 @@ func EntryPoint(root *cli.Command) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
rs.Add(cli.OptionSpec{
|
rs.Add(cli.OptionSpec{
|
||||||
Name: `--color-scheme`, Type: "choices", Dest: `Color_scheme`, Choices: "no-preference, light, dark",
|
Name: `--override -o`, Type: "list", Dest: `Override`,
|
||||||
Completer: cli.NamesCompleter("Choices for color-scheme", "no-preference", "light", "dark"),
|
Help: "Override individual configuration options, can be specified multiple times. Syntax: :italic:`name=value`. For example: :italic:`-o color_scheme=dark`",
|
||||||
Help: "The color scheme for your system. This sets the initial value of the color scheme. It can be changed subsequently by using the color-scheme sub-command.",
|
|
||||||
})
|
})
|
||||||
rs.Add(cli.OptionSpec{
|
rs.Add(cli.OptionSpec{
|
||||||
Name: `--accent-color`,
|
Name: `--config -c`, Type: "list", Dest: `Config`,
|
||||||
Help: "The RGB accent color for your system, can be specified as a color name or in hex a decimal format.",
|
Help: strings.ReplaceAll(strings.ReplaceAll(kitty.ConfigHelp, "{appname}", "kitty"), "{conf_name}", server_conf_name),
|
||||||
Default: "cyan",
|
|
||||||
})
|
|
||||||
rs.Add(cli.OptionSpec{
|
|
||||||
Name: `--contrast`, Type: "choices", Choices: "normal, high",
|
|
||||||
Help: "The preferred contrast level. Choices: normal, high",
|
|
||||||
Default: "normal",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
parent.AddSubCommand(&cli.Command{
|
parent.AddSubCommand(&cli.Command{
|
||||||
Name: "enable-portal",
|
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",
|
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 --color-scheme=whatever` 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`",
|
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) {
|
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
|
||||||
err = enable_portal()
|
err = enable_portal()
|
||||||
return utils.IfElse(err == nil, 0, 1), err
|
return utils.IfElse(err == nil, 0, 1), err
|
||||||
@@ -189,5 +196,8 @@ func EntryPoint(root *cli.Command) {
|
|||||||
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.",
|
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",
|
Type: "bool-set",
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func EntryPoint(root *cli.Command) {
|
||||||
|
create_cmd(root, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,35 @@
|
|||||||
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
|
# 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', 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.')
|
||||||
|
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
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func to_color(spec string) (v dbus.Variant, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPortal(opts *Options) (p *Portal, err error) {
|
func NewPortal(opts *Config) (p *Portal, err error) {
|
||||||
ans := Portal{}
|
ans := Portal{}
|
||||||
ans.settings = SettingsMap{
|
ans.settings = SettingsMap{
|
||||||
SETTINGS_CANARY_NAMESPACE: map[string]dbus.Variant{
|
SETTINGS_CANARY_NAMESPACE: map[string]dbus.Variant{
|
||||||
@@ -66,16 +66,16 @@ func NewPortal(opts *Options) (p *Portal, err error) {
|
|||||||
}
|
}
|
||||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE] = map[string]dbus.Variant{}
|
ans.settings[PORTAL_APPEARANCE_NAMESPACE] = map[string]dbus.Variant{}
|
||||||
switch opts.Color_scheme {
|
switch opts.Color_scheme {
|
||||||
case "dark":
|
case Color_scheme_dark:
|
||||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(DARK))
|
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(DARK))
|
||||||
case "light":
|
case Color_scheme_light:
|
||||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(LIGHT))
|
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(LIGHT))
|
||||||
default:
|
default:
|
||||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(NO_PREFERENCE))
|
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.AccentColor)
|
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_ACCENT_COLOR_KEY], err = to_color(opts.Accent_color)
|
||||||
var contrast uint32
|
var contrast uint32
|
||||||
if opts.Contrast == "high" {
|
if opts.Contrast == Contrast_high {
|
||||||
contrast = 1
|
contrast = 1
|
||||||
}
|
}
|
||||||
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_CONTRAST_KEY] = dbus.MakeVariant(contrast)
|
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_CONTRAST_KEY] = dbus.MakeVariant(contrast)
|
||||||
|
|||||||
@@ -462,6 +462,14 @@ func GetOptionValue[T any](self *Command, name string) (ans T, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Command) OptionsSeenOnCommandLine() map[string]bool {
|
||||||
|
ans := make(map[string]bool)
|
||||||
|
for name, opt := range self.option_map {
|
||||||
|
ans[name] = opt != nil && len(opt.values_from_cmdline) > 0
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Command) GetOptionValues(pointer_to_options_struct any) error {
|
func (self *Command) GetOptionValues(pointer_to_options_struct any) error {
|
||||||
val := reflect.ValueOf(pointer_to_options_struct).Elem()
|
val := reflect.ValueOf(pointer_to_options_struct).Elem()
|
||||||
if val.Kind() != reflect.Struct {
|
if val.Kind() != reflect.Struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user