-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
player/dialog/file_dialog: add file dialog for macOS, Windows and Linux #15845
base: master
Are you sure you want to change the base?
Conversation
kasper93
commented
Feb 10, 2025
•
edited
Loading
edited
- - figure out multi file selection or disable it
- - working macOS impl
- - connect more commands (?)
- - add Linux impl
@Akemi: Could you help me with macOS implementation? I tried to put something together to make sure the api will work nicely, but it is missing filters and probably doesn't work at all currently. Also I made objc, but I don't mind replacing it completely with swift impl or anything. |
Currently connected only to |
9f42128
to
38844b3
Compare
sure, i will have a look. give me a few days to think about the implementation details for macOS. from the top of my head, i would probably move the (open) dialog functionality (https://github.com/mpv-player/mpv/blob/master/osdep/mac/menu_bar.swift#L325-L361) out of the menu bar into its own class and make it reusable. also extending its functionality to be usable with your changes. if you don't mind, i would prepare something you can then just (re-)use here. |
I think it's better to add a separate command instead of making loadfile accepting empty url, because the semantics of the A separate command which opens the file dialog in a separate thread, and signals the core after the file is selected would be a better idea. This can reuse the the |
Could you explain the issue, I don't understand. It works perfectly fine.
Why? It already spawns a thread, unlocks core and wait for user selection. Also you can use asynchronous command if you don't want to wait for loadfile selection on calling thread. |
38844b3
to
e1fc1ae
Compare
Added |
84e3947
to
589654d
Compare
Download the artifacts for this pull request: |
Is there a plan to add the url box? rossy/mpv-open-file-dialog#2 https://github.com/v-ji/mpv-open-url-dialog/commit/afff96d785c9a95acdf87041f021c367c099c470 |
I think the support for file dialogs should be added to the |
This will be useful for third-party scripts and greatly increases scalability |
Sorry, I didn't notice So to make this viable, |
Not having synchronized access to mpctx doesn't mean that we cannot use parts of it that are thread-safe, like for example
The behavior of |
2a9bbc3
to
a4c405e
Compare
a4c405e
to
aa64876
Compare
Added |
0438edd
to
64b6db0
Compare
@na-na-hi: Would command like that meet your quality standards for low-level command? { "load", cmd_load,
{
{"flags", OPT_FLAGS(v.i,
{"file", 1 << 0}, // default
{"list", 1 << 1},
{"track", 1 << 2},
{"dir", 1 << 3},
{"append", 1 << 4}, // default
{"insert", 1 << 5},
{"end", 1 << 6}, // default
{"at", 1 << 7},
{"next", 1 << 8},
{"play", 1 << 9},
{"select", 1 << 10},
{"auto", 1 << 11},
{"cached", 1 << 12},
// note those are both useful for track type selection as well as dialog filtering (by accident)
{"subtitle", 1 << 13},
{"audio", 1 << 14},
{"video", 1 << 15},
{"image", 1 << 16},
{"dlg", 1 << 17}),
.flags = MP_CMD_OPT_ARG},
// could be vararg, but not sure if we prefer types
{"arg0", OPT_PATHLIST(v.str_list), .flags = MP_CMD_OPT_ARG},
{"arg1", OPT_INT(v.i), .flags = MP_CMD_OPT_ARG},
{"arg2", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
{"arg3", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG},
{"arg4", OPT_KEYVALUELIST(v.str_list), .flags = MP_CMD_OPT_ARG},
}, Than you can add scripts and helpers for each high level use-cases. As for usage
and finally we can then have keybinds
and in select {"Open file(s)", "load file+dlg+replace+play", true},
{"Open directory", "load dir+dlg", true},
{"Load subtitles", "load subtitle+dlg", true},
|
Sorry to not comment on or seriously think about this until after the code has been written considering what I'm about to type but I don't think we need this. xdg-desktop-portal links to libgio so any system that has a portal implementation should be guaranteed to have it. I can't seriously think there is going to be a large amount of people out there that would really disable the gio backend and enable the libsystemd one. And I don't understand what the practical advantage would even be. They both just call portal stuff anyway. Maybe one library is better/worse but that's not really relevant to user. Ideally it would use libportal but as I understand kasper said the API was too limited, so we dropped that idea. Maybe it can be revisited later if that ever gets better. In terms of availability, libgio is way wider as well. Non-systemd distros, BSDs and apparently even Windows (lol). Unless there is some actual advantage to using sdbus to communicate to portals instead of just gio, I don't think we should have it. It seems like borderline dead code. |
I fully agree on that. It's one commit, which can be skipped. |
d621b6b
to
c3d150c
Compare
Changes:
For command load please see #15927 |
c3d150c
to
8a2f5db
Compare
@@ -6061,7 +6061,7 @@ static void cmd_loadfile(void *p) | |||
|
|||
void *tmp = talloc_new(NULL); | |||
|
|||
if (!files || !files[0] || !files[0][0]) { | |||
if ((!files || !files[0] || !files[0][0]) && mp_input_is_interactive_cmd(cmd->cmd)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the interactive prefix idea but unfortunately this doesn't quite emulate the old behavior. loadfile
will instantly exit mpv since the url is empty but it's optional so it's still not a hard error. How about just dropping the empty url part of the implementation and just letting whatever is selected by the dialog (or not selected) override anything that is passed in the url part of the command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the report. This is fixed now, there was a typo in the check below.
Also interactive
prefix means that iteration may happen, but not that it will/should happen.
As for the |
If URL is not provided file dialog will be open on supported platforms with selection for files (loadfile) or directories (loaddir).
For now it is just WID and works only on Windows implementation. For X11 and Wayland we would need to produce proper window identifier which is currently not supported by mpv. See: https://github.com/flatpak/xdg-desktop-portal/blob/71649cd9876072ed5c12a07928784b6c463a79eb/doc/window-identifiers.rst
Allows to select file dialog providers on platforms where there is no native implementation and we have to do all sort of weird things to make it work.
It grew too big for osdep.
It grew too big, and some platforms can have multiple implementations, so it only makes sense to organize it accordingly. Initially the idea was to have it as a osdep implementation, single for each platform, neat and simple, but we are past that point.
8a2f5db
to
50528a8
Compare
one thing nice to add if possible is in uosc it has
So in other words when Open file(s) or Open directory in select.lua menu it'll default to a particular default directory rather than just / (root dir) assuming there is no file loaded. Currently if there already is a file loaded it'll open up the directory which contains the loaded file which is great. |