From 96f42f210841b17ec6a2d38e139cf44936f038fd Mon Sep 17 00:00:00 2001 From: Evan Mezeske Date: Tue, 30 Jun 2026 12:11:43 -0700 Subject: [PATCH] Linux: Fix FileChooser ignoring the initial directory with zenity --- .../native/juce_FileChooser_linux.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_FileChooser_linux.cpp b/modules/juce_gui_basics/native/juce_FileChooser_linux.cpp index 48d977e1796f..b151d0fd8081 100644 --- a/modules/juce_gui_basics/native/juce_FileChooser_linux.cpp +++ b/modules/juce_gui_basics/native/juce_FileChooser_linux.cpp @@ -265,10 +265,23 @@ class FileChooser::Native final : public FileChooser::Pimpl, else File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory(); - auto filename = owner.startingFile.getFileName(); + // zenity needs an absolute path in --filename: a bare relative name is + // ignored and the dialog falls back to $HOME. For a directory, a trailing + // separator tells zenity to open inside it rather than selecting it within + // its parent. + String startPath; - if (! filename.isEmpty()) - args.add ("--filename=" + filename); + if (owner.startingFile.isDirectory()) + startPath = File::addTrailingSeparator (owner.startingFile.getFullPathName()); + else if (owner.startingFile.getParentDirectory().exists()) + startPath = owner.startingFile.getFullPathName(); + else if (owner.startingFile.getFileName().isNotEmpty()) + startPath = File::getSpecialLocation (File::userHomeDirectory) + .getChildFile (owner.startingFile.getFileName()) + .getFullPathName(); + + if (startPath.isNotEmpty()) + args.add ("--filename=" + startPath); // supplying the window ID of the topmost window makes sure that Zenity pops up.. if (uint64 topWindowID = getTopWindowID())