From be63598355eacafc880ce90c457e21d56820265d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Aug 2025 20:47:26 +0530 Subject: [PATCH] desktop-ui: Add config to control file chooser popup size Fixes #8894 --- kittens/desktop_ui/main.py | 5 +++++ kittens/desktop_ui/portal.go | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kittens/desktop_ui/main.py b/kittens/desktop_ui/main.py index 8ddc63505..597d252fa 100644 --- a/kittens/desktop_ui/main.py +++ b/kittens/desktop_ui/main.py @@ -23,6 +23,11 @@ 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.') +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.' diff --git a/kittens/desktop_ui/portal.go b/kittens/desktop_ui/portal.go index 143d9cf7a..76060130e 100644 --- a/kittens/desktop_ui/portal.go +++ b/kittens/desktop_ui/portal.go @@ -756,11 +756,31 @@ func (self *Portal) run_file_chooser(cfd ChooseFilesData) (response uint32, resu cmd := func() *exec.Cmd { self.lock.Lock() defer self.lock.Unlock() + edge, lines, columns := `center`, ``, `` + if self.opts.File_chooser_size != "" { + l, c, _ := strings.Cut(self.opts.File_chooser_size, " ") + if li, err := strconv.Atoi(strings.TrimSpace(l)); err == nil { + if ci, err := strconv.Atoi(strings.TrimSpace(c)); err == nil { + if li < 10 || ci < 40 { + log.Printf("file chooser size %s too small, ignoring", self.opts.File_chooser_size) + } else { + edge, lines, columns = `center-sized`, l, c + } + } else { + log.Printf("file chooser size %s invalid with error: %s\n", self.opts.File_chooser_size, err) + } + } else { + log.Printf("file chooser size %s invalid with error: %s\n", self.opts.File_chooser_size, err) + } + } args := []string{ - "+kitten", "panel", "--layer=overlay", "--edge=center", "--focus-policy=exclusive", + "+kitten", "panel", "--layer=overlay", "--edge=" + edge, "--focus-policy=exclusive", "-o", "background_opacity=0.85", "--wait-for-single-instance-window-close", "--grab-keyboard", "--single-instance", "--instance-group", "cfp-" + strconv.Itoa(os.Getpid()), } + if edge == "center-sized" { + args = append(args, "--lines="+lines, "--columns="+columns) + } for _, x := range self.opts.File_chooser_kitty_conf { args = append(args, `-c`, x) }