desktop-ui: Add config to control file chooser popup size

Fixes #8894
This commit is contained in:
Kovid Goyal
2025-08-12 20:47:26 +05:30
parent 7a27144b7a
commit be63598355
2 changed files with 26 additions and 1 deletions

View File

@@ -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.'

View File

@@ -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)
}