player: add drag-and-drop option

Some platforms (wayland) apparently have a lot of trouble with drag and
drop. The default behavior is still the same which is basically obeying
what we get from the window manager/compositor, but the --drag-and-drop
option allows forcibly overriding the drag and drop behavior. i.e. you
can force it to always replace the playlist or append at the end. This
only implements this in X11 and Wayland but in theory windows and macos
could find this option useful (both hardcode the shift key for
appending). Patches welcome.
This commit is contained in:
Dudemanguy 2023-05-20 16:51:12 -05:00
parent 2f8d9322fd
commit 8ecf2d37eb
5 changed files with 25 additions and 5 deletions

View File

@ -3067,6 +3067,14 @@ Window
``--snap-window``
(Windows only) Snap the player window to screen edges.
``--drag-and-drop=<auto|replace|append>``
(X11 and Wayland only)
Controls the default behavior of drag and drop on platforms that support this.
``auto`` will obey what the underlying os/platform gives mpv. Typically, holding
shift during the drag and drop will append the item to the playlist. Otherwise,
it will completely replace it. ``replace`` and ``append`` always force replacing
and appending to the playlist respectively.
``--ontop``
Makes the player window stay on top of other windows.

View File

@ -106,6 +106,8 @@ static const struct m_sub_options screenshot_conf = {
static const m_option_t mp_vo_opt_list[] = {
{"vo", OPT_SETTINGSLIST(video_driver_list, &vo_obj_list)},
{"taskbar-progress", OPT_BOOL(taskbar_progress)},
{"drag-and-drop", OPT_CHOICE(drag_and_drop, {"auto", -1}, {"replace", 0},
{"append", 1})},
{"snap-window", OPT_BOOL(snap_window)},
{"ontop", OPT_BOOL(ontop)},
{"ontop-level", OPT_CHOICE(ontop_level, {"window", -1}, {"system", -2},
@ -196,6 +198,7 @@ const struct m_sub_options vo_sub_opts = {
.size = sizeof(struct mp_vo_opts),
.defaults = &(const struct mp_vo_opts){
.video_driver_list = NULL,
.drag_and_drop = -1,
.monitor_pixel_aspect = 1.0,
.screen_id = -1,
.fsscreen_id = -1,

View File

@ -11,6 +11,7 @@ typedef struct mp_vo_opts {
bool taskbar_progress;
bool snap_window;
int drag_and_drop;
bool ontop;
int ontop_level;
bool fullscreen;

View File

@ -535,8 +535,12 @@ static void data_offer_action(void *data, struct wl_data_offer *wl_data_offer, u
{
struct vo_wayland_state *wl = data;
if (dnd_action) {
wl->dnd_action = dnd_action & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY ?
DND_REPLACE : DND_APPEND;
if (wl->vo_opts->drag_and_drop >= 0) {
wl->dnd_action = wl->vo_opts->drag_and_drop;
} else {
wl->dnd_action = dnd_action & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY ?
DND_REPLACE : DND_APPEND;
}
MP_VERBOSE(wl, "DND action is %s\n",
wl->dnd_action == DND_REPLACE ? "DND_REPLACE" : "DND_APPEND");
}

View File

@ -988,9 +988,13 @@ static void vo_x11_dnd_handle_selection(struct vo *vo, XSelectionEvent *se)
void *prop = x11_get_property(x11, x11->window, XAs(x11, DND_PROPERTY),
x11->dnd_requested_format, 8, &nitems);
if (prop) {
enum mp_dnd_action action =
x11->dnd_requested_action == XA(x11, XdndActionCopy) ?
DND_REPLACE : DND_APPEND;
enum mp_dnd_action action;
if (x11->opts->drag_and_drop >= 0) {
action = x11->opts->drag_and_drop;
} else {
action = x11->dnd_requested_action == XA(x11, XdndActionCopy) ?
DND_REPLACE : DND_APPEND;
}
char *mime_type = x11_dnd_mime_type(x11, x11->dnd_requested_format);
MP_VERBOSE(x11, "Dropping type: %s (%s)\n",