3b75b2c2f134b990ab8dea5967b0cb33749db9f9
[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_log.h"
28 #include "SDL_hints.h"
29 #include "SDL_loadso.h"
30
31 #include "SDL_tizenvideo.h"
32 #include "SDL_tizentouch.h"
33 #include "SDL_tizenkeyboard.h"
34 #include "SDL_tizenmouse.h"
35 #include "SDL_tizenevents_c.h"
36
37 #include "SDL_tizenwindow.h"
38 #include "SDL_tizenopengles.h"
39
40 #include "../../events/SDL_mouse_c.h"
41 #include "../../joystick/tizen/SDL_sysjoystick_c.h"
42
43 #include "../SDL_egl_c.h"
44 #include "../SDL_sysvideo.h"
45 #include "../../events/SDL_windowevents_c.h"
46
47 #include <Ecore_Ipc.h>
48 #include <Ecore_Wl2.h>
49 #include <unistd.h>
50 #include <string.h>
51
52 /*SDL indicator*/
53 Ecore_Ipc_Server *ipc = NULL;
54 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
55
56 #define IPC_HEAD(_type) \
57    Ecore_Ipc_Event_Client_##_type *e = event; \
58    if (ecore_ipc_client_server_get(e->client) != ipc) \
59      return ECORE_CALLBACK_PASS_ON
60
61 void _tizen_quickpanel_on(SDL_WindowData *wind)
62 {
63     SDL_Log("[SDL]Quick panel on");
64     ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_ON);
65     ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_SHOWN);
66 }
67
68 void _tizen_quickpanel_off(SDL_WindowData *wind)
69 {
70     SDL_Log("[SDL]Quick panel off");
71     ecore_wl2_window_indicator_state_set(wind->window, ECORE_WL2_INDICATOR_STATE_OFF);
72     ecore_wl2_indicator_visible_type_set(wind->window, ECORE_WL2_INDICATOR_VISIBLE_TYPE_HIDDEN);
73 }
74
75 void Tizen_ExecuteIndicatorProcess(SDL_WindowData *wind)
76 {
77     SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
78     if(!videoData) return;
79
80     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Tizen Indicator is not supported");
81 }
82
83 void
84 Tizen_TerminateIndicatorProcess(SDL_WindowData *wind)
85 {
86     if(!wind) return;
87
88     SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
89     if(videoData->indicator_on)
90     {
91         _tizen_ecore_ipc_client_send(OP_TERMINATE, 0, 0, 0);
92         _tizen_quickpanel_off(wind);
93     }
94 }
95
96 void
97 Tizen_chk_indicator(SDL_Window *window)
98 {
99     SDL_WindowData *wind = window->driverdata;
100     int screen_w, screen_h;
101     int rotation = wind->rotation % 360;
102     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
103
104     if(rotation % 180 == 0)
105         ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
106     else
107         ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
108
109     if(window->w == screen_w && window->h == screen_h && window->x == 0 && window->y == 0 && !(window->flags & SDL_WINDOW_BORDERLESS))
110     {
111         SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
112         if(!videoData->indicator_on)
113         {
114             wind->support_indicator = SDL_TRUE;
115             Tizen_ExecuteIndicatorProcess(wind);
116         }
117     }
118     else
119     {
120         wind->support_indicator = SDL_FALSE;
121         Tizen_TerminateIndicatorProcess(wind);
122     }
123 }
124
125 void
126 _tizen_ecore_ipc_client_send(int major, int minor, int ref, int ref_to)
127 {
128     Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
129     Eina_List *l;
130     Ecore_Ipc_Client *cl;
131     EINA_LIST_FOREACH(ipc_clients, l, cl)
132     ecore_ipc_client_send(cl, major, minor, ref, ref_to, 0, NULL, 0);
133 }
134
135 static Eina_Bool
136 _cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
137 {
138     IPC_HEAD(Add);
139
140     SDL_Log("[SDL]_cb_client_add");
141
142     SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
143     videoData->indicator_on = SDL_TRUE;
144
145     SDL_Window * window = SDL_GetVideoDevice()->windows;
146     SDL_WindowData *wind = window->driverdata;
147
148     int window_w, window_h;
149     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
150
151     ecore_wl2_display_screen_size_get(wl2_display, &window_w, &window_h);
152
153     _tizen_ecore_ipc_client_send(OP_INDICATOR_SHOW, wind->rotation, wind->g_res_id, videoData->indicator_mode);
154
155     return ECORE_CALLBACK_DONE;
156 }
157
158 static Eina_Bool
159 _cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
160 {
161     IPC_HEAD(Del);
162     SDL_Log("[SDL]_cb_client_del");
163     Eina_List *ipc_clients = ecore_ipc_server_clients_get(ipc);
164     Eina_List *l;
165     Ecore_Ipc_Client *cl;
166     EINA_LIST_FOREACH(ipc_clients, l, cl)
167     {
168         ecore_ipc_client_del(cl);
169     }
170
171     SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
172     videoData->indicator_on = SDL_FALSE;
173
174     return ECORE_CALLBACK_DONE;
175 }
176
177 static Eina_Bool
178 _cb_client_data(void *data, int type EINA_UNUSED, void *event)
179 {
180     IPC_HEAD(Data);
181
182     Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)event;
183     SDL_Log("[SDL]_cb_client_data: %d -> %d", epcEvent->major, epcEvent->minor);
184
185     SDL_VideoData* videoData = SDL_GetVideoDevice()->driverdata;
186     SDL_Window * window = (SDL_Window*)eina_hash_find(videoData->windows, &videoData->indicator_parent_id);
187     if (!window)
188     {
189         SDL_Log("window is null");
190         return ECORE_CALLBACK_PASS_ON;
191     }
192
193     switch(epcEvent->major)
194     {
195     case OP_INDICATOR_INIT:
196         videoData->indicator_height = epcEvent->minor;
197         _tizen_quickpanel_on(window->driverdata);
198     break;
199     case OP_INDICATOR_SHOW:
200         videoData->indicator_visible = SDL_TRUE;
201     break;
202     case OP_INDICATOR_HIDE:
203         if(epcEvent->minor == 1)
204         {
205             _tizen_quickpanel_off(window->driverdata);
206         }
207         else if(epcEvent->minor == 2)
208         {
209             videoData->indicator_visible = SDL_FALSE;
210         }
211     break;
212     case OP_TERMINATE:
213         videoData->indicator_on = SDL_FALSE;
214         videoData->indicator_visible = SDL_FALSE;
215     break;
216     }
217
218     return ECORE_CALLBACK_DONE;
219 }
220
221 int
222 _tizen_init_ecore_ipc()
223 {
224
225     if(!ipc)
226     {
227         if(!ecore_ipc_init())
228             SDL_Log("[SDL]Fail ecore_ipc");
229
230         ipc = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, "sdl_indicator", 0, NULL);
231
232         if(!ipc)
233             ecore_ipc_shutdown();
234
235         mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _cb_client_add, NULL));
236         mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _cb_client_del, NULL));
237         mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _cb_client_data, NULL));
238     }
239     return 0;
240 }
241
242 SDL_bool
243 Tizen_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
244 {
245     SDL_WindowData *wmdata = (SDL_WindowData *)window->driverdata;
246     info->info.tizen.egl_display = NULL;
247     info->info.tizen.egl_surface = NULL;
248 #if SDL_VIDEO_OPENGL_EGL
249     if (_this->egl_data)
250     {
251        info->info.tizen.egl_display = (void*)_this->egl_data->egl_display;
252     }
253     info->info.tizen.egl_surface = (void*)wmdata->egl_surface;
254 #endif
255     info->subsystem = SDL_SYSWM_TIZEN;
256     return SDL_TRUE;
257 }
258
259 int
260 Tizen_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
261 {
262     return 0;  /* just succeed, the real work is done elsewhere. */
263 }
264
265 void
266 Tizen_SetWindowTitle(_THIS, SDL_Window * window)
267 {
268     SDL_WindowData *wind = window->driverdata;
269     ecore_wl2_window_title_set(wind->window, window->title);
270 }
271
272 void
273 Tizen_ShowWindow(_THIS, SDL_Window *window)
274 {
275     SDL_WindowData *wind = window->driverdata;
276     ecore_wl2_window_show(wind->window);
277 }
278
279
280 void
281 Tizen_HideWindow(_THIS, SDL_Window *window)
282 {
283     SDL_WindowData *wind = window->driverdata;
284     ecore_wl2_window_hide(wind->window);
285 }
286
287 void
288 Tizen_RaiseWindow(_THIS, SDL_Window *window)
289 {
290     SDL_WindowData *wind = window->driverdata;
291     ecore_wl2_window_iconified_set(wind->window, SDL_FALSE);
292     ecore_wl2_window_raise(wind->window);
293 }
294
295 void
296 Tizen_SetWindowFullscreen(_THIS, SDL_Window *window,
297                           SDL_VideoDisplay *_display, SDL_bool fullscreen)
298 {
299     SDL_WindowData *wind = window->driverdata;
300     if(!wind) return;
301
302     int screen_w, screen_h;
303     int rotation = (wind->output_rotation + wind->rotation) % 360;
304     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
305
306     if(rotation == 90 || rotation == 270)
307         ecore_wl2_display_screen_size_get(wl2_display, &screen_h, &screen_w);
308     else
309         ecore_wl2_display_screen_size_get(wl2_display, &screen_w, &screen_h);
310
311     _tizen_set_window_size(window, screen_w, screen_h);
312     Tizen_SetWindowSize(_this, window);
313
314     window->fullscreen_mode.w = screen_w;
315     window->fullscreen_mode.h = screen_h;
316 }
317
318 void
319 _tizen_set_window_size(SDL_Window * window, int w, int h)
320 {
321     if(!window)
322     {
323         SDL_SetError("Invalid window");
324         return;
325     }
326
327     SDL_VideoDevice *_this = SDL_GetVideoDevice();
328     if (!_this) {
329         SDL_SetError("Video subsystem has not been initialized");
330         return;
331     }
332
333     if (window->magic != &_this->window_magic) {
334         return;
335     }
336
337     if (w <= 0) {
338         SDL_InvalidParamError("w");
339         return;
340     }
341     if (h <= 0) {
342         SDL_InvalidParamError("h");
343         return;
344     }
345
346     /* Make sure we don't exceed any window size limits */
347     if (window->min_w && w < window->min_w)
348     {
349         w = window->min_w;
350     }
351     if (window->max_w && w > window->max_w)
352     {
353         w = window->max_w;
354     }
355     if (window->min_h && h < window->min_h)
356     {
357         h = window->min_h;
358     }
359     if (window->max_h && h > window->max_h)
360     {
361         h = window->max_h;
362     }
363
364     if(window->flags & SDL_WINDOW_FULLSCREEN)
365     {
366         window->fullscreen_mode.w = w;
367         window->fullscreen_mode.h = h;
368     }
369
370     window->windowed.w = w;
371     window->windowed.h = h;
372
373     window->w = w;
374     window->h = h;
375 }
376
377 void
378 _tizen_send_rotation_event(SDL_Window *window, unsigned int angle)
379 {
380     SDL_Event event;
381     SDL_WindowData *wind;
382     wind = window->driverdata;
383
384     SDL_memset(&event, 0, sizeof(event));
385     event.type = SDL_ROTATEEVENT;
386     event.user.code = 0;
387     if (wind->support_pre_rotation)
388         event.user.data1 = (void*)0;
389     else
390         event.user.data1 = (void*)angle;
391     event.user.data2 = (void*)-1;
392
393     SDL_PushEvent(&event);
394     return;
395 }
396
397 int
398 _tizen_get_rotation_idx(int rotation)
399 {
400     return ((rotation % 360) / 90);
401 }
402
403 void
404 _tizen_rotation_do(SDL_Window *window, SDL_WindowData* wind, int rotation)
405 {
406     int window_w, window_h;
407     if(wind->rotation == 0 || wind->rotation == 180)
408         ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_w, &window_h);
409     else
410         ecore_wl2_window_geometry_get(wind->window, 0, 0, &window_h, &window_w);
411
412     _tizen_set_window_size(window, window_w, window_h);
413
414 #if SDL_VIDEO_OPENGL_EGL
415     if (window->flags & SDL_WINDOW_OPENGL)
416     {
417         if(wind->support_pre_rotation)
418         {
419             wl_egl_window_tizen_set_rotation(wind->egl_window, 360 - rotation);
420             wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx(rotation));
421             wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(wind->rotation));
422         }
423         else
424         {
425             wl_egl_window_resize(wind->egl_window, window_w, window_h, 0, 0);
426             wl_egl_window_tizen_set_buffer_transform(wind->egl_window, _tizen_get_rotation_idx((360 - wind->rotation)));
427             wl_egl_window_tizen_set_window_transform(wind->egl_window, _tizen_get_rotation_idx(0));
428         }
429     }
430 #endif
431     _tizen_send_rotation_event(window, 0);
432     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
433
434 }
435
436 void
437 Tizen_rotate_update(SDL_Window *window)
438 {
439     SDL_WindowData *wind = window->driverdata;
440     if(!wind) return;
441
442     int screen_rotation;
443     if (ecore_wl2_window_ignore_output_transform_get(wind->window))
444     {
445         screen_rotation = 0;
446     }
447     else
448     {
449         Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
450         screen_rotation = ecore_wl2_output_transform_get(output) * 90;
451     }
452
453     //Set Screen Rotation
454     wind->output_rotation = screen_rotation;
455
456     ecore_wl2_window_rotation_set(wind->window, wind->rotation);
457
458     int rotation = (wind->output_rotation + wind->rotation) % 360;
459     _tizen_rotation_do(window, wind, rotation);
460 }
461
462 SDL_Window*
463 Tizen_FindWindow(_THIS, Ecore_Wl2_Window *ewin)
464 {
465     SDL_VideoData *data = _this->driverdata;
466     int id;
467
468     id = ecore_wl2_window_id_get(ewin);
469     return (SDL_Window*)eina_hash_find(data->windows, &id);
470 }
471
472 void
473 _tizen_window_orientaiton_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
474 {
475     char *p_str = NULL;
476     char orientation_type[4][20] = {"Portrait","LandscapeLeft","PortraitUpsideDown","LandscapeRight"};
477     int checked[4] = {0,};
478     int i;
479     unsigned int j = 0;
480     SDL_WindowData *wind = (SDL_WindowData*)userdata;
481     Ecore_Wl2_Window *window = wind->window;
482
483     if (wind->rotation_supported == 0)
484         return;
485
486     SDL_assert(SDL_strncmp(name, SDL_HINT_ORIENTATIONS, SDL_strlen(SDL_HINT_ORIENTATIONS)) == 0);
487
488     if ((oldValue == NULL) && (newValue == NULL))
489         return;
490
491     for (i=0;i<4;i++) {
492         p_str = SDL_strstr(newValue, orientation_type[i]);
493         if (p_str) {
494             if (p_str == newValue) {
495                 int rot = 0;
496                 if (i == 0) rot = 0;
497                 else if (i == 1) rot = 90;
498                 else if (i == 2) rot = 180;
499                 else if (i == 3) rot = 270;
500                 wind->rotation = rot;
501             }
502
503             if (i == 0) {
504                 checked[j] = 0;
505             }
506             else if (i == 1) {
507                 checked[j] = 90;
508             }
509             else if (i == 2) {
510                 checked[j] = 180;
511             }
512             else if (i == 3) {
513                 checked[j] = 270;
514             }
515             j++;
516         }
517     }
518
519     if (j > 0) {
520         if (j == 1) {
521             ecore_wl2_window_preferred_rotation_set(window, wind->rotation);
522         }else {
523             ecore_wl2_window_available_rotations_set(window, (const int*)checked, j);
524         }
525     }
526
527     SDL_Window *sdl_window = Tizen_FindWindow(SDL_GetVideoDevice(), window);
528     if (!sdl_window)
529     {
530         SDL_Log("Rotate error: sdl_window is null");
531         return;
532     }
533
534     Tizen_rotate_update(sdl_window);
535 }
536
537 void
538 _tizen_window_orientation_add_hint(void *data)
539 {
540     SDL_WindowData *wind = (SDL_WindowData*)data;
541     if (wind->rotation_supported == 0)
542         return;
543
544     SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, _tizen_window_orientaiton_hint_callback, data);
545 }
546
547 static Eina_Bool
548 _tizen_cb_output_transform(void *data, int type EINA_UNUSED, void *event)
549 {
550     SDL_Window * window = SDL_GetVideoDevice()->windows;
551     SDL_WindowData *wind = window->driverdata;
552
553     if(!wind) return ECORE_CALLBACK_PASS_ON;
554
555     Ecore_Wl2_Event_Output_Transform *ev = event;
556     Ecore_Wl2_Output *output;
557
558     output = ecore_wl2_window_output_find(wind->window);
559     if (output != ev->output) return ECORE_CALLBACK_PASS_ON;
560
561     wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
562
563
564    return ECORE_CALLBACK_PASS_ON;
565 }
566
567 static Eina_Bool
568 _tizen_cb_ignore_output_transform(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
569 {
570     SDL_Window * window = SDL_GetVideoDevice()->windows;
571     SDL_WindowData *wind = window->driverdata;
572
573     if(!wind) return ECORE_CALLBACK_PASS_ON;
574
575     wind->received_rotation = TIZEN_ROTATION_RECEIVED_SCREEN_ROTATION;
576
577    return ECORE_CALLBACK_PASS_ON;
578 }
579
580 void
581 _tizen_output_transform_register(SDL_WindowData *wind)
582 {
583     if(!wind) return;
584
585     Ecore_Wl2_Output *output = ecore_wl2_window_output_find(wind->window);
586     wind->output_rotation = ecore_wl2_output_transform_get(output) * 90;
587
588     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM,
589                              _tizen_cb_output_transform, NULL));
590     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,
591                              _tizen_cb_ignore_output_transform, NULL));
592 }
593
594 void
595 _tizen_indicator_opacity_hint_callback(void *userdata, const char *name, const char *oldValue, const char *newValue)
596 {
597     SDL_VideoData *data = (SDL_VideoData *)userdata;
598
599     if ((oldValue == NULL) && (newValue == NULL))
600         return;
601
602     SDL_assert(SDL_strncmp(name, SDL_HINT_TIZEN_INDICATOR_OPACITY, SDL_strlen(SDL_HINT_TIZEN_INDICATOR_OPACITY)) == 0);
603     char indicator_type[4][20] = {"opaque","translucent","transparent","bg_transparent"};
604     for (int i=0;i<4;i++) {
605         if(SDL_strncmp(newValue, indicator_type[i], SDL_strlen(indicator_type[i])) == 0)
606         {
607             data->indicator_mode = i+1;
608             break;
609         }
610     }
611 }
612
613 unsigned int
614 SDL_Tizen_GetSupportedAuxiliaryHintCount(SDL_Window *window)
615 {
616     SDL_WindowData *wind = NULL;
617     Ecore_Wl2_Window *ecore_window = NULL;
618     Eina_List* hints = NULL;
619
620     if (!window || !window->driverdata) {
621         return 0;
622     }
623
624     wind = (SDL_WindowData *) window->driverdata;
625     ecore_window = wind->window;
626     if (!ecore_window) {
627         SDL_Log("AddAuxiliaryHint: ecore_window is null");
628         return 0;
629     }
630
631     hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
632     int count = 0;
633     if (hints) {
634         Eina_List* l = NULL;
635         for (l = hints; l; l = eina_list_next(l)) {
636             count++;
637         }
638     }
639     return count;
640 }
641
642 const char*
643 SDL_Tizen_GetSupportedAuxiliaryHint(SDL_Window *window, unsigned int index)
644 {
645     SDL_WindowData *wind = NULL;
646     Ecore_Wl2_Window *ecore_window = NULL;
647     Eina_List* hints = NULL;
648
649     if (!window || !window->driverdata) {
650         return NULL;
651     }
652
653     wind = (SDL_WindowData *) window->driverdata;
654     ecore_window = wind->window;
655     if (!ecore_window) {
656         SDL_Log("AddAuxiliaryHint: ecore_window is null");
657         return NULL;
658     }
659
660     hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
661
662     if (hints) {
663         Eina_List* l = NULL;
664         char* supported_hint = NULL;
665         int i = 0;
666         for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l), (supported_hint = (char*)(eina_list_data_get(l)))) {
667             if (i == index) {
668                 return supported_hint;
669             }
670             i++;
671         }
672     }
673     return NULL;
674 }
675
676 Ecore_Wl2_Window*
677 SDL_Tizen_GetNativeWindow(SDL_Window *window)
678 {
679     SDL_WindowData *wind = NULL;
680     Ecore_Wl2_Window *ecore_window = NULL;
681
682     if (!window || !window->driverdata) {
683         return NULL;
684     }
685
686     wind = (SDL_WindowData *) window->driverdata;
687     if (wind->window) {
688         ecore_window = wind->window;
689     }
690
691     return ecore_window;
692 }
693
694 unsigned int
695 SDL_Tizen_AddAuxiliaryHint(SDL_Window *window, const char *hint, const char *value)
696 {
697     SDL_WindowData *wind = NULL;
698     Ecore_Wl2_Window *ecore_window = NULL;
699     Eina_List* hints = NULL;
700     SDL_bool supported = SDL_FALSE;
701
702     if (!window || !window->driverdata) {
703         return 0;
704     }
705
706     wind = (SDL_WindowData *) window->driverdata;
707     ecore_window = wind->window;
708     if (!ecore_window) {
709         SDL_Log("AddAuxiliaryHint: ecore_window is null");
710         return 0;
711     }
712
713     hints = ecore_wl2_window_aux_hints_supported_get(ecore_window);
714     if (hints) {
715         Eina_List* l = NULL;
716         char* supported_hint = NULL;
717         for (l = hints, (supported_hint = (char*)(eina_list_data_get(l))); l; l = eina_list_next(l),
718             (supported_hint = (char*)(eina_list_data_get(l)))) {
719             if (!SDL_strncmp(supported_hint, hint, strlen(hint))) {
720                  supported = SDL_TRUE;
721                  break;
722             }
723
724         }
725     }
726
727     if (!supported) {
728         SDL_Log("AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint);
729         return 0;
730     }
731
732     unsigned int new_id = 1;
733     if ((wind->auxiliaryHints).auxHintHeader) {
734         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
735         AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
736         while (auxiliaryHint) {
737             if (!SDL_strncmp(auxiliaryHint->hint, hint, strlen(hint))) {
738                 auxiliaryHint->value = value;
739                 SDL_Log("AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", auxiliaryHint->hint, auxiliaryHint->value, auxiliaryHint->id);
740                 return auxiliaryHint->id;
741             }
742             auxiliaryHint = nextAuxiliaryHint;
743             nextAuxiliaryHint = NULL;
744             if(auxiliaryHint) {
745                 nextAuxiliaryHint = auxiliaryHint->next;
746             }
747             new_id++;
748         }
749     }
750
751     // Add the hint
752     AuxiliaryHint* newAuxiliaryHint = (AuxiliaryHint *)SDL_calloc(1, sizeof(AuxiliaryHint));
753     if (!newAuxiliaryHint) {
754         SDL_Log("AddAuxiliaryHint: Fail calloc");
755         return 0;
756     }
757
758     newAuxiliaryHint->id = new_id;
759     newAuxiliaryHint->hint = hint;
760     newAuxiliaryHint->value = value;
761     newAuxiliaryHint->next = NULL;
762     if (new_id != 1) {
763         newAuxiliaryHint->next = (wind->auxiliaryHints).auxHintHeader;
764     }
765
766     (wind->auxiliaryHints).auxHintHeader = newAuxiliaryHint;
767     (wind->auxiliaryHints).size++;
768     ecore_wl2_window_aux_hint_add(ecore_window, (int)new_id, hint, value);
769     SDL_Log("AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint, value, new_id);
770
771     return new_id;
772 }
773
774 SDL_bool
775 SDL_Tizen_RemoveAuxiliaryHint(SDL_Window *window, unsigned int id)
776 {
777     SDL_WindowData *wind = NULL;
778     Ecore_Wl2_Window *ecore_window = NULL;
779
780     if (!window || !window->driverdata) {
781         return SDL_FALSE;
782     }
783
784     wind = (SDL_WindowData *) window->driverdata;
785     ecore_window = wind->window;
786
787     if (!ecore_window) {
788         SDL_Log("RemoveAuxiliaryHint: ecore_window is null");
789         return SDL_FALSE;
790     }
791
792     if (id == 0) {
793       SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
794       return SDL_FALSE;
795     }
796
797     if ((wind->auxiliaryHints).auxHintHeader) {
798         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
799         AuxiliaryHint* prevAuxiliaryHint = NULL;
800         AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
801         while (auxiliaryHint) {
802             if (auxiliaryHint->id == id) {
803                 SDL_Log("RemoveAuxiliaryHint: id = %d, hint = %s\n", id, auxiliaryHint->hint);
804                 ecore_wl2_window_aux_hint_del(ecore_window, (int)id);
805                 if (auxiliaryHint == (wind->auxiliaryHints).auxHintHeader) {
806                     (wind->auxiliaryHints).auxHintHeader = auxiliaryHint->next;
807                 } else {
808                     prevAuxiliaryHint->next = nextAuxiliaryHint;
809                 }
810                 SDL_free(auxiliaryHint);
811                 (wind->auxiliaryHints).size--;
812                 return SDL_TRUE;
813             }
814             prevAuxiliaryHint = auxiliaryHint;
815             auxiliaryHint = nextAuxiliaryHint;
816             nextAuxiliaryHint = NULL;
817             if(auxiliaryHint) {
818                 nextAuxiliaryHint = auxiliaryHint->next;
819             }
820         }
821     }
822     return SDL_FALSE;
823 }
824
825 SDL_bool
826 SDL_Tizen_SetAuxiliaryHint(SDL_Window *window, unsigned int id, const char *value)
827 {
828     SDL_WindowData *wind = NULL;
829     Ecore_Wl2_Window *ecore_window = NULL;
830
831     if (!window || !window->driverdata) {
832         return SDL_FALSE;
833     }
834
835     wind = (SDL_WindowData *) window->driverdata;
836     ecore_window = wind->window;
837
838     if (!ecore_window) {
839         return SDL_FALSE;
840     }
841
842     if (id == 0) {
843       SDL_Log( "RemoveAuxiliaryHint: Invalid id [%d]\n", id );
844       return SDL_FALSE;
845     }
846
847     if ((wind->auxiliaryHints).auxHintHeader) {
848         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
849         AuxiliaryHint* nextAuxiliaryHint = auxiliaryHint->next;
850         while (auxiliaryHint) {
851             if (auxiliaryHint->id == id) {
852                 ecore_wl2_window_aux_hint_change(ecore_window, (int)id, value);
853                 auxiliaryHint->value = value;
854                 SDL_Log("SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
855                 return SDL_TRUE;
856             }
857             auxiliaryHint = nextAuxiliaryHint;
858             nextAuxiliaryHint = NULL;
859             if(auxiliaryHint) {
860                 nextAuxiliaryHint = auxiliaryHint->next;
861             }
862         }
863     }
864     return SDL_FALSE;
865 }
866
867 const char*
868 SDL_Tizen_GetAuxiliaryHintValue(SDL_Window *window, unsigned int id)
869 {
870     SDL_WindowData *wind = NULL;
871     if (!window || !window->driverdata) {
872         return NULL;
873     }
874
875     wind = (SDL_WindowData *) window->driverdata;
876     if (id == 0) {
877       SDL_Log( "GetAuxiliaryHintValue: Invalid id [%d]\n", id );
878       return NULL;
879     }
880
881     if ((wind->auxiliaryHints).auxHintHeader) {
882         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
883         while (auxiliaryHint) {
884             if (auxiliaryHint->id == id) {
885                 SDL_Log("GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, auxiliaryHint->hint, auxiliaryHint->value);
886                 return auxiliaryHint->value;
887             }
888             auxiliaryHint = auxiliaryHint->next;
889         }
890     }
891     return NULL;
892 }
893
894 unsigned int
895 SDL_Tizen_GetAuxiliaryHintId(SDL_Window *window, const char *hint)
896 {
897     SDL_WindowData *wind = NULL;
898     if (!window || !window->driverdata) {
899         return 0;
900     }
901
902     wind = (SDL_WindowData *) window->driverdata;
903
904     if (hint == NULL || (wind->auxiliaryHints).size <= 0) {
905       SDL_Log( "GetAuxiliaryHintId: auxiliaryHints size is 0]\n");
906       return 0;
907     }
908
909     if ((wind->auxiliaryHints).auxHintHeader) {
910         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
911         for (unsigned int i = 0; i < (wind->auxiliaryHints).size; i++) {
912             if (auxiliaryHint->hint == hint) {
913                 SDL_Log("GetAuxiliaryHintId: hint = %s, id = %d\n", hint, auxiliaryHint->id);
914                 return auxiliaryHint->id;
915             }
916             auxiliaryHint = auxiliaryHint->next;
917         }
918     }
919     SDL_Log("GetAuxiliaryHintId: Invalid hint! [%s]\n", hint);
920
921     return 0;
922 }
923
924 SDL_bool
925 SDL_Tizen_GetWindowAcceptFocus(SDL_Window * window)
926 {
927     SDL_WindowData *data = NULL;
928
929     if (!window || !window->driverdata) {
930         return SDL_FALSE;
931     }
932
933     data = (SDL_WindowData *) window->driverdata;
934     if (!data->window) {
935         return SDL_FALSE;
936     }
937
938     return !ecore_wl2_window_focus_skip_get(data->window);
939 }
940
941 SDL_bool
942 SDL_Tizen_SetWindowAcceptFocus(SDL_Window * window, SDL_bool accept)
943 {
944     SDL_WindowData *data = NULL;
945
946     if (!window || !window->driverdata) {
947         return SDL_FALSE;
948     }
949
950     data = (SDL_WindowData *) window->driverdata;
951     if (!data->window) {
952         return SDL_FALSE;
953     }
954
955     ecore_wl2_window_focus_skip_set(data->window, !accept);
956     return SDL_TRUE;
957 }
958
959 int
960 Tizen_CreateWindow(_THIS, SDL_Window *window)
961 {
962     SDL_VideoData *data = _this->driverdata;
963     SDL_WindowData *wind;
964     Ecore_Wl2_Global *global;
965     Eina_Iterator *globals;
966     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
967     Ecore_Wl2_Window *parent_wl2_window = NULL;
968
969     wind = calloc(1, sizeof * wind);
970     if (!wind) {
971         return SDL_OutOfMemory();
972     }
973     (wind->auxiliaryHints).size = 0;
974     (wind->auxiliaryHints).auxHintHeader = NULL;
975     window->driverdata = wind;
976     window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */
977
978 #if SDL_VIDEO_OPENGL_EGL
979     if (window->flags & SDL_WINDOW_OPENGL) {
980         SDL_GL_LoadLibrary(NULL);
981     }
982 #endif
983
984 #if SDL_VIDEO_VULKAN
985     if (window->flags & SDL_WINDOW_VULKAN) {
986         if (!_this->Vulkan_GetInstanceExtensions) {
987             SDL_SetError("No Vulkan support in video driver");
988         }
989
990         if (_this->Vulkan_LoadLibrary(_this, NULL) < 0) {
991             SDL_SetError("Fail to load Vulkan Library");
992         }
993     }
994 #endif
995
996     if (window->x == SDL_WINDOWPOS_UNDEFINED) {
997         window->x = 0;
998     }
999     if (window->y == SDL_WINDOWPOS_UNDEFINED) {
1000         window->y = 0;
1001     }
1002
1003     if (!(globals = ecore_wl2_display_globals_get(wl2_display)))
1004       {
1005          SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to get wayland globals");
1006          return -1;
1007       }
1008
1009     if(window->next)
1010     {
1011         parent_wl2_window = ((SDL_WindowData *)(window->next->driverdata))->window;
1012     }
1013     wind->window = ecore_wl2_window_new(wl2_display, parent_wl2_window,
1014                                        window->x, window->y, window->w, window->h);
1015     if (!wind->window) {
1016         SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window");
1017         if(globals) {
1018             eina_iterator_free(globals);
1019         }
1020         return -1;
1021     }
1022     ecore_wl2_window_position_set(wind->window, window->x, window->y);
1023     _tizen_output_transform_register(wind);
1024 #if 0
1025     wind->wl2_surface = ecore_wl2_surface_create(wind->window, EINA_FALSE);
1026     if (!wind->wl2_surface) {
1027         SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1028         return -1;
1029     }
1030 #endif
1031     wind->surface = ecore_wl2_window_surface_get(wind->window);
1032     if (!wind->surface) {
1033         SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Failed to create wayland window surface");
1034         if(globals) {
1035             eina_iterator_free(globals);
1036         }
1037         return -1;
1038     }
1039
1040     ecore_wl2_window_type_set(wind->window, ECORE_WL2_WINDOW_TYPE_UTILITY);
1041
1042     wind->rotation = 0;
1043     wind->rotation_supported = 0;
1044     wind->received_rotation = TIZEN_ROTATION_RECEIVED_NONE;
1045
1046 #if SDL_VIDEO_OPENGL_EGL
1047     if (window->flags & SDL_WINDOW_OPENGL) {
1048
1049         if(wind->output_rotation == 90 || wind->output_rotation == 270)
1050             wind->egl_window = wl_egl_window_create(wind->surface, window->h, window->w);
1051         else
1052             wind->egl_window = wl_egl_window_create(wind->surface, window->w, window->h);
1053
1054         /* Create the GLES window surface */
1055         wind->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wind->egl_window);
1056         if (wind->egl_surface == EGL_NO_SURFACE) {
1057             SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "failed to create a window surface");
1058             if(globals) {
1059                 eina_iterator_free(globals);
1060             }
1061             return -1;
1062         }
1063
1064         if (!_this->gl_config.alpha_size) {
1065             ecore_wl2_window_opaque_region_set(wind->window, window->x, window->y, window->w, window->h);
1066         }
1067         else {
1068             wl_surface_set_opaque_region(wind->surface, NULL);
1069         }
1070
1071         //Support PreRotation
1072         wind->support_pre_rotation = 0;
1073         if (wl_egl_window_tizen_get_capabilities(wind->egl_window) == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED ) {
1074             wind->support_pre_rotation = 1;
1075         }
1076         else
1077         {
1078             wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1079         }
1080
1081
1082     }
1083 #endif
1084
1085     wind->id = ecore_wl2_window_id_get(wind->window);
1086     eina_hash_add(data->windows, &wind->id, window);
1087
1088     Tizen_InitKeyboard(_this);
1089     SDL_SetMouseFocus(window);
1090
1091     EINA_ITERATOR_FOREACH(globals, global) {
1092          if (!strcmp(global->interface, "tizen_policy_ext")) {
1093               wind->rotation_supported = 1;
1094               break;
1095            }
1096       }
1097     eina_iterator_free(globals);
1098     // Add orientaiton hint cb
1099     _tizen_window_orientation_add_hint((void*)wind);
1100     SDL_AddHintCallback(SDL_HINT_TIZEN_INDICATOR_OPACITY, _tizen_indicator_opacity_hint_callback, data);
1101
1102     Tizen_rotate_update(window);
1103
1104     return 0;
1105 }
1106
1107 void
1108 Tizen_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
1109 {
1110     if(!bordered)
1111     {
1112         SDL_WindowData *wind = window->driverdata;
1113         wind->support_indicator = SDL_FALSE;
1114         Tizen_TerminateIndicatorProcess(window->driverdata);
1115     }
1116 }
1117
1118 void
1119 Tizen_SetWindowSize(_THIS, SDL_Window *window)
1120 {
1121     SDL_WindowData *wind = window->driverdata;
1122     if (!wind->egl_window)
1123         return;
1124
1125 // TODO : consider to rotation status.
1126 #if SDL_VIDEO_OPENGL_EGL
1127     if (window->flags & SDL_WINDOW_OPENGL)
1128     {
1129         int rotation = (wind->output_rotation + wind->rotation) % 360;
1130         if(rotation == 90 || rotation == 270)
1131         {
1132             ecore_wl2_window_geometry_set(wind->window, window->y, window->x, window->h, window->w);
1133             wl_egl_window_resize(wind->egl_window, window->h, window->w, 0, 0);
1134         }
1135         else
1136         {
1137             ecore_wl2_window_geometry_set(wind->window, window->x, window->y, window->w, window->h);
1138             wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
1139         }
1140     }
1141     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
1142 #endif
1143 }
1144
1145 void
1146 Tizen_GetWindowSize(_THIS, SDL_Window *window, int *w, int *h)
1147 {
1148     SDL_WindowData *wind = window->driverdata;
1149     if (!wind->window) {
1150         return;
1151     }
1152
1153     if (w) *w = window->w;
1154     if (h) *h = window->h;
1155 }
1156
1157 void
1158 Tizen_SetWindowPosition(_THIS, SDL_Window * window)
1159 {
1160     SDL_WindowData *wind = window->driverdata;
1161     if (!wind->window) {
1162         return;
1163     }
1164
1165     // TODO : consider to rotation status.
1166     ecore_wl2_window_position_set(wind->window, window->x, window->y);
1167 }
1168
1169 void
1170 Tizen_DestroyWindow(_THIS, SDL_Window *window)
1171 {
1172     SDL_VideoData *data = _this->driverdata;
1173     SDL_WindowData *wind = window->driverdata;
1174
1175     if (data) {
1176         AuxiliaryHint* auxiliaryHint = (wind->auxiliaryHints).auxHintHeader;
1177         if (auxiliaryHint) {
1178             AuxiliaryHint* nextAuxiliaryHints = auxiliaryHint->next;
1179             while (auxiliaryHint) {
1180                 SDL_free(auxiliaryHint);
1181                 auxiliaryHint = nextAuxiliaryHints;
1182                 nextAuxiliaryHints = NULL;
1183                 if (auxiliaryHint) {
1184                     nextAuxiliaryHints = auxiliaryHint->next;
1185                 }
1186             }
1187         }
1188         eina_hash_del(data->windows, &wind->id, window);
1189 #if SDL_VIDEO_OPENGL_EGL
1190     if (window->flags & SDL_WINDOW_OPENGL) {
1191         SDL_EGL_DestroySurface(_this, wind->egl_surface);
1192         wl_egl_window_destroy(wind->egl_window);
1193     }
1194 #endif
1195         ecore_wl2_window_free(wind->window);
1196         SDL_free(wind);
1197     }
1198
1199     window->driverdata = NULL;
1200 }
1201
1202 int
1203 Tizen_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
1204 {
1205     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
1206     if (opacity < 1.0f) {
1207         ecore_wl2_window_alpha_set(data->window, true);
1208     } else {
1209         ecore_wl2_window_alpha_set(data->window, false);
1210     }
1211     return 0;
1212 }
1213
1214 Eina_Bool
1215 _tizen_cb_event_window_visibility_change(void *data, int type, void *event)
1216 {
1217     _THIS = data;
1218     Ecore_Wl2_Event_Window_Visibility_Change *ev;
1219     Ecore_Wl2_Window *ew;
1220     SDL_Window *window;
1221
1222     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1223
1224
1225     ev = event;
1226     ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1227     window = Tizen_FindWindow(_this, ew);
1228     if (!window) {
1229         return ECORE_CALLBACK_PASS_ON;
1230     }
1231
1232     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
1233     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1234     return ECORE_CALLBACK_PASS_ON;
1235 }
1236
1237 Eina_Bool
1238 _tizen_cb_window_configure(void *data, int type EINA_UNUSED, void *event)
1239 {
1240    _THIS = data;
1241    Ecore_Wl2_Window *ew;
1242    SDL_Window *window;
1243    SDL_WindowData *wind;
1244    Ecore_Wl2_Event_Window_Configure *ev;
1245
1246    Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1247
1248    ev = event;
1249    ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1250    window = Tizen_FindWindow(_this, ew);
1251    if (!window) {
1252        return ECORE_CALLBACK_PASS_ON;
1253    }
1254
1255    wind = window->driverdata;
1256    if (!wind) {
1257        return ECORE_CALLBACK_PASS_ON;
1258    }
1259
1260    if (wind->rotation_supported == 0){
1261       return ECORE_CALLBACK_PASS_ON;
1262    }
1263
1264    return ECORE_CALLBACK_PASS_ON;
1265 }
1266
1267 Eina_Bool
1268 _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event)
1269 {
1270     _THIS = data;
1271     Ecore_Wl2_Event_Window_Rotation *ev;
1272     Ecore_Wl2_Window *ew;
1273     SDL_Window *window;
1274     SDL_WindowData *wind;
1275
1276     Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
1277
1278     ev = event;
1279     if (!ev) {
1280         return ECORE_CALLBACK_PASS_ON;
1281     }
1282
1283     ew = ecore_wl2_display_window_find(wl2_display, ev->win);
1284     window = Tizen_FindWindow(_this, ew);
1285     if (!window) {
1286         return ECORE_CALLBACK_PASS_ON;
1287     }
1288
1289     wind = window->driverdata;
1290     if (!wind) {
1291         return ECORE_CALLBACK_PASS_ON;
1292     }
1293
1294     /* set ecore_wl2 window rotation */
1295     wind->rotation = ev->angle;
1296     wind->received_rotation = TIZEN_ROTATION_RECEIVED_WINDOW_ROATION;
1297
1298     return ECORE_CALLBACK_PASS_ON;
1299 }
1300
1301 static Eina_Bool _tizen_cb_event_window_show(void *data, int type, void *event)
1302 {
1303     Ecore_Wl2_Event_Window_Show *e;
1304     uint32_t g_res_id = 0;
1305
1306     e = event;
1307     if (e->data[0] > 0)
1308         g_res_id = e->data[0];
1309
1310     if(g_res_id!=0)
1311     {
1312         SDL_VideoData *this = SDL_GetVideoDevice()->driverdata;
1313         SDL_Window * window = (SDL_Window*)eina_hash_find(this->windows, &e->win);
1314         if (!window)
1315         {
1316             SDL_Log("window is null");
1317             return ECORE_CALLBACK_PASS_ON;
1318         }
1319         SDL_WindowData *wind = window->driverdata;
1320         if (!wind)
1321         {
1322             SDL_Log("window->driverdata is null");
1323             return ECORE_CALLBACK_PASS_ON;
1324         }
1325         wind->g_res_id = g_res_id;
1326         SDL_Log("[SDL] SDL Window Resource ID %d", g_res_id);
1327     }
1328
1329     return ECORE_CALLBACK_PASS_ON;
1330 }
1331
1332 int
1333 Tizen_InitWindow(_THIS)
1334 {
1335     SDL_VideoData *data = _this->driverdata;
1336
1337     data->windows = eina_hash_int32_new(NULL);
1338
1339     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
1340                         _tizen_cb_event_window_visibility_change,_this));
1341     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE,
1342                         _tizen_cb_event_window_rotate,_this));
1343     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE,
1344                         _tizen_cb_window_configure,_this));
1345     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
1346                         _tizen_cb_event_window_show, _this));
1347
1348     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_KEY_UP,
1349                         _tizen_cb_event_keyup_change,_this));
1350     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
1351                         _tizen_cb_event_keydown_change,_this));
1352
1353     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
1354                         _tizen_cb_event_mousedown_change,_this));
1355     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
1356                         _tizen_cb_event_mouseup_change,_this));
1357     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
1358                         _tizen_cb_event_mousemove_change,_this));
1359     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
1360                         _tizen_cb_event_mouse_in,_this));
1361     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
1362                         _tizen_cb_event_mouse_out,_this));
1363
1364     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN,
1365                         _tizen_cb_event_focus_in,_this));
1366     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT,
1367                         _tizen_cb_event_focus_out,_this));
1368
1369     mEcoreEventHandler.push_back(ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
1370                         _tizen_cb_event_joystick_change,_this));
1371
1372     return 0;
1373 }
1374
1375 void
1376 Tizen_DeinitWindow(_THIS)
1377 {
1378     int size = mECoreEventHandler.size();
1379     for (int i = 0; i < size; i++)
1380     {
1381         ecore_event_handler_del(*mECoreEventHandler[i]);
1382     }
1383     mEcoreEventHandler.Clear();
1384
1385     SDL_VideoData *data = _this->driverdata;
1386
1387     eina_hash_free(data->windows);
1388 }
1389 #endif /* SDL_VIDEO_DRIVER_TIZEN */
1390
1391 /* vi: set ts=4 sw=4 expandtab: */