efl/src/lib/ecore_input/ecore_input.c

140 lines
4.2 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include "Ecore.h"
#include "ecore_private.h"
#include "Ecore_Input.h"
#include "ecore_input_private.h"
int _ecore_input_log_dom = -1;
EAPI int ECORE_EVENT_KEY_DOWN = 0;
EAPI int ECORE_EVENT_KEY_UP = 0;
EAPI int ECORE_EVENT_MOUSE_BUTTON_DOWN = 0;
EAPI int ECORE_EVENT_MOUSE_BUTTON_UP = 0;
EAPI int ECORE_EVENT_MOUSE_MOVE = 0;
EAPI int ECORE_EVENT_MOUSE_WHEEL = 0;
EAPI int ECORE_EVENT_MOUSE_IN = 0;
EAPI int ECORE_EVENT_MOUSE_OUT = 0;
Expose device (e.g. pen) axis information to applications Summary: This patch set adds the necessary code to expose device axis state to applications. This was primarily written with graphics tablets in mind, which -- in addition to acting like a mouse -- also provide information about pen pressure, tilt, etc. Other devices could potentially benefit from this API as well: touchscreens, joysticks, knob controllers, "spaceballs", etc. Whenever an update to the device state is recieved, an "Axis update" event is synthesized. This event contains the updated information, typically scaled and normalized to a particular logical range (e.g. zero to one for pressure, -pi to pi radians for angles, etc.). Information about the tool which generated the event is also stored so that applications can disambiguate events from multiple devices (or in the case of multitouch screens, individual fingers). This API is only wired up for use with X11 at the moment. Support for other backends (e.g. Wayland) should be easy to add for those familiar them. **Note**: The following is a list of changes from the "v2" patches originally sent to the mailinglist //Define and implement new Ecore_Event_Axis_Update events// * Harcode axis labels instead of including xserver-properties.h * Use C89-style comments * Use doxygen comments * Update comment text to note axes with unbounded/undefined ranges/units * Create "Ecore_Axis" and "Ecore_Axis_Label" typedefs * Reference typedef'd instead of raw types * Adjust how we count through valuators to support tilt/az * Add support for tilt and azimuth * Tweak memory management in case number of valuators differ * Expand TWIST axis normalization to declared range * Only normalize TWIST axis if resolution == 1 (wacom bug) * Cache label atoms on first use to minimize round-trips //Implement EVAS_CALLBACK_AXIS_UPDATE event and friends// * Update to doxygen comments * Update comment text to note axes with unbounded/undefined ranges/units * Typedef 'Evas_Axis_Label', 'Evas_Axis' * Move typedef for 'Evas_Event_Axis_Update' * Reference typedef'd instead of raw types //Wire the Ecore and Evas implementations of axis update events together// * Expose ecore_event_evas_axis_update in Ecore_Input_Evas.h * Move ecore_event_evas_axis_update to more logical position //DEBUG: Add axis update logging to evas-multi-touch.c// * Removed from patch set //Make evas-multi-touch demo use new axis functionality// * Have pressure adjust rectangle brightness instead of size * Use more available axis data when rendering rectangle (azimuth, tilt, twist) Test Plan: The evas-multi-touch demo was updated to support axis update events. A graphics tablet was then used to verify that the pressure, azimuth, tilt, and twist data was coming through correctly. Reviewers: cedric, raster Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1514 Conflicts: src/lib/ecore_input/Ecore_Input.h Carsten Haitzler - ** fixed forward enum typedefs (make things unhappy) ** fixed conflict above ** fixed wrong param type for _evas_canvas_event_feed_axis_update() ** fixed @sinces to be 1.13 ** fixed formatting/indeting ** fixed order of operation reliance in if's with ()'s to be clear ** fixed functions to be static that should have been
2014-11-24 19:07:50 -08:00
EAPI int ECORE_EVENT_AXIS_UPDATE = 0;
EAPI int ECORE_EVENT_MOUSE_BUTTON_CANCEL = 0;
EAPI int ECORE_EVENT_JOYSTICK = 0;
static int _ecore_event_init_count = 0;
EAPI int
ecore_event_init(void)
{
if (++_ecore_event_init_count != 1)
return _ecore_event_init_count;
if (!ecore_init())
{
_ecore_event_init_count--;
return 0;
}
_ecore_input_log_dom = eina_log_domain_register
("ecore_input", ECORE_INPUT_DEFAULT_LOG_COLOR);
if(_ecore_input_log_dom < 0)
{
EINA_LOG_ERR("Impossible to create a log domain for the ecore input module.");
return --_ecore_event_init_count;
}
ECORE_EVENT_KEY_DOWN = ecore_event_type_new();
ECORE_EVENT_KEY_UP = ecore_event_type_new();
ECORE_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new();
ECORE_EVENT_MOUSE_BUTTON_UP = ecore_event_type_new();
ECORE_EVENT_MOUSE_MOVE = ecore_event_type_new();
ECORE_EVENT_MOUSE_WHEEL = ecore_event_type_new();
ECORE_EVENT_MOUSE_IN = ecore_event_type_new();
ECORE_EVENT_MOUSE_OUT = ecore_event_type_new();
Expose device (e.g. pen) axis information to applications Summary: This patch set adds the necessary code to expose device axis state to applications. This was primarily written with graphics tablets in mind, which -- in addition to acting like a mouse -- also provide information about pen pressure, tilt, etc. Other devices could potentially benefit from this API as well: touchscreens, joysticks, knob controllers, "spaceballs", etc. Whenever an update to the device state is recieved, an "Axis update" event is synthesized. This event contains the updated information, typically scaled and normalized to a particular logical range (e.g. zero to one for pressure, -pi to pi radians for angles, etc.). Information about the tool which generated the event is also stored so that applications can disambiguate events from multiple devices (or in the case of multitouch screens, individual fingers). This API is only wired up for use with X11 at the moment. Support for other backends (e.g. Wayland) should be easy to add for those familiar them. **Note**: The following is a list of changes from the "v2" patches originally sent to the mailinglist //Define and implement new Ecore_Event_Axis_Update events// * Harcode axis labels instead of including xserver-properties.h * Use C89-style comments * Use doxygen comments * Update comment text to note axes with unbounded/undefined ranges/units * Create "Ecore_Axis" and "Ecore_Axis_Label" typedefs * Reference typedef'd instead of raw types * Adjust how we count through valuators to support tilt/az * Add support for tilt and azimuth * Tweak memory management in case number of valuators differ * Expand TWIST axis normalization to declared range * Only normalize TWIST axis if resolution == 1 (wacom bug) * Cache label atoms on first use to minimize round-trips //Implement EVAS_CALLBACK_AXIS_UPDATE event and friends// * Update to doxygen comments * Update comment text to note axes with unbounded/undefined ranges/units * Typedef 'Evas_Axis_Label', 'Evas_Axis' * Move typedef for 'Evas_Event_Axis_Update' * Reference typedef'd instead of raw types //Wire the Ecore and Evas implementations of axis update events together// * Expose ecore_event_evas_axis_update in Ecore_Input_Evas.h * Move ecore_event_evas_axis_update to more logical position //DEBUG: Add axis update logging to evas-multi-touch.c// * Removed from patch set //Make evas-multi-touch demo use new axis functionality// * Have pressure adjust rectangle brightness instead of size * Use more available axis data when rendering rectangle (azimuth, tilt, twist) Test Plan: The evas-multi-touch demo was updated to support axis update events. A graphics tablet was then used to verify that the pressure, azimuth, tilt, and twist data was coming through correctly. Reviewers: cedric, raster Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1514 Conflicts: src/lib/ecore_input/Ecore_Input.h Carsten Haitzler - ** fixed forward enum typedefs (make things unhappy) ** fixed conflict above ** fixed wrong param type for _evas_canvas_event_feed_axis_update() ** fixed @sinces to be 1.13 ** fixed formatting/indeting ** fixed order of operation reliance in if's with ()'s to be clear ** fixed functions to be static that should have been
2014-11-24 19:07:50 -08:00
ECORE_EVENT_AXIS_UPDATE = ecore_event_type_new();
ECORE_EVENT_MOUSE_BUTTON_CANCEL = ecore_event_type_new();
ECORE_EVENT_JOYSTICK = ecore_event_type_new();
ecore_input_joystick_init();
return _ecore_event_init_count;
}
EAPI int
ecore_event_shutdown(void)
{
if (--_ecore_event_init_count != 0)
return _ecore_event_init_count;
ecore_event_type_flush(ECORE_EVENT_KEY_DOWN,
ECORE_EVENT_KEY_UP,
ECORE_EVENT_MOUSE_BUTTON_DOWN,
ECORE_EVENT_MOUSE_BUTTON_UP,
ECORE_EVENT_MOUSE_MOVE,
ECORE_EVENT_MOUSE_WHEEL,
ECORE_EVENT_MOUSE_IN,
ECORE_EVENT_MOUSE_OUT,
ECORE_EVENT_AXIS_UPDATE,
ECORE_EVENT_MOUSE_BUTTON_CANCEL,
ECORE_EVENT_JOYSTICK);
ecore_input_joystick_shutdown();
eina_log_domain_unregister(_ecore_input_log_dom);
_ecore_input_log_dom = -1;
ecore_shutdown();
return _ecore_event_init_count;
}
typedef struct _Ecore_Event_Modifier_Match Ecore_Event_Modifier_Match;
struct _Ecore_Event_Modifier_Match
{
const char *key;
Ecore_Event_Modifier modifier;
unsigned int event_modifier;
};
static const Ecore_Event_Modifier_Match matchs[] = {
{ "Shift_L", ECORE_SHIFT, ECORE_EVENT_MODIFIER_SHIFT },
{ "Shift_R", ECORE_SHIFT, ECORE_EVENT_MODIFIER_SHIFT },
{ "Alt_L", ECORE_ALT, ECORE_EVENT_MODIFIER_ALT },
{ "Alt_R", ECORE_ALT, ECORE_EVENT_MODIFIER_ALT },
{ "Control_L", ECORE_CTRL, ECORE_EVENT_MODIFIER_CTRL },
{ "Control_R", ECORE_CTRL, ECORE_EVENT_MODIFIER_CTRL },
{ "Caps_Lock", ECORE_CAPS, ECORE_EVENT_MODIFIER_CAPS },
{ "Super_L", ECORE_WIN, ECORE_EVENT_MODIFIER_WIN },
{ "Super_R", ECORE_WIN, ECORE_EVENT_MODIFIER_WIN },
{ "ISO_Level3_Shift", ECORE_MODE, ECORE_EVENT_MODIFIER_ALTGR },
{ "Scroll_Lock", ECORE_SCROLL, ECORE_EVENT_MODIFIER_SCROLL }
};
EAPI unsigned int
ecore_event_modifier_mask(Ecore_Event_Modifier modifier)
{
size_t i;
for (i = 0; i < sizeof (matchs) / sizeof (Ecore_Event_Modifier_Match); i++)
if (matchs[i].modifier == modifier)
return matchs[i].event_modifier;
return 0;
}
EAPI Ecore_Event_Modifier
ecore_event_update_modifier(const char *key, Ecore_Event_Modifiers *modifiers, int inc)
{
size_t i;
for (i = 0; i < sizeof (matchs) / sizeof (Ecore_Event_Modifier_Match); i++)
if (strcmp(matchs[i].key, key) == 0)
{
2010-09-30 00:31:11 -07:00
if (modifiers && matchs[i].modifier < modifiers->size)
modifiers->array[matchs[i].modifier] += inc;
return matchs[i].modifier;
}
return ECORE_NONE;
}