Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: GNUser on March 19, 2024, 12:33:16 PM

Title: [Solved] how to change default filename for gtk3 print dialog's "Print to File"?
Post by: GNUser on March 19, 2024, 12:33:16 PM
Hello, friends. Many gtk3 applications (e.g., brave with --disable-print-preview flag, geany) bring up gtk3's print dialog when user presses Ctrl+p.

The gtk3 print dialog uses ~/Documents/output.pdf as a default output filename across all applications I've tried:

(https://forum.tinycorelinux.net/index.php?action=dlattach;topic=26926.0;attach=6789)

Does anyone whether this default can be changed? I'm specifically trying to change the default directory. I know I can click on the filename and change the directory that way, but doing this repeatedly is tiresome.

I found some promising-sounding variables named GTK_PRINT_SETTINGS_OUTPUT_FOO and G_USER_DIRECTORY_DOCUMENTS here (https://wiki.gnome.org/Initiatives/GnomeGoals/PrintToFile) but, alas, setting and exporting those variables has no effect.

My hope is that someone knows an easy way to change the default ~/Documents/output.pdf to something else--for example, with an environmental variable or a setting in ~/.config/gtk-3.0/settings.ini. If someone knows for a fact that this default filename is hardwired into gtk3, that would also be helpful to know (so that I stop trying to customize this--recompiling gtk3 for this purpose is not something I want to do).
Title: Re: how to change default filename for gtk3 print dialog's "Print to File"?
Post by: GNUser on March 19, 2024, 02:29:18 PM
Sorry, I forgot to mention I'm on TCL15 x86_64. All relevant extensions are from the official repository (gtk3 v3.24.39, geany v1.37, brave-browser v1.63.174).
Title: Re: how to change default filename for gtk3 print dialog's "Print to File"?
Post by: Rich on March 19, 2024, 02:46:56 PM
Hi GNUser
I just hit Ctrl-P while in Firefox. The Firefox print dialog opened up.
It had a "Print using the system dialog" Clicking that link brought
up the gtk3 print dialog. When I selected "Print to File", it defaulted
to  "~/mozilla.pdf".  That makes me suspect it might get set by the
application.
Title: Re: how to change default filename for gtk3 print dialog's "Print to File"?
Post by: GNUser on March 19, 2024, 03:03:42 PM
Firefox ... "~/mozilla.pdf".
Interesting. Thank you for sharing this data point.

That makes me suspect it might get set by the application.
Either that or gtk3 provides a mechanism for an application to specify a filename, with "~/Documents/output.pdf" serving as a fallback/default if the application does not specify anything. Given that geany and brave-browser both suggest "~/Documents/output.pdf", I favor my theory that a default exists. But I guess without studying gtk3's source code, it's hard to be sure either way.

EDIT:
I took another look at https://wiki.gnome.org/Initiatives/GnomeGoals/PrintToFile . Part of the document reads: The GTK+-provided fallback, '~/Documents/output.pdf'. So it does seem that, while an application can override it, "~/Documents/output.pdf" is the default filename for "Print to File".
Title: Re: how to change default filename for gtk3 print dialog's "Print to File"?
Post by: GNUser on March 19, 2024, 03:09:30 PM
Hi, Rich. I found that some applications (e.g., Thunderbird and Firefox) allow the user to specify the desired default filename. See here (https://superuser.com/a/1289734).

Unfortunately, I don't think the two applications I am interested in (geany and brave-browser) offer such a setting. For me, it seems that I'm going to have to change this in gtk3 if at all.
Title: Re: how to change default filename for gtk3 print dialog's "Print to File"?
Post by: GNUser on March 19, 2024, 09:02:04 PM
I found an acceptable solution.

gtk3 is hardwired to use $XDG_DOCUMENTS_DIR/output.pdf as default filename for "Print to File".

XDG_DOCUMENTS_DIR can be customized in ~/.config/user-dirs.dirs. With this, for example:

Code: [Select]
$ cat ~/.config/user-dirs.dirs
XDG_DOCUMENTS_DIR="$HOME/my_favorite_directory"
the default filename for "Print to File" (for applications that don't specify a default filename, such as geany and brave-browser) becomes $HOME/my_favorite_directory/output.pdf.

This solution may have some side effects, but it is good enough for me. Topic may be marked as solved.