ecore_drm: add built-in devices by libinput_path 98/66398/3
authorDuna Oh <duna.oh@samsung.com>
Mon, 18 Apr 2016 14:16:33 +0000 (23:16 +0900)
committerDuna Oh <duna.oh@samsung.com>
Tue, 19 Apr 2016 01:41:45 +0000 (10:41 +0900)
getenv("PATH_DEVICES_NUM")
getenv("PATH_DEVICE_1")

Signed-off-by: Duna Oh <duna.oh@samsung.com>
Change-Id: If85fef4d49b6f9a33b4fdee59a442015c8bfe9d8

src/lib/ecore_drm/Ecore_Drm.h
src/lib/ecore_drm/ecore_drm_inputs.c
src/modules/ecore_evas/engines/drm/ecore_evas_drm.c

index e3b8f38..a75db8e 100644 (file)
@@ -644,6 +644,7 @@ EAPI unsigned int ecore_drm_output_crtc_buffer_get(Ecore_Drm_Output *output);
 EAPI unsigned int ecore_drm_output_connector_id_get(Ecore_Drm_Output *output);
 
 /* TODO: Doxy */
+EAPI Eina_Bool ecore_drm_inputs_devices_create(Ecore_Drm_Device *dev);
 EAPI Eina_Bool ecore_drm_inputs_create(Ecore_Drm_Device *dev);
 EAPI void ecore_drm_inputs_destroy(Ecore_Drm_Device *dev);
 EAPI Eina_Bool ecore_drm_inputs_enable(Ecore_Drm_Input *input);
index 54f781f..e42ac74 100644 (file)
@@ -513,6 +513,96 @@ err:
    return EINA_FALSE;
 }
 
+EAPI Eina_Bool
+ecore_drm_inputs_devices_create(Ecore_Drm_Device *dev)
+{
+   Ecore_Drm_Input *input;
+   struct libinput_device *device;
+   int devices_num;
+   char *env;
+   Eina_Stringshare *path;
+
+   /* check for valid device */
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
+
+   TRACE_INPUT_BEGIN(ecore_drm_inputs_devices_create);
+   TRACE_EFL_BEGIN(DRM INPUTS DEVICES CREATE);
+
+   if ((env = getenv("PATH_DEVICES_NUM")))
+     devices_num = atoi(env);
+   if (!env || devices_num == 0)
+     {
+        TRACE_INPUT_END();
+        TRACE_EFL_END();
+        return EINA_TRUE;
+     }
+
+   INF("PATH_DEVICES_NUM : %d", devices_num);
+
+   /* try to allocate space for new input structure */
+   if (!(input = calloc(1, sizeof(Ecore_Drm_Input))))
+     {
+        TRACE_INPUT_END();
+        TRACE_EFL_END();
+        return EINA_FALSE;
+     }
+
+   /* set reference for parent device */
+   input->dev = dev;
+
+   /* try to create libinput context */
+   input->libinput =
+     libinput_path_create_context(&_input_interface, input);
+   if (!input->libinput)
+     {
+        ERR("Could not create libinput path context: %m");
+        goto err;
+     }
+
+   /* set libinput log priority */
+   libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
+
+   for (int i = 0; i < devices_num; i++)
+     {
+        char buf[1024] = "PATH_DEVICE_";
+        eina_convert_itoa(i + 1, buf + 12);
+        env = getenv(buf);
+        if (env)
+          {
+             path = eina_stringshare_add(env);
+             device = libinput_path_add_device(input->libinput, path);
+             if (!device)
+               ERR("Failed to initialized device %s", path);
+             else
+               INF("libinput_path created input device %s", path);
+          }
+     }
+
+   /* process pending events */
+   _input_events_process(input);
+
+   /* enable this input */
+   if (!ecore_drm_inputs_enable(input))
+     {
+        ERR("Failed to enable input");
+        goto err;
+     }
+
+   /* append this input */
+   dev->inputs = eina_list_append(dev->inputs, input);
+
+   TRACE_EFL_END();
+   TRACE_INPUT_END();
+   return EINA_TRUE;
+
+err:
+   if (input->libinput) libinput_unref(input->libinput);
+   free(input);
+   TRACE_EFL_END();
+   TRACE_INPUT_END();
+   return EINA_FALSE;
+}
+
 EAPI void 
 ecore_drm_inputs_destroy(Ecore_Drm_Device *dev)
 {
index 508ddf3..c8b8c85 100644 (file)
@@ -567,6 +567,13 @@ _ecore_evas_drm_init(const char *device)
      }
 
    /* try to create inputs */
+   if (!ecore_drm_inputs_devices_create(dev))
+     {
+        ERR("Could not create inputs from path: %m");
+        goto input_err;
+     }
+
+   /* try to create inputs */
    if (!ecore_drm_inputs_create(dev))
      {
         ERR("Could not create inputs: %m");