raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=4f6873905be8f28971d5cf89bf395f6a4e6e7518

commit 4f6873905be8f28971d5cf89bf395f6a4e6e7518
Author: Shinwoo Kim <cinoo....@samsung.com>
Date:   Thu Apr 13 14:53:47 2017 +0900

    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
---
 src/examples/ecore/ecore_input_joystick_example.c |  4 ++++
 src/lib/ecore_input/Ecore_Input.h                 | 11 ++++++++++
 src/lib/ecore_input/ecore_input_joystick.c        | 25 +++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/src/examples/ecore/ecore_input_joystick_example.c 
b/src/examples/ecore/ecore_input_joystick_example.c
index c2c962b..a39f065 100644
--- a/src/examples/ecore/ecore_input_joystick_example.c
+++ b/src/examples/ecore/ecore_input_joystick_example.c
@@ -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();
diff --git a/src/lib/ecore_input/Ecore_Input.h 
b/src/lib/ecore_input/Ecore_Input.h
index 4949ff7..c701301 100644
--- a/src/lib/ecore_input/Ecore_Input.h
+++ b/src/lib/ecore_input/Ecore_Input.h
@@ -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
diff --git a/src/lib/ecore_input/ecore_input_joystick.c 
b/src/lib/ecore_input/ecore_input_joystick.c
index 4f2fd11..7051597 100644
--- a/src/lib/ecore_input/ecore_input_joystick.c
+++ b/src/lib/ecore_input/ecore_input_joystick.c
@@ -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;
+}

-- 


Reply via email to