2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
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.
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:
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.
23 #include "../../SDL_internal.h"
25 #if SDL_VIDEO_DRIVER_TIZEN
28 #include "SDL_stdinc.h"
29 #include "SDL_assert.h"
32 #include "SDL_tizenevents_c.h"
33 #include "SDL_tizenkeyboard.h"
35 #include "../../events/SDL_sysevents.h"
36 #include "../../events/SDL_events_c.h"
37 #include "../../events/scancodes_xfree86.h"
38 #include "../../events/scancodes_tizen.h"
40 extern TizenKeyboard tizen_keyboard;
43 TranslateKeycode(int keycode)
45 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
47 if (keycode < SDL_arraysize(Tizen_Keycodes)) {
48 scancode = Tizen_Keycodes[keycode];
50 if (scancode == SDL_SCANCODE_UNKNOWN) {
51 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Unknown keycode %d",keycode);
57 Tizen_PumpEvents(_THIS)
59 ecore_main_loop_iterate_may_block(0);
63 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
65 int modifier = ECORE_IMF_KEYBOARD_MODIFIER_NONE; // If no other matches returns NONE.
68 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
70 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
73 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
75 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
78 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
80 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
83 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
85 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
88 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
90 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
93 return (Ecore_IMF_Keyboard_Modifiers)modifier;
97 _tizen_cb_event_keyup_change(void *data, int type, void *event)
99 if (!event) return ECORE_CALLBACK_PASS_ON;
101 Ecore_Event_Key * e = event;
102 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
103 if (!e->key) return ECORE_CALLBACK_PASS_ON;
105 if (tizen_keyboard.imf_context) {
106 Ecore_IMF_Event_Key_Up ecore_ev;
108 ecore_ev.keyname = e->keyname;
109 ecore_ev.key = e->key;
110 ecore_ev.string = e->string;
111 ecore_ev.compose = e->compose;
112 ecore_ev.timestamp = e->timestamp;
113 ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers );
114 ecore_ev.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
116 if (ecore_imf_context_filter_event(tizen_keyboard.imf_context,
117 ECORE_IMF_EVENT_KEY_UP,
118 (Ecore_IMF_Event *)&ecore_ev)) {
119 return ECORE_CALLBACK_PASS_ON;
123 if (SDL_GetEventState(SDL_TEXTINPUT)) {
124 if (!strcmp(e->key, "BackSpace")) {
125 scancode = SDL_GetScancodeFromName(e->key);
126 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
128 else if (!strcmp(e->key, "Delete") ||
129 (!strcmp(e->key, "KP_Delete") && !e->string)) {
130 scancode = SDL_GetScancodeFromName(e->key);
131 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
133 else if ((!strcmp(e->key, "Return")) || (!strcmp(e->key, "KP_Enter"))) {
134 scancode = SDL_GetScancodeFromName(e->key);
135 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
137 else if (e->string) {
141 scancode = TranslateKeycode(e->keycode);
142 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
145 scancode = TranslateKeycode(e->keycode);
146 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
149 return ECORE_CALLBACK_PASS_ON;
153 _tizen_cb_event_keydown_change(void *data, int type, void *event)
155 if (!event) return ECORE_CALLBACK_PASS_ON;
157 Ecore_Event_Key * e = event;
158 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
159 if (!e->key) return ECORE_CALLBACK_PASS_ON;
161 if (tizen_keyboard.imf_context) {
162 Ecore_IMF_Event_Key_Down ecore_ev;
164 ecore_ev.keyname = e->keyname;
165 ecore_ev.key = e->key;
166 ecore_ev.string = e->string;
167 ecore_ev.compose = e->compose;
168 ecore_ev.timestamp = e->timestamp;
169 ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers );
170 ecore_ev.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
172 if (ecore_imf_context_filter_event(tizen_keyboard.imf_context,
173 ECORE_IMF_EVENT_KEY_DOWN,
174 (Ecore_IMF_Event *)&ecore_ev)) {
175 return ECORE_CALLBACK_PASS_ON;
179 if (SDL_GetEventState(SDL_TEXTINPUT)) {
180 if (!strcmp(e->key, "BackSpace")) {
181 scancode = SDL_GetScancodeFromName(e->key);
182 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
184 else if (!strcmp(e->key, "Delete") ||
185 (!strcmp(e->key, "KP_Delete") && !e->string)) {
186 scancode = SDL_GetScancodeFromName(e->key);
187 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
189 else if ((!strcmp(e->key, "Return")) || (!strcmp(e->key, "KP_Enter"))) {
190 scancode = SDL_GetScancodeFromName(e->key);
191 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
193 else if (e->string) {
194 SDL_SendKeyboardText(e->string);
197 scancode = TranslateKeycode(e->keycode);
198 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
201 scancode = TranslateKeycode(e->keycode);
202 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
205 return ECORE_CALLBACK_PASS_ON;
209 _tizen_cb_event_focus_in(void *data, int type EINA_UNUSED, void *event)
211 SDL_VideoDevice *_this = SDL_GetVideoDevice();
212 Ecore_Wl_Event_Focus_In *ev;
217 ew = ecore_wl_window_find(ev->win);
218 window = Tizen_FindWindow(_this, ew);
220 SDL_SetKeyboardFocus(window);
221 return ECORE_CALLBACK_PASS_ON;
225 _tizen_cb_event_focus_out(void *data, int type EINA_UNUSED, void *event)
227 SDL_SetKeyboardFocus(NULL);
228 return ECORE_CALLBACK_PASS_ON;
230 #endif /* SDL_VIDEO_DRIVER_TIZEN */
232 /* vi: set ts=4 sw=4 expandtab: */