forked from enlightenment/efl
ecore_input: add API to get name of joystick.
Summary: The Ecore_Event_Joystick would be not enough information on user side. Because the button index such as ECORE_EVENT_JOYSTICK_BUTTON_SELECT/START/META, etc could be mapped to different button for different named joystick. Test Plan: Using example Reviewers: raster, cedric, jpeg Reviewed By: raster Differential Revision: https://phab.enlightenment.org/D4669
This commit is contained in:
parent
b04f584346
commit
4f6873905b
|
@ -32,6 +32,10 @@ _joystick_event_handler_cb(void *data, int type EINA_UNUSED, void *event)
|
|||
break;
|
||||
}
|
||||
|
||||
const char *joystick_name;
|
||||
joystick_name = ecore_input_joystick_name_get(ev->index);
|
||||
printf("joystick name is: %s (index: %d)\n", joystick_name, ev->index);
|
||||
|
||||
if (ev->type == ECORE_EVENT_JOYSTICK_EVENT_TYPE_BUTTON &&
|
||||
ev->button.index == ECORE_EVENT_JOYSTICK_BUTTON_START)
|
||||
ecore_main_loop_quit();
|
||||
|
|
|
@ -478,6 +478,17 @@ extern "C" {
|
|||
*/
|
||||
EAPI int ecore_input_joystick_event_axis_deadzone_get(void);
|
||||
|
||||
/**
|
||||
* Get name of joystick
|
||||
*
|
||||
* This function returns the name string of the joysitck. If @p index
|
||||
* does not exist, or on error, this function returns NULL.
|
||||
*
|
||||
* @param index The index of joystick.
|
||||
* @return name of joystick.
|
||||
* @since 1.20
|
||||
*/
|
||||
EAPI Eina_Slstr *ecore_input_joystick_name_get(int index);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -621,3 +621,28 @@ ecore_input_joystick_event_axis_deadzone_get(void)
|
|||
{
|
||||
return _event_axis_deadzone;
|
||||
}
|
||||
|
||||
EAPI Eina_Slstr *
|
||||
ecore_input_joystick_name_get(int index)
|
||||
{
|
||||
#ifdef JSIOCGNAME
|
||||
int fd;
|
||||
char name[128];
|
||||
Eina_List *l;
|
||||
Joystick_Info *ji;
|
||||
|
||||
EINA_LIST_FOREACH(joystick_list, l, ji)
|
||||
{
|
||||
if (index == ji->index)
|
||||
{
|
||||
fd = ecore_main_fd_handler_fd_get(ji->fd_handler);
|
||||
if (fd < 0) return NULL;
|
||||
|
||||
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
|
||||
strncpy(name, "Unknown", sizeof(name));
|
||||
return eina_slstr_copy_new(name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue