ecore_fb: use libinput for all inputs

This commit is contained in:
Nicolas Aguirre 2016-03-18 09:01:45 +01:00
parent a02edfc86b
commit 608c328579
8 changed files with 1664 additions and 7 deletions

View File

@ -3122,10 +3122,12 @@ AC_ARG_ENABLE([tslib],
### Checks for libraries
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [ecore])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [ecore-input])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eeze])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eo])
EFL_INTERNAL_DEPEND_PKG([ECORE_FB], [eina])
EFL_OPTIONAL_DEPEND_PKG([ECORE_FB], [${want_tslib}], [TSLIB], [tslib])
EFL_DEPEND_PKG([ECORE_FB], [LIBINPUT], [libinput >= 0.6.0 xkbcommon >= 0.3.0])
EFL_ADD_FEATURE([ECORE_FB], [tslib])
EFL_EVAL_PKGS([ECORE_FB])

View File

@ -14,7 +14,10 @@ lib/ecore_fb/ecore_fb_li.c \
lib/ecore_fb/ecore_fb_ts.c \
lib/ecore_fb/ecore_fb_vt.c \
lib/ecore_fb/ecore_fb_keytable.h \
lib/ecore_fb/ecore_fb_private.h
lib/ecore_fb/ecore_fb_private.h \
lib/ecore_fb/ecore_fb_inputs.c \
lib/ecore_fb/ecore_fb_evdev.c \
lib/ecore_fb/ecore_fb_device.c
lib_ecore_fb_libecore_fb_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ECORE_FB_CFLAGS@
lib_ecore_fb_libecore_fb_la_LIBADD = @ECORE_FB_LIBS@

View File

@ -66,6 +66,23 @@ enum _Ecore_Fb_Input_Device_Cap
*/
typedef enum _Ecore_Fb_Input_Device_Cap Ecore_Fb_Input_Device_Cap;
/* opaque structure to represent a fb input */
typedef struct _Ecore_Fb_Input Ecore_Fb_Input;
/* opaque structure to represent a fb evdev input */
typedef struct _Ecore_Fb_Evdev Ecore_Fb_Evdev;
/* opaque structure to represent a fb seat */
typedef struct _Ecore_Fb_Seat Ecore_Fb_Seat;
/* opaque structure to represent a fb device */
typedef struct _Ecore_Fb_Device Ecore_Fb_Device;
/* opaque structure to represent a fb output */
typedef struct _Ecore_Fb_Output Ecore_Fb_Output;
/* ecore_fb_vt.c */
EAPI void ecore_fb_callback_gain_set(void (*func) (void *data), void *data);
EAPI void ecore_fb_callback_lose_set(void (*func) (void *data), void *data);
@ -90,6 +107,18 @@ EAPI void ecore_fb_size_get(int *w, int *h);
EAPI void ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap);
EAPI void ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap);
/* ecore_fb_inputs.c */
EAPI Eina_Bool ecore_fb_inputs_create(Ecore_Fb_Device *dev);
EAPI void ecore_fb_inputs_destroy(Ecore_Fb_Device *dev);
EAPI Eina_Bool ecore_fb_inputs_enable(Ecore_Fb_Input *input);
EAPI void ecore_fb_inputs_disable(Ecore_Fb_Input *input);
EAPI void ecore_fb_inputs_device_axis_size_set(Ecore_Fb_Evdev *dev, int w, int h);
/* ecore_fb_devices */
EAPI Ecore_Fb_Device *ecore_fb_device_find(const char *name);
EAPI void ecore_fb_device_window_set(Ecore_Fb_Device *dev, unsigned int window);
/**
* @}
*/

View File

@ -5,6 +5,9 @@
#include "Ecore_Fb.h"
#include "ecore_fb_private.h"
/* external variables */
int _ecore_fb_log_dom = -1;
static void _ecore_fb_size_get(int *w, int *h);
static int _ecore_fb_init_count = 0;
@ -43,6 +46,43 @@ ecore_fb_init(const char *name EINA_UNUSED)
if (++_ecore_fb_init_count != 1)
return _ecore_fb_init_count;
/* try to init eina */
if (!eina_init()) return --_ecore_fb_init_count;
/* try to init ecore */
if (!ecore_init())
{
eina_shutdown();
return --_ecore_fb_init_count;
}
/* try to init ecore_event */
if (!ecore_event_init())
{
ecore_shutdown();
eina_shutdown();
return --_ecore_fb_init_count;
}
/* set logging level */
eina_log_level_set(EINA_LOG_LEVEL_DBG);
/* try to create logging domain */
_ecore_fb_log_dom =
eina_log_domain_register("ecore_fb", ECORE_FB_DEFAULT_LOG_COLOR);
if (!_ecore_fb_log_dom)
{
EINA_LOG_ERR("Could not create log domain for Ecore_Fb");
goto log_err;
}
/* set default logging level for this domain */
if (!eina_log_domain_level_check(_ecore_fb_log_dom, EINA_LOG_LEVEL_DBG))
eina_log_domain_level_set("ecore_fb", EINA_LOG_LEVEL_DBG);
/* try to init eeze */
if (!eeze_init()) goto eeze_err;
if (!ecore_fb_vt_init())
return --_ecore_fb_init_count;
@ -50,10 +90,21 @@ ecore_fb_init(const char *name EINA_UNUSED)
{
oldhand = signal(SIGINT, nosigint);
}
_ecore_fb_size_get(&_ecore_fb_console_w, &_ecore_fb_console_h);
return _ecore_fb_init_count;
eeze_err:
eina_log_domain_unregister(_ecore_fb_log_dom);
_ecore_fb_log_dom = -1;
log_err:
ecore_event_shutdown();
ecore_shutdown();
eina_shutdown();
return --_ecore_fb_init_count;
}
/**
@ -76,7 +127,7 @@ ecore_fb_shutdown(void)
signal(SIGINT, oldhand);
oldhand = NULL;
}
ecore_fb_vt_shutdown();
return _ecore_fb_init_count;

View File

@ -0,0 +1,72 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ecore_fb_private.h"
static Eina_List *fb_devices;
EAPI Ecore_Fb_Device *
ecore_fb_device_find(const char *name)
{
Ecore_Fb_Device *dev = NULL;
Eina_List *devs, *l;
const char *device;
/* try to get a list of fb devics */
if (!(devs = eeze_udev_find_by_type(EEZE_UDEV_TYPE_GRAPHICS, name)))
{
return NULL;
}
DBG("Find Framebuffer Device: %s", name);
EINA_LIST_FOREACH(devs, l, device)
{
const char *devpath;
const char *devseat;
const char *devparent;
if (!(devpath = eeze_udev_syspath_get_devpath(device)))
continue;
DBG("Found Fb Device");
DBG("\tDevice: %s", device);
DBG("\tDevpath: %s", devpath);
if ((name) && (!strstr(name, devpath)))
{
eina_stringshare_del(devpath);
if ((dev = calloc(1, sizeof(Ecore_Fb_Device))))
{
dev->seat = eeze_udev_syspath_get_property(device, "ID_SEAT");
if (!dev->seat) dev->seat = eina_stringshare_add("seat0");
fb_devices = eina_list_append(fb_devices, dev);
/* try to create xkb context */
if (!(dev->xkb_ctx = xkb_context_new(0)))
{
ERR("Failed to create xkb context: %m");
return EINA_FALSE;
}
}
break;
}
eina_stringshare_del(devpath);
}
EINA_LIST_FREE(devs, device)
eina_stringshare_del(device);
return dev;
}
EAPI void
ecore_fb_device_window_set(Ecore_Fb_Device *dev, unsigned int window)
{
/* check for valid device */
EINA_SAFETY_ON_TRUE_RETURN((!dev));
dev->window = window;
}

View File

@ -0,0 +1,982 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_fb_private.h"
#include <ctype.h>
static void _device_modifiers_update(Ecore_Fb_Evdev *edev);
static void
_device_calibration_set(Ecore_Fb_Evdev *edev)
{
const char *sysname;
float cal[6];
const char *device;
Eina_List *devices;
const char *vals;
enum libinput_config_status status;
int width, height;
if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
(libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
return;
sysname = libinput_device_get_sysname(edev->device);
devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
if (eina_list_count(devices) < 1) return;
ecore_fb_size_get(&width, &height);
EINA_LIST_FREE(devices, device)
{
vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
if ((!vals) ||
(sscanf(vals, "%f %f %f %f %f %f",
&cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
goto cont;
cal[2] /= width;
cal[5] /= height;
status =
libinput_device_config_calibration_set_matrix(edev->device, cal);
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
ERR("Failed to apply calibration");
cont:
eina_stringshare_del(device);
continue;
}
}
static void
_device_output_set(Ecore_Fb_Evdev *edev)
{
Ecore_Fb_Input *input;
Ecore_Fb_Output *output = NULL;
const char *oname;
if (!edev->seat) return;
if (!(input = edev->seat->input)) return;
/* oname = libinput_device_get_output_name(edev->device); */
/* if (oname) */
/* { */
/* Eina_List *l; */
/* DBG("Device Has Output Name: %s", oname); */
/* EINA_LIST_FOREACH(input->dev->outputs, l, output) */
/* if ((output->name) && (!strcmp(output->name, oname))) break; */
/* } */
/* if (!output) */
/* output = eina_list_nth(input->dev->outputs, 0); */
/* if (!output) return; */
/* edev->output = output; */
if (libinput_device_has_capability(edev->device,
LIBINPUT_DEVICE_CAP_POINTER))
{
Ecore_Fb_Input *pointer_input;
Ecore_Event_Mouse_Move *ev;
int width, height;
ecore_fb_size_get(&width, &height);
edev->mouse.dx = width / 2;
edev->mouse.dy = height / 2;
/* send a fake motion event to let other know the initial pos of mouse */
if (!(pointer_input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
ev->window = (Ecore_Window)pointer_input->dev->window;
ev->event_window = (Ecore_Window)pointer_input->dev->window;
ev->root_window = (Ecore_Window)pointer_input->dev->window;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->same_screen = 1;
ev->x = edev->mouse.dx;
ev->y = edev->mouse.dy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
}
static void
_device_configure(Ecore_Fb_Evdev *edev)
{
int width, height;
ecore_fb_size_get(&width, &height);
if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
{
Eina_Bool tap = EINA_FALSE;
tap = libinput_device_config_tap_get_default_enabled(edev->device);
libinput_device_config_tap_set_enabled(edev->device, tap);
}
edev->mouse.minx = 0;
edev->mouse.miny = 0;
edev->mouse.maxw = width;
edev->mouse.maxh = height;
_device_output_set(edev);
_device_calibration_set(edev);
}
static void
_device_keyboard_setup(Ecore_Fb_Evdev *edev)
{
Ecore_Fb_Input *input;
if ((!edev) || (!edev->seat)) return;
if (!(input = edev->seat->input)) return;
if (!input->dev->xkb_ctx) return;
/* create keymap from xkb context */
edev->xkb.keymap = xkb_map_new_from_names(input->dev->xkb_ctx, NULL, 0);
if (!edev->xkb.keymap)
{
ERR("Failed to create keymap: %m");
return;
}
/* create xkb state */
if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
{
ERR("Failed to create xkb state: %m");
return;
}
edev->xkb.ctrl_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
edev->xkb.alt_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
edev->xkb.shift_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
edev->xkb.win_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
edev->xkb.scroll_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
edev->xkb.num_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
edev->xkb.caps_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
edev->xkb.altgr_mask =
1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
}
static int
_device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
{
unsigned long hbytes = 0;
unsigned char c;
if (!keysym) return 0;
hbytes = (keysym >> 8);
if (!(bytes &&
((hbytes == 0) ||
((hbytes == 0xFF) &&
(((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
(keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
(keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
(keysym == XKB_KEY_KP_Enter) ||
((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
(keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
return 0;
if (keysym == XKB_KEY_KP_Space)
c = (XKB_KEY_space & 0x7F);
else if (hbytes == 0xFF)
c = (keysym & 0x7F);
else
c = (keysym & 0xFF);
if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
{
if (((c >= '@') && (c < '\177')) || c == ' ')
c &= 0x1F;
else if (c == '2')
c = '\000';
else if ((c >= '3') && (c <= '7'))
c -= ('3' - '\033');
else if (c == '8')
c = '\177';
else if (c == '/')
c = '_' & 0x1F;
}
buffer[0] = c;
return 1;
}
static void
_device_modifiers_update_device(Ecore_Fb_Evdev *edev, Ecore_Fb_Evdev *from)
{
xkb_mod_mask_t mask;
edev->xkb.depressed =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
edev->xkb.latched =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
edev->xkb.locked =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
edev->xkb.group =
xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
mask = (edev->xkb.depressed | edev->xkb.latched);
if (mask & from->xkb.ctrl_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
if (mask & from->xkb.alt_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
if (mask & from->xkb.shift_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
if (mask & from->xkb.win_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
if (mask & from->xkb.scroll_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
if (mask & from->xkb.num_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
if (mask & from->xkb.caps_mask)
edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
if (mask & from->xkb.altgr_mask)
edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
}
static void
_device_modifiers_update(Ecore_Fb_Evdev *edev)
{
edev->xkb.modifiers = 0;
if (edev->seat_caps & EVDEV_SEAT_KEYBOARD)
_device_modifiers_update_device(edev, edev);
else
{
Eina_List *l;
Ecore_Fb_Evdev *ed;
EINA_LIST_FOREACH(edev->seat->devices, l, ed)
{
if (!(ed->seat_caps & EVDEV_SEAT_KEYBOARD)) continue;
_device_modifiers_update_device(edev, ed);
}
}
}
static void
_device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
uint32_t timestamp;
uint32_t code, nsyms;
const xkb_keysym_t *syms;
enum libinput_key_state state;
int key_count;
xkb_keysym_t sym = XKB_KEY_NoSymbol;
char key[256], keyname[256], compose_buffer[256];
Ecore_Event_Key *e;
char *tmp = NULL, *compose = NULL;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
timestamp = libinput_event_keyboard_get_time(event);
code = libinput_event_keyboard_get_key(event) + 8;
state = libinput_event_keyboard_get_key_state(event);
key_count = libinput_event_keyboard_get_seat_key_count(event);
/* ignore key events that are not seat wide state changes */
if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
return;
xkb_state_update_key(edev->xkb.state, code,
(state ? XKB_KEY_DOWN : XKB_KEY_UP));
/* get the keysym for this code */
nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
if (nsyms == 1) sym = syms[0];
/* get the keyname for this sym */
memset(key, 0, sizeof(key));
xkb_keysym_get_name(sym, key, sizeof(key));
memset(keyname, 0, sizeof(keyname));
memcpy(keyname, key, sizeof(keyname));
if (keyname[0] == '\0')
snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
/* if shift is active, we need to transform the key to lower */
if (xkb_state_mod_index_is_active(edev->xkb.state,
xkb_map_mod_get_index(edev->xkb.keymap,
XKB_MOD_NAME_SHIFT),
XKB_STATE_MODS_EFFECTIVE))
{
if (keyname[0] != '\0')
keyname[0] = tolower(keyname[0]);
}
memset(compose_buffer, 0, sizeof(compose_buffer));
if (_device_keysym_translate(sym, edev->xkb.modifiers,
compose_buffer, sizeof(compose_buffer)))
{
compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
if (!compose)
{
ERR("Ecore_FB cannot convert input key string '%s' to UTF-8. "
"Is Eina built with iconv support?", compose_buffer);
}
else
tmp = compose;
}
if (!compose) compose = compose_buffer;
e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
((compose[0] != '\0') ? strlen(compose) : 0) + 3);
if (!e) return;
e->keyname = (char *)(e + 1);
e->key = e->keyname + strlen(keyname) + 1;
e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
e->string = e->compose;
strcpy((char *)e->keyname, keyname);
strcpy((char *)e->key, key);
if (strlen(compose)) strcpy((char *)e->compose, compose);
e->window = (Ecore_Window)input->dev->window;
e->event_window = (Ecore_Window)input->dev->window;
e->root_window = (Ecore_Window)input->dev->window;
e->timestamp = timestamp;
e->same_screen = 1;
e->keycode = code;
_device_modifiers_update(edev);
e->modifiers = edev->xkb.modifiers;
if (state)
ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
else
ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
if (tmp) free(tmp);
}
static void
_device_pointer_motion(Ecore_Fb_Evdev *edev, struct libinput_event_pointer *event)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Move *ev;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
if (edev->mouse.ix < edev->mouse.minx)
edev->mouse.dx = edev->mouse.ix = edev->mouse.minx;
else if (edev->mouse.ix >= (edev->mouse.minx + edev->mouse.maxw))
edev->mouse.dx = edev->mouse.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
if (edev->mouse.iy < edev->mouse.miny)
edev->mouse.dy = edev->mouse.iy = edev->mouse.miny;
else if (edev->mouse.iy >= (edev->mouse.miny + edev->mouse.maxh))
edev->mouse.dy = edev->mouse.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = libinput_event_pointer_get_time(event);
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
static void
_device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.dx += libinput_event_pointer_get_dx(event);
edev->mouse.dy += libinput_event_pointer_get_dy(event);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
edev->mouse.ix = edev->mouse.dx;
edev->mouse.iy = edev->mouse.dy;
_device_pointer_motion(edev, event);
}
static void
_device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
int width, height;
ecore_fb_size_get(&width, &height);
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.dx =
libinput_event_pointer_get_absolute_x_transformed(event, width);
edev->mouse.dy =
libinput_event_pointer_get_absolute_y_transformed(event, height);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
_device_pointer_motion(edev, event);
}
static void
_device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Button *ev;
enum libinput_button_state state;
uint32_t button, timestamp;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
state = libinput_event_pointer_get_button_state(event);
button = libinput_event_pointer_get_button(event);
timestamp = libinput_event_pointer_get_time(event);
button = ((button & 0x00F) + 1);
if (button == 3) button = 2;
else if (button == 2) button = 3;
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
if (state)
{
unsigned int current;
current = timestamp;
edev->mouse.did_double = EINA_FALSE;
edev->mouse.did_triple = EINA_FALSE;
if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
(button == edev->mouse.prev_button))
{
edev->mouse.did_double = EINA_TRUE;
if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
(button == edev->mouse.last_button))
{
edev->mouse.did_triple = EINA_TRUE;
edev->mouse.prev = 0;
edev->mouse.last = 0;
current = 0;
}
}
edev->mouse.last = edev->mouse.prev;
edev->mouse.prev = current;
edev->mouse.last_button = edev->mouse.prev_button;
edev->mouse.prev_button = button;
}
ev->buttons = button;
if (edev->mouse.did_double)
ev->double_click = 1;
if (edev->mouse.did_triple)
ev->triple_click = 1;
if (state)
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
else
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
}
static void
_device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
{
Ecore_Fb_Evdev *edev;
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Wheel *ev;
uint32_t timestamp;
enum libinput_pointer_axis axis;
if (!(edev = libinput_device_get_user_data(device))) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)))) return;
timestamp = libinput_event_pointer_get_time(event);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
#if LIBINPUT_HIGHER_08
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
if (libinput_event_pointer_has_axis(event, axis))
ev->z = libinput_event_pointer_get_axis_value(event, axis);
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
if (libinput_event_pointer_has_axis(event, axis))
{
ev->direction = 1;
ev->z = libinput_event_pointer_get_axis_value(event, axis);
}
#else
axis = libinput_event_pointer_get_axis(event);
if (axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) ev->direction = 1;
ev->z = libinput_event_pointer_get_axis_value(event);
#endif
ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
}
Ecore_Fb_Evdev *
_ecore_fb_evdev_device_create(Ecore_Fb_Seat *seat, struct libinput_device *device)
{
Ecore_Fb_Evdev *edev;
Eina_List *devices;
EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
/* try to allocate space for new evdev */
if (!(edev = calloc(1, sizeof(Ecore_Fb_Evdev)))) return NULL;
edev->seat = seat;
edev->device = device;
edev->path = eina_stringshare_add(libinput_device_get_sysname(device));
devices = eeze_udev_find_by_filter("input", NULL, edev->path);
if (eina_list_count(devices) >= 1)
{
Eina_List *l;
const char *dev, *name;
EINA_LIST_FOREACH(devices, l, dev)
{
name = eeze_udev_syspath_get_devname(dev);
if (strstr(name, edev->path))
{
eina_stringshare_replace(&edev->path, eeze_udev_syspath_get_devpath(dev));
break;
}
}
EINA_LIST_FREE(devices, dev)
eina_stringshare_del(dev);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
{
edev->seat_caps |= EVDEV_SEAT_KEYBOARD;
_device_keyboard_setup(edev);
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
{
edev->seat_caps |= EVDEV_SEAT_POINTER;
/* TODO: make this configurable */
edev->mouse.threshold = 250;
}
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
{
edev->seat_caps |= EVDEV_SEAT_TOUCH;
}
libinput_device_set_user_data(device, edev);
libinput_device_ref(device);
/* configure device */
_device_configure(edev);
return edev;
}
static void
_device_handle_touch_event_send(Ecore_Fb_Evdev *edev, struct libinput_event_touch *event, int state)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Button *ev;
uint32_t timestamp, button = 0;
if (!edev) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
timestamp = libinput_event_touch_get_time(event);
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = timestamp;
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
{
unsigned int current;
current = timestamp;
edev->mouse.did_double = EINA_FALSE;
edev->mouse.did_triple = EINA_FALSE;
if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
(button == edev->mouse.prev_button))
{
edev->mouse.did_double = EINA_TRUE;
if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
(button == edev->mouse.last_button))
{
edev->mouse.did_triple = EINA_TRUE;
edev->mouse.prev = 0;
edev->mouse.last = 0;
current = 0;
}
}
edev->mouse.last = edev->mouse.prev;
edev->mouse.prev = current;
edev->mouse.last_button = edev->mouse.prev_button;
edev->mouse.prev_button = button;
}
ev->buttons = ((button & 0x00F) + 1);
if (edev->mouse.did_double)
ev->double_click = 1;
if (edev->mouse.did_triple)
ev->triple_click = 1;
ecore_event_add(state, ev, NULL, NULL);
}
static void
_device_handle_touch_motion_send(Ecore_Fb_Evdev *edev, struct libinput_event_touch *event)
{
Ecore_Fb_Input *input;
Ecore_Event_Mouse_Move *ev;
if (!edev) return;
if (!(input = edev->seat->input)) return;
if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
ev->window = (Ecore_Window)input->dev->window;
ev->event_window = (Ecore_Window)input->dev->window;
ev->root_window = (Ecore_Window)input->dev->window;
ev->timestamp = libinput_event_touch_get_time(event);
ev->same_screen = 1;
_device_modifiers_update(edev);
ev->modifiers = edev->xkb.modifiers;
ev->modifiers = 0;
ev->x = edev->mouse.ix;
ev->y = edev->mouse.iy;
ev->root.x = ev->x;
ev->root.y = ev->y;
ev->multi.device = edev->mt_slot;
ev->multi.radius = 1;
ev->multi.radius_x = 1;
ev->multi.radius_y = 1;
ev->multi.pressure = 1.0;
ev->multi.angle = 0.0;
ev->multi.x = ev->x;
ev->multi.y = ev->y;
ev->multi.root.x = ev->x;
ev->multi.root.y = ev->y;
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
}
static void
_device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
int width, height;
ecore_fb_size_get(&width, &height);
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mouse.ix = edev->mouse.dx =
libinput_event_touch_get_x_transformed(event, width);
edev->mouse.iy = edev->mouse.dy =
libinput_event_touch_get_y_transformed(event, height);
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_motion_send(edev, event);
_device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
}
static void
_device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
int width, height;
ecore_fb_size_get(&width, &height);
edev->mouse.dx =
libinput_event_touch_get_x_transformed(event, width);
edev->mouse.dy =
libinput_event_touch_get_y_transformed(event, height);
if (floor(edev->mouse.dx) == edev->mouse.ix &&
floor(edev->mouse.dy) == edev->mouse.iy) return;
edev->mouse.ix = edev->mouse.dx;
edev->mouse.iy = edev->mouse.dy;
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_motion_send(edev, event);
}
static void
_device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
{
Ecore_Fb_Evdev *edev;
if (!(edev = libinput_device_get_user_data(device))) return;
edev->mt_slot = libinput_event_touch_get_seat_slot(event);
_device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
}
static void
_device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
{
/* DBG("Unhandled Touch Frame Event"); */
}
void
_ecore_fb_evdev_device_destroy(Ecore_Fb_Evdev *edev)
{
EINA_SAFETY_ON_NULL_RETURN(edev);
if (edev->seat_caps & EVDEV_SEAT_KEYBOARD)
{
if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
}
if (edev->path) eina_stringshare_del(edev->path);
if (edev->device) libinput_device_unref(edev->device);
free(edev);
}
Eina_Bool
_ecore_fb_evdev_event_process(struct libinput_event *event)
{
struct libinput_device *device;
Eina_Bool ret = EINA_TRUE;
device = libinput_event_get_device(event);
switch (libinput_event_get_type(event))
{
case LIBINPUT_EVENT_KEYBOARD_KEY:
_device_handle_key(device, libinput_event_get_keyboard_event(event));
break;
case LIBINPUT_EVENT_POINTER_MOTION:
_device_handle_pointer_motion(device,
libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
_device_handle_pointer_motion_absolute(device,
libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_BUTTON:
_device_handle_button(device, libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_POINTER_AXIS:
_device_handle_axis(device, libinput_event_get_pointer_event(event));
break;
case LIBINPUT_EVENT_TOUCH_DOWN:
_device_handle_touch_down(device, libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_MOTION:
_device_handle_touch_motion(device,
libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_UP:
_device_handle_touch_up(device, libinput_event_get_touch_event(event));
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
_device_handle_touch_frame(device, libinput_event_get_touch_event(event));
break;
default:
ret = EINA_FALSE;
break;
}
return ret;
}
/**
* @brief Set the axis size of the given device.
*
* @param dev The device to set the axis size to.
* @param w The width of the axis.
* @param h The height of the axis.
*
* This function sets set the width @p w and height @p h of the axis
* of device @p dev. If @p dev is a relative input device, a width and
* height must set for it. If its absolute set the ioctl correctly, if
* not, unsupported device.
*/
EAPI void
ecore_fb_inputs_device_axis_size_set(Ecore_Fb_Evdev *edev, int w, int h)
{
const char *sysname;
float cal[6];
const char *device;
Eina_List *devices;
const char *vals;
enum libinput_config_status status;
EINA_SAFETY_ON_NULL_RETURN(edev);
EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
(libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
return;
sysname = libinput_device_get_sysname(edev->device);
devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
if (eina_list_count(devices) < 1) return;
EINA_LIST_FREE(devices, device)
{
vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
if ((!vals) ||
(sscanf(vals, "%f %f %f %f %f %f",
&cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
goto cont;
cal[2] /= w;
cal[5] /= h;
status =
libinput_device_config_calibration_set_matrix(edev->device, cal);
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
ERR("Failed to apply calibration");
cont:
eina_stringshare_del(device);
continue;
}
}

View File

@ -0,0 +1,371 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_fb_private.h"
EAPI int ECORE_FB_EVENT_SEAT_ADD = -1;
/* local functions */
int
_ecore_fb_launcher_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;
}
void
_ecore_fb_launcher_device_close(const char *device EINA_UNUSED, int fd)
{
close(fd);
}
static int
_cb_open_restricted(const char *path, int flags, void *data)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
Eina_List *l, *ll;
int fd = -1;
if (!(input = data)) return -1;
/* try to open the device */
fd = _ecore_fb_launcher_device_open_no_pending(path, flags);
if (fd < 0) ERR("Could not open device");
EINA_LIST_FOREACH(input->dev->seats, l, seat)
{
EINA_LIST_FOREACH(seat->devices, ll, edev)
{
if (strstr(path, edev->path))
{
edev->fd = fd;
return fd;
}
}
}
return fd;
}
static void
_cb_close_restricted(int fd, void *data)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
Eina_List *l, *ll;
if (!(input = data)) return;
EINA_LIST_FOREACH(input->dev->seats, l, seat)
{
EINA_LIST_FOREACH(seat->devices, ll, edev)
{
if (edev->fd == fd)
{
_ecore_fb_launcher_device_close(edev->path, fd);
return;
}
}
}
}
static Ecore_Fb_Seat *
_seat_create(Ecore_Fb_Input *input, const char *seat)
{
Ecore_Fb_Seat *s;
/* try to allocate space for new seat */
if (!(s = calloc(1, sizeof(Ecore_Fb_Seat))))
return NULL;
s->input = input;
s->name = eina_stringshare_add(seat);
/* add this new seat to list */
input->dev->seats = eina_list_append(input->dev->seats, s);
ecore_event_add(ECORE_FB_EVENT_SEAT_ADD, NULL, NULL, NULL);
return s;
}
static Ecore_Fb_Seat *
_seat_get(Ecore_Fb_Input *input, const char *seat)
{
Ecore_Fb_Seat *s;
Eina_List *l;
/* search for this name in existing seats */
EINA_LIST_FOREACH(input->dev->seats, l, s)
if (!strcmp(s->name, seat)) return s;
return _seat_create(input, seat);
}
static void
_device_added(Ecore_Fb_Input *input, struct libinput_device *device)
{
struct libinput_seat *libinput_seat;
const char *seat_name;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
libinput_seat = libinput_device_get_seat(device);
seat_name = libinput_seat_get_logical_name(libinput_seat);
/* try to get a seat */
if (!(seat = _seat_get(input, seat_name)))
{
ERR("Could not get matching seat: %s", seat_name);
return;
}
/* try to create a new evdev device */
if (!(edev = _ecore_fb_evdev_device_create(seat, device)))
{
ERR("Failed to create new evdev device");
return;
}
/* append this device to the seat */
seat->devices = eina_list_append(seat->devices, edev);
}
static void
_device_removed(Ecore_Fb_Input *input EINA_UNUSED, struct libinput_device *device)
{
Ecore_Fb_Evdev *edev;
/* try to get the evdev structure */
if (!(edev = libinput_device_get_user_data(device)))
return;
/* remove this evdev from the seat's list of devices */
edev->seat->devices = eina_list_remove(edev->seat->devices, edev);
/* tell launcher to release device */
_ecore_fb_launcher_device_close(edev->path, edev->fd);
/* destroy this evdev */
_ecore_fb_evdev_device_destroy(edev);
}
static int
_udev_event_process(struct libinput_event *event)
{
struct libinput *libinput;
struct libinput_device *device;
Ecore_Fb_Input *input;
Eina_Bool ret = EINA_TRUE;
libinput = libinput_event_get_context(event);
input = libinput_get_user_data(libinput);
device = libinput_event_get_device(event);
switch (libinput_event_get_type(event))
{
case LIBINPUT_EVENT_DEVICE_ADDED:
_device_added(input, device);
break;
case LIBINPUT_EVENT_DEVICE_REMOVED:
_device_removed(input, device);
break;
default:
ret = EINA_FALSE;
}
return ret;
}
static void
_input_event_process(struct libinput_event *event)
{
if (_udev_event_process(event)) return;
if (_ecore_fb_evdev_event_process(event)) return;
}
static void
_input_events_process(Ecore_Fb_Input *input)
{
struct libinput_event *event;
while ((event = libinput_get_event(input->libinput)))
{
_input_event_process(event);
libinput_event_destroy(event);
}
}
static Eina_Bool
_cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
{
Ecore_Fb_Input *input;
if (!(input = data)) return EINA_TRUE;
if (libinput_dispatch(input->libinput) != 0)
ERR("Failed to dispatch libinput events: %m");
/* process pending events */
_input_events_process(input);
return EINA_TRUE;
}
const struct libinput_interface _input_interface =
{
_cb_open_restricted,
_cb_close_restricted,
};
/* public functions */
EAPI Eina_Bool
ecore_fb_inputs_create(Ecore_Fb_Device *dev)
{
Ecore_Fb_Input *input;
/* check for valid device */
EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
/* try to allocate space for new input structure */
if (!(input = calloc(1, sizeof(Ecore_Fb_Input))))
return EINA_FALSE;
/* set reference for parent device */
input->dev = dev;
/* try to create libinput context */
input->libinput =
libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
if (!input->libinput)
{
ERR("Could not create libinput context: %m");
goto err;
}
/* set libinput log priority */
libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
/* assign udev seat */
if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
{
ERR("Failed to assign seat: %m");
goto err;
}
/* process pending events */
_input_events_process(input);
/* enable this input */
if (!ecore_fb_inputs_enable(input))
{
ERR("Failed to enable input");
goto err;
}
/* append this input */
dev->inputs = eina_list_append(dev->inputs, input);
return EINA_TRUE;
err:
if (input->libinput) libinput_unref(input->libinput);
free(input);
return EINA_FALSE;
}
EAPI void
ecore_fb_inputs_destroy(Ecore_Fb_Device *dev)
{
Ecore_Fb_Input *input;
Ecore_Fb_Seat *seat;
Ecore_Fb_Evdev *edev;
EINA_SAFETY_ON_NULL_RETURN(dev);
EINA_LIST_FREE(dev->seats, seat)
{
EINA_LIST_FREE(seat->devices, edev)
{
_ecore_fb_launcher_device_close(edev->path, edev->fd);
_ecore_fb_evdev_device_destroy(edev);
}
if (seat->name) eina_stringshare_del(seat->name);
free(seat);
}
EINA_LIST_FREE(dev->inputs, input)
{
if (input->hdlr) ecore_main_fd_handler_del(input->hdlr);
if (input->libinput) libinput_unref(input->libinput);
free(input);
}
}
EAPI Eina_Bool
ecore_fb_inputs_enable(Ecore_Fb_Input *input)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(input->libinput, EINA_FALSE);
input->fd = libinput_get_fd(input->libinput);
if (!input->hdlr)
{
input->hdlr =
ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
_cb_input_dispatch, input, NULL, NULL);
}
if (input->suspended)
{
if (libinput_resume(input->libinput) != 0)
goto err;
input->suspended = EINA_FALSE;
/* process pending events */
_input_events_process(input);
}
input->enabled = EINA_TRUE;
input->suspended = EINA_FALSE;
return EINA_TRUE;
err:
input->enabled = EINA_FALSE;
if (input->hdlr) ecore_main_fd_handler_del(input->hdlr);
input->hdlr = NULL;
return EINA_FALSE;
}
EAPI void
ecore_fb_inputs_disable(Ecore_Fb_Input *input)
{
EINA_SAFETY_ON_NULL_RETURN(input);
EINA_SAFETY_ON_TRUE_RETURN(input->suspended);
/* suspend this input */
libinput_suspend(input->libinput);
/* process pending events */
_input_events_process(input);
input->suspended = EINA_TRUE;
}

View File

@ -1,6 +1,10 @@
#ifndef _ECORE_FB_PRIVATE_H
#define _ECORE_FB_PRIVATE_H
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
#include "Ecore.h"
#include "ecore_private.h"
#include "Ecore_Input.h"
@ -18,7 +22,7 @@
#include <linux/vt.h>
#include <linux/fb.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
#define kernel_ulong_t unsigned long
#define kernel_ulong_t unsigned long
#define BITS_PER_LONG 32
#include <linux/input.h>
#undef kernel_ulong_t
@ -26,12 +30,15 @@
#else
#include <linux/input.h>
#endif
#include <libinput.h>
#include <xkbcommon/xkbcommon.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include "Ecore_Fb.h"
#include <Eeze.h>
#include <Ecore_Fb.h>
#ifdef EAPI
# undef EAPI
@ -47,13 +54,148 @@
# define EAPI
#endif
# ifdef ECORE_FB_DEFAULT_LOG_COLOR
# undef ECORE_FB_DEFAULT_LOG_COLOR
# endif
# define ECORE_FB_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
# ifdef ERR
# undef ERR
# endif
# ifdef DBG
# undef DBG
# endif
# ifdef INF
# undef INF
# endif
# ifdef WRN
# undef WRN
# endif
# ifdef CRIT
# undef CRIT
# endif
extern int _ecore_fb_log_dom;
# define ERR(...) EINA_LOG_DOM_ERR(_ecore_fb_log_dom, __VA_ARGS__)
# define DBG(...) EINA_LOG_DOM_DBG(_ecore_fb_log_dom, __VA_ARGS__)
# define INF(...) EINA_LOG_DOM_INFO(_ecore_fb_log_dom, __VA_ARGS__)
# define WRN(...) EINA_LOG_DOM_WARN(_ecore_fb_log_dom, __VA_ARGS__)
# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_fb_log_dom, __VA_ARGS__)
typedef enum _Ecore_Fb_Seat_Capabilities
{
EVDEV_SEAT_POINTER = (1 << 0),
EVDEV_SEAT_KEYBOARD = (1 << 1),
EVDEV_SEAT_TOUCH = (1 << 2),
} Ecore_Fb_Seat_Capabilities;
struct _Ecore_Fb_Output
{
Ecore_Fb_Device *dev;
int x, y, phys_width, phys_height;
const char *make, *model, *name;
Eina_List *modes;
};
struct _Ecore_Fb_Device
{
Eina_List *inputs;
Eina_List *seats;
Eina_List *outputs;
const char *seat;
int window;
struct xkb_context *xkb_ctx;
};
struct _Ecore_Fb_Seat
{
// struct libinput_seat *seat;
const char *name;
Ecore_Fb_Input *input;
Eina_List *devices;
};
struct _Ecore_Fb_Input
{
int fd;
Ecore_Fb_Device *dev;
struct libinput *libinput;
Ecore_Fd_Handler *hdlr;
Eina_Bool enabled : 1;
Eina_Bool suspended : 1;
};
struct _Ecore_Fb_Evdev
{
Ecore_Fb_Seat *seat;
struct libinput_device *device;
const char *path;
int fd;
int mt_slot;
Ecore_Fb_Output *output;
/* struct */
/* { */
/* int min_x, min_y; */
/* int max_x, max_y; */
/* double rel_w, rel_h; */
/* struct */
/* { */
/* int x[2]; */
/* int y[2]; */
/* Eina_Bool down : 1; */
/* } pt[EVDEV_MAX_SLOTS]; */
/* } abs; */
struct
{
int ix, iy;
int minx, miny, maxw, maxh;
double dx, dy;
unsigned int last, prev;
uint32_t threshold;
Eina_Bool did_double : 1;
Eina_Bool did_triple : 1;
uint32_t prev_button, last_button;
} mouse;
struct
{
struct xkb_keymap *keymap;
struct xkb_state *state;
xkb_mod_mask_t ctrl_mask;
xkb_mod_mask_t alt_mask;
xkb_mod_mask_t shift_mask;
xkb_mod_mask_t win_mask;
xkb_mod_mask_t scroll_mask;
xkb_mod_mask_t num_mask;
xkb_mod_mask_t caps_mask;
xkb_mod_mask_t altgr_mask;
unsigned int modifiers;
unsigned int depressed, latched, locked, group;
} xkb;
/* Ecore_Fb_Evdev_Capabilities caps; */
Ecore_Fb_Seat_Capabilities seat_caps;
};
/* ecore_fb_li.c */
struct _Ecore_Fb_Input_Device
{
int fd;
Ecore_Fd_Handler *handler;
int listen;
struct
struct
{
Ecore_Fb_Input_Device_Cap cap;
char *name;
@ -98,6 +240,11 @@ EAPI void ecore_fb_ts_event_window_set(void *window);
int ecore_fb_vt_init(void);
void ecore_fb_vt_shutdown(void);
/* ecore_fb_evdev.c */
Ecore_Fb_Evdev *_ecore_fb_evdev_device_create(Ecore_Fb_Seat *seat, struct libinput_device *device);
void _ecore_fb_evdev_device_destroy(Ecore_Fb_Evdev *evdev);
Eina_Bool _ecore_fb_evdev_event_process(struct libinput_event *event);
/* hacks to stop people NEEDING #include <linux/h3600_ts.h> */
#ifndef TS_SET_CAL
#define TS_SET_CAL 0x4014660b
@ -105,7 +252,7 @@ void ecore_fb_vt_shutdown(void);
#ifndef TS_GET_CAL
#define TS_GET_CAL 0x8014660a
#endif
#undef EAPI
#define EAPI