options: add no to drag-and-drop

Suggested by @sfan5. Naturally, "no" disables all drag and drop
behavior.
This commit is contained in:
Dudemanguy 2023-06-12 18:09:21 -05:00
parent b45be3d6e9
commit 6625a94608
4 changed files with 29 additions and 23 deletions

View File

@ -3085,13 +3085,14 @@ Window
``--snap-window``
(Windows only) Snap the player window to screen edges.
``--drag-and-drop=<auto|replace|append>``
``--drag-and-drop=<no|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.
and appending to the playlist respectively. ``no`` disables all drag and drop
behavior.
``--ontop``
Makes the player window stay on top of other windows.

View File

@ -38,6 +38,7 @@
#include "m_config.h"
#include "m_option.h"
#include "common/common.h"
#include "input/event.h"
#include "stream/stream.h"
#include "video/csputils.h"
#include "video/hwdec.h"
@ -106,8 +107,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})},
{"drag-and-drop", OPT_CHOICE(drag_and_drop, {"no", -2}, {"auto", -1},
{"replace", DND_REPLACE}, {"append", DND_APPEND})},
{"snap-window", OPT_BOOL(snap_window)},
{"ontop", OPT_BOOL(ontop)},
{"ontop-level", OPT_CHOICE(ontop_level, {"window", -1}, {"system", -2},

View File

@ -515,9 +515,10 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer,
{
struct vo_wayland_state *wl = data;
int score = mp_event_get_mime_type_score(wl->vo->input_ctx, mime_type);
if (score > wl->dnd_mime_score) {
if (score > wl->dnd_mime_score && wl->vo_opts->drag_and_drop != -2) {
wl->dnd_mime_score = score;
talloc_free(wl->dnd_mime_type);
if (wl->dnd_mime_type)
talloc_free(wl->dnd_mime_type);
wl->dnd_mime_type = talloc_strdup(wl, mime_type);
MP_VERBOSE(wl, "Given DND offer with mime type %s\n", wl->dnd_mime_type);
}
@ -530,7 +531,7 @@ static void data_offer_source_actions(void *data, struct wl_data_offer *offer, u
static void data_offer_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action)
{
struct vo_wayland_state *wl = data;
if (dnd_action) {
if (dnd_action && wl->vo_opts->drag_and_drop != -2) {
if (wl->vo_opts->drag_and_drop >= 0) {
wl->dnd_action = wl->vo_opts->drag_and_drop;
} else {
@ -570,13 +571,14 @@ static void data_device_handle_enter(void *data, struct wl_data_device *wl_ddev,
return;
}
wl_data_offer_set_actions(id, WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY |
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
if (wl->vo_opts->drag_and_drop != -2) {
wl_data_offer_set_actions(id, WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY |
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
wl_data_offer_accept(id, serial, wl->dnd_mime_type);
MP_VERBOSE(wl, "Accepting DND offer with mime type %s\n", wl->dnd_mime_type);
}
wl_data_offer_accept(id, serial, wl->dnd_mime_type);
MP_VERBOSE(wl, "Accepting DND offer with mime type %s\n", wl->dnd_mime_type);
}
static void data_device_handle_leave(void *data, struct wl_data_device *wl_ddev)
@ -590,18 +592,18 @@ static void data_device_handle_leave(void *data, struct wl_data_device *wl_ddev)
wl->dnd_offer = NULL;
}
MP_VERBOSE(wl, "Releasing DND offer with mime type %s\n", wl->dnd_mime_type);
talloc_free(wl->dnd_mime_type);
wl->dnd_mime_type = NULL;
wl->dnd_mime_score = 0;
if (wl->vo_opts->drag_and_drop != -2) {
MP_VERBOSE(wl, "Releasing DND offer with mime type %s\n", wl->dnd_mime_type);
if (wl->dnd_mime_type)
TA_FREEP(&wl->dnd_mime_type);
wl->dnd_mime_score = 0;
}
}
static void data_device_handle_motion(void *data, struct wl_data_device *wl_ddev,
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{
struct vo_wayland_state *wl = data;
wl_data_offer_accept(wl->dnd_offer, time, wl->dnd_mime_type);
}
@ -616,11 +618,12 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_ddev)
return;
}
MP_VERBOSE(wl, "Receiving DND offer with mime %s\n", wl->dnd_mime_type);
if (wl->vo_opts->drag_and_drop != -2) {
MP_VERBOSE(wl, "Receiving DND offer with mime %s\n", wl->dnd_mime_type);
wl_data_offer_receive(wl->dnd_offer, wl->dnd_mime_type, pipefd[1]);
}
wl_data_offer_receive(wl->dnd_offer, wl->dnd_mime_type, pipefd[1]);
close(pipefd[1]);
wl->dnd_fd = pipefd[0];
}

View File

@ -982,7 +982,8 @@ static void vo_x11_dnd_handle_selection(struct vo *vo, XSelectionEvent *se)
if (se->selection == XA(x11, XdndSelection) &&
se->property == XAs(x11, DND_PROPERTY) &&
se->target == x11->dnd_requested_format)
se->target == x11->dnd_requested_format &&
x11->opts->drag_and_drop != -2)
{
int nitems;
void *prop = x11_get_property(x11, x11->window, XAs(x11, DND_PROPERTY),