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
27 #include "SDL_stdinc.h"
28 #include "SDL_assert.h"
31 #include "SDL_tizenevents_c.h"
32 #include "SDL_tizenkeyboard.h"
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"
39 extern TizenKeyboard tizen_keyboard;
42 TranslateKeycode(int keycode)
44 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
46 if (keycode < SDL_arraysize(Tizen_Keycodes)) {
47 scancode = Tizen_Keycodes[keycode];
49 if (scancode == SDL_SCANCODE_UNKNOWN) {
50 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Unknown keycode %d",keycode);
56 Tizen_PumpEvents(_THIS)
58 ecore_main_loop_iterate_may_block(0);
61 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
63 int modifier = ECORE_IMF_KEYBOARD_MODIFIER_NONE; // If no other matches returns NONE.
66 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
68 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
71 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
73 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
76 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
78 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
81 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
83 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
86 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
88 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
91 return (Ecore_IMF_Keyboard_Modifiers)modifier;
95 _tizen_cb_event_keyup_change(void *data, int type, void *event)
97 if (!event) return ECORE_CALLBACK_PASS_ON;
99 Ecore_Event_Key * e = event;
100 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
101 if (!e->key) return ECORE_CALLBACK_PASS_ON;
103 if (tizen_keyboard.imf_context) {
104 Ecore_IMF_Event_Key_Up ecore_ev;
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);
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;
122 scancode = TranslateKeycode(e->keycode);
123 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
125 return ECORE_CALLBACK_PASS_ON;
129 _tizen_cb_event_keydown_change(void *data, int type, void *event)
131 if (!event) return ECORE_CALLBACK_PASS_ON;
133 Ecore_Event_Key * e = event;
134 SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
135 if (!e->key) return ECORE_CALLBACK_PASS_ON;
137 if (tizen_keyboard.imf_context) {
138 Ecore_IMF_Event_Key_Down ecore_ev;
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);
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;
156 scancode = TranslateKeycode(e->keycode);
157 SDL_SendKeyboardKey(SDL_PRESSED, scancode);
159 // Don't care that TEXTINPUT is enabled because SendKeyboardText() handles it.
161 SDL_SendKeyboardText(e->string);
164 return ECORE_CALLBACK_PASS_ON;
168 _tizen_cb_event_focus_in(void *data, int type EINA_UNUSED, void *event)
170 SDL_VideoDevice *_this = SDL_GetVideoDevice();
171 Ecore_Wl2_Event_Focus_In *ev;
172 Ecore_Wl2_Window *ew;
173 Ecore_Wl2_Display *wl2_display;
177 wl2_display = ecore_wl2_connected_display_get(NULL);
179 ew = ecore_wl2_display_window_find(wl2_display, ev->window);
180 window = Tizen_FindWindow(_this, ew);
182 SDL_SetKeyboardFocus(window);
183 return ECORE_CALLBACK_PASS_ON;
187 _tizen_cb_event_focus_out(void *data, int type EINA_UNUSED, void *event)
189 SDL_SetKeyboardFocus(NULL);
190 return ECORE_CALLBACK_PASS_ON;
192 #endif /* SDL_VIDEO_DRIVER_TIZEN */
194 /* vi: set ts=4 sw=4 expandtab: */