input: rename mp_event_drop_files to mp_input_drop_files

Move it to input.c. Will be used in next commit.
This commit is contained in:
nanahi
2026-03-30 18:50:40 -04:00
committed by Kacper Michajłow
parent cdbe01c3db
commit 5e0932e785
6 changed files with 58 additions and 56 deletions
+1 -50
View File
@@ -18,55 +18,6 @@
#include "event.h"
#include "input.h"
#include "common/msg.h"
#include "player/external_files.h"
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files,
enum mp_dnd_action action)
{
bool all_sub = true;
for (int i = 0; i < num_files; i++)
all_sub &= mp_might_be_subtitle_file(files[i]);
if (all_sub) {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"osd-auto",
"sub-add",
files[i],
NULL
};
mp_input_run_cmd(ictx, cmd);
}
} else if (action == DND_INSERT_NEXT) {
/* To insert the entries in the correct order, we iterate over them
backwards */
for (int i = num_files - 1; i >= 0; i--) {
const char *cmd[] = {
"osd-auto",
"loadfile",
files[i],
/* Since we're inserting in reverse, wait til the final item
is added to start playing */
(i > 0) ? "insert-next" : "insert-next-play",
NULL
};
mp_input_run_cmd(ictx, cmd);
}
} else {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"osd-auto",
"loadfile",
files[i],
/* Either start playing the dropped files right away
or add them to the end of the current playlist */
(i == 0 && action == DND_REPLACE) ? "replace" : "append-play",
NULL
};
mp_input_run_cmd(ictx, cmd);
}
}
}
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
bstr data, enum mp_dnd_action action)
@@ -84,7 +35,7 @@ int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
char *s = bstrto0(tmp, line);
MP_TARRAY_APPEND(tmp, files, num_files, s);
}
mp_event_drop_files(ictx, num_files, files, action);
mp_input_drop_files(ictx, num_files, files, action);
talloc_free(tmp);
return num_files > 0;
} else {
-4
View File
@@ -27,10 +27,6 @@ enum mp_dnd_action {
DND_INSERT_NEXT,
};
// Enqueue files for playback after drag and drop
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files,
enum mp_dnd_action action);
// Drop data in a specific format (identified by the mimetype).
// Returns <0 on error, ==0 if data was ok but empty, >0 on success.
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
+50
View File
@@ -33,6 +33,7 @@
#include "osdep/io.h"
#include "misc/rendezvous.h"
#include "event.h"
#include "input.h"
#include "keycodes.h"
#include "osdep/threads.h"
@@ -44,6 +45,7 @@
#include "options/path.h"
#include "mpv_talloc.h"
#include "options/options.h"
#include "player/external_files.h"
#include "misc/bstr.h"
#include "misc/node.h"
#include "stream/stream.h"
@@ -1276,6 +1278,54 @@ bool mp_input_test_dragging(struct input_ctx *ictx, int x, int y)
return r;
}
void mp_input_drop_files(struct input_ctx *ictx, int num_files, char **files,
enum mp_dnd_action action)
{
bool all_sub = true;
for (int i = 0; i < num_files; i++)
all_sub &= mp_might_be_subtitle_file(files[i]);
if (all_sub) {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"osd-auto",
"sub-add",
files[i],
NULL
};
mp_input_run_cmd(ictx, cmd);
}
} else if (action == DND_INSERT_NEXT) {
/* To insert the entries in the correct order, we iterate over them
backwards */
for (int i = num_files - 1; i >= 0; i--) {
const char *cmd[] = {
"osd-auto",
"loadfile",
files[i],
/* Since we're inserting in reverse, wait til the final item
is added to start playing */
(i > 0) ? "insert-next" : "insert-next-play",
NULL
};
mp_input_run_cmd(ictx, cmd);
}
} else {
for (int i = 0; i < num_files; i++) {
const char *cmd[] = {
"osd-auto",
"loadfile",
files[i],
/* Either start playing the dropped files right away
or add them to the end of the current playlist */
(i == 0 && action == DND_REPLACE) ? "replace" : "append-play",
NULL
};
mp_input_run_cmd(ictx, cmd);
}
}
}
unsigned int mp_input_get_mouse_event_counter(struct input_ctx *ictx)
{
// Make the frontend always display the mouse cursor (as long as it's not
+5
View File
@@ -22,6 +22,7 @@
#include "misc/bstr.h"
#include "cmd.h"
#include "event.h"
#define MP_MAX_TABLET_PAD_BUTTONS 10
@@ -205,6 +206,10 @@ bool mp_input_test_mouse_active(struct input_ctx *ictx, int x, int y);
// returns false, some VOs will initiate window dragging.
bool mp_input_test_dragging(struct input_ctx *ictx, int x, int y);
// Enqueue files for playback after drag and drop
void mp_input_drop_files(struct input_ctx *ictx, int num_files, char **files,
enum mp_dnd_action action);
// Initialize the input system
struct mpv_global;
struct input_ctx *mp_input_init(struct mpv_global *global,
+1 -1
View File
@@ -264,7 +264,7 @@ class InputHelper: NSObject {
let filesClean = files.map { $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }
var filesPtr = filesClean.map { UnsafeMutablePointer<CChar>(strdup($0)) }
mp_event_drop_files(input, Int32(files.count), &filesPtr, action)
mp_input_drop_files(input, Int32(files.count), &filesPtr, action)
for charPtr in filesPtr { free(UnsafeMutablePointer(mutating: charPtr)) }
}
}
+1 -1
View File
@@ -171,7 +171,7 @@ static STDMETHODIMP DropTarget_Drop(IDropTarget *self, IDataObject *pDataObj,
}
GlobalUnlock(medium.hGlobal);
mp_event_drop_files(t->input_ctx, recvd_files, files, action);
mp_input_drop_files(t->input_ctx, recvd_files, files, action);
talloc_free(files);
}