1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

input: move files drag and drop to a new event.c file

event.c will be used to feed the input queue with 'global' events that don't
mesh well with the usual check_events path in mpv.
This commit is contained in:
Stefano Pigozzi 2014-01-04 16:59:22 +01:00
parent bb3ea1580e
commit 082c5c19a1
8 changed files with 89 additions and 43 deletions

50
input/event.c Normal file
View File

@ -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>");
}
}
}

21
input/event.h Normal file
View File

@ -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);

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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" ),