Change std:vector to eina_array
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenevents.c
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4   Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5
6   This software is provided 'as-is', without any express or implied
7   warranty.  In no event will the authors be held liable for any damages
8   arising from the use of this software.
9
10   Permission is granted to anyone to use this software for any purpose,
11   including commercial applications, and to alter it and redistribute it
12   freely, subject to the following restrictions:
13
14   1. The origin of this software must not be misrepresented; you must not
15      claim that you wrote the original software. If you use this software
16      in a product, an acknowledgment in the product documentation would be
17      appreciated but is not required.
18   2. Altered source versions must be plainly marked as such, and must not be
19      misrepresented as being the original software.
20   3. This notice may not be removed or altered from any source distribution.
21 */
22
23 #include "../../SDL_internal.h"
24
25 #if SDL_VIDEO_DRIVER_TIZEN
26
27 #include "SDL_stdinc.h"
28 #include "SDL_assert.h"
29 #include "SDL_log.h"
30
31 #include "SDL_tizenevents_c.h"
32 #include "SDL_tizenkeyboard.h"
33
34 #include "../../events/SDL_sysevents.h"
35 #include "../../events/SDL_events_c.h"
36 #include "../../events/scancodes_xfree86.h"
37 #include "../../events/scancodes_tizen.h"
38
39 extern TizenKeyboard tizen_keyboard;
40
41 static SDL_Scancode
42 TranslateKeycode(int keycode)
43 {
44     SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
45
46     if (keycode < SDL_arraysize(Tizen_Keycodes)) {
47         scancode = Tizen_Keycodes[keycode];
48     }
49     if (scancode == SDL_SCANCODE_UNKNOWN) {
50         SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Unknown keycode %d",keycode);
51     }
52     return scancode;
53 }
54
55 void
56 Tizen_PumpEvents(_THIS)
57 {
58     ecore_main_loop_iterate_may_block(0);
59 }
60
61 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
62 {
63    int modifier =  ECORE_IMF_KEYBOARD_MODIFIER_NONE;  // If no other matches returns NONE.
64
65
66    if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h
67    {
68      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h
69    }
70
71    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
72    {
73      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
74    }
75
76    if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
77    {
78      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
79    }
80
81    if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
82    {
83      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
84    }
85
86    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
87    {
88      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
89    }
90
91    return (Ecore_IMF_Keyboard_Modifiers)modifier;
92 }
93
94 Eina_Bool
95 _tizen_cb_event_keyup_change(void *data, int type, void *event)
96 {
97     if (!event) return ECORE_CALLBACK_PASS_ON;
98
99     Ecore_Event_Key * e = event;
100     SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
101     if (!e->key) return ECORE_CALLBACK_PASS_ON;
102
103     if (tizen_keyboard.imf_context) {
104         Ecore_IMF_Event_Key_Up ecore_ev;
105
106         ecore_ev.keyname   = e->keyname;
107         ecore_ev.key       = e->key;
108         ecore_ev.string    = e->string;
109         ecore_ev.compose   = e->compose;
110         ecore_ev.timestamp = e->timestamp;
111         ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers );
112         ecore_ev.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
113         ecore_ev.dev_name  = ecore_device_name_get(e->dev);
114
115         if (ecore_imf_context_filter_event(tizen_keyboard.imf_context,
116                                            ECORE_IMF_EVENT_KEY_UP,
117                                            (Ecore_IMF_Event *)&ecore_ev)) {
118             return ECORE_CALLBACK_PASS_ON;
119         }
120     }
121
122     scancode = TranslateKeycode(e->keycode);
123     SDL_SendKeyboardKey(SDL_RELEASED, scancode);
124
125     return ECORE_CALLBACK_PASS_ON;
126 }
127
128 Eina_Bool
129 _tizen_cb_event_keydown_change(void *data, int type, void *event)
130 {
131     if (!event) return ECORE_CALLBACK_PASS_ON;
132
133     Ecore_Event_Key * e = event;
134     SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
135     if (!e->key) return ECORE_CALLBACK_PASS_ON;
136
137     if (tizen_keyboard.imf_context) {
138         Ecore_IMF_Event_Key_Down ecore_ev;
139
140         ecore_ev.keyname   = e->keyname;
141         ecore_ev.key       = e->key;
142         ecore_ev.string    = e->string;
143         ecore_ev.compose   = e->compose;
144         ecore_ev.timestamp = e->timestamp;
145         ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers );
146         ecore_ev.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
147         ecore_ev.dev_name  = ecore_device_name_get(e->dev);
148
149         if (ecore_imf_context_filter_event(tizen_keyboard.imf_context,
150                                            ECORE_IMF_EVENT_KEY_DOWN,
151                                            (Ecore_IMF_Event *)&ecore_ev)) {
152             return ECORE_CALLBACK_PASS_ON;
153         }
154     }
155
156     scancode = TranslateKeycode(e->keycode);
157     SDL_SendKeyboardKey(SDL_PRESSED, scancode);
158
159     // Don't care that TEXTINPUT is enabled because SendKeyboardText() handles it.
160     if (e->string) {
161         SDL_SendKeyboardText(e->string);
162     }
163
164     return ECORE_CALLBACK_PASS_ON;
165 }
166
167 Eina_Bool
168 _tizen_cb_event_focus_in(void *data, int type EINA_UNUSED, void *event)
169 {
170     SDL_VideoDevice *_this = SDL_GetVideoDevice();
171     Ecore_Wl2_Event_Focus_In *ev;
172     Ecore_Wl2_Window *ew;
173     Ecore_Wl2_Display *wl2_display;
174     SDL_Window *window;
175
176     ev = event;
177     wl2_display = ecore_wl2_connected_display_get(NULL);
178
179     ew = ecore_wl2_display_window_find(wl2_display, ev->window);
180     window = Tizen_FindWindow(_this, ew);
181
182     SDL_SetKeyboardFocus(window);
183     return ECORE_CALLBACK_PASS_ON;
184 }
185
186 Eina_Bool
187 _tizen_cb_event_focus_out(void *data, int type EINA_UNUSED, void *event)
188 {
189     SDL_SetKeyboardFocus(NULL);
190     return ECORE_CALLBACK_PASS_ON;
191 }
192 #endif /* SDL_VIDEO_DRIVER_TIZEN */
193
194 /* vi: set ts=4 sw=4 expandtab: */