[SDL] Add Key and Mouse Event
[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 && SDL_VIDEO_OPENGL_EGL
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
34 #include "SDL_tizenmouse.h"
35 #include "SDL_tizenevents_c.h"
36
37 #include <wayland-egl.h>
38
39 SDL_bool
40 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
41 {
42     TRACE_ENTER();
43     return SDL_TRUE;
44 }
45
46 int
47 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
48 {
49     TRACE_ENTER();
50     return 0;  /* just succeed, the real work is done elsewhere. */
51 }
52
53 void
54 Tizen_ShowWindow(_THIS, SDL_Window *window)
55 {
56     TRACE_ENTER();
57     SDL_WindowData *wind = window->driverdata;
58
59     ecore_wl_window_show(wind->window);
60 }
61
62 void
63 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
64                           SDL_VideoDisplay *_display, SDL_bool fullscreen)
65 {
66     TRACE_ENTER();
67     /*DO NOTHING*/
68 }
69
70 int
71 Tizen_CreateWindow(_THIS, SDL_Window *window)
72 {
73     TRACE_ENTER();
74     SDL_VideoData *data = _this->driverdata;
75     SDL_WindowData *wind;
76
77     wind = calloc(1, sizeof * wind);
78     if (wind == NULL)
79         return SDL_OutOfMemory();
80
81     window->driverdata = wind;
82
83     if (!(window->flags & SDL_WINDOW_OPENGL)) {
84         SDL_GL_LoadLibrary(NULL);
85         window->flags |= SDL_WINDOW_OPENGL;
86     }
87
88     if (window->x == SDL_WINDOWPOS_UNDEFINED) {
89         window->x = 0;
90     }
91     if (window->y == SDL_WINDOWPOS_UNDEFINED) {
92         window->y = 0;
93     }
94
95     wind->window = ecore_wl_window_new(NULL,
96                                        window->x, window->y, window->w, window->h,
97                                        ECORE_WL_WINDOW_BUFFER_TYPE_SHM);
98     ecore_wl_window_surface_create(wind->window);
99
100     wind->egl_window = wl_egl_window_create(ecore_wl_window_surface_get(wind->window), window->w, window->h);
101
102     /* Create the GLES window surface */
103     wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
104     if (wind->egl_surface == EGL_NO_SURFACE) {
105         return SDL_SetError("failed to create a window surface");
106     }
107
108     wind->id = ecore_wl_window_id_get(wind->window);
109     eina_hash_add(data->windows, &wind->id, window);
110
111     return 0;
112 }
113
114 void
115 Tizen_SetWindowSize(_THIS, SDL_Window *window)
116 {
117     TRACE_ENTER();
118     SDL_WindowData *wind = window->driverdata;
119
120     wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
121 }
122
123 void
124 Tizen_DestroyWindow(_THIS, SDL_Window *window)
125 {
126     TRACE_ENTER();
127     SDL_VideoData *data = _this->driverdata;
128     SDL_WindowData *wind = window->driverdata;
129
130     if (data) {
131         eina_hash_del(data->windows, &wind->id, window);
132
133         SDL_EGL_DestroySurface(_this, wind->egl_surface);
134         wl_egl_window_destroy(wind->egl_window);
135         ecore_wl_window_free(wind->window);
136
137         SDL_free(wind);
138     }
139
140     window->driverdata = NULL;
141 }
142
143 static SDL_Window*
144 __tizen_find_window(_THIS, Ecore_Wl_Window *ewin)
145 {
146     SDL_VideoData *data = _this->driverdata;
147     int id;
148
149     id = ecore_wl_window_id_get(ewin);
150     return (SDL_Window*)eina_hash_find(data->windows, &id);
151 }
152
153 static Eina_Bool
154 __tizen_cb_window_visibility_change(void *data, int type, void *event)
155 {
156     _THIS = data;
157     Ecore_Wl_Event_Window_Visibility_Change *ev;
158     Ecore_Wl_Window *ew;
159     SDL_Window *window;
160
161     ev = event;
162     ew = ecore_wl_window_find(ev->win);
163     window = __tizen_find_window(_this, ew);
164
165     printf("SAMPLE EV : visibility window:%p, ecore_wl_window:%p\n", window, ew);
166     
167     return ECORE_CALLBACK_PASS_ON;
168 }
169
170 int 
171 Tizen_InitWindow(_THIS)
172 {
173     TRACE_ENTER();
174     SDL_VideoData *data = _this->driverdata;
175
176     data->windows = eina_hash_int32_new(NULL);
177     
178     ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
179                         __tizen_cb_window_visibility_change, _this);
180     ecore_event_handler_add(ECORE_EVENT_KEY_UP,
181                         __tizen_cb_event_keyup_change,  NULL);
182     ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
183                         __tizen_cb_event_keydown_change,        NULL);
184
185     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
186                         __tizen_cb_event_mousedown_change,      _this);
187     ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
188                         __tizen_cb_event_mouseup_change,        _this);
189     ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
190                         __tizen_cb_event_mousemove_change,      _this);
191
192     return 0;
193 }
194
195 void
196 Tizen_DeinitWindow(_THIS)
197 {
198     TRACE_ENTER();
199     SDL_VideoData *data = _this->driverdata;
200
201     eina_hash_free(data->windows);
202 }
203 #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
204
205 /* vi: set ts=4 sw=4 expandtab: */