From f832d2019cc96d750a17f9df3aec3feff78dc5a3 Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Fri, 1 Apr 2016 13:04:25 -0400 Subject: [PATCH] elput: Add API function to initialize and shutdown input devices Signed-off-by: Chris Michael --- src/Makefile_Elput.am | 1 + src/lib/elput/Elput.h | 31 ++++++++++++++- src/lib/elput/elput_input.c | 87 +++++++++++++++++++++++++++++++++++++++++++ src/lib/elput/elput_private.h | 13 +++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/lib/elput/elput_input.c diff --git a/src/Makefile_Elput.am b/src/Makefile_Elput.am index 3e1ed58..c79763e 100644 --- a/src/Makefile_Elput.am +++ b/src/Makefile_Elput.am @@ -9,6 +9,7 @@ dist_installed_elputmainheaders_DATA = \ lib/elput/Elput.h lib_elput_libelput_la_SOURCES = \ +lib/elput/elput_input.c \ lib/elput/elput_logind.c \ lib/elput/elput_manager.c \ lib/elput/elput.c \ diff --git a/src/lib/elput/Elput.h b/src/lib/elput/Elput.h index 44a861c..234597f 100644 --- a/src/lib/elput/Elput.h +++ b/src/lib/elput/Elput.h @@ -39,6 +39,7 @@ typedef struct _Elput_Manager Elput_Manager; * * @li @ref Elput_Init_Group * @li @ref Elput_Manager_Group + * @li @ref Elput_Input_Group * */ @@ -75,7 +76,6 @@ EAPI int elput_shutdown(void); * * Functions that deal with connecting, disconnecting, opening, closing * of input devices. - * */ /** @@ -127,6 +127,35 @@ EAPI int elput_manager_open(Elput_Manager *manager, const char *path, int flags) */ EAPI void elput_manager_close(Elput_Manager *manager, int fd); +/** + * @defgroup Elput_Input_Group Elput input functions + * + * Functions that deal with setup of inputs + */ + +/** + * Initialize input + * + * @param manager + * @param seat + * + * @return EINA_TRUE on success, EINA_FALSE on failure + * + * @ingroup Elput_Input_Group + * @since 1.18 + */ +EAPI Eina_Bool elput_input_init(Elput_Manager *manager, const char *seat); + +/** + * Shutdown input + * + * @param manager + * + * @ingroup Elput_Input_Group + * @since 1.18 + */ +EAPI void elput_input_shutdown(Elput_Manager *manager); + # endif # undef EAPI diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c new file mode 100644 index 0000000..a2a4ccb --- /dev/null +++ b/src/lib/elput/elput_input.c @@ -0,0 +1,87 @@ +#include "elput_private.h" + +static int +_cb_open_restricted(const char *path, int flags, void *data) +{ + Elput_Manager *em; + + em = data; + return elput_manager_open(em, path, flags); +} + +static void +_cb_close_restricted(int fd, void *data) +{ + Elput_Manager *em; + + em = data; + elput_manager_close(em, fd); +} + +const struct libinput_interface _input_interface = +{ + _cb_open_restricted, + _cb_close_restricted, +}; + +static void +_process_event(struct libinput_event *event) +{ + /* TODO */ +} + +static void +_process_events(Elput_Input *ei) +{ + struct libinput_event *event; + + while ((event = libinput_get_event(ei->lib))) + { + _process_event(event); + libinput_event_destroy(event); + } +} + +EAPI Eina_Bool +elput_input_init(Elput_Manager *manager, const char *seat) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE); + + memset(&manager->input, 0, sizeof(Elput_Input)); + + manager->input.lib = + libinput_udev_create_context(&_input_interface, manager, eeze_udev_get()); + if (!manager->input.lib) + { + ERR("libinput could not create udev context"); + goto udev_err; + } + + if (libinput_udev_assign_seat(manager->input.lib, seat) != 0) + { + ERR("libinput could not assign udev seat"); + goto seat_err; + } + + _process_events(&manager->input); + + /* TODO */ + + return EINA_TRUE; + +seat_err: + libinput_unref(manager->input.lib); +udev_err: + return EINA_FALSE; +} + +EAPI void +elput_input_shutdown(Elput_Manager *manager) +{ + EINA_SAFETY_ON_NULL_RETURN(manager); + EINA_SAFETY_ON_NULL_RETURN(&manager->input); + + /* TODO */ + + libinput_unref(manager->input.lib); +} diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h index c500a55..6d88943 100644 --- a/src/lib/elput/elput_private.h +++ b/src/lib/elput/elput_private.h @@ -64,6 +64,17 @@ typedef struct _Elput_Interface void (*close)(Elput_Manager *manager, int fd); } Elput_Interface; +typedef struct _Elput_Input +{ + struct libinput *lib; + + Ecore_Fd_Handler *hdlr; + + Eina_List *seats; + + Eina_Bool suspended : 1; +} Elput_Input; + struct _Elput_Manager { Elput_Interface *interface; @@ -80,6 +91,8 @@ struct _Elput_Manager Eldbus_Connection *conn; } dbus; + Elput_Input input; + Eina_Bool sync : 1; }; -- 2.7.4