lmms icon indicating copy to clipboard operation
lmms copied to clipboard

Use native file dialog

Open AW1534 opened this issue 1 year ago • 34 comments

Uses native file dialog for save and open dialogs. This is optional, but enabled by default. In the "Save As" dialog, if native dialogs are enabled, the save options will appear as a seperate dialog. Screenshot_20250421_200545 (only tested in KDE with dolphin)

closes #5240

pre-merge checklist

  • [x] Verify native file dialogs work on Plasma
  • [ ] Verify native file dialogs work on GNOME
  • [ ] Verify native file dialogs work on at least one other GTK-based desktop (e.g. XFCE or Cinnamon)
  • [ ] Confirm the light/dark theme is respected or falls back gracefully
  • [ ] Test to find out if QTBUG-27186 causes regressions
  • [ ] Test AppImage and manual build

AW1534 avatar Apr 21 '25 23:04 AW1534

For some reason, no matter whether the "Use native file dialog" setting is checked, even after restarting, when I try to open a file or export a project, it still shows the default Qt file browser. I would expect my default file browser to be Nautilus.

image

I'm using the linux-x86_64 build on Arch Linux + GNOME + ~~wayland~~(my settings say wayland but the log says "Defaulting to QT_QPA_PLATFORM="xcb" for compatibility purposes.")

regulus79 avatar Apr 22 '25 20:04 regulus79

crap. I'm getting this too on the AppImage. Looks like I didn't push all my changes

AW1534 avatar Apr 22 '25 20:04 AW1534

Never mind, the remote branch is completely up to date. It looks like this issue only affects the AppImages. @regulus79 are you using the AppImage?

AW1534 avatar Apr 22 '25 20:04 AW1534

are you using the AppImage?

Yes

regulus79 avatar Apr 22 '25 20:04 regulus79

For some reason, no matter whether the "Use native file dialog" setting is checked, even after restarting, when I try to open a file or export a project, it still shows the default Qt file browser. I would expect my default file browser to be Nautilus.

@tresf any idea what could be causing this?

AW1534 avatar May 04 '25 12:05 AW1534

For some reason, no matter whether the "Use native file dialog" setting is checked, even after restarting, when I try to open a file or export a project, it still shows the default Qt file browser. I would expect my default file browser to be Nautilus.

@tresf any idea what could be causing this?

https://github.com/olive-editor/olive/issues/484#issuecomment-464394121

tresf avatar May 05 '25 04:05 tresf

Possibly some more info... https://github.com/probonopd/linuxdeployqt/issues/60

tresf avatar May 05 '25 05:05 tresf

For some reason, no matter whether the "Use native file dialog" setting is checked, even after restarting, when I try to open a file or export a project, it still shows the default Qt file browser. I would expect my default file browser to be Nautilus.

@tresf any idea what could be causing this?

Ok, I think I found it... https://wiki.archlinux.org/title/XDG_Desktop_Portal, quoting:

[...] any application can use portals to provide uniform access to features independent of desktops and toolkits. This is commonly used, for example, to allow screen sharing on Wayland via PipeWire, or to use file open and save dialogs on Firefox that use the same toolkit as your current desktop environment.

Peeking through the Qt plugins folder, I found plugins/platformthemes/libqxdgdesktopportal.so which might be our ticket to get these to look native. First, I have to find out how to provide this to linuxdeploy-plugin-qt.. here's what we set currently:

https://github.com/LMMS/lmms/blob/61736a97b6ee880f0d118b1659ffe1639afbf384/cmake/linux/LinuxDeploy.cmake#L138-L140

tresf avatar May 05 '25 20:05 tresf

So, it looks like linuxdeploy-plugin-qt will deploy this file by default but only if it's there...

This suggests it may be as simple as adding qt5-xdgdesktopportal-platformtheme to our dependencies...

Shard Intel/ARM64 deps: https://github.com/LMMS/lmms/blob/61736a97b6ee880f0d118b1659ffe1639afbf384/.github/workflows/deps-ubuntu-24.04-gcc.txt#L42-L44

@AW1534 want to give it a try?

tresf avatar May 05 '25 20:05 tresf

That didn't fix it. I found KDEPlasmaPlatformTheme5.so and libqgtk3.so on my system so I could add them into the repo if needed, I just don't know where.

AW1534 avatar May 05 '25 21:05 AW1534

That didn't fix it. I found KDEPlasmaPlatformTheme5.so and libqgtk3.so on my system so I could add them into the repo if needed, I just don't know where.

Ok, to add those too (I'm EXTREMELY skeptical of this proposal because libqgtk3.so hard-links SOOO many files) is:

lmms/cmake/linux/LinuxDeploy.cmake:

   # Inform linuxdeploy-plugin-qt about wayland plugin 
   set(ENV{EXTRA_PLATFORM_PLUGINS} "libqwayland-generic.so") 
   set(ENV{EXTRA_QT_MODULES} "waylandcompositor") 
+  # Toggle experimental platform theming support
+  set(ENV{DEPLOY_PLATFORM_THEMES} 1)

tresf avatar May 05 '25 21:05 tresf

That didn't fix it. I found KDEPlasmaPlatformTheme5.so and libqgtk3.so on my system so I could add them into the repo if needed, I just don't know where.

Ok, to add those too (I'm EXTREMELY skeptical of this proposal because libqgtk3.so hard-links SOOO many files) is:

lmms/cmake/linux/LinuxDeploy.cmake:

   # Inform linuxdeploy-plugin-qt about wayland plugin 
   set(ENV{EXTRA_PLATFORM_PLUGINS} "libqwayland-generic.so") 
   set(ENV{EXTRA_QT_MODULES} "waylandcompositor") 
+  # Toggle experimental platform theming support
+  set(ENV{DEPLOY_PLATFORM_THEMES} 1)

don't I need to place the libraries somewhere? maybe the include folder?

AW1534 avatar May 05 '25 21:05 AW1534

don't I need to place the libraries somewhere? maybe the include folder?

No, I linked the logic earlier, but here it is again:

So, it looks like linuxdeploy-plugin-qt will deploy this file by default but only if it's there...

Check the top half of the conditional...

tresf avatar May 05 '25 21:05 tresf

Check the top half of the conditional...

But its an AppImage so its quarantined with access to only files in its container. So unless the files are available in the container, that shouldn't work. Maybe I'm misunderstanding though

AW1534 avatar May 05 '25 21:05 AW1534

Didn't fix it for me

AW1534 avatar May 05 '25 22:05 AW1534

But its an AppImage so its quarantined with access to only files in its container.

This is not true. AppImages aren't sandboxed like Flatpaks are.

Didn't fix it for me

It may be impossible. I'll see what I can find.

tresf avatar May 06 '25 05:05 tresf

Didn't fix it for me

It definitely tried...

WARNING: Deploying all platform themes and styles [experimental feature] 
Deploying shared library /usr/lib/aarch64-linux-gnu/qt5/plugins/platformthemes/libqxdgdesktopportal.so (destination: /home/runner/work/lmms/lmms/build/_CPack_Packages/Linux/External/lmms-1.3.0-alpha.1.837+pr7856.c2e8c58-linux-aarch64/LMMS.AppDir/usr/plugins/platformthemes/)
Deploying dependencies for ELF file /usr/lib/aarch64-linux-gnu/qt5/plugins/platformthemes/libqxdgdesktopportal.so 

... but it looks like the gtk and qt plugins are missing, probably another dependency. I'll see what I can find.

tresf avatar May 06 '25 16:05 tresf

Looks like the gtk and qt plugins are missing, probably another dependency. I'll see what I can find.

according to chatgpt, these packages may need to be installed in the build environment: plasma-integration qt5-gtk-platformtheme

(conversation link)

AW1534 avatar May 06 '25 16:05 AW1534

Looks like the gtk and qt plugins are missing, probably another dependency. I'll see what I can find.

according to chatgpt, these packages may need to be installed in the build environment: plasma-integration qt5-gtk-platformtheme

(conversation link)

Yes, please add plasma-integration too.

tresf avatar May 06 '25 16:05 tresf

There are some more as well but we can wait for people to complain... before bombarding our platformthemes folder.

:~$ apt-cache search platformtheme

qt5-gtk-platformtheme - Qt 5 GTK+ 3 platform theme
qt5-gtk2-platformtheme - Qt 5 extra widget styles - GTK+ 2 Platform theme
qt5-ukui-platformtheme - Qt5 QPA platform theme of UKUI
qt5-xdgdesktopportal-platformtheme - Qt 5 XDG Desktop Portal platform theme
qt6-gtk-platformtheme - Qt 6 GTK+ 3 platform theme
qt6-xdgdesktopportal-platformtheme - Qt 6 XDG Desktop Portal platform theme

tresf avatar May 06 '25 16:05 tresf

It works! It took a good 1.5 seconds to open the native dialog the very first time, but after that it was instant, even after restarting the AppImage

AW1534 avatar May 06 '25 17:05 AW1534

@regulus79 could you retest on gnome please?

AW1534 avatar May 06 '25 17:05 AW1534

It works now! However, the filedialog is in light mode, while my system is in dark mode.

Also, when exporting files, changing the file type doesn't automatically change the file extension, and if you leave off the file extension, it defaults to .wav, no matter what type you have selected in the drop-down.

Also the dropdown menu is a little weird how you can't see everything at once until you mouse over down. But that's probably an issue with the file explorer, not lmms image

Also, does this increase the size of the builds? I noticed the linux builds are about 12 MB larger compared to the past couple commits on master.

regulus79 avatar May 06 '25 20:05 regulus79

@regulus79 thank you for testing! This sounds like a LOT of downsides compared to the upsides of having it look native. Perhaps we take the win on macOS and Windows and just leave Linux to fallback to the LMMS-decorated one? This would still reduce the code complexity but without the nuance of worrying about Gtk theme propagation into the AppImage and the delay caused by loading the Gtk libraries the first time.

tresf avatar May 06 '25 20:05 tresf

@regulus79 thank you for testing! This sounds like a LOT of downsides compared to the upsides of having it look native. Perhaps we take the win on macOS and Windows and just leave Linux to fallback to the LMMS-decorated one? This would still reduce the code complexity but without the nuance of worrying about Gtk theme propagation into the AppImage and the delay caused by loading the Gtk libraries the first time.

I think it should still be optional. Maybe disabled by default on linux, but still optional. the built in file chooser seriously sucks.

AW1534 avatar May 06 '25 22:05 AW1534

I think it should still be optional. Maybe disabled by default on linux, but still optional. the built in file chooser seriously sucks.

I would agree if stuff were readable, quoting:

Also the dropdown menu is a little weird how you can't see everything at once until you mouse over down. But that's probably an issue with the file explorer, not lmms

I don't use Linux though so whatever people think.

tresf avatar May 06 '25 22:05 tresf

I think it should still be optional. Maybe disabled by default on linux, but still optional. the built in file chooser seriously sucks.

I would agree if stuff were readable, quoting:

Also the dropdown menu is a little weird how you can't see everything at once until you mouse over down. But that's probably an issue with the file explorer, not lmms

I don't use Linux though so whatever people think.

But as you know, linux is fragmented. And while the GTK theme might be messed up for GNOME, it's much better for KDE. I don't think we should be arbitrarily limiting options just because it doesn't work well on GTK. But, since we can't guarantee readability on linux, we should keep it off by default.

AW1534 avatar May 06 '25 22:05 AW1534

we should keep it off by default.

I'd vote the opposite, if it's better, make it useable and we can allow an AppImage flag to disable.

tresf avatar May 06 '25 22:05 tresf

we should keep it off by default.

I'd vote the opposite, if it's better, make it useable and we can allow an AppImage flag to disable.

I mean if we can fix it, that's great.

If I had to guess what was causing the issue, i'd say its because the LMMS theme is partially bleeding through, and since the LMMS text is white, the nautilus text is being turned white, even though it's in light mode. I think to fix this we just find a way to put nautilus in dark mode. This may be as simple as GTK_THEME=Adwaita:dark. It's also possible to get something more dynamic, by detecting the user's preferred theme. I asked chatgpt to generate me an AppRun script, but I don't even know bash so I don't know if it will work, but it could be a good starting point.

#!/bin/bash
HERE="$(dirname "$(readlink -f "$0")")"

# Prefer user-defined theme if already set
if [ -z "$GTK_THEME" ]; then
  # Attempt to detect current GTK theme (for GNOME-based desktops)
  DETECTED_THEME="$(gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null | tr -d "'")"

  if echo "$DETECTED_THEME" | grep -iq "dark"; then
    export GTK_THEME="$DETECTED_THEME"
  elif gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null | grep -q 'prefer-dark'; then
    # GNOME 42+ prefers color-scheme
    export GTK_THEME="${DETECTED_THEME}:dark"
  fi
fi

# Force native file dialogs via GTK
export QT_QPA_PLATFORMTHEME=gtk3

# Run LMMS
exec "${HERE}/usr/bin/lmms" "$@"

As for the file extention thing, I have no clue. I tried to reproduce that on dolphin and couldn't. There seems to be a (maybe related?) open bug report on Qt: https://bugreports.qt.io/browse/QTBUG-27186

AW1534 avatar May 06 '25 23:05 AW1534

It works now!

What OS? Ubuntu 24.04 still shows the non-native dialog with this PR for me. I tried both with the AppImage and a local build. I tried with QT_QPA_PLATFORMTHEME set to gtk3, gtk2, qt5ct.

tresf avatar May 07 '25 04:05 tresf