summaryrefslogtreecommitdiff
path: root/src/lib/ecore_input/ecore_input.c
blob: 2954bcd2fc7642dbf143241832732e6d4cc5aebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#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;
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();
   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)
       {
          if (modifiers && matchs[i].modifier < modifiers->size)
            modifiers->array[matchs[i].modifier] += inc;
          return matchs[i].modifier;
       }

   return ECORE_NONE;
}