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