Merge pull request #5420 from fr500/remap-redux

remap-redux part 1
This commit is contained in:
Twinaphex 2017-09-11 07:39:47 +02:00 committed by GitHub
commit ba24d6440a
27 changed files with 686 additions and 47 deletions

View File

@ -1441,6 +1441,10 @@ ifeq ($(HAVE_NETWORKING), 1)
endif
endif
ifeq ($(HAVE_KEYMAPPER), 1)
OBJ += input/input_mapper.o
endif
ifeq ($(HAVE_NETWORKGAMEPAD), 1)
OBJ += input/input_remote.o \
cores/libretro-net-retropad/net_retropad_core.o

View File

@ -2491,6 +2491,14 @@ TODO: Add a setting for these tweaks */
command_event(CMD_EVENT_REMOTE_DEINIT, NULL);
input_driver_init_remote();
break;
case CMD_EVENT_MAPPER_DEINIT:
input_driver_deinit_mapper();
break;
case CMD_EVENT_MAPPER_INIT:
command_event(CMD_EVENT_MAPPER_DEINIT, NULL);
input_driver_init_mapper();
break;
case CMD_EVENT_LOG_FILE_DEINIT:
retro_main_log_file_deinit();
break;

View File

@ -193,6 +193,10 @@ enum event_command
CMD_EVENT_REMOTE_INIT,
/* Deinitializes remote gamepad interface. */
CMD_EVENT_REMOTE_DEINIT,
/* Initializes keyboard to gamepad mapper interface. */
CMD_EVENT_MAPPER_INIT,
/* Deinitializes keyboard to gamepad mapper interface. */
CMD_EVENT_MAPPER_DEINIT,
/* Reinitializes audio driver. */
CMD_EVENT_AUDIO_REINIT,
/* Resizes windowed scale. Will reinitialize video driver. */

View File

@ -1241,6 +1241,9 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
#ifdef HAVE_NETWORKGAMEPAD
SETTING_BOOL("network_remote_enable", &settings->bools.network_remote_enable, false, false /* TODO */, false);
#endif
#ifdef HAVE_KEYMAPPER
SETTING_BOOL("keymapper_enable", &settings->bools.keymapper_enable, true, true /* TODO */, false);
#endif
#ifdef HAVE_NETWORKING
SETTING_BOOL("netplay_nat_traversal", &settings->bools.netplay_nat_traversal, true, true, false);
#endif
@ -1343,6 +1346,9 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
#ifdef HAVE_NETWORKGAMEPAD
SETTING_UINT("network_remote_base_port", &settings->uints.network_remote_base_port, true, network_remote_base_port, false);
#endif
#ifdef HAVE_KEYMAPPER
SETTING_UINT("keymapper_port", &settings->uints.keymapper_port, true, 0, false);
#endif
#ifdef GEKKO
SETTING_UINT("video_viwidth", &settings->uints.video_viwidth, true, video_viwidth, false);
#endif

View File

@ -199,6 +199,7 @@ typedef struct settings
bool savestate_thumbnail_enable;
bool network_cmd_enable;
bool stdin_cmd_enable;
bool keymapper_enable;
bool network_remote_enable;
bool network_remote_enable_user[MAX_USERS];
bool load_dummy_on_core_shutdown;
@ -274,6 +275,7 @@ typedef struct settings
unsigned audio_block_frames;
unsigned audio_latency;
unsigned input_remap_ids[MAX_USERS][RARCH_CUSTOM_BIND_LIST_END];
unsigned input_keymapper_ids[RARCH_CUSTOM_BIND_LIST_END];
/* Set by autoconfiguration in joypad_autoconfig_dir.
* Does not override main binds. */
@ -303,6 +305,7 @@ typedef struct settings
unsigned autosave_interval;
unsigned network_cmd_port;
unsigned network_remote_base_port;
unsigned keymapper_port;
unsigned video_window_x;
unsigned video_window_y;
unsigned video_monitor_index;

View File

@ -1097,6 +1097,10 @@ MENU
#include "../cores/libretro-net-retropad/net_retropad_core.c"
#endif
#ifdef HAVE_KEYMAPPER
#include "../input/input_mapper.c"
#endif
#include "../command.c"
#ifdef __cplusplus

View File

@ -34,6 +34,10 @@
#include "input_remote.h"
#endif
#ifdef HAVE_KEYMAPPER
#include "input_mapper.h"
#endif
#include "input_driver.h"
#include "input_keymaps.h"
#include "input_remapping.h"
@ -346,6 +350,9 @@ static command_t *input_driver_command = NULL;
#ifdef HAVE_NETWORKGAMEPAD
static input_remote_t *input_driver_remote = NULL;
#endif
#ifdef HAVE_KEYMAPPER
static input_mapper_t *input_driver_mapper = NULL;
#endif
const input_driver_t *current_input = NULL;
void *current_input_data = NULL;
static bool input_driver_block_hotkey = false;
@ -572,6 +579,11 @@ void input_poll(void)
if (input_driver_remote)
input_remote_poll(input_driver_remote, max_users);
#endif
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_poll(input_driver_mapper);
#endif
}
/**
@ -655,6 +667,11 @@ int16_t input_state(unsigned port, unsigned device,
input_remote_state(&res, port, device, idx, id);
#endif
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_state(&res, port, device, idx, id);
#endif
/* Don't allow turbo for D-pad. */
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
@ -1327,6 +1344,15 @@ void input_driver_deinit_remote(void)
#endif
}
void input_driver_deinit_mapper(void)
{
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_free(input_driver_mapper);
input_driver_mapper = NULL;
#endif
}
bool input_driver_init_remote(void)
{
#ifdef HAVE_NETWORKGAMEPAD
@ -1347,6 +1373,26 @@ bool input_driver_init_remote(void)
return false;
}
bool input_driver_init_mapper(void)
{
#ifdef HAVE_KEYMAPPER
settings_t *settings = config_get_ptr();
if (!settings->bools.keymapper_enable)
return false;
input_driver_mapper = input_mapper_new(
settings->uints.keymapper_port);
if (input_driver_mapper)
return true;
RARCH_ERR("Failed to initialize input mapper.\n");
#endif
return false;
}
bool input_driver_grab_mouse(void)
{
if (!current_input || !current_input->grab_mouse)

View File

@ -397,6 +397,10 @@ void input_driver_deinit_remote(void);
bool input_driver_init_remote(void);
void input_driver_deinit_mapper(void);
bool input_driver_init_mapper(void);
bool input_driver_grab_mouse(void);
bool input_driver_ungrab_mouse(void);

136
input/input_mapper.c Normal file
View File

@ -0,0 +1,136 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <retro_miscellaneous.h>
#include <libretro.h>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "input_mapper.h"
#include "../configuration.h"
#include "../msg_hash.h"
#include "../verbosity.h"
#define MAPPER_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
#define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
struct input_mapper
{
/* The controller port that will be polled*/
uint8_t port;
/* This is a bitmask of (1 << key_bind_id). */
uint64_t buttons;
/* Left X, Left Y, Right X, Right Y */
int16_t analog[4];
/* the whole keyboard state */
uint32_t keys[RETROK_LAST / 32 + 1];
};
static input_mapper_t *mapper_ptr;
input_mapper_t *input_mapper_new(uint16_t port)
{
settings_t *settings = config_get_ptr();
input_mapper_t* handle = (input_mapper_t*)
calloc(1, sizeof(*handle));
if (!handle)
return NULL;
handle->port = port;
mapper_ptr = handle;
return handle;
}
void input_mapper_free(input_mapper_t *handle)
{
free (handle);
}
void input_mapper_poll(input_mapper_t *handle)
{
settings_t *settings = config_get_ptr();
unsigned device = settings->uints.input_libretro_device[handle->port];
device &= RETRO_DEVICE_MASK;
/* for now we only handle keyboard inputs */
if (device == RETRO_DEVICE_KEYBOARD)
{
memset(handle->keys, 0, sizeof(handle->keys));
for (int i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
{
if(i < RETROK_LAST)
{
if (input_state(handle->port, RETRO_DEVICE_JOYPAD, 0, i))
{
MAPPER_SET_KEY (handle, settings->uints.input_keymapper_ids[i]);
input_keyboard_event(true, settings->uints.input_keymapper_ids[i], 0, 0, RETRO_DEVICE_KEYBOARD);
}
else
input_keyboard_event(false, settings->uints.input_keymapper_ids[i], 0, 0, RETRO_DEVICE_KEYBOARD);
}
}
}
return;
}
void input_mapper_state(
int16_t *ret,
unsigned port,
unsigned device,
unsigned idx,
unsigned id)
{
settings_t *settings = config_get_ptr();
switch (device)
{
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
/*
RARCH_LOG("State: UDLR %u %u %u %u\n",
MAPPER_GET_KEY(mapper_ptr, RETROK_UP),
MAPPER_GET_KEY(mapper_ptr, RETROK_DOWN),
MAPPER_GET_KEY(mapper_ptr, RETROK_LEFT),
MAPPER_GET_KEY(mapper_ptr, RETROK_RIGHT)
);*/
if (MAPPER_GET_KEY(mapper_ptr, id))
*ret |= 1;
}
break;
}
return;
}

51
input/input_mapper.h Normal file
View File

@ -0,0 +1,51 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INPUT_MAPPER_H__
#define INPUT_MAPPER_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
typedef struct input_mapper input_mapper_t;
input_mapper_t *input_mapper_new(uint16_t port);
void input_mapper_free(input_mapper_t *handle);
void input_mapper_poll(input_mapper_t *handle);
bool input_mapper_key_pressed(int key);
void input_mapper_state(
int16_t *ret,
unsigned port,
unsigned device,
unsigned idx,
unsigned id);
RETRO_END_DECLS
#endif

View File

@ -734,6 +734,12 @@ void input_state_overlay(input_overlay_t *ol, int16_t *ret,
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
/*RARCH_LOG("UDLR %u %u %u %u\n",
OVERLAY_GET_KEY(ol_state, RETROK_UP),
OVERLAY_GET_KEY(ol_state, RETROK_DOWN),
OVERLAY_GET_KEY(ol_state, RETROK_LEFT),
OVERLAY_GET_KEY(ol_state, RETROK_RIGHT)
);*/
if (OVERLAY_GET_KEY(ol_state, id))
*ret |= 1;
}

View File

@ -1,6 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2015-2017 - Andrés Suárez
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch 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 Found-
@ -23,6 +23,7 @@
#include "input_remapping.h"
#include "../configuration.h"
#include "../retroarch.h"
#include "../verbosity.h"
static unsigned old_analog_dpad_mode[MAX_USERS];
static unsigned old_libretro_device[MAX_USERS];
@ -50,8 +51,9 @@ bool input_remapping_load_file(void *data, const char *path)
for (i = 0; i < MAX_USERS; i++)
{
char buf_tmp[64];
char s1[64], s2[64];
char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}};
char keymapper_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 4][128] =
{ "b", "y", "select", "start",
"up", "down", "left", "right",
@ -61,17 +63,41 @@ bool input_remapping_load_file(void *data, const char *path)
old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i];
old_libretro_device[i] = settings->uints.input_libretro_device[i];
snprintf(buf_tmp, sizeof(buf_tmp), "input_player%u", i + 1);
s1[0] = '\0';
s2[0] = '\0';
snprintf(s1, sizeof(s1), "input_player%u", i + 1);
snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++)
{
int key_remap = -1;
fill_pathname_join_delim(key_ident[j], buf_tmp,
fill_pathname_join_delim(key_ident[j], s1,
key_strings[j], '_', sizeof(key_ident[j]));
fill_pathname_join_delim(keymapper_ident[j], s2,
key_strings[j], '_', sizeof(key_ident[j]));
if (config_get_int(conf, key_ident[j], &key_remap)
&& key_remap < RARCH_FIRST_CUSTOM_BIND)
settings->uints.input_remap_ids[i][j] = key_remap;
key_remap = -1;
if (settings->uints.keymapper_port == i)
{
if (config_get_int(conf, keymapper_ident[j], &key_remap))
{
settings->uints.input_keymapper_ids[j] = key_remap;
#if 0
RARCH_LOG ("%s: %u\n", keymapper_ident[j], settings->uints.input_keymapper_ids[j]);
#endif
}
else
settings->uints.input_keymapper_ids[j] = RETROK_UNKNOWN;
}
}
for (j = 0; j < 4; j++)
@ -81,7 +107,7 @@ bool input_remapping_load_file(void *data, const char *path)
snprintf(key_ident[RARCH_FIRST_CUSTOM_BIND + j],
sizeof(key_ident[RARCH_FIRST_CUSTOM_BIND + j]),
"%s_%s",
buf_tmp,
s1,
key_strings[RARCH_FIRST_CUSTOM_BIND + j]);
if (config_get_int(conf, key_ident[RARCH_FIRST_CUSTOM_BIND + j],
@ -90,11 +116,11 @@ bool input_remapping_load_file(void *data, const char *path)
key_remap;
}
snprintf(buf_tmp, sizeof(buf_tmp), "input_player%u_analog_dpad_mode", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], buf_tmp);
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1);
snprintf(buf_tmp, sizeof(buf_tmp), "input_libretro_device_p%u", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_libretro_device[i], buf_tmp);
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
CONFIG_GET_INT_BASE(conf, settings, uints.input_libretro_device[i], s1);
}
config_file_free(conf);
@ -144,22 +170,27 @@ bool input_remapping_save_file(const char *path)
for (i = 0; i < max_users; i++)
{
char buf_tmp[64];
char s1[64], s2[64];
char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}};
char keymapper_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}};
char key_strings[RARCH_FIRST_CUSTOM_BIND + 4][128] = {
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x", "l_y", "r_x", "r_y" };
buf_tmp[0] = '\0';
s1[0] = '\0';
s2[0] = '\0';
snprintf(buf_tmp, sizeof(buf_tmp), "input_player%u", i + 1);
snprintf(s1, sizeof(s1), "input_player%u", i + 1);
snprintf(s2, sizeof(s2), "input_player%u_key", i + 1);
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++)
{
fill_pathname_join_delim(key_ident[j], buf_tmp,
key_strings[j], '_', sizeof(key_ident[j]));
fill_pathname_join_delim(key_ident[j], s1,
key_strings[j], '_', sizeof(key_ident[j]));
fill_pathname_join_delim(keymapper_ident[j], s2,
key_strings[j], '_', sizeof(key_ident[j]));
/* only save values that have been modified */
if(j < RARCH_FIRST_CUSTOM_BIND)
@ -168,6 +199,10 @@ bool input_remapping_save_file(const char *path)
config_set_int(conf, key_ident[j], settings->uints.input_remap_ids[i][j]);
else
config_unset(conf,key_ident[j]);
if (settings->uints.keymapper_port == i &&
settings->uints.input_keymapper_ids[j] != RETROK_UNKNOWN)
config_set_int(conf, keymapper_ident[j], settings->uints.input_keymapper_ids[j]);
}
else
{
@ -177,10 +212,10 @@ bool input_remapping_save_file(const char *path)
config_unset(conf,key_ident[j]);
}
}
snprintf(buf_tmp, sizeof(buf_tmp), "input_libretro_device_p%u", i + 1);
config_set_int(conf, buf_tmp, input_config_get_device(i));
snprintf(buf_tmp, sizeof(buf_tmp), "input_player%u_analog_dpad_mode", i + 1);
config_set_int(conf, buf_tmp, settings->uints.input_analog_dpad_mode[i]);
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
config_set_int(conf, s1, input_config_get_device(i));
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
config_set_int(conf, s1, settings->uints.input_analog_dpad_mode[i]);
}
ret = config_file_write(conf, remap_file);

View File

@ -1,5 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch 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 Found-

View File

@ -169,18 +169,18 @@ void input_remote_free(input_remote_t *handle, unsigned max_users)
#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
static void input_remote_parse_packet(struct remote_message *msg, unsigned user)
{
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
/* Parse message */
switch (msg->device)
{
case RETRO_DEVICE_JOYPAD:
ol_state->buttons[user] &= ~(1 << msg->id);
input_state->buttons[user] &= ~(1 << msg->id);
if (msg->state)
ol_state->buttons[user] |= 1 << msg->id;
input_state->buttons[user] |= 1 << msg->id;
break;
case RETRO_DEVICE_ANALOG:
ol_state->analog[msg->index * 2 + msg->id][user] = msg->state;
input_state->analog[msg->index * 2 + msg->id][user] = msg->state;
break;
}
}
@ -202,17 +202,17 @@ void input_remote_state(
case RETRO_DEVICE_ANALOG:
{
unsigned base = 0;
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
if (!ol_state)
if (!input_state)
return;
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
base = 2;
if (id == RETRO_DEVICE_ID_ANALOG_Y)
base += 1;
if (ol_state && ol_state->analog[base][port])
*ret = ol_state->analog[base][port];
if (input_state && input_state->analog[base][port])
*ret = input_state->analog[base][port];
}
break;
}
@ -220,19 +220,19 @@ void input_remote_state(
bool input_remote_key_pressed(int key, unsigned port)
{
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
if (!ol_state)
if (!input_state)
return false;
return (ol_state->buttons[port] & (UINT64_C(1) << key));
return (input_state->buttons[port] & (UINT64_C(1) << key));
}
void input_remote_poll(input_remote_t *handle, unsigned max_users)
{
unsigned user;
settings_t *settings = config_get_ptr();
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
for(user = 0; user < max_users; user++)
{
@ -257,11 +257,11 @@ void input_remote_poll(input_remote_t *handle, unsigned max_users)
else if ((ret != -1) || ((errno != EAGAIN) && (errno != ENOENT)))
#endif
{
ol_state->buttons[user] = 0;
ol_state->analog[0][user] = 0;
ol_state->analog[1][user] = 0;
ol_state->analog[2][user] = 0;
ol_state->analog[3][user] = 0;
input_state->buttons[user] = 0;
input_state->analog[0][user] = 0;
input_state->analog[1][user] = 0;
input_state->analog[2][user] = 0;
input_state->analog[3][user] = 0;
}
}
}

View File

@ -1567,6 +1567,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_UPDATE_SLANG_SHADERS,
"Update Slang Shaders")
MSG_HASH(MENU_ENUM_LABEL_VALUE_USER,
"User")
MSG_HASH(MENU_ENUM_LABEL_VALUE_KEYBOARD,
"Kbd")
MSG_HASH(MENU_ENUM_LABEL_VALUE_USER_INTERFACE_SETTINGS,
"User Interface")
MSG_HASH(MENU_ENUM_LABEL_VALUE_USER_LANGUAGE,

View File

@ -39,6 +39,7 @@
#include "../../performance_counters.h"
#include "../../paths.h"
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../wifi/wifi_driver.h"
#ifndef BIND_ACTION_GET_VALUE
@ -47,6 +48,8 @@
cbs->action_get_value_ident = #name;
#endif
extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];
static void menu_action_setting_disp_set_label_cheat_num_passes(
file_list_t* list,
unsigned *w, unsigned type, unsigned i,
@ -485,6 +488,38 @@ static void menu_action_setting_disp_set_label_input_desc(
}
#ifdef HAVE_KEYMAPPER
static void menu_action_setting_disp_set_label_input_desc_kbd(
file_list_t* list,
unsigned *w, unsigned type, unsigned i,
const char *label,
char *s, size_t len,
const char *entry_label,
const char *path,
char *s2, size_t len2)
{
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned remap_id =
settings->uints.input_keymapper_ids[type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN];
char desc[PATH_MAX_LENGTH];
if (!settings)
return;
for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN; key_id++)
{
if(remap_id == key_descriptors[key_id].key)
break;
}
snprintf(desc, sizeof(desc), "Keyboard %s", key_descriptors[key_id].desc);
strlcpy(s, desc, len);
*w = 19;
strlcpy(s2, path, len2);
}
#endif
static void menu_action_setting_disp_set_label_cheat(
file_list_t* list,
unsigned *w, unsigned type, unsigned i,
@ -1726,6 +1761,14 @@ static int menu_cbs_init_bind_get_string_representation_compare_type(
BIND_ACTION_GET_VALUE(cbs,
menu_action_setting_disp_set_label_libretro_perf_counters);
}
#ifdef HAVE_KEYMAPPER
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_GET_VALUE(cbs,
menu_action_setting_disp_set_label_input_desc_kbd);
}
#endif
else
{
switch (type)

View File

@ -46,6 +46,8 @@
} while(0)
#endif
extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];
#ifdef HAVE_SHADER_MANAGER
static int generic_shader_action_parameter_left(
struct video_shader_parameter *param,
@ -111,6 +113,37 @@ static int action_left_input_desc(unsigned type, const char *label,
return 0;
}
#ifdef HAVE_KEYMAPPER
static int action_left_input_desc_kbd(unsigned type, const char *label,
bool wraparound)
{
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned offset = type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN;
unsigned remap_id =
settings->uints.input_keymapper_ids[offset];
char desc[PATH_MAX_LENGTH];
if (!settings)
return 0;
for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN; key_id++)
{
if(remap_id == key_descriptors[key_id].key)
break;
}
if (key_id > 0)
key_id--;
else
key_id = MENU_SETTINGS_INPUT_DESC_KBD_END - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN;
settings->uints.input_keymapper_ids[offset] = key_descriptors[key_id].key;
return 0;
}
#endif
static int action_left_scroll(unsigned type, const char *label,
bool wraparound)
{
@ -538,6 +571,13 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
{
BIND_ACTION_LEFT(cbs, action_left_input_desc);
}
#ifdef HAVE_KEYMAPPER
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_LEFT(cbs, action_left_input_desc_kbd);
}
#endif
else if ((type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START))
{
BIND_ACTION_LEFT(cbs, playlist_association_left);

View File

@ -37,6 +37,7 @@
#include "../../managers/cheat_manager.h"
#include "../../file_path_special.h"
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../ui/ui_companion_driver.h"
#ifndef BIND_ACTION_RIGHT
@ -47,6 +48,8 @@
} while(0)
#endif
extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];
#ifdef HAVE_SHADER_MANAGER
static int generic_shader_action_parameter_right(struct video_shader_parameter *param,
unsigned type, const char *label, bool wraparound)
@ -99,27 +102,58 @@ int action_right_cheat(unsigned type, const char *label,
wraparound);
}
int action_right_input_desc(unsigned type, const char *label,
#ifdef HAVE_KEYMAPPER
int action_right_input_desc_kbd(unsigned type, const char *label,
bool wraparound)
{
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned offset = type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN;
unsigned remap_id =
settings->uints.input_keymapper_ids[offset];
char desc[PATH_MAX_LENGTH];
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
if (!settings)
return 0;
for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN; key_id++)
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
if(remap_id == key_descriptors[key_id].key)
break;
}
if (key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN)
key_id++;
else
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < 4 - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
key_id = 0;
settings->uints.input_keymapper_ids[offset] = key_descriptors[key_id].key;
return 0;
}
#endif
int action_right_input_desc(unsigned type, const char *label,
bool wraparound)
{
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
else
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < 4 - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
return 0;
}
static int action_right_scroll(unsigned type, const char *label,
bool wraparound)
@ -406,6 +440,13 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
{
BIND_ACTION_RIGHT(cbs, action_right_input_desc);
}
#ifdef HAVE_KEYMAPPER
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_RIGHT(cbs, action_right_input_desc_kbd);
}
#endif
else if ((type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START))
{
BIND_ACTION_RIGHT(cbs, playlist_association_right);

View File

@ -145,6 +145,12 @@ static int action_select_input_desc(const char *path, const char *label, unsigne
return action_right_input_desc(type, label, true);
}
static int action_select_input_desc_kbd(const char *path, const char *label, unsigned type,
size_t idx)
{
return action_right_input_desc_kbd(type, label, true);
}
static int menu_cbs_init_bind_select_compare_type(
menu_file_list_cbs_t *cbs, unsigned type)
{
@ -170,6 +176,13 @@ static int menu_cbs_init_bind_select_compare_type(
{
BIND_ACTION_SELECT(cbs, action_select_input_desc);
}
#ifdef HAVE_KEYMAPPER
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_SELECT(cbs, action_select_input_desc_kbd);
}
#endif
else
{
switch (type)

View File

@ -32,6 +32,151 @@ static void menu_cbs_init_log(const char *entry_label, const char *bind_label, c
#endif
}
struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END] =
{
{RETROK_FIRST, "Unmapped"},
{RETROK_BACKSPACE, "Backspace"},
{RETROK_TAB, "Tab"},
{RETROK_CLEAR, "Clear"},
{RETROK_RETURN, "Return"},
{RETROK_PAUSE, "Pause"},
{RETROK_ESCAPE, "Escape"},
{RETROK_SPACE, "Space"},
{RETROK_EXCLAIM, "!"},
{RETROK_QUOTEDBL, "\""},
{RETROK_HASH, "#"},
{RETROK_DOLLAR, "$"},
{RETROK_AMPERSAND, "&"},
{RETROK_QUOTE, "\'"},
{RETROK_LEFTPAREN, "("},
{RETROK_RIGHTPAREN, ")"},
{RETROK_ASTERISK, "*"},
{RETROK_PLUS, "+"},
{RETROK_COMMA, ","},
{RETROK_MINUS, "-"},
{RETROK_PERIOD, "."},
{RETROK_SLASH, "/"},
{RETROK_0, "0"},
{RETROK_1, "1"},
{RETROK_2, "2"},
{RETROK_3, "3"},
{RETROK_4, "4"},
{RETROK_5, "5"},
{RETROK_6, "6"},
{RETROK_7, "7"},
{RETROK_8, "8"},
{RETROK_9, "9"},
{RETROK_COLON, ":"},
{RETROK_SEMICOLON, ";"},
{RETROK_LESS, "-"},
{RETROK_EQUALS, "="},
{RETROK_GREATER, ">"},
{RETROK_QUESTION, "?"},
{RETROK_AT, "@"},
{RETROK_LEFTBRACKET, "["},
{RETROK_BACKSLASH, "\\"},
{RETROK_RIGHTBRACKET, "]"},
{RETROK_CARET, "^"},
{RETROK_UNDERSCORE, "_"},
{RETROK_BACKQUOTE, "`"},
{RETROK_a, "a"},
{RETROK_b, "b"},
{RETROK_c, "c"},
{RETROK_d, "d"},
{RETROK_e, "e"},
{RETROK_f, "f"},
{RETROK_g, "g"},
{RETROK_h, "h"},
{RETROK_i, "i"},
{RETROK_j, "j"},
{RETROK_k, "k"},
{RETROK_l, "l"},
{RETROK_m, "m"},
{RETROK_n, "n"},
{RETROK_o, "o"},
{RETROK_p, "p"},
{RETROK_q, "q"},
{RETROK_r, "r"},
{RETROK_s, "s"},
{RETROK_t, "t"},
{RETROK_u, "u"},
{RETROK_v, "v"},
{RETROK_w, "w"},
{RETROK_x, "x"},
{RETROK_y, "y"},
{RETROK_z, "z"},
{RETROK_DELETE, "Delete"},
{RETROK_KP0, "Numpad 0"},
{RETROK_KP1, "Numpad 1"},
{RETROK_KP2, "Numpad 2"},
{RETROK_KP3, "Numpad 3"},
{RETROK_KP4, "Numpad 4"},
{RETROK_KP5, "Numpad 5"},
{RETROK_KP6, "Numpad 6"},
{RETROK_KP7, "Numpad 7"},
{RETROK_KP8, "Numpad 8"},
{RETROK_KP9, "Numpad 9"},
{RETROK_KP_PERIOD, "Numpad ."},
{RETROK_KP_DIVIDE, "Numpad /"},
{RETROK_KP_MULTIPLY, "Numpad *"},
{RETROK_KP_MINUS, "Numpad -"},
{RETROK_KP_PLUS, "Numpad +"},
{RETROK_KP_ENTER, "Numpad Enter"},
{RETROK_KP_EQUALS, "Numpad ="},
{RETROK_UP, "Up"},
{RETROK_DOWN, "Down"},
{RETROK_RIGHT, "Right"},
{RETROK_LEFT, "Left"},
{RETROK_INSERT, "Insert"},
{RETROK_HOME, "Home"},
{RETROK_END, "End"},
{RETROK_PAGEUP, "Page Up"},
{RETROK_PAGEDOWN, "Page Down"},
{RETROK_F1, "F1"},
{RETROK_F2, "F2"},
{RETROK_F3, "F3"},
{RETROK_F4, "F4"},
{RETROK_F5, "F5"},
{RETROK_F6, "F6"},
{RETROK_F7, "F7"},
{RETROK_F8, "F8"},
{RETROK_F9, "F9"},
{RETROK_F10, "F10"},
{RETROK_F11, "F11"},
{RETROK_F12, "F12"},
{RETROK_F13, "F13"},
{RETROK_F14, "F14"},
{RETROK_F15, "F15"},
{RETROK_NUMLOCK, "Num Lock"},
{RETROK_CAPSLOCK, "Caps Lock"},
{RETROK_SCROLLOCK, "Scroll Lock"},
{RETROK_RSHIFT, "Right Shift"},
{RETROK_LSHIFT, "Left Shift"},
{RETROK_RCTRL, "Right Control"},
{RETROK_LCTRL, "Left Control"},
{RETROK_RALT, "Right Alt"},
{RETROK_LALT, "Left Alt"},
{RETROK_RMETA, "Right Meta"},
{RETROK_LMETA, "Left Meta"},
{RETROK_LSUPER, "Right Super"},
{RETROK_RSUPER, "Left Super"},
{RETROK_MODE, "Mode"},
{RETROK_COMPOSE, "Compose"},
{RETROK_HELP, "Help"},
{RETROK_PRINT, "Print"},
{RETROK_SYSREQ, "Sys Req"},
{RETROK_BREAK, "Break"},
{RETROK_MENU, "Menu"},
{RETROK_POWER, "Power"},
{RETROK_EURO, ""},
{RETROK_UNDO, "Undo"}
};
/* This sets up all the callback functions for a menu entry.
*
* OK : When we press the 'OK' button on an entry.

View File

@ -27,6 +27,15 @@
RETRO_BEGIN_DECLS
typedef struct key_desc
{
/* libretro key id */
unsigned key;
/* description */
char desc[32];
} key_desc_t;
enum
{
ACTION_OK_DL_DEFAULT = 0,
@ -152,6 +161,9 @@ int core_setting_right(unsigned type, const char *label,
int action_right_input_desc(unsigned type, const char *label,
bool wraparound);
int action_right_input_desc_kbd(unsigned type, const char *label,
bool wraparound);
int action_right_cheat(unsigned type, const char *label,
bool wraparound);

View File

@ -62,6 +62,7 @@
#include "../configuration.h"
#include "../file_path_special.h"
#include "../defaults.h"
#include "../verbosity.h"
#include "../managers/cheat_manager.h"
#include "../managers/core_option_manager.h"
#include "../paths.h"
@ -3503,6 +3504,34 @@ static int menu_displaylist_parse_options_remappings(
}
}
}
#ifdef HAVE_KEYMAPPER
if (system)
{
settings_t *settings = config_get_ptr();
unsigned device = settings->uints.input_libretro_device[settings->uints.keymapper_port];
device &= RETRO_DEVICE_MASK;
if (device == RETRO_DEVICE_KEYBOARD)
{
for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++)
{
char desc_label[64];
unsigned user = settings->uints.keymapper_port + 1;
unsigned desc_offset = retro_id;
const char *description = NULL;
desc_label[0] = '\0';
snprintf(desc_label, sizeof(desc_label),
"%s: ", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B + retro_id));
menu_entries_append_enum(info->list, desc_label, "",
MSG_UNKNOWN,
MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + retro_id, 0, 0);
}
}
}
#endif
return 0;
}

View File

@ -206,6 +206,8 @@ enum menu_settings_type
MENU_SETTINGS_CHEAT_END = MENU_SETTINGS_CHEAT_BEGIN + (MAX_CHEAT_COUNTERS - 1),
MENU_SETTINGS_INPUT_DESC_BEGIN,
MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + (MAX_USERS * (RARCH_FIRST_CUSTOM_BIND + 4)),
MENU_SETTINGS_INPUT_DESC_KBD_BEGIN,
MENU_SETTINGS_INPUT_DESC_KBD_END = MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + 135,
MENU_SETTINGS_LAST
};

View File

@ -927,6 +927,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_NEAREST,
MENU_ENUM_LABEL_VALUE_UNKNOWN,
MENU_ENUM_LABEL_VALUE_USER,
MENU_ENUM_LABEL_VALUE_KEYBOARD,
MENU_ENUM_LABEL_VALUE_CHEAT,
MENU_ENUM_LABEL_VALUE_SHADER,
MENU_ENUM_LABEL_VALUE_DIRECTORY_CONTENT,

View File

@ -68,7 +68,7 @@ else
DEFINES += -DHAVE_OPENGLES2
endif
DEFINES += -DRARCH_MOBILE -DHAVE_GRIFFIN -DHAVE_STB_VORBIS -DHAVE_LANGEXTRA -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DGLSL_DEBUG -DHAVE_DYLIB -DHAVE_EGL -DHAVE_GLSL -DHAVE_MENU -DHAVE_RGUI -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DINLINE=inline -DHAVE_THREADS -D__LIBRETRO__ -DHAVE_RSOUND -DHAVE_NETWORKGAMEPAD -DHAVE_NETWORKING -DRARCH_INTERNAL -DHAVE_FILTERS_BUILTIN -DHAVE_MATERIALUI -DHAVE_XMB -DHAVE_SHADERPIPELINE -DHAVE_LIBRETRODB -DHAVE_STB_FONT -DHAVE_IMAGEVIEWER -DHAVE_UPDATE_ASSETS -DHAVE_CC_RESAMPLER -DHAVE_MINIUPNPC -DHAVE_BUILTINMINIUPNPC -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR
DEFINES += -DRARCH_MOBILE -DHAVE_GRIFFIN -DHAVE_STB_VORBIS -DHAVE_LANGEXTRA -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DGLSL_DEBUG -DHAVE_DYLIB -DHAVE_EGL -DHAVE_GLSL -DHAVE_MENU -DHAVE_RGUI -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DINLINE=inline -DHAVE_THREADS -D__LIBRETRO__ -DHAVE_RSOUND -DHAVE_NETWORKGAMEPAD -DHAVE_NETWORKING -DRARCH_INTERNAL -DHAVE_FILTERS_BUILTIN -DHAVE_MATERIALUI -DHAVE_XMB -DHAVE_SHADERPIPELINE -DHAVE_LIBRETRODB -DHAVE_STB_FONT -DHAVE_IMAGEVIEWER -DHAVE_UPDATE_ASSETS -DHAVE_CC_RESAMPLER -DHAVE_MINIUPNPC -DHAVE_BUILTINMINIUPNPC -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -DHAVE_KEYMAPPER -DHAVE_NETWORKGAMEPAD
DEFINES += -DWANT_IFADDRS
ifeq ($(HAVE_VULKAN),1)

View File

@ -28,6 +28,7 @@ HAVE_SSA=auto # SSA/ASS for FFmpeg subtitle support
HAVE_DYLIB=auto # Dynamic loading support
HAVE_NETWORKING=auto # Networking features (recommended)
HAVE_NETWORKGAMEPAD=auto # Networked game pad (plus baked-in core)
HAVE_KEYMAPPER=yes # Networked game pad (plus baked-in core)
C89_NETWORKGAMEPAD=no
HAVE_MINIUPNPC=auto # Mini UPnP client library (for NAT traversal)
HAVE_BUILTINMINIUPNPC=yes # Bake in Mini UPnP client library (for NAT traversal)

View File

@ -1289,6 +1289,7 @@ bool retroarch_main_init(int argc, char *argv[])
drivers_init(DRIVERS_CMD_ALL);
command_event(CMD_EVENT_COMMAND_INIT, NULL);
command_event(CMD_EVENT_REMOTE_INIT, NULL);
command_event(CMD_EVENT_MAPPER_INIT, NULL);
command_event(CMD_EVENT_REWIND_INIT, NULL);
command_event(CMD_EVENT_CONTROLLERS_INIT, NULL);
command_event(CMD_EVENT_RECORD_INIT, NULL);
@ -1455,6 +1456,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
command_event(CMD_EVENT_COMMAND_DEINIT, NULL);
command_event(CMD_EVENT_REMOTE_DEINIT, NULL);
command_event(CMD_EVENT_MAPPER_DEINIT, NULL);
command_event(CMD_EVENT_AUTOSAVE_DEINIT, NULL);