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