Skip to content

Commit

Permalink
wayland: Open content from drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinKinloch committed Dec 29, 2024
1 parent d2dae40 commit dc3965b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,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 \
Expand Down
16 changes: 13 additions & 3 deletions input/common/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
#define _GNU_SOURCE /* See feature_test_macros(7) */
#endif

#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif

#ifdef HAVE_GLIB
#include <glib.h>
#endif

#include "../../tasks/task_content.h"
#include "../../paths.h"

#include <stdint.h>
#include <string.h>

Expand Down Expand Up @@ -1037,9 +1048,8 @@ static void wl_data_device_handle_drop(void *data,

/* TODO/FIXME: Convert from file:// URI, Implement file loading
* Drag and Drop */
#if 0
if (wayland_load_content_from_drop(g_filename_from_uri(line, NULL, NULL)))
RARCH_WARN("----- wayland_load_content_from_drop success\n");
#ifdef HAVE_GLIB
path_set(RARCH_PATH_NEXT_CONTENT, g_filename_from_uri(line, NULL, NULL));
#endif
}

Expand Down
1 change: 1 addition & 0 deletions paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum rarch_path_type
RARCH_PATH_NAMES,
RARCH_PATH_CONFIG,
RARCH_PATH_CONTENT,
RARCH_PATH_NEXT_CONTENT,
RARCH_PATH_CONFIG_APPEND,
RARCH_PATH_CONFIG_OVERRIDE,
RARCH_PATH_CORE_OPTIONS,
Expand Down
1 change: 1 addition & 0 deletions qb/config.libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,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
Expand Down
1 change: 1 addition & 0 deletions qb/config.params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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
Expand Down
86 changes: 86 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct rarch_state
char launch_arguments[4096];
char path_default_shader_preset[PATH_MAX_LENGTH];
char path_content[PATH_MAX_LENGTH];
char path_next_content[PATH_MAX_LENGTH];
char path_libretro[PATH_MAX_LENGTH];
char path_config_file[PATH_MAX_LENGTH];
char path_config_append_file[PATH_MAX_LENGTH];
Expand Down Expand Up @@ -2400,6 +2401,8 @@ char *path_get_ptr(enum rarch_path_type type)
{
case RARCH_PATH_CONTENT:
return p_rarch->path_content;
case RARCH_PATH_NEXT_CONTENT:
return p_rarch->path_next_content;
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return p_rarch->path_default_shader_preset;
case RARCH_PATH_BASENAME:
Expand Down Expand Up @@ -2440,6 +2443,8 @@ const char *path_get(enum rarch_path_type type)
{
case RARCH_PATH_CONTENT:
return p_rarch->path_content;
case RARCH_PATH_NEXT_CONTENT:
return p_rarch->path_next_content;
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return p_rarch->path_default_shader_preset;
case RARCH_PATH_CORE_OPTIONS:
Expand Down Expand Up @@ -2480,6 +2485,8 @@ size_t path_get_realsize(enum rarch_path_type type)
{
case RARCH_PATH_CONTENT:
return sizeof(p_rarch->path_content);
case RARCH_PATH_NEXT_CONTENT:
return sizeof(p_rarch->path_next_content);
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return sizeof(p_rarch->path_default_shader_preset);
case RARCH_PATH_CORE_OPTIONS:
Expand Down Expand Up @@ -2548,6 +2555,10 @@ bool path_set(enum rarch_path_type type, const char *path)
strlcpy(p_rarch->path_content, path,
sizeof(p_rarch->path_content));
break;
case RARCH_PATH_NEXT_CONTENT:
strlcpy(p_rarch->path_next_content, path,
sizeof(p_rarch->path_next_content));
break;
case RARCH_PATH_NONE:
break;
case RARCH_PATH_BASENAME:
Expand Down Expand Up @@ -2595,6 +2606,10 @@ bool path_is_empty(enum rarch_path_type type)
if (string_is_empty(p_rarch->path_content))
return true;
break;
case RARCH_PATH_NEXT_CONTENT:
if (string_is_empty(p_rarch->path_next_content))
return true;
break;
case RARCH_PATH_CORE:
if (string_is_empty(p_rarch->path_libretro))
return true;
Expand Down Expand Up @@ -2631,6 +2646,9 @@ void path_clear(enum rarch_path_type type)
case RARCH_PATH_CONTENT:
*p_rarch->path_content = '\0';
break;
case RARCH_PATH_NEXT_CONTENT:
*p_rarch->path_next_content = '\0';
break;
case RARCH_PATH_CORE_OPTIONS:
*p_rarch->path_core_options_file = '\0';
break;
Expand Down Expand Up @@ -2660,6 +2678,7 @@ void path_clear(enum rarch_path_type type)
static void path_clear_all(void)
{
path_clear(RARCH_PATH_CONTENT);
path_clear(RARCH_PATH_NEXT_CONTENT);
path_clear(RARCH_PATH_CONFIG);
path_clear(RARCH_PATH_CONFIG_APPEND);
path_clear(RARCH_PATH_CONFIG_OVERRIDE);
Expand Down Expand Up @@ -5785,6 +5804,68 @@ void main_exit(void *args)
#endif
}


static bool load_next_content(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(&current_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;
}

/**
* main_entry:
*
Expand Down Expand Up @@ -5888,6 +5969,11 @@ int rarch_main(int argc, char *argv[], void *data)
{
int ret;
bool app_exit = false;

if (!path_is_empty(RARCH_PATH_NEXT_CONTENT) && !string_is_equal(path_get(RARCH_PATH_CONTENT), path_get(RARCH_PATH_NEXT_CONTENT))) {
load_next_content(path_get(RARCH_PATH_NEXT_CONTENT));
}

#ifdef HAVE_QT
ui_companion_qt.application->process_events();
#endif
Expand Down

0 comments on commit dc3965b

Please sign in to comment.