mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
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:
@@ -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/>.
|
||||
*/
|
||||
|
||||
#include "bstr/bstr.h"
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user