(Android) Rename handle_hotplug_get_device_name into android_input_get_id_name
This commit is contained in:
parent
5deb9a31e6
commit
f65950521e
|
@ -293,7 +293,20 @@ static inline void android_input_poll_event_type_key(android_input_t *android, s
|
||||||
*handled = 0;
|
*handled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_hotplug_get_device_name(char *buf, size_t size, int id)
|
static int android_input_get_id_port(android_input_t *android, int id, int source)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD))
|
||||||
|
return 0; // touch overlay is always player 1
|
||||||
|
|
||||||
|
for (i = 0; i < android->pads_connected; i++)
|
||||||
|
if (android->state_device_ids[i] == id)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool android_input_get_id_name(char *buf, size_t size, int id)
|
||||||
{
|
{
|
||||||
jclass class;
|
jclass class;
|
||||||
jmethodID method, getName;
|
jmethodID method, getName;
|
||||||
|
@ -301,47 +314,50 @@ static void handle_hotplug_get_device_name(char *buf, size_t size, int id)
|
||||||
JNIEnv *env = (JNIEnv*)jni_thread_getenv();
|
JNIEnv *env = (JNIEnv*)jni_thread_getenv();
|
||||||
|
|
||||||
if (!env)
|
if (!env)
|
||||||
return;
|
goto error;
|
||||||
|
|
||||||
buf[0] = '\0';
|
|
||||||
|
|
||||||
class = NULL;
|
class = NULL;
|
||||||
FIND_CLASS(env, class, "android/view/InputDevice");
|
FIND_CLASS(env, class, "android/view/InputDevice");
|
||||||
if (!class)
|
if (!class)
|
||||||
return;
|
goto error;
|
||||||
|
|
||||||
method = NULL;
|
method = NULL;
|
||||||
GET_STATIC_METHOD_ID(env, method, class, "getDevice", "(I)Landroid/view/InputDevice;");
|
GET_STATIC_METHOD_ID(env, method, class, "getDevice", "(I)Landroid/view/InputDevice;");
|
||||||
if (!method)
|
if (!method)
|
||||||
return;
|
goto error;
|
||||||
|
|
||||||
device = NULL;
|
device = NULL;
|
||||||
CALL_OBJ_STATIC_METHOD_PARAM(env, device, class, method, (jint)id);
|
CALL_OBJ_STATIC_METHOD_PARAM(env, device, class, method, (jint)id);
|
||||||
if (!device)
|
if (!device)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to find device for ID: %d\n", id);
|
RARCH_ERR("Failed to find device for ID: %d\n", id);
|
||||||
return;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
getName = NULL;
|
getName = NULL;
|
||||||
GET_METHOD_ID(env, getName, class, "getName", "()Ljava/lang/String;");
|
GET_METHOD_ID(env, getName, class, "getName", "()Ljava/lang/String;");
|
||||||
if (!getName)
|
if (!getName)
|
||||||
return;
|
goto error;
|
||||||
|
|
||||||
name = NULL;
|
name = NULL;
|
||||||
CALL_OBJ_METHOD(env, name, device, getName);
|
CALL_OBJ_METHOD(env, name, device, getName);
|
||||||
if (!name)
|
if (!name)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to find name for device ID: %d\n", id);
|
RARCH_ERR("Failed to find name for device ID: %d\n", id);
|
||||||
return;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
const char *str = (*env)->GetStringUTFChars(env, name, 0);
|
const char *str = (*env)->GetStringUTFChars(env, name, 0);
|
||||||
if (str)
|
if (str)
|
||||||
strlcpy(buf, str, size);
|
strlcpy(buf, str, size);
|
||||||
(*env)->ReleaseStringUTFChars(env, name, str);
|
(*env)->ReleaseStringUTFChars(env, name, str);
|
||||||
|
|
||||||
RARCH_LOG("device name: %s\n", buf);
|
RARCH_LOG("device name: %s\n", buf);
|
||||||
|
return true;
|
||||||
|
error:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_hotplug(struct android_app *android_app, unsigned *port, unsigned id,
|
static void handle_hotplug(struct android_app *android_app, unsigned *port, unsigned id,
|
||||||
|
@ -360,7 +376,7 @@ static void handle_hotplug(struct android_app *android_app, unsigned *port, unsi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_hotplug_get_device_name(device_name, sizeof(device_name), id);
|
android_input_get_id_name(device_name, sizeof(device_name), id);
|
||||||
|
|
||||||
//FIXME: Ugly hack, see other FIXME note below.
|
//FIXME: Ugly hack, see other FIXME note below.
|
||||||
if (strstr(device_name, "keypad-game-zeus") || strstr(device_name, "keypad-zeus"))
|
if (strstr(device_name, "keypad-game-zeus") || strstr(device_name, "keypad-zeus"))
|
||||||
|
@ -554,18 +570,6 @@ static void handle_hotplug(struct android_app *android_app, unsigned *port, unsi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int android_input_get_id_port(android_input_t *android, int id, int source)
|
|
||||||
{
|
|
||||||
unsigned i;
|
|
||||||
if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD))
|
|
||||||
return 0; // touch overlay is always player 1
|
|
||||||
|
|
||||||
for (i = 0; i < android->pads_connected; i++)
|
|
||||||
if (android->state_device_ids[i] == id)
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle all events. If our activity is in pause state, block until we're unpaused.
|
// Handle all events. If our activity is in pause state, block until we're unpaused.
|
||||||
static void android_input_poll(void *data)
|
static void android_input_poll(void *data)
|
||||||
|
|
Loading…
Reference in New Issue