[tizen] internal feature - Input Skip
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenwindow.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_sysvideo.h"
28 #include "../../events/SDL_windowevents_c.h"
29 #include "../SDL_egl_c.h"
30 #include "SDL_tizenwindow.h"
31 #include "SDL_tizenvideo.h"
32 #include "SDL_tizentouch.h"
33 #include "SDL_tizenkeyboard.h"
34
35 #include "SDL_tizenmouse.h"
36 #include "SDL_tizenevents_c.h"
37 #include "SDL_log.h"
38 #include "../../events/SDL_mouse_c.h"
39
40 #include <wayland-egl.h>
41
42 SDL_bool
43 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
44 {
45     SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
46     SDL_VideoData  *video_data  = (SDL_VideoData *)_this->driverdata;
47
48 //    info->info.tizen.display = video_data->display;
49 //    info->info.tizen.surface = wmdata->surface;
50 //    info->info.tizen.shell_surface = NULL;
51     info->info.tizen.egl_display = NULL;
52     info->info.tizen.egl_surface = NULL;
53 #if SDL_VIDEO_OPENGL_EGL
54     if (_this->egl_data)
55     {
56        info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
57     }
58     info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
59 #endif
60     info->subsystem = SDL_SYSWM_TIZEN;
61     return SDL_TRUE;
62 }
63
64 int
65 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
66 {
67     return 0;  /* just succeed, the real work is done elsewhere. */
68 }
69
70 void
71 Tizen_ShowWindow(_THIS, SDL_Window *window)
72 {
73     SDL_WindowData *wind = window->driverdata;
74
75     ecore_wl_window_show(wind->window);
76 }
77
78 void
79 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
80                           SDL_VideoDisplay *_display, SDL_bool fullscreen)
81 {
82     /*DO NOTHING*/
83 }
84
85 int
86 Tizen_CreateWindow(_THIS, SDL_Window *window)
87 {
88     SDL_VideoData *data = _this->driverdata;
89     SDL_WindowData *wind;
90
91     wind = calloc(1, sizeof * wind);
92     if (!wind)
93         return SDL_OutOfMemory();
94
95     window->driverdata = wind;
96
97 #if SDL_VIDEO_OPENGL_EGL
98     if (window->flags & SDL_WINDOW_OPENGL) {
99         SDL_GL_LoadLibrary(NULL);
100     }
101 #endif
102
103     if (window->x == SDL_WINDOWPOS_UNDEFINED) {
104         window->x = 0;
105     }
106     if (window->y == SDL_WINDOWPOS_UNDEFINED) {
107         window->y = 0;
108     }
109
110     wind->window = ecore_wl_window_new(NULL,
111                                        window->x, window->y, window->w, window->h,
112                                        ECORE_WL_WINDOW_BUFFER_TYPE_SHM);
113     wind->surface = ecore_wl_window_surface_create(wind->window);
114     ecore_wl_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h);
115 #if SDL_VIDEO_OPENGL_EGL
116     if (window->flags & SDL_WINDOW_OPENGL) {
117         wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h);
118
119         /* Create the GLES window surface */
120         wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
121         if (wind->egl_surface == EGL_NO_SURFACE) {
122             return SDL_SetError("failed to create a window surface");
123         }
124     }
125 #endif
126
127     wind->id = ecore_wl_window_id_get(wind->window);
128     eina_hash_add(data->windows, &wind->id, window);
129
130     if(keyboard.imf_context == NULL)
131         Tizen_InitKeyboard(_this);
132
133     SDL_SetMouseFocus(window);
134
135     if (window->flags & 0x00008000) {
136         SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "---------------------------------------");
137         SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[SDL] touch bypass setting is done!\n");
138         SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "---------------------------------------");
139         ecore_wl_window_input_region_set(wind->window, -1, -1, 1, 1);
140         //ecore_wl_window_focus_skip_set(wind->window, EINA_TRUE);
141     }
142
143     return 0;
144 }
145
146 void
147 Tizen_SetWindowSize(_THIS, SDL_Window *window)
148 {
149     SDL_WindowData *wind = window->driverdata;
150 #if SDL_VIDEO_OPENGL_EGL
151     if (window->flags & SDL_WINDOW_OPENGL) {
152         ecore_wl_window_opaque_region_set(wind->window,window->x, window->y, window->w, window->h);
153         wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
154     }
155 #endif
156 }
157
158 void
159 Tizen_DestroyWindow(_THIS, SDL_Window *window)
160 {
161     SDL_VideoData *data = _this->driverdata;
162     SDL_WindowData *wind = window->driverdata;
163
164     if (data) {
165         eina_hash_del(data->windows, &wind->id, window);
166 #if SDL_VIDEO_OPENGL_EGL
167     if (window->flags & SDL_WINDOW_OPENGL) {
168         SDL_EGL_DestroySurface(_this, wind->egl_surface);
169         wl_egl_window_destroy(wind->egl_window);
170     }
171 #endif
172         ecore_wl_window_free(wind->window);
173         SDL_free(wind);
174     }
175
176     window->driverdata = NULL;
177 }
178
179 static SDL_Window*
180 __tizen_find_window(_THIS, Ecore_Wl_Window *ewin)
181 {
182     SDL_VideoData *data = _this->driverdata;
183     int id;
184
185     id = ecore_wl_window_id_get(ewin);
186     return (SDL_Window*)eina_hash_find(data->windows, &id);
187 }
188
189 static Eina_Bool
190 __tizen_cb_window_visibility_change(void *data, int type, void *event)
191 {
192     _THIS = data;
193     Ecore_Wl_Event_Window_Visibility_Change *ev;
194     Ecore_Wl_Window *ew;
195     SDL_Window *window;
196
197     ev = event;
198     ew = ecore_wl_window_find(ev->win);
199     window = __tizen_find_window(_this, ew);
200
201     SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "visibility window: %p, ecore_wl_window: %p\n", window, ew);
202
203     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
204     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
205
206     return ECORE_CALLBACK_PASS_ON;
207 }
208
209 int
210 Tizen_InitWindow(_THIS)
211 {
212     SDL_VideoData *data = _this->driverdata;
213
214     data->windows = eina_hash_int32_new(NULL);
215
216     ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
217                         __tizen_cb_window_visibility_change, _this);
218     ecore_event_handler_add(ECORE_EVENT_KEY_UP,
219                         __tizen_cb_event_keyup_change,  NULL);
220     ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
221                         __tizen_cb_event_keydown_change,        NULL);
222     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
223                         __tizen_cb_event_mousedown_change,      _this);
224     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
225                         __tizen_cb_event_mouseup_change,        _this);
226     ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
227                         __tizen_cb_event_mousemove_change,      _this);
228
229     return 0;
230 }
231
232 void
233 Tizen_DeinitWindow(_THIS)
234 {
235     SDL_VideoData *data = _this->driverdata;
236
237     eina_hash_free(data->windows);
238 }
239 #endif /* SDL_VIDEO_DRIVER_TIZEN */
240
241 /* vi: set ts=4 sw=4 expandtab: */