1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #include "Ecore.h"
9 #include "ecore_private.h"
10
11 #include "Ecore_Input.h"
12 #include "ecore_input_private.h"
13
14
15 int _ecore_input_log_dom = -1;
16
17 EAPI int ECORE_EVENT_KEY_DOWN = 0;
18 EAPI int ECORE_EVENT_KEY_UP = 0;
19 EAPI int ECORE_EVENT_MOUSE_BUTTON_DOWN = 0;
20 EAPI int ECORE_EVENT_MOUSE_BUTTON_UP = 0;
21 EAPI int ECORE_EVENT_MOUSE_MOVE = 0;
22 EAPI int ECORE_EVENT_MOUSE_WHEEL = 0;
23 EAPI int ECORE_EVENT_MOUSE_IN = 0;
24 EAPI int ECORE_EVENT_MOUSE_OUT = 0;
25 EAPI int ECORE_EVENT_AXIS_UPDATE = 0;
26 EAPI int ECORE_EVENT_MOUSE_BUTTON_CANCEL = 0;
27 EAPI int ECORE_EVENT_JOYSTICK = 0;
28
29 static int _ecore_event_init_count = 0;
30
31 EAPI int
ecore_event_init(void)32 ecore_event_init(void)
33 {
34 if (++_ecore_event_init_count != 1)
35 return _ecore_event_init_count;
36 if (!ecore_init())
37 {
38 _ecore_event_init_count--;
39 return 0;
40 }
41
42 _ecore_input_log_dom = eina_log_domain_register
43 ("ecore_input", ECORE_INPUT_DEFAULT_LOG_COLOR);
44 if(_ecore_input_log_dom < 0)
45 {
46 EINA_LOG_ERR("Impossible to create a log domain for the ecore input module.");
47 return --_ecore_event_init_count;
48 }
49
50 ECORE_EVENT_KEY_DOWN = ecore_event_type_new();
51 ECORE_EVENT_KEY_UP = ecore_event_type_new();
52 ECORE_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new();
53 ECORE_EVENT_MOUSE_BUTTON_UP = ecore_event_type_new();
54 ECORE_EVENT_MOUSE_MOVE = ecore_event_type_new();
55 ECORE_EVENT_MOUSE_WHEEL = ecore_event_type_new();
56 ECORE_EVENT_MOUSE_IN = ecore_event_type_new();
57 ECORE_EVENT_MOUSE_OUT = ecore_event_type_new();
58 ECORE_EVENT_AXIS_UPDATE = ecore_event_type_new();
59 ECORE_EVENT_MOUSE_BUTTON_CANCEL = ecore_event_type_new();
60 ECORE_EVENT_JOYSTICK = ecore_event_type_new();
61
62 ecore_input_joystick_init();
63
64 return _ecore_event_init_count;
65 }
66
67 EAPI int
ecore_event_shutdown(void)68 ecore_event_shutdown(void)
69 {
70 if (--_ecore_event_init_count != 0)
71 return _ecore_event_init_count;
72
73 ecore_event_type_flush(ECORE_EVENT_KEY_DOWN,
74 ECORE_EVENT_KEY_UP,
75 ECORE_EVENT_MOUSE_BUTTON_DOWN,
76 ECORE_EVENT_MOUSE_BUTTON_UP,
77 ECORE_EVENT_MOUSE_MOVE,
78 ECORE_EVENT_MOUSE_WHEEL,
79 ECORE_EVENT_MOUSE_IN,
80 ECORE_EVENT_MOUSE_OUT,
81 ECORE_EVENT_AXIS_UPDATE,
82 ECORE_EVENT_MOUSE_BUTTON_CANCEL,
83 ECORE_EVENT_JOYSTICK);
84 ecore_input_joystick_shutdown();
85 eina_log_domain_unregister(_ecore_input_log_dom);
86 _ecore_input_log_dom = -1;
87 ecore_shutdown();
88 return _ecore_event_init_count;
89 }
90
91 typedef struct _Ecore_Event_Modifier_Match Ecore_Event_Modifier_Match;
92 struct _Ecore_Event_Modifier_Match
93 {
94 const char *key;
95 Ecore_Event_Modifier modifier;
96 unsigned int event_modifier;
97 };
98
99 static const Ecore_Event_Modifier_Match matchs[] = {
100 { "Shift_L", ECORE_SHIFT, ECORE_EVENT_MODIFIER_SHIFT },
101 { "Shift_R", ECORE_SHIFT, ECORE_EVENT_MODIFIER_SHIFT },
102 { "Alt_L", ECORE_ALT, ECORE_EVENT_MODIFIER_ALT },
103 { "Alt_R", ECORE_ALT, ECORE_EVENT_MODIFIER_ALT },
104 { "Control_L", ECORE_CTRL, ECORE_EVENT_MODIFIER_CTRL },
105 { "Control_R", ECORE_CTRL, ECORE_EVENT_MODIFIER_CTRL },
106 { "Caps_Lock", ECORE_CAPS, ECORE_EVENT_MODIFIER_CAPS },
107 { "Super_L", ECORE_WIN, ECORE_EVENT_MODIFIER_WIN },
108 { "Super_R", ECORE_WIN, ECORE_EVENT_MODIFIER_WIN },
109 { "ISO_Level3_Shift", ECORE_MODE, ECORE_EVENT_MODIFIER_ALTGR },
110 { "Scroll_Lock", ECORE_SCROLL, ECORE_EVENT_MODIFIER_SCROLL }
111 };
112
113 EAPI unsigned int
ecore_event_modifier_mask(Ecore_Event_Modifier modifier)114 ecore_event_modifier_mask(Ecore_Event_Modifier modifier)
115 {
116 size_t i;
117
118 for (i = 0; i < sizeof (matchs) / sizeof (Ecore_Event_Modifier_Match); i++)
119 if (matchs[i].modifier == modifier)
120 return matchs[i].event_modifier;
121
122 return 0;
123 }
124
125 EAPI Ecore_Event_Modifier
ecore_event_update_modifier(const char * key,Ecore_Event_Modifiers * modifiers,int inc)126 ecore_event_update_modifier(const char *key, Ecore_Event_Modifiers *modifiers, int inc)
127 {
128 size_t i;
129
130 for (i = 0; i < sizeof (matchs) / sizeof (Ecore_Event_Modifier_Match); i++)
131 if (strcmp(matchs[i].key, key) == 0)
132 {
133 if (modifiers && matchs[i].modifier < modifiers->size)
134 modifiers->array[matchs[i].modifier] += inc;
135 return matchs[i].modifier;
136 }
137
138 return ECORE_NONE;
139 }
140