mirror of https://github.com/mpv-player/mpv
video/out: remove some code duplication between X11 and wayland
Both X11 and Wayland support the same format for drag & drop operations (text/uri-list), and the code for that was copied from x11_common.c to wayland_common.c. Factor it out.
This commit is contained in:
parent
6534839154
commit
7c6bb321eb
|
@ -48,3 +48,27 @@ void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mp_event_drop_mime_data(struct input_ctx *ictx, const char *mime_type,
|
||||||
|
bstr data)
|
||||||
|
{
|
||||||
|
// X11 and Wayland file list format.
|
||||||
|
if (strcmp(mime_type, "text/uri-list") == 0) {
|
||||||
|
void *tmp = talloc_new(NULL);
|
||||||
|
int num_files = 0;
|
||||||
|
char **files = NULL;
|
||||||
|
while (data.len) {
|
||||||
|
bstr line = bstr_getline(data, &data);
|
||||||
|
line = bstr_strip_linebreaks(line);
|
||||||
|
if (bstr_startswith0(line, "#"))
|
||||||
|
continue;
|
||||||
|
char *s = bstrto0(tmp, line);
|
||||||
|
MP_TARRAY_APPEND(tmp, files, num_files, s);
|
||||||
|
}
|
||||||
|
mp_event_drop_files(ictx, num_files, files);
|
||||||
|
talloc_free(tmp);
|
||||||
|
return num_files > 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,14 @@
|
||||||
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "bstr/bstr.h"
|
||||||
|
|
||||||
struct input_ctx;
|
struct input_ctx;
|
||||||
|
|
||||||
// Enqueue files for playback after drag and drop
|
// Enqueue files for playback after drag and drop
|
||||||
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files);
|
void mp_event_drop_files(struct input_ctx *ictx, int num_files, char **files);
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
bstr data);
|
||||||
|
|
|
@ -734,30 +734,6 @@ static void shedule_resize(struct vo_wayland_state *wl,
|
||||||
wl->vo->dheight = height;
|
wl->vo->dheight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stolen from x11 code
|
|
||||||
// The data is in the form of the mimetype text/uri-list.
|
|
||||||
static bool dnd_handle_drop_data(struct vo *vo, bstr data)
|
|
||||||
{
|
|
||||||
void *tmp = talloc_new(NULL);
|
|
||||||
int num_files = 0;
|
|
||||||
char **files = NULL;
|
|
||||||
|
|
||||||
while (data.len) {
|
|
||||||
bstr line = bstr_getline(data, &data);
|
|
||||||
line = bstr_strip_linebreaks(line);
|
|
||||||
if (bstr_startswith0(line, "#"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
char *s = bstrto0(tmp, line);
|
|
||||||
MP_TARRAY_APPEND(tmp, files, num_files, s);
|
|
||||||
|
|
||||||
}
|
|
||||||
mp_event_drop_files(vo->input_ctx, num_files, files);
|
|
||||||
|
|
||||||
talloc_free(tmp);
|
|
||||||
return num_files > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool create_display (struct vo_wayland_state *wl)
|
static bool create_display (struct vo_wayland_state *wl)
|
||||||
{
|
{
|
||||||
wl->display.display = wl_display_connect(NULL);
|
wl->display.display = wl_display_connect(NULL);
|
||||||
|
@ -1038,7 +1014,8 @@ static int vo_wayland_check_events (struct vo *vo)
|
||||||
if (has_read < to_read) {
|
if (has_read < to_read) {
|
||||||
buffer[str_len] = 0;
|
buffer[str_len] = 0;
|
||||||
struct bstr file_list = bstr0(buffer);
|
struct bstr file_list = bstr0(buffer);
|
||||||
dnd_handle_drop_data(wl->vo, file_list);
|
mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
||||||
|
file_list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -736,25 +736,6 @@ void vo_x11_uninit(struct vo *vo)
|
||||||
vo->x11 = NULL;
|
vo->x11 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The data is in the form of the mimetype text/uri-list.
|
|
||||||
static bool dnd_handle_drop_data(struct vo *vo, bstr data)
|
|
||||||
{
|
|
||||||
void *tmp = talloc_new(NULL);
|
|
||||||
int num_files = 0;
|
|
||||||
char **files = NULL;
|
|
||||||
while (data.len) {
|
|
||||||
bstr line = bstr_getline(data, &data);
|
|
||||||
line = bstr_strip_linebreaks(line);
|
|
||||||
if (bstr_startswith0(line, "#"))
|
|
||||||
continue;
|
|
||||||
char *s = bstrto0(tmp, line);
|
|
||||||
MP_TARRAY_APPEND(tmp, files, num_files, s);
|
|
||||||
}
|
|
||||||
mp_event_drop_files(vo->input_ctx, num_files, files);
|
|
||||||
talloc_free(tmp);
|
|
||||||
return num_files > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vo_x11_dnd_init_window(struct vo *vo)
|
static void vo_x11_dnd_init_window(struct vo *vo)
|
||||||
{
|
{
|
||||||
struct vo_x11_state *x11 = vo->x11;
|
struct vo_x11_state *x11 = vo->x11;
|
||||||
|
@ -860,7 +841,8 @@ static void vo_x11_dnd_handle_selection(struct vo *vo, XSelectionEvent *se)
|
||||||
if (!bytes_left && type == x11->dnd_requested_format && format == 8)
|
if (!bytes_left && type == x11->dnd_requested_format && format == 8)
|
||||||
{
|
{
|
||||||
// No idea if this is guaranteed to be \0-padded, so use bstr.
|
// No idea if this is guaranteed to be \0-padded, so use bstr.
|
||||||
success = dnd_handle_drop_data(vo, (bstr){prop, nitems});
|
success = mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
|
||||||
|
(bstr){prop, nitems}) > 0;
|
||||||
}
|
}
|
||||||
XFree(prop);
|
XFree(prop);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue