#include "e_comp_wl_input_intern.h"
#include "e_main_intern.h"
#include "e_comp_input_intern.h"
-#include <libudev.h>
+#include "e_utils_intern.h"
+#include <libudev.h>
#include <glib.h>
#include <fcntl.h>
-
#ifdef HAVE_SYSTEMD
# include <systemd/sd-daemon.h>
#endif
+#define E_INPUT_ENV_LIBINPUT_LOG_DISABLE "E_INPUT_LIBINPUT_LOG_DISABLE"
+#define E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG "E_INPUT_LIBINPUT_LOG_EINA_LOG"
+
typedef struct {
E_Input_Thread_Safe_Call_Cb safe_call_cb;
unsigned int data_length;
return;
}
}
+
+
+static int
+_device_open_no_pending(const char *device, int flags)
+{
+ int fd = -1;
+ struct stat s;
+
+ fd = open(device, flags | O_CLOEXEC);
+
+ if (fd < 0) return fd;
+ if (fstat(fd, &s) == -1)
+ {
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+/* local functions */
+static int
+_e_input_device_cb_open_restricted(const char *path, int flags, void *data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+ int fd = -1;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(input, -1);
+
+ /* try to open the device */
+ fd = _device_open_no_pending(path, flags);
+
+ if (fd < 0)
+ {
+ ERR("Could not open device");
+ return -1;
+ }
+
+ return fd;
+}
+
+static void
+_e_input_device_cb_close_restricted(int fd, void *data)
+{
+ if (fd >= 0) close(fd);
+}
+
+const struct libinput_interface _input_interface =
+{
+ _e_input_device_cb_open_restricted,
+ _e_input_device_cb_close_restricted,
+};
+
+static void
+_e_input_backend_input_thread_name_set(void)
+{
+ eina_thread_name_set(eina_thread_self(), "input-device-thread");
+}
+
+static void
+_e_input_backend_libinput_log_handler(struct libinput *libinput EINA_UNUSED,
+ enum libinput_log_priority priority,
+ const char *format, va_list args)
+{
+ char buf[1024] = {0,};
+
+ vsnprintf(buf, 1024, format, args);
+ switch (priority)
+ {
+ case LIBINPUT_LOG_PRIORITY_DEBUG:
+ EIDBG("%s", buf);
+ break;
+ case LIBINPUT_LOG_PRIORITY_INFO:
+ EIINF("%s", buf);
+ break;
+ case LIBINPUT_LOG_PRIORITY_ERROR:
+ EIERR("%s", buf);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+_einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
+
+ /* try to create libinput context */
+ struct udev *udev = udev_new();
+
+ input->libinput =
+ libinput_udev_create_context(&_input_interface, input, udev);
+ udev_unref(udev);
+
+ if (!input->libinput)
+ {
+ free(input);
+
+ ERR("Could not create libinput context: %m");
+ return;
+ }
+
+ _e_input_backend_input_thread_name_set();
+
+ if (input->log_disable)
+ libinput_log_set_handler(input->libinput, NULL);
+ else
+ {
+ if (input->log_use_eina)
+ libinput_log_set_handler(input->libinput, _e_input_backend_libinput_log_handler);
+ libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
+ }
+
+ TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
+ /* assign udev seat */
+ if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
+ {
+ ERR("Failed to assign seat: %m");
+ TRACE_INPUT_END();
+ return;
+ }
+ TRACE_INPUT_END();
+
+ return;
+}
+
+static void
+_einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
+{
+ //TODO : do if there is something to do in main thread
+}
+
+static void
+_einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+ E_Input_Device *dev = NULL;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev);
+
+ input->thread = NULL;
+
+ /* enable this input */
+ if (!e_input_backend_enable_input(input))
+ {
+ ERR("Failed to enable input");
+ return;
+ }
+
+ /* append this input */
+ dev = input->dev;
+ dev->inputs = eina_list_append(dev->inputs, input);
+
+ /* process pending events */
+ e_input_backend_events_process(input);
+}
+
+static void
+_einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+
+ input->thread = NULL;
+}
+
+static Eina_Bool
+_e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
+
+ input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
+ (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
+ (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
+ (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
+ return !!(input->thread);
+}
+
+EINTERN E_Input_Backend *
+e_input_backend_create_libinput_udev()
+{
+ E_Input_Backend *input;
+ char *env = NULL;
+ int buf_size = 0;
+ int res = 0;
+
+ /* try to allocate space for new input structure */
+ if (!(input = calloc(1, sizeof(E_Input_Backend))))
+ {
+ return NULL;
+ }
+
+ input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
+ input->log_disable = EINA_FALSE;
+ input->log_use_eina = EINA_FALSE;
+
+ env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
+ if ((env) && (atoi(env) == 1))
+ input->log_disable = EINA_TRUE;
+ else
+ {
+ if (env) E_FREE(env);
+
+ env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
+ if ((env) && (atoi(env) == 1))
+ input->log_use_eina = EINA_TRUE;
+ }
+ E_FREE(env);
+
+ env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
+
+ if (env)
+ {
+ libinput_udev_set_udev_monitor_event_source(env);
+ }
+ E_FREE(env);
+
+ env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
+
+ if ((env) && (buf_size = atoi(env)))
+ {
+ res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
+ if (res)
+ ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
+ }
+ E_FREE(env);
+
+ if (e_input_thread_mode_get())
+ {
+ e_input_backend_thread_input_backend_set(input);
+ return input;
+ }
+
+ if (e_input_thread_enabled_get())
+ {
+ /* initialize libinput udev backend within an ecore thread */
+ if (!_e_input_device_input_thread_init_udev_backend(input))
+ {
+ ERR("Failed to initialize e_input backend (libinput udev backend) !");
+ goto err;
+ }
+
+ return input;
+ }
+
+ if (!e_input_backend_libinput_context_create(input))
+ goto err;
+
+ /* enable this input */
+ if (!e_input_backend_enable_input(input))
+ {
+ ERR("Failed to enable input");
+ goto err;
+ }
+
+ /* process pending events */
+ e_input_backend_events_process(input);
+
+ return input;
+
+err:
+ if (input->libinput) libinput_unref(input->libinput);
+ free(input);
+
+ return NULL;
+}
+
+static void
+_einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
+{
+ char *env = NULL;
+ struct libinput_device *device;
+ E_Input_Backend *input = (E_Input_Backend *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
+
+ /* try to create libinput context */
+ input->libinput =
+ libinput_path_create_context(&_input_interface, input);
+ if (!input->libinput)
+ {
+ free(input);
+
+ ERR("Could not create libinput path context: %m");
+ return;
+ }
+
+ _e_input_backend_input_thread_name_set();
+
+ if (input->log_disable)
+ libinput_log_set_handler(input->libinput, NULL);
+ else
+ {
+ if (input->log_use_eina)
+ libinput_log_set_handler(input->libinput, _e_input_backend_libinput_log_handler);
+ libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
+ }
+
+ TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
+ for (int i = 0; i < input->path_ndevices; i++)
+ {
+ char buf[1024] = "PATH_DEVICE_";
+ eina_convert_itoa(i + 1, buf + 12);
+ env = e_util_env_get(buf);
+
+ if (env)
+ {
+ device = libinput_path_add_device(input->libinput, env);
+ if (!device)
+ ERR("Failed to initialized device %s", env);
+ else
+ INF("libinput_path created input device %s", env);
+ E_FREE(env);
+ }
+ }
+ TRACE_INPUT_END();
+
+ return;
+}
+
+static void
+_einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
+{
+ //TODO : do if there is something to do in main thread
+}
+
+static void
+_einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+ E_Input_Device *dev = NULL;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+ EINA_SAFETY_ON_NULL_RETURN(input->dev);
+
+ input->thread = NULL;
+
+ /* enable this input */
+ if (!e_input_backend_enable_input(input))
+ {
+ ERR("Failed to enable input");
+ return;
+ }
+
+ /* append this input */
+ dev = input->dev;
+ dev->inputs = eina_list_append(dev->inputs, input);
+
+ /* process pending events */
+ e_input_backend_events_process(input);
+}
+
+static void
+_einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
+{
+ E_Input_Backend *input = (E_Input_Backend *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN(input);
+
+ input->thread = NULL;
+}
+
+static Eina_Bool
+_e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
+
+ input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
+ (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
+ (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
+ (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
+ return !!(input->thread);
+}
+
+EINTERN E_Input_Backend *
+e_input_backend_create_libinput_path(int ndevices)
+{
+ E_Input_Backend *input;
+ struct libinput_device *device;
+ char *env;
+
+ /* try to allocate space for new input structure */
+ if (!(input = calloc(1, sizeof(E_Input_Backend))))
+ {
+ return NULL;
+ }
+
+ input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
+ input->path_ndevices = ndevices;
+ input->log_disable = EINA_FALSE;
+ input->log_use_eina = EINA_FALSE;
+
+ env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
+ if ((env) && (atoi(env) == 1))
+ input->log_disable = EINA_TRUE;
+ else
+ {
+ if (env) E_FREE(env);
+
+ env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
+ if ((env) && (atoi(env) == 1))
+ input->log_use_eina = EINA_TRUE;
+ }
+ E_FREE(env);
+
+ if (e_input_thread_enabled_get())
+ {
+ /* initialize libinput path backend within an ecore thread */
+ if (!_e_input_device_input_thread_init_path_backend(input))
+ {
+ ERR("Failed to initialize e_input backend (libinput path backend) !");
+ goto err;
+ }
+
+ return input;
+ }
+
+ /* 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;
+ }
+
+ if (input->log_disable)
+ libinput_log_set_handler(input->libinput, NULL);
+ else
+ {
+ if (input->log_use_eina)
+ libinput_log_set_handler(input->libinput, _e_input_backend_libinput_log_handler);
+ libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
+ }
+
+ TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
+ for (int i = 0; i < ndevices; i++)
+ {
+ char buf[1024] = "PATH_DEVICE_";
+ eina_convert_itoa(i + 1, buf + 12);
+ env = e_util_env_get(buf);
+ if (env)
+ {
+ device = libinput_path_add_device(input->libinput, env);
+ if (!device)
+ ERR("Failed to initialized device %s", env);
+ else
+ INF("libinput_path created input device %s", env);
+ E_FREE(env);
+ }
+ }
+ TRACE_INPUT_END();
+
+ /* enable this input */
+ if (!e_input_backend_enable_input(input))
+ {
+ ERR("Failed to enable input");
+ goto err;
+ }
+
+ /* process pending events */
+ e_input_backend_events_process(input);
+
+ return input;
+
+err:
+ if (input->libinput) libinput_unref(input->libinput);
+ free(input);
+
+ return NULL;
+}
+
+EINTERN Eina_Bool
+e_input_backend_libinput_context_create(E_Input_Backend *input)
+{
+ /* try to create libinput context */
+ struct udev *udev = udev_new();
+
+ input->libinput =
+ libinput_udev_create_context(&_input_interface, input, udev);
+ udev_unref(udev);
+
+ if (!input->libinput)
+ {
+ ERR("Could not create libinput context: %m");
+ return EINA_FALSE;
+ }
+
+ if (!input->dev)
+ return EINA_FALSE;
+
+ if (input->log_disable)
+ libinput_log_set_handler(input->libinput, NULL);
+ else
+ {
+ if (input->log_use_eina)
+ libinput_log_set_handler(input->libinput, _e_input_backend_libinput_log_handler);
+
+ libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
+ }
+
+ /* assign udev seat */
+ TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
+ if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
+ {
+ ERR("Failed to assign seat: %m");
+ TRACE_INPUT_END();
+ return EINA_FALSE;
+ }
+ TRACE_INPUT_END();
+
+ return EINA_TRUE;
+}
EINTERN void e_input_backend_events_process(E_Input_Backend *input);
EINTERN void e_input_backend_key_event_list_add(Ecore_Event_Key *key);
+EINTERN E_Input_Backend *e_input_backend_create_libinput_udev(void);
+EINTERN E_Input_Backend *e_input_backend_create_libinput_path(int ndevices);
+EINTERN Eina_Bool e_input_backend_libinput_context_create(E_Input_Backend *input);
+
#endif
#include <sys/stat.h>
#include <fcntl.h>
-#define E_INPUT_ENV_LIBINPUT_LOG_DISABLE "E_INPUT_LIBINPUT_LOG_DISABLE"
-#define E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG "E_INPUT_LIBINPUT_LOG_EINA_LOG"
-
/* e_input_device private variable */
static Eina_List *einput_devices;
static E_Input_Device *e_input_device_default = NULL;
struct xkb_keymap *cached_keymap;
struct xkb_context *cached_context;
-static int
-_device_open_no_pending(const char *device, int flags)
-{
- int fd = -1;
- struct stat s;
-
- fd = open(device, flags | O_CLOEXEC);
-
- if (fd < 0) return fd;
- if (fstat(fd, &s) == -1)
- {
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-/* local functions */
-static int
-_e_input_device_cb_open_restricted(const char *path, int flags, void *data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
- int fd = -1;
-
- EINA_SAFETY_ON_NULL_RETURN_VAL(input, -1);
-
- /* try to open the device */
- fd = _device_open_no_pending(path, flags);
-
- if (fd < 0)
- {
- ERR("Could not open device");
- return -1;
- }
-
- return fd;
-}
-
-static void
-_e_input_device_cb_close_restricted(int fd, void *data)
-{
- if (fd >= 0) close(fd);
-}
-
-const struct libinput_interface _input_interface =
-{
- _e_input_device_cb_open_restricted,
- _e_input_device_cb_close_restricted,
-};
-
static E_Input_Device *
_e_input_device_default_get(void)
{
return res;
}
-static void
-_libinput_log_handler(struct libinput *libinput EINA_UNUSED,
- enum libinput_log_priority priority,
- const char *format, va_list args)
-{
- char buf[1024] = {0,};
-
- vsnprintf(buf, 1024, format, args);
- switch (priority)
- {
- case LIBINPUT_LOG_PRIORITY_DEBUG:
- EIDBG("%s", buf);
- break;
- case LIBINPUT_LOG_PRIORITY_INFO:
- EIINF("%s", buf);
- break;
- case LIBINPUT_LOG_PRIORITY_ERROR:
- EIERR("%s", buf);
- break;
- default:
- break;
- }
-}
-
EINTERN Eina_Bool
e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend)
{
return EINA_TRUE;
}
-static void
-_e_input_device_input_thread_name_set(void)
-{
- eina_thread_name_set(eina_thread_self(), "input-device-thread");
-}
-
-static void
-_einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
- EINA_SAFETY_ON_NULL_RETURN(input->dev);
- EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
-
- /* try to create libinput context */
- struct udev *udev = udev_new();
-
- input->libinput =
- libinput_udev_create_context(&_input_interface, input, udev);
- udev_unref(udev);
-
- if (!input->libinput)
- {
- free(input);
-
- ERR("Could not create libinput context: %m");
- return;
- }
-
- _e_input_device_input_thread_name_set();
-
- if (input->log_disable)
- libinput_log_set_handler(input->libinput, NULL);
- else
- {
- if (input->log_use_eina)
- libinput_log_set_handler(input->libinput, _libinput_log_handler);
- libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
- }
-
- TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
- /* assign udev seat */
- if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
- {
- ERR("Failed to assign seat: %m");
- TRACE_INPUT_END();
- return;
- }
- TRACE_INPUT_END();
-
- return;
-}
-
-static void
-_einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
-{
- //TODO : do if there is something to do in main thread
-}
-
-static void
-_einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
- E_Input_Device *dev = NULL;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
- EINA_SAFETY_ON_NULL_RETURN(input->dev);
-
- input->thread = NULL;
-
- /* enable this input */
- if (!e_input_backend_enable_input(input))
- {
- ERR("Failed to enable input");
- return;
- }
-
- /* append this input */
- dev = input->dev;
- dev->inputs = eina_list_append(dev->inputs, input);
-
- /* process pending events */
- e_input_backend_events_process(input);
-}
-
-static void
-_einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
-
- input->thread = NULL;
-}
-
-static Eina_Bool
-_e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
-{
- EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
-
- input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
- (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
- (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
- (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
- return !!(input->thread);
-}
-
-/* public functions */
-EINTERN E_Input_Backend *
-e_input_backend_create_libinput_udev()
-{
- E_Input_Backend *input;
- char *env = NULL;
- int buf_size = 0;
- int res = 0;
-
- /* try to allocate space for new input structure */
- if (!(input = calloc(1, sizeof(E_Input_Backend))))
- {
- return NULL;
- }
-
- input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
- input->log_disable = EINA_FALSE;
- input->log_use_eina = EINA_FALSE;
-
- env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
- if ((env) && (atoi(env) == 1))
- input->log_disable = EINA_TRUE;
- else
- {
- if (env) E_FREE(env);
-
- env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
- if ((env) && (atoi(env) == 1))
- input->log_use_eina = EINA_TRUE;
- }
- E_FREE(env);
-
- env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
-
- if (env)
- {
- libinput_udev_set_udev_monitor_event_source(env);
- }
- E_FREE(env);
-
- env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
-
- if ((env) && (buf_size = atoi(env)))
- {
- res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
- if (res)
- ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
- }
- E_FREE(env);
-
- if (e_input_thread_mode_get())
- {
- e_input_backend_thread_input_backend_set(input);
- return input;
- }
-
- if (e_input_thread_enabled_get())
- {
- /* initialize libinput udev backend within an ecore thread */
- if (!_e_input_device_input_thread_init_udev_backend(input))
- {
- ERR("Failed to initialize e_input backend (libinput udev backend) !");
- goto err;
- }
-
- return input;
- }
-
- if (!e_input_backend_libinput_context_create(input))
- goto err;
-
- /* enable this input */
- if (!e_input_backend_enable_input(input))
- {
- ERR("Failed to enable input");
- goto err;
- }
-
- /* process pending events */
- e_input_backend_events_process(input);
-
- return input;
-
-err:
- if (input->libinput) libinput_unref(input->libinput);
- free(input);
-
- return NULL;
-}
-
-EINTERN Eina_Bool
-e_input_backend_libinput_context_create(E_Input_Backend *input)
-{
- /* try to create libinput context */
- struct udev *udev = udev_new();
-
- input->libinput =
- libinput_udev_create_context(&_input_interface, input, udev);
- udev_unref(udev);
-
- if (!input->libinput)
- {
- ERR("Could not create libinput context: %m");
- return EINA_FALSE;
- }
-
- if (!input->dev)
- return EINA_FALSE;
-
- if (input->log_disable)
- libinput_log_set_handler(input->libinput, NULL);
- else
- {
- if (input->log_use_eina)
- libinput_log_set_handler(input->libinput, _libinput_log_handler);
-
- libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
- }
-
- /* assign udev seat */
- TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
- if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
- {
- ERR("Failed to assign seat: %m");
- TRACE_INPUT_END();
- return EINA_FALSE;
- }
- TRACE_INPUT_END();
-
- return EINA_TRUE;
-}
-
-static void
-_einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
-{
- char *env = NULL;
- struct libinput_device *device;
- E_Input_Backend *input = (E_Input_Backend *)data;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
- EINA_SAFETY_ON_NULL_RETURN(input->dev);
- EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
-
- /* try to create libinput context */
- input->libinput =
- libinput_path_create_context(&_input_interface, input);
- if (!input->libinput)
- {
- free(input);
-
- ERR("Could not create libinput path context: %m");
- return;
- }
-
- _e_input_device_input_thread_name_set();
-
- if (input->log_disable)
- libinput_log_set_handler(input->libinput, NULL);
- else
- {
- if (input->log_use_eina)
- libinput_log_set_handler(input->libinput, _libinput_log_handler);
- libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
- }
-
- TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
- for (int i = 0; i < input->path_ndevices; i++)
- {
- char buf[1024] = "PATH_DEVICE_";
- eina_convert_itoa(i + 1, buf + 12);
- env = e_util_env_get(buf);
-
- if (env)
- {
- device = libinput_path_add_device(input->libinput, env);
- if (!device)
- ERR("Failed to initialized device %s", env);
- else
- INF("libinput_path created input device %s", env);
- E_FREE(env);
- }
- }
- TRACE_INPUT_END();
-
- return;
-}
-
-static void
-_einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
-{
- //TODO : do if there is something to do in main thread
-}
-
-static void
-_einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
- E_Input_Device *dev = NULL;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
- EINA_SAFETY_ON_NULL_RETURN(input->dev);
-
- input->thread = NULL;
-
- /* enable this input */
- if (!e_input_backend_enable_input(input))
- {
- ERR("Failed to enable input");
- return;
- }
-
- /* append this input */
- dev = input->dev;
- dev->inputs = eina_list_append(dev->inputs, input);
-
- /* process pending events */
- e_input_backend_events_process(input);
-}
-
-static void
-_einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
-{
- E_Input_Backend *input = (E_Input_Backend *)data;
-
- EINA_SAFETY_ON_NULL_RETURN(input);
-
- input->thread = NULL;
-}
-
-static Eina_Bool
-_e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
-{
- EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
-
- input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
- (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
- (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
- (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
- return !!(input->thread);
-}
-
-EINTERN E_Input_Backend *
-e_input_backend_create_libinput_path(int ndevices)
-{
- E_Input_Backend *input;
- struct libinput_device *device;
- char *env;
-
- /* try to allocate space for new input structure */
- if (!(input = calloc(1, sizeof(E_Input_Backend))))
- {
- return NULL;
- }
-
- input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
- input->path_ndevices = ndevices;
- input->log_disable = EINA_FALSE;
- input->log_use_eina = EINA_FALSE;
-
- env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
- if ((env) && (atoi(env) == 1))
- input->log_disable = EINA_TRUE;
- else
- {
- if (env) E_FREE(env);
-
- env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
- if ((env) && (atoi(env) == 1))
- input->log_use_eina = EINA_TRUE;
- }
- E_FREE(env);
-
- if (e_input_thread_enabled_get())
- {
- /* initialize libinput path backend within an ecore thread */
- if (!_e_input_device_input_thread_init_path_backend(input))
- {
- ERR("Failed to initialize e_input backend (libinput path backend) !");
- goto err;
- }
-
- return input;
- }
-
- /* 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;
- }
-
- if (input->log_disable)
- libinput_log_set_handler(input->libinput, NULL);
- else
- {
- if (input->log_use_eina)
- libinput_log_set_handler(input->libinput, _libinput_log_handler);
- libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
- }
-
- TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
- for (int i = 0; i < ndevices; i++)
- {
- char buf[1024] = "PATH_DEVICE_";
- eina_convert_itoa(i + 1, buf + 12);
- env = e_util_env_get(buf);
- if (env)
- {
- device = libinput_path_add_device(input->libinput, env);
- if (!device)
- ERR("Failed to initialized device %s", env);
- else
- INF("libinput_path created input device %s", env);
- E_FREE(env);
- }
- }
- TRACE_INPUT_END();
-
- /* enable this input */
- if (!e_input_backend_enable_input(input))
- {
- ERR("Failed to enable input");
- goto err;
- }
-
- /* process pending events */
- e_input_backend_events_process(input);
-
- return input;
-
-err:
- if (input->libinput) libinput_unref(input->libinput);
- free(input);
-
- return NULL;
-}
-
void
e_input_device_output_changed(E_Input_Device *dev)
{
#include "e_intern.h"
#include "e_input_intern.h"
-#include "e_input_backend_intern.h"
struct _E_Input_Device
{
EINTERN Eina_Bool e_input_device_keyboard_remap_set(E_Input_Device *dev, int *from_keys, int *to_keys, int num);
EINTERN Eina_Bool e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend);
-EINTERN E_Input_Backend *e_input_backend_create_libinput_udev(void);
-EINTERN E_Input_Backend *e_input_backend_create_libinput_path(int ndevices);
EINTERN Eina_Bool e_input_device_libinput_log_level_set(E_Input_Device *dev, unsigned int level);
EINTERN void e_input_device_pointer_xy_get(E_Input_Device *dev, int *x, int *y);
EINTERN const char *e_input_evdev_seatname_get(E_Input_Evdev *evdev);
EINTERN Eina_Bool e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname);
-EINTERN Eina_Bool e_input_backend_libinput_context_create(E_Input_Backend *input);
-
#endif