summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--input/event.c50
-rw-r--r--input/event.h21
-rw-r--r--input/input.c9
-rw-r--r--input/input.h4
-rw-r--r--video/out/vo.c41
-rw-r--r--video/out/wayland_common.c3
-rw-r--r--video/out/x11_common.c3
-rw-r--r--wscript_build.py1
8 files changed, 89 insertions, 43 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 */
diff --git a/video/out/vo.c b/video/out/vo.c
index 68fb7d0ee7..99efc9eec9 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -43,7 +43,6 @@
#include "video/mp_image.h"
#include "video/vfcap.h"
#include "sub/osd.h"
-#include "sub/find_subfiles.h"
//
// Externally visible list of all vo drivers
@@ -620,43 +619,3 @@ void vo_mouse_movement(struct vo *vo, int posx, int posy)
vo_control(vo, VOCTRL_WINDOW_TO_OSD_COORDS, p);
mp_input_set_mouse_pos(vo->input_ctx, p[0], p[1]);
}
-
-static void run_cmd(struct vo *vo, const char **cmd)
-{
- mp_cmd_t *cmdt = mp_input_parse_cmd_strv(vo->log,
- MP_ON_OSD_AUTO,
- cmd, "<window>");
- mp_input_queue_cmd(vo->input_ctx, cmdt);
-}
-
-// Handle drag & drop event of a list of files on the VO window.
-void vo_drop_files(struct vo *vo, 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
- };
- run_cmd(vo, cmd);
- }
- } 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_VERBOSE(vo, "received dropped file: %s\n", files[i]);
- run_cmd(vo, cmd);
- }
- }
-}
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index a5b73c1c6f..7f48563204 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -44,6 +44,7 @@
#include "osdep/timer.h"
#include "input/input.h"
+#include "input/event.h"
#include "input/keycodes.h"
#define MOD_SHIFT_MASK 0x01
@@ -751,7 +752,7 @@ static bool dnd_handle_drop_data(struct vo *vo, bstr data)
MP_TARRAY_APPEND(tmp, files, num_files, s);
}
- vo_drop_files(vo, num_files, files);
+ mp_event_drop_files(vo->input_ctx, num_files, files);
talloc_free(tmp);
return num_files > 0;
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index 2e8b0917ac..a48c3f6e0e 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -27,6 +27,7 @@
#include "options/options.h"
#include "common/msg.h"
#include "input/input.h"
+#include "input/event.h"
#include "libavutil/common.h"
#include "x11_common.h"
#include "talloc.h"
@@ -749,7 +750,7 @@ static bool dnd_handle_drop_data(struct vo *vo, bstr data)
char *s = bstrto0(tmp, line);
MP_TARRAY_APPEND(tmp, files, num_files, s);
}
- vo_drop_files(vo, num_files, files);
+ mp_event_drop_files(vo->input_ctx, num_files, files);
talloc_free(tmp);
return num_files > 0;
}
diff --git a/wscript_build.py b/wscript_build.py
index 4f216e41fb..8b7ca79995 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -197,6 +197,7 @@ def build(ctx):
## Input
( "input/cmd_list.c" ),
( "input/cmd_parse.c" ),
+ ( "input/event.c" ),
( "input/input.c" ),
( "input/keycodes.c" ),
( "input/joystick.c", "joystick" ),