From 5ee7a43a2991addc3c32c84d4ba06f734b5d4595 Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Wed, 17 Apr 2024 16:15:24 +0100 Subject: [PATCH] wayland: Open content from drag and drop --- Makefile.common | 5 +++ input/common/wayland_common.c | 69 ++++++++++++++++++++++++++++++++++- qb/config.libs.sh | 1 + qb/config.params.sh | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Makefile.common b/Makefile.common index f7158506cff..f743f5a0b76 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1265,6 +1265,11 @@ ifeq ($(HAVE_WAYLAND), 1) endif +ifeq (${HAVE_GLIB}, 1) + DEF_FLAGS += $(GLIB_CFLAGS) + LIBS += $(GLIB_LIBS) +endif + # XML OBJ += \ $(LIBRETRO_COMM_DIR)/formats/xml/rxml.o \ diff --git a/input/common/wayland_common.c b/input/common/wayland_common.c index 1a36c61b602..0e7c9a993dd 100644 --- a/input/common/wayland_common.c +++ b/input/common/wayland_common.c @@ -18,6 +18,12 @@ #define _GNU_SOURCE /* See feature_test_macros(7) */ #endif +#ifdef HAVE_GLIB +#include +#endif +#include "../../tasks/task_content.h" +#include "../../paths.h" + #include #include @@ -947,6 +953,67 @@ static void wl_data_device_handle_motion(void *data, struct wl_data_device *data_device, uint32_t time, wl_fixed_t x, wl_fixed_t y) { } +static bool wayland_load_content_from_drop(const char* path) +{ + core_info_list_t *core_info_list = NULL; + core_info_get_list(&core_info_list); + if (core_info_list) + { + size_t list_size; + content_ctx_info_t content_info = { 0 }; + const core_info_t *core_info = NULL; + core_info_list_get_supported_cores(core_info_list, + (const char*)path, &core_info, &list_size); + if (list_size) + { + path_set(RARCH_PATH_CONTENT, path); + + if (!path_is_empty(RARCH_PATH_CONTENT)) + { + unsigned i; + core_info_t *current_core = NULL; + core_info_get_current_core(¤t_core); + + /*we already have path for libretro core */ + for (i = 0; i < list_size; i++) + { + const core_info_t *info = (const core_info_t*)&core_info[i]; + + if (string_is_equal(path_get(RARCH_PATH_CORE), info->path)) + { + /* Our previous core supports the current rom */ + task_push_load_content_with_current_core_from_companion_ui( + NULL, + &content_info, + CORE_TYPE_PLAIN, + NULL, NULL); + return true; + } + } + } + } + + if (list_size >= 1) + { + /*pick core that only exists and is bound to work. Ish. */ + const core_info_t *info = (const core_info_t*)&core_info[0]; + + if (info) + { + task_push_load_content_with_new_core_from_companion_ui( + info->path, NULL, NULL, NULL, NULL, &content_info, NULL, NULL); + return true; + } + } + else + { + RARCH_WARN("There are no core to open %s\n", path); + } + } + + return false; +} + static void wl_data_device_handle_drop(void *data, struct wl_data_device *data_device) { @@ -994,7 +1061,7 @@ static void wl_data_device_handle_drop(void *data, /* TODO/FIXME: Convert from file:// URI, Implement file loading * Drag and Drop */ -#if 0 +#ifdef HAVE_GLIB if (wayland_load_content_from_drop(g_filename_from_uri(line, NULL, NULL))) RARCH_WARN("----- wayland_load_content_from_drop success\n"); #endif diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 39092b5e6cb..754caab65fa 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -264,6 +264,7 @@ else check_lib '' AL -lopenal alcOpenDevice fi +check_pkgconf GLIB glib-2.0 2.78.0 check_pkgconf RSOUND rsound 1.1 check_pkgconf ROAR libroar 1.0.12 check_val '' JACK -ljack '' jack 0.120.1 '' false diff --git a/qb/config.params.sh b/qb/config.params.sh index d261c8f6f37..59b93ba93d4 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -104,6 +104,7 @@ HAVE_WAYLAND=auto # Wayland support HAVE_LIBDECOR=auto # libdecor support C89_WAYLAND=no CXX_WAYLAND=no +HAVE_GLIB=auto # GLib support HAVE_DYNAMIC_EGL=no # Dynamic library EGL support HAVE_EGL=auto # EGL context support HAVE_VG=auto # OpenVG support