summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/event.c50
-rw-r--r--input/event.h21
-rw-r--r--input/input.c9
-rw-r--r--input/input.h4
4 files changed, 84 insertions, 0 deletions
diff --git a/input/event.c b/input/event.c
new file mode 100644
index 0000000000..20ef80d36a
--- /dev/null
+++ b/input/event.c
@@ -0,0 +1,50 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "event.h"
+#include "input.h"
+#include "common/msg.h"
+#include "sub/find_subfiles.h"
+
+void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files)
+{
+ 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[] = {
+ "sub_add",
+ files[i],
+ NULL
+ };
+ mp_input_run_cmd(ictx, cmd, "<drop-subtitle>");
+ }
+ } else {
+ for (int i = 0; i < num_files; i++) {
+ const char *cmd[] = {
+ "loadfile",
+ files[i],
+ /* Start playing the dropped files right away */
+ (i == 0) ? "replace" : "append",
+ NULL
+ };
+ mp_input_run_cmd(ictx, cmd, "<drop-files>");
+ }
+ }
+}
diff --git a/input/event.h b/input/event.h
new file mode 100644
index 0000000000..38aae3ceb2
--- /dev/null
+++ b/input/event.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+struct input_ctx;
+
+// Enqueue files for playback after drag and drop
+void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files);
diff --git a/input/input.c b/input/input.c
index 6ef5bab1f5..620bd17396 100644
--- a/input/input.c
+++ b/input/input.c
@@ -1660,3 +1660,12 @@ struct mp_cmd *mp_input_parse_cmd(struct input_ctx *ictx, bstr str,
{
return mp_input_parse_cmd_(ictx->log, str, location);
}
+
+void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd,
+ const char *location)
+{
+ mp_cmd_t *cmdt = mp_input_parse_cmd_strv(ictx->log,
+ MP_ON_OSD_AUTO,
+ cmd, location);
+ mp_input_queue_cmd(ictx, cmdt);
+}
diff --git a/input/input.h b/input/input.h
index f0e9f8d5e9..de9d143265 100644
--- a/input/input.h
+++ b/input/input.h
@@ -210,6 +210,10 @@ int mp_input_check_interrupt(struct input_ctx *ictx, int time);
// characters. If false, count Right Alt as the modifier Alt key.
bool mp_input_use_alt_gr(struct input_ctx *ictx);
+// Runs a command parsing the input string array
+void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd,
+ const char *location);
+
extern int async_quit_request;
#endif /* MPLAYER_INPUT_H */