Merge "Add Maximize/Minimized in Window" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Ecore is littered with C style cast
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wold-style-cast"
21
22 // CLASS HEADER
23 #include <dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/input/common/key-impl.h>
27 #include <dali/internal/window-system/common/window-impl.h>
28 #include <dali/internal/window-system/common/window-render-surface.h>
29 #include <dali/internal/window-system/common/window-system.h>
30
31 // EXTERNAL_HEADERS
32 #include <Ecore_Input.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/public-api/adaptor-framework/window-enumerations.h>
35 #include <dali/public-api/events/mouse-button.h>
36 #include <dali/public-api/object/any.h>
37 #include <vconf-keys.h>
38 #include <vconf.h>
39 #include <wayland-egl-tizen.h>
40
41 namespace Dali
42 {
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 namespace
48 {
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW_BASE");
51 #endif
52
53 const uint32_t     MAX_TIZEN_CLIENT_VERSION = 7;
54 const unsigned int PRIMARY_TOUCH_BUTTON_ID  = 1;
55
56 const char* DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
57
58 #ifdef DALI_ELDBUS_AVAILABLE
59 // DBUS accessibility
60 const char* BUS       = "org.enlightenment.wm-screen-reader";
61 const char* INTERFACE = "org.tizen.GestureNavigation";
62 const char* PATH      = "/org/tizen/GestureNavigation";
63 #endif // DALI_ELDBUS_AVAILABLE
64
65 struct KeyCodeMap
66 {
67   xkb_keysym_t  keySym;
68   xkb_keycode_t keyCode;
69   bool          isKeyCode;
70 };
71
72 /**
73  * Get the device name from the provided ecore key event
74  */
75 void GetDeviceName(Ecore_Event_Key* keyEvent, std::string& result)
76 {
77   const char* ecoreDeviceName = ecore_device_name_get(keyEvent->dev);
78
79   if(ecoreDeviceName)
80   {
81     result = ecoreDeviceName;
82   }
83 }
84
85 /**
86  * Get the device class from the provided ecore event
87  */
88 void GetDeviceClass(Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass)
89 {
90   switch(ecoreDeviceClass)
91   {
92     case ECORE_DEVICE_CLASS_SEAT:
93     {
94       deviceClass = Device::Class::USER;
95       break;
96     }
97     case ECORE_DEVICE_CLASS_KEYBOARD:
98     {
99       deviceClass = Device::Class::KEYBOARD;
100       break;
101     }
102     case ECORE_DEVICE_CLASS_MOUSE:
103     {
104       deviceClass = Device::Class::MOUSE;
105       break;
106     }
107     case ECORE_DEVICE_CLASS_TOUCH:
108     {
109       deviceClass = Device::Class::TOUCH;
110       break;
111     }
112     case ECORE_DEVICE_CLASS_PEN:
113     {
114       deviceClass = Device::Class::PEN;
115       break;
116     }
117     case ECORE_DEVICE_CLASS_POINTER:
118     {
119       deviceClass = Device::Class::POINTER;
120       break;
121     }
122     case ECORE_DEVICE_CLASS_GAMEPAD:
123     {
124       deviceClass = Device::Class::GAMEPAD;
125       break;
126     }
127     default:
128     {
129       deviceClass = Device::Class::NONE;
130       break;
131     }
132   }
133 }
134
135 void GetDeviceSubclass(Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass)
136 {
137   switch(ecoreDeviceSubclass)
138   {
139     case ECORE_DEVICE_SUBCLASS_FINGER:
140     {
141       deviceSubclass = Device::Subclass::FINGER;
142       break;
143     }
144     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
145     {
146       deviceSubclass = Device::Subclass::FINGERNAIL;
147       break;
148     }
149     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
150     {
151       deviceSubclass = Device::Subclass::KNUCKLE;
152       break;
153     }
154     case ECORE_DEVICE_SUBCLASS_PALM:
155     {
156       deviceSubclass = Device::Subclass::PALM;
157       break;
158     }
159     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
160     {
161       deviceSubclass = Device::Subclass::HAND_SIDE;
162       break;
163     }
164     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
165     {
166       deviceSubclass = Device::Subclass::HAND_FLAT;
167       break;
168     }
169     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
170     {
171       deviceSubclass = Device::Subclass::PEN_TIP;
172       break;
173     }
174     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
175     {
176       deviceSubclass = Device::Subclass::TRACKPAD;
177       break;
178     }
179     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
180     {
181       deviceSubclass = Device::Subclass::TRACKPOINT;
182       break;
183     }
184     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
185     {
186       deviceSubclass = Device::Subclass::TRACKBALL;
187       break;
188     }
189     case ECORE_DEVICE_SUBCLASS_REMOCON:
190     {
191       deviceSubclass = Device::Subclass::REMOCON;
192       break;
193     }
194     case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
195     {
196       deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
197       break;
198     }
199     default:
200     {
201       deviceSubclass = Device::Subclass::NONE;
202       break;
203     }
204   }
205 }
206
207 void FindKeyCode(struct xkb_keymap* keyMap, xkb_keycode_t key, void* data)
208 {
209   KeyCodeMap* foundKeyCode = static_cast<KeyCodeMap*>(data);
210   if(foundKeyCode->isKeyCode)
211   {
212     return;
213   }
214
215   xkb_keysym_t        keySym  = foundKeyCode->keySym;
216   int                 nsyms   = 0;
217   const xkb_keysym_t* symsOut = NULL;
218
219   nsyms = xkb_keymap_key_get_syms_by_level(keyMap, key, 0, 0, &symsOut);
220
221   if(nsyms && symsOut)
222   {
223     if(*symsOut == keySym)
224     {
225       foundKeyCode->keyCode   = key;
226       foundKeyCode->isKeyCode = true;
227     }
228   }
229 }
230
231 /////////////////////////////////////////////////////////////////////////////////////////////////
232 // Window Callbacks
233 /////////////////////////////////////////////////////////////////////////////////////////////////
234
235 /// Called when the window iconify state is changed.
236 static Eina_Bool EcoreEventWindowIconifyStateChanged(void* data, int type, void* event)
237 {
238   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
239   if(windowBase)
240   {
241     return windowBase->OnIconifyStateChanged(data, type, event);
242   }
243
244   return ECORE_CALLBACK_PASS_ON;
245 }
246
247 /// Called when the window gains focus
248 static Eina_Bool EcoreEventWindowFocusIn(void* data, int type, void* event)
249 {
250   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
251   if(windowBase)
252   {
253     return windowBase->OnFocusIn(data, type, event);
254   }
255
256   return ECORE_CALLBACK_PASS_ON;
257 }
258
259 /// Called when the window loses focus
260 static Eina_Bool EcoreEventWindowFocusOut(void* data, int type, void* event)
261 {
262   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
263   if(windowBase)
264   {
265     return windowBase->OnFocusOut(data, type, event);
266   }
267
268   return ECORE_CALLBACK_PASS_ON;
269 }
270
271 /// Called when the output is transformed
272 static Eina_Bool EcoreEventOutputTransform(void* data, int type, void* event)
273 {
274   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
275   if(windowBase)
276   {
277     return windowBase->OnOutputTransform(data, type, event);
278   }
279
280   return ECORE_CALLBACK_PASS_ON;
281 }
282
283 /// Called when the output transform should be ignored
284 static Eina_Bool EcoreEventIgnoreOutputTransform(void* data, int type, void* event)
285 {
286   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
287   if(windowBase)
288   {
289     return windowBase->OnIgnoreOutputTransform(data, type, event);
290   }
291
292   return ECORE_CALLBACK_PASS_ON;
293 }
294
295 /**
296  * Called when rotate event is recevied.
297  */
298 static Eina_Bool EcoreEventRotate(void* data, int type, void* event)
299 {
300   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
301   if(windowBase)
302   {
303     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EcoreEventRotate\n");
304     windowBase->OnRotation(data, type, event);
305   }
306   return ECORE_CALLBACK_PASS_ON;
307 }
308
309 /**
310  * Called when configure event is recevied.
311  */
312 static Eina_Bool EcoreEventConfigure(void* data, int type, void* event)
313 {
314   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
315   if(windowBase)
316   {
317     windowBase->OnConfiguration(data, type, event);
318   }
319   return ECORE_CALLBACK_PASS_ON;
320 }
321
322 /////////////////////////////////////////////////////////////////////////////////////////////////
323 // Touch Callbacks
324 /////////////////////////////////////////////////////////////////////////////////////////////////
325
326 /**
327  * Called when a touch down is received.
328  */
329 static Eina_Bool EcoreEventMouseButtonDown(void* data, int type, void* event)
330 {
331   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
332   if(windowBase)
333   {
334     windowBase->OnMouseButtonDown(data, type, event);
335   }
336   return ECORE_CALLBACK_PASS_ON;
337 }
338
339 /**
340  * Called when a touch up is received.
341  */
342 static Eina_Bool EcoreEventMouseButtonUp(void* data, int type, void* event)
343 {
344   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
345   if(windowBase)
346   {
347     windowBase->OnMouseButtonUp(data, type, event);
348   }
349   return ECORE_CALLBACK_PASS_ON;
350 }
351
352 /**
353  * Called when a touch motion is received.
354  */
355 static Eina_Bool EcoreEventMouseButtonMove(void* data, int type, void* event)
356 {
357   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
358   if(windowBase)
359   {
360     windowBase->OnMouseButtonMove(data, type, event);
361   }
362   return ECORE_CALLBACK_PASS_ON;
363 }
364
365 /**
366  * Called when a touch is canceled.
367  */
368 static Eina_Bool EcoreEventMouseButtonCancel(void* data, int type, void* event)
369 {
370   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
371   if(windowBase)
372   {
373     windowBase->OnMouseButtonCancel(data, type, event);
374   }
375   return ECORE_CALLBACK_PASS_ON;
376 }
377
378 /**
379  * Called when a mouse wheel is received.
380  */
381 static Eina_Bool EcoreEventMouseWheel(void* data, int type, void* event)
382 {
383   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
384   if(windowBase)
385   {
386     windowBase->OnMouseWheel(data, type, event);
387   }
388   return ECORE_CALLBACK_PASS_ON;
389 }
390
391 /**
392  * Called when a detent rotation event is recevied.
393  */
394 static Eina_Bool EcoreEventDetentRotation(void* data, int type, void* event)
395 {
396   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
397   if(windowBase)
398   {
399     windowBase->OnDetentRotation(data, type, event);
400   }
401   return ECORE_CALLBACK_PASS_ON;
402 }
403
404 /////////////////////////////////////////////////////////////////////////////////////////////////
405 // Key Callbacks
406 /////////////////////////////////////////////////////////////////////////////////////////////////
407
408 /**
409  * Called when a key down is received.
410  */
411 static Eina_Bool EcoreEventKeyDown(void* data, int type, void* event)
412 {
413   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
414   if(windowBase)
415   {
416     windowBase->OnKeyDown(data, type, event);
417   }
418   return ECORE_CALLBACK_PASS_ON;
419 }
420
421 /**
422  * Called when a key up is received.
423  */
424 static Eina_Bool EcoreEventKeyUp(void* data, int type, void* event)
425 {
426   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
427   if(windowBase)
428   {
429     windowBase->OnKeyUp(data, type, event);
430   }
431   return ECORE_CALLBACK_PASS_ON;
432 }
433
434 /////////////////////////////////////////////////////////////////////////////////////////////////
435 // Selection Callbacks
436 /////////////////////////////////////////////////////////////////////////////////////////////////
437
438 /**
439  * Called when the source window notifies us the content in clipboard is selected.
440  */
441 static Eina_Bool EcoreEventDataSend(void* data, int type, void* event)
442 {
443   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
444   if(windowBase)
445   {
446     windowBase->OnDataSend(data, type, event);
447   }
448   return ECORE_CALLBACK_PASS_ON;
449 }
450
451 /**
452 * Called when the source window sends us about the selected content.
453 * For example, when item is selected in the clipboard.
454 */
455 static Eina_Bool EcoreEventDataReceive(void* data, int type, void* event)
456 {
457   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
458   if(windowBase)
459   {
460     windowBase->OnDataReceive(data, type, event);
461   }
462   return ECORE_CALLBACK_PASS_ON;
463 }
464
465 /////////////////////////////////////////////////////////////////////////////////////////////////
466 // Effect Start/End Callbacks
467 /////////////////////////////////////////////////////////////////////////////////////////////////
468
469 /**
470  * Called when transition animation of the window's shown/hidden is started by window manager.
471  */
472 static Eina_Bool EcoreEventEffectStart(void* data, int type, void* event)
473 {
474   WindowBaseEcoreWl2*           windowBase  = static_cast<WindowBaseEcoreWl2*>(data);
475   Ecore_Wl2_Event_Effect_Start* effectStart = static_cast<Ecore_Wl2_Event_Effect_Start*>(event);
476   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventEffectStart, effect type[ %d ]\n", effectStart->type);
477   if(windowBase)
478   {
479     if(effectStart->type < 3) // only under restack
480     {
481       windowBase->OnTransitionEffectEvent(WindowEffectState::START, static_cast<WindowEffectType>(effectStart->type));
482     }
483   }
484   return ECORE_CALLBACK_PASS_ON;
485 }
486
487 /**
488  * Called when transition animation of the window's shown/hidden is ended by window manager.
489  */
490 static Eina_Bool EcoreEventEffectEnd(void* data, int type, void* event)
491 {
492   Ecore_Wl2_Event_Effect_Start* effectEnd  = static_cast<Ecore_Wl2_Event_Effect_Start*>(event);
493   WindowBaseEcoreWl2*           windowBase = static_cast<WindowBaseEcoreWl2*>(data);
494   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventEffectEnd, effect type[ %d ]\n", effectEnd->type);
495   if(windowBase)
496   {
497     if(effectEnd->type < 3) // only under restack
498     {
499       windowBase->OnTransitionEffectEvent(WindowEffectState::END, static_cast<WindowEffectType>(effectEnd->type));
500     }
501   }
502   return ECORE_CALLBACK_PASS_ON;
503 }
504
505 /////////////////////////////////////////////////////////////////////////////////////////////////
506 // Keyboard Repeat Settings Changed Callbacks
507 /////////////////////////////////////////////////////////////////////////////////////////////////
508
509 static Eina_Bool EcoreEventSeatKeyboardRepeatChanged(void* data, int type, void* event)
510 {
511   Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed* keyboardRepeat = static_cast<Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed*>(event);
512   WindowBaseEcoreWl2*                           windowBase     = static_cast<WindowBaseEcoreWl2*>(data);
513   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventSeatKeyboardRepeatChanged, id[ %d ]\n", keyboardRepeat->id);
514   if(windowBase)
515   {
516     windowBase->OnKeyboardRepeatSettingsChanged();
517   }
518
519   return ECORE_CALLBACK_RENEW;
520 }
521
522 /////////////////////////////////////////////////////////////////////////////////////////////////
523 // Keymap Changed Callbacks
524 /////////////////////////////////////////////////////////////////////////////////////////////////
525
526 static Eina_Bool EcoreEventSeatKeymapChanged(void* data, int type, void* event)
527 {
528   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
529   if(windowBase)
530   {
531     windowBase->KeymapChanged(data, type, event);
532   }
533
534   return ECORE_CALLBACK_RENEW;
535 }
536
537 /////////////////////////////////////////////////////////////////////////////////////////////////
538 // Font Callbacks
539 /////////////////////////////////////////////////////////////////////////////////////////////////
540
541 /**
542  * Called when a font name is changed.
543  */
544 static void VconfNotifyFontNameChanged(keynode_t* node, void* data)
545 {
546   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
547   if(windowBase)
548   {
549     windowBase->OnFontNameChanged();
550   }
551 }
552
553 /**
554  * Called when a font size is changed.
555  */
556 static void VconfNotifyFontSizeChanged(keynode_t* node, void* data)
557 {
558   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
559   if(windowBase)
560   {
561     windowBase->OnFontSizeChanged();
562   }
563 }
564
565 /////////////////////////////////////////////////////////////////////////////////////////////////
566 // Window Redraw Request Event Callbacks
567 /////////////////////////////////////////////////////////////////////////////////////////////////
568
569 static Eina_Bool EcoreEventWindowRedrawRequest(void* data, int type, void* event)
570 {
571   Ecore_Wl2_Event_Window_Redraw_Request* windowRedrawRequest = static_cast<Ecore_Wl2_Event_Window_Redraw_Request*>(event);
572   WindowBaseEcoreWl2*                    windowBase          = static_cast<WindowBaseEcoreWl2*>(data);
573   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventWindowRedrawRequest, window[ %d ]\n", windowRedrawRequest->win);
574   if(windowBase)
575   {
576     windowBase->OnEcoreEventWindowRedrawRequest();
577   }
578
579   return ECORE_CALLBACK_RENEW;
580 }
581
582 /////////////////////////////////////////////////////////////////////////////////////////////////
583 // Window Auxiliary Message Callbacks
584 /////////////////////////////////////////////////////////////////////////////////////////////////
585 static Eina_Bool EcoreEventWindowAuxiliaryMessage(void* data, int type, void* event)
586 {
587   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
588   if(windowBase)
589   {
590     windowBase->OnEcoreEventWindowAuxiliaryMessage(event);
591   }
592   return ECORE_CALLBACK_RENEW;
593 }
594
595 /////////////////////////////////////////////////////////////////////////////////////////////////
596 // ElDBus Accessibility Callbacks
597 /////////////////////////////////////////////////////////////////////////////////////////////////
598
599 #ifdef DALI_ELDBUS_AVAILABLE
600 // Callback for Ecore ElDBus accessibility events.
601 static void EcoreElDBusAccessibilityNotification(void* context, const Eldbus_Message* message)
602 {
603   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(context);
604   if(windowBase)
605   {
606     windowBase->OnEcoreElDBusAccessibilityNotification(context, message);
607   }
608 }
609 #endif // DALI_ELDBUS_AVAILABLE
610
611 static void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
612 {
613   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
614   if(windowBase)
615   {
616     windowBase->RegistryGlobalCallback(data, registry, name, interface, version);
617   }
618 }
619
620 static void RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
621 {
622   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
623   if(windowBase)
624   {
625     windowBase->RegistryGlobalCallbackRemove(data, registry, id);
626   }
627 }
628
629 static void TizenPolicyConformant(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant)
630 {
631 }
632
633 static void TizenPolicyConformantArea(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
634 {
635 }
636
637 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
638 {
639   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
640   if(windowBase)
641   {
642     windowBase->TizenPolicyNotificationChangeDone(data, tizenPolicy, surface, level, state);
643   }
644 }
645
646 static void TizenPolicyTransientForDone(void* data, struct tizen_policy* tizenPolicy, uint32_t childId)
647 {
648 }
649
650 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
651 {
652   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
653   if(windowBase)
654   {
655     windowBase->TizenPolicyScreenModeChangeDone(data, tizenPolicy, surface, mode, state);
656   }
657 }
658
659 static void TizenPolicyIconifyStateChanged(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force)
660 {
661 }
662
663 static void TizenPolicySupportedAuxiliaryHints(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints)
664 {
665 }
666
667 static void TizenPolicyAllowedAuxiliaryHint(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id)
668 {
669 }
670
671 static void TizenPolicyAuxiliaryMessage(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options)
672 {
673 }
674
675 static void TizenPolicyConformantRegion(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial)
676 {
677 }
678
679 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
680 {
681   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
682   if(windowBase)
683   {
684     windowBase->DisplayPolicyBrightnessChangeDone(data, displayPolicy, surface, brightness, state);
685   }
686 }
687
688 const struct wl_registry_listener registryListener =
689   {
690     RegistryGlobalCallback,
691     RegistryGlobalCallbackRemove};
692
693 const struct tizen_policy_listener tizenPolicyListener =
694   {
695     TizenPolicyConformant,
696     TizenPolicyConformantArea,
697     TizenPolicyNotificationChangeDone,
698     TizenPolicyTransientForDone,
699     TizenPolicyScreenModeChangeDone,
700     TizenPolicyIconifyStateChanged,
701     TizenPolicySupportedAuxiliaryHints,
702     TizenPolicyAllowedAuxiliaryHint,
703     TizenPolicyAuxiliaryMessage,
704     TizenPolicyConformantRegion};
705
706 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
707   {
708     DisplayPolicyBrightnessChangeDone};
709
710 } // unnamed namespace
711
712 WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surface, bool isTransparent)
713 : mEcoreEventHandler(),
714   mEcoreWindow(nullptr),
715   mWlSurface(nullptr),
716   mWlInputPanel(nullptr),
717   mWlOutput(nullptr),
718   mWlInputPanelSurface(nullptr),
719   mEglWindow(nullptr),
720   mDisplay(nullptr),
721   mEventQueue(nullptr),
722   mTizenPolicy(nullptr),
723   mTizenDisplayPolicy(nullptr),
724   mKeyMap(nullptr),
725   mSupportedAuxiliaryHints(),
726   mWindowPositionSize(positionSize),
727   mAuxiliaryHints(),
728   mType(WindowType::NORMAL),
729   mNotificationLevel(-1),
730   mScreenOffMode(0),
731   mBrightness(0),
732   mWindowRotationAngle(0),
733   mScreenRotationAngle(0),
734   mSupportedPreProtation(0),
735   mNotificationChangeState(0),
736   mScreenOffModeChangeState(0),
737   mBrightnessChangeState(0),
738   mLastSubmittedMoveResizeSerial(0),
739   mMoveResizeSerial(0),
740   mNotificationLevelChangeDone(true),
741   mScreenOffModeChangeDone(true),
742   mVisible(true),
743   mOwnSurface(false),
744   mBrightnessChangeDone(true)
745 #ifdef DALI_ELDBUS_AVAILABLE
746   ,
747   mSystemConnection(NULL)
748 #endif
749 {
750   Initialize(positionSize, surface, isTransparent);
751 }
752
753 WindowBaseEcoreWl2::~WindowBaseEcoreWl2()
754 {
755 #ifdef DALI_ELDBUS_AVAILABLE
756   // Close down ElDBus connections.
757   if(mSystemConnection)
758   {
759     eldbus_connection_unref(mSystemConnection);
760   }
761 #endif // DALI_ELDBUS_AVAILABLE
762
763   vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged);
764   vconf_ignore_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged);
765
766   for(Dali::Vector<Ecore_Event_Handler*>::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter)
767   {
768     ecore_event_handler_del(*iter);
769   }
770   mEcoreEventHandler.Clear();
771
772   if(mEventQueue)
773   {
774     wl_event_queue_destroy(mEventQueue);
775   }
776
777   mSupportedAuxiliaryHints.clear();
778   mAuxiliaryHints.clear();
779
780   if(mEglWindow != NULL)
781   {
782     wl_egl_window_destroy(mEglWindow);
783     mEglWindow = NULL;
784   }
785
786   if(mOwnSurface)
787   {
788     ecore_wl2_window_free(mEcoreWindow);
789
790     WindowSystem::Shutdown();
791   }
792 }
793
794 void WindowBaseEcoreWl2::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
795 {
796   if(surface.Empty() == false)
797   {
798     // check we have a valid type
799     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(Ecore_Wl2_Window*)) && "Surface type is invalid");
800
801     mEcoreWindow = AnyCast<Ecore_Wl2_Window*>(surface);
802   }
803   else
804   {
805     // we own the surface about to created
806     WindowSystem::Initialize();
807
808     mOwnSurface = true;
809     CreateWindow(positionSize);
810   }
811
812   mWlSurface = ecore_wl2_window_surface_get(mEcoreWindow);
813
814   SetTransparency(isTransparent);
815
816   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this));
817   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this));
818   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this));
819   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this));
820   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this));
821
822   // Register Rotate event
823   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE, EcoreEventRotate, this));
824
825   // Register Configure event
826   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE, EcoreEventConfigure, this));
827
828   // Register Touch events
829   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, this));
830   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, this));
831   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, this));
832   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, this));
833
834   // Register Mouse wheel events
835   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, this));
836
837   // Register Detent event
838   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DETENT_ROTATE, EcoreEventDetentRotation, this));
839
840   // Register Key events
841   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this));
842   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this));
843
844   // Register Selection event - clipboard selection
845   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this));
846   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, this));
847
848   // Register Effect Start/End event
849   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_START, EcoreEventEffectStart, this));
850   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_END, EcoreEventEffectEnd, this));
851
852   // Register Keyboard repeat event
853   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYBOARD_REPEAT_CHANGED, EcoreEventSeatKeyboardRepeatChanged, this));
854
855   // Register Window redraw request event
856   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_REDRAW_REQUEST, EcoreEventWindowRedrawRequest, this));
857
858   // Register Window auxiliary event
859   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_AUX_MESSAGE, EcoreEventWindowAuxiliaryMessage, this));
860
861   // Register Vconf notify - font name and size
862   vconf_notify_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this);
863   vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, this);
864
865   InitializeEcoreElDBus();
866
867   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
868   mDisplay                   = ecore_wl2_display_get(display);
869
870   if(mDisplay)
871   {
872     wl_display* displayWrapper = static_cast<wl_display*>(wl_proxy_create_wrapper(mDisplay));
873     if(displayWrapper)
874     {
875       mEventQueue = wl_display_create_queue(mDisplay);
876       if(mEventQueue)
877       {
878         wl_proxy_set_queue(reinterpret_cast<wl_proxy*>(displayWrapper), mEventQueue);
879
880         wl_registry* registry = wl_display_get_registry(displayWrapper);
881         wl_registry_add_listener(registry, &registryListener, this);
882       }
883
884       wl_proxy_wrapper_destroy(displayWrapper);
885     }
886   }
887
888   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(display);
889
890   if(ecoreWlInput)
891   {
892     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
893
894     mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYMAP_CHANGED, EcoreEventSeatKeymapChanged, this));
895   }
896
897   // get auxiliary hint
898   Eina_List* hints = ecore_wl2_window_aux_hints_supported_get(mEcoreWindow);
899   if(hints)
900   {
901     Eina_List* l    = NULL;
902     char*      hint = NULL;
903
904     for(l = hints, (hint = static_cast<char*>(eina_list_data_get(l))); l; l = eina_list_next(l), (hint = static_cast<char*>(eina_list_data_get(l))))
905     {
906       mSupportedAuxiliaryHints.push_back(hint);
907
908       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::Initialize: %s\n", hint);
909     }
910   }
911 }
912
913 Eina_Bool WindowBaseEcoreWl2::OnIconifyStateChanged(void* data, int type, void* event)
914 {
915   Ecore_Wl2_Event_Window_Iconify_State_Change* iconifyChangedEvent(static_cast<Ecore_Wl2_Event_Window_Iconify_State_Change*>(event));
916   Eina_Bool                                    handled(ECORE_CALLBACK_PASS_ON);
917
918   if(iconifyChangedEvent->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
919   {
920     if(iconifyChangedEvent->iconified == EINA_TRUE)
921     {
922       mIconifyChangedSignal.Emit(true);
923     }
924     else
925     {
926       mIconifyChangedSignal.Emit(false);
927     }
928     handled = ECORE_CALLBACK_DONE;
929   }
930
931   return handled;
932 }
933
934 Eina_Bool WindowBaseEcoreWl2::OnFocusIn(void* data, int type, void* event)
935 {
936   Ecore_Wl2_Event_Focus_In* focusInEvent(static_cast<Ecore_Wl2_Event_Focus_In*>(event));
937
938   if(focusInEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
939   {
940     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n");
941
942     mFocusChangedSignal.Emit(true);
943   }
944
945   return ECORE_CALLBACK_PASS_ON;
946 }
947
948 Eina_Bool WindowBaseEcoreWl2::OnFocusOut(void* data, int type, void* event)
949 {
950   Ecore_Wl2_Event_Focus_Out* focusOutEvent(static_cast<Ecore_Wl2_Event_Focus_Out*>(event));
951
952   if(focusOutEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
953   {
954     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n");
955
956     mFocusChangedSignal.Emit(false);
957   }
958
959   return ECORE_CALLBACK_PASS_ON;
960 }
961
962 Eina_Bool WindowBaseEcoreWl2::OnOutputTransform(void* data, int type, void* event)
963 {
964   Ecore_Wl2_Event_Output_Transform* transformEvent(static_cast<Ecore_Wl2_Event_Output_Transform*>(event));
965
966   if(transformEvent->output == ecore_wl2_window_output_find(mEcoreWindow))
967   {
968     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow);
969
970     mScreenRotationAngle = GetScreenRotationAngle();
971
972     mOutputTransformedSignal.Emit();
973   }
974
975   return ECORE_CALLBACK_PASS_ON;
976 }
977
978 Eina_Bool WindowBaseEcoreWl2::OnIgnoreOutputTransform(void* data, int type, void* event)
979 {
980   Ecore_Wl2_Event_Ignore_Output_Transform* ignoreTransformEvent(static_cast<Ecore_Wl2_Event_Ignore_Output_Transform*>(event));
981
982   if(ignoreTransformEvent->win == mEcoreWindow)
983   {
984     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow);
985
986     mScreenRotationAngle = GetScreenRotationAngle();
987
988     mOutputTransformedSignal.Emit();
989   }
990
991   return ECORE_CALLBACK_PASS_ON;
992 }
993
994 void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event)
995 {
996   Ecore_Wl2_Event_Window_Rotation* ev(static_cast<Ecore_Wl2_Event_Window_Rotation*>(event));
997
998   if(ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
999   {
1000     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h);
1001
1002     RotationEvent rotationEvent;
1003     rotationEvent.angle     = ev->angle;
1004     rotationEvent.winResize = 0;
1005
1006     if(ev->w == 0 || ev->h == 0)
1007     {
1008       // Use previous client side window's size.
1009       if(mWindowRotationAngle == 90 || mWindowRotationAngle == 270)
1010       {
1011         ev->w = mWindowPositionSize.height;
1012         ev->h = mWindowPositionSize.width;
1013       }
1014       else
1015       {
1016         ev->w = mWindowPositionSize.width;
1017         ev->h = mWindowPositionSize.height;
1018       }
1019     }
1020
1021     mWindowRotationAngle = ev->angle;
1022
1023     if(ev->angle == 0 || ev->angle == 180)
1024     {
1025       rotationEvent.width  = ev->w;
1026       rotationEvent.height = ev->h;
1027     }
1028     else
1029     {
1030       rotationEvent.width  = ev->h;
1031       rotationEvent.height = ev->w;
1032     }
1033
1034     mWindowPositionSize.width  = rotationEvent.width;
1035     mWindowPositionSize.height = rotationEvent.height;
1036
1037     mRotationSignal.Emit(rotationEvent);
1038   }
1039 }
1040
1041 void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
1042 {
1043   Ecore_Wl2_Event_Window_Configure* ev(static_cast<Ecore_Wl2_Event_Window_Configure*>(event));
1044
1045   if(ev && ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1046   {
1047     // Note: To comply with the wayland protocol, Dali should make an ack_configure
1048     // by calling ecore_wl2_window_commit
1049
1050     int tempWidth  = static_cast<int>(ev->w);
1051     int tempHeight = static_cast<int>(ev->h);
1052
1053     // Initialize with previous size for skip resize when new size is 0.
1054     // When window is just moved or window is resized by client application,
1055     // The configure notification event's size will be 0.
1056     // If new size is 0, the resized work should be skip.
1057     int  newWidth    = mWindowPositionSize.width;
1058     int  newHeight   = mWindowPositionSize.height;
1059     bool windowMoved = false, windowResized = false;
1060
1061     if(ev->x != mWindowPositionSize.x || ev->y != mWindowPositionSize.y)
1062     {
1063       windowMoved = true;
1064     }
1065
1066     if(tempWidth != 0 && tempHeight != 0 && (tempWidth != mWindowPositionSize.width || tempHeight != mWindowPositionSize.height))
1067     {
1068       windowResized = true;
1069       newWidth      = tempWidth;
1070       newHeight     = tempHeight;
1071     }
1072
1073     if(windowMoved || windowResized)
1074     {
1075       Dali::PositionSize newPositionSize(ev->x, ev->y, newWidth, newHeight);
1076       mWindowPositionSize = newPositionSize;
1077       DALI_LOG_RELEASE_INFO("Update position & resize signal by server, x[%d] y[%d] w[%d] h[%d]\n", newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height);
1078       mUpdatePositionSizeSignal.Emit(newPositionSize);
1079     }
1080
1081     ecore_wl2_window_commit(mEcoreWindow, EINA_FALSE);
1082   }
1083 }
1084
1085 void WindowBaseEcoreWl2::OnMouseButtonDown(void* data, int type, void* event)
1086 {
1087   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1088
1089   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1090   {
1091     Device::Class::Type    deviceClass;
1092     Device::Subclass::Type deviceSubclass;
1093
1094     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1095     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1096
1097     PointState::Type state(PointState::DOWN);
1098
1099     if(deviceClass != Device::Class::Type::MOUSE)
1100     {
1101       // Check if the buttons field is set and ensure it's the primary touch button.
1102       // If this event was triggered by buttons other than the primary button (used for touch), then
1103       // just send an interrupted event to Core.
1104       if(touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID))
1105       {
1106         state = PointState::INTERRUPTED;
1107       }
1108     }
1109
1110     Integration::Point point;
1111     point.SetDeviceId(touchEvent->multi.device);
1112     point.SetState(state);
1113     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1114     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1115     point.SetPressure(touchEvent->multi.pressure);
1116     point.SetAngle(Degree(touchEvent->multi.angle));
1117     point.SetDeviceClass(deviceClass);
1118     point.SetDeviceSubclass(deviceSubclass);
1119     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1120
1121     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1122   }
1123 }
1124
1125 void WindowBaseEcoreWl2::OnMouseButtonUp(void* data, int type, void* event)
1126 {
1127   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1128
1129   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1130   {
1131     Device::Class::Type    deviceClass;
1132     Device::Subclass::Type deviceSubclass;
1133
1134     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1135     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1136
1137     Integration::Point point;
1138     point.SetDeviceId(touchEvent->multi.device);
1139     point.SetState(PointState::UP);
1140     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1141     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1142     point.SetPressure(touchEvent->multi.pressure);
1143     point.SetAngle(Degree(touchEvent->multi.angle));
1144     point.SetDeviceClass(deviceClass);
1145     point.SetDeviceSubclass(deviceSubclass);
1146     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1147
1148     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1149   }
1150 }
1151
1152 void WindowBaseEcoreWl2::OnMouseButtonMove(void* data, int type, void* event)
1153 {
1154   Ecore_Event_Mouse_Move* touchEvent = static_cast<Ecore_Event_Mouse_Move*>(event);
1155
1156   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1157   {
1158     Device::Class::Type    deviceClass;
1159     Device::Subclass::Type deviceSubclass;
1160
1161     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1162     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1163
1164     Integration::Point point;
1165     point.SetDeviceId(touchEvent->multi.device);
1166     point.SetState(PointState::MOTION);
1167     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1168     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1169     point.SetPressure(touchEvent->multi.pressure);
1170     point.SetAngle(Degree(touchEvent->multi.angle));
1171     point.SetDeviceClass(deviceClass);
1172     point.SetDeviceSubclass(deviceSubclass);
1173
1174     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1175   }
1176 }
1177
1178 void WindowBaseEcoreWl2::OnMouseButtonCancel(void* data, int type, void* event)
1179 {
1180   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1181
1182   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1183   {
1184     Integration::Point point;
1185     point.SetDeviceId(touchEvent->multi.device);
1186     point.SetState(PointState::INTERRUPTED);
1187     point.SetScreenPosition(Vector2(0.0f, 0.0f));
1188
1189     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1190
1191     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseButtonCancel\n");
1192   }
1193 }
1194
1195 void WindowBaseEcoreWl2::OnMouseWheel(void* data, int type, void* event)
1196 {
1197   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast<Ecore_Event_Mouse_Wheel*>(event);
1198
1199   if(mouseWheelEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1200   {
1201     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
1202
1203     Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
1204
1205     mWheelEventSignal.Emit(wheelEvent);
1206   }
1207 }
1208
1209 void WindowBaseEcoreWl2::OnDetentRotation(void* data, int type, void* event)
1210 {
1211   Ecore_Event_Detent_Rotate* detentEvent = static_cast<Ecore_Event_Detent_Rotate*>(event);
1212
1213   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::OnDetentRotation\n");
1214
1215   int32_t clockwise = (detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1216
1217   Integration::WheelEvent wheelEvent(Integration::WheelEvent::CUSTOM_WHEEL, detentEvent->direction, 0, Vector2(0.0f, 0.0f), clockwise, detentEvent->timestamp);
1218
1219   mWheelEventSignal.Emit(wheelEvent);
1220 }
1221
1222 void WindowBaseEcoreWl2::OnKeyDown(void* data, int type, void* event)
1223 {
1224   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1225
1226   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1227   {
1228     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyDown\n");
1229
1230     std::string keyName(keyEvent->keyname);
1231     std::string logicalKey("");
1232     std::string keyString("");
1233     std::string compose("");
1234
1235     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1236     if(keyEvent->compose)
1237     {
1238       compose = keyEvent->compose;
1239     }
1240
1241     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1242     if(keyEvent->key)
1243     {
1244       logicalKey = keyEvent->key;
1245     }
1246
1247     int keyCode = 0;
1248     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1249
1250     if(keyCode == 0)
1251     {
1252       // Get a specific key code from dali key look up table.
1253       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1254     }
1255
1256     keyCode = (keyCode == -1) ? 0 : keyCode;
1257     int           modifier(keyEvent->modifiers);
1258     unsigned long time = keyEvent->timestamp;
1259     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1260     {
1261       keyCode = atoi(keyEvent->keyname + 8);
1262     }
1263
1264     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1265     if(keyEvent->string)
1266     {
1267       keyString = keyEvent->string;
1268     }
1269
1270     std::string            deviceName;
1271     Device::Class::Type    deviceClass;
1272     Device::Subclass::Type deviceSubclass;
1273
1274     GetDeviceName(keyEvent, deviceName);
1275     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1276     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1277
1278     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::DOWN, compose, deviceName, deviceClass, deviceSubclass);
1279
1280     mKeyEventSignal.Emit(keyEvent);
1281   }
1282 }
1283
1284 void WindowBaseEcoreWl2::OnKeyUp(void* data, int type, void* event)
1285 {
1286   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1287
1288   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1289   {
1290     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp\n");
1291
1292 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
1293     // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
1294     if(keyEvent->event_flags & ECORE_EVENT_FLAG_CANCEL)
1295     {
1296       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp: This event flag indicates the event is canceled. \n");
1297       return;
1298     }
1299 #endif // Since ecore 1.23 version
1300
1301     std::string keyName(keyEvent->keyname);
1302     std::string logicalKey("");
1303     std::string keyString("");
1304     std::string compose("");
1305
1306     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1307     if(keyEvent->compose)
1308     {
1309       compose = keyEvent->compose;
1310     }
1311
1312     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1313     if(keyEvent->key)
1314     {
1315       logicalKey = keyEvent->key;
1316     }
1317
1318     int keyCode = 0;
1319     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1320
1321     if(keyCode == 0)
1322     {
1323       // Get a specific key code from dali key look up table.
1324       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1325     }
1326
1327     keyCode = (keyCode == -1) ? 0 : keyCode;
1328     int           modifier(keyEvent->modifiers);
1329     unsigned long time = keyEvent->timestamp;
1330     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1331     {
1332       keyCode = atoi(keyEvent->keyname + 8);
1333     }
1334
1335     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1336     if(keyEvent->string)
1337     {
1338       keyString = keyEvent->string;
1339     }
1340
1341     std::string            deviceName;
1342     Device::Class::Type    deviceClass;
1343     Device::Subclass::Type deviceSubclass;
1344
1345     GetDeviceName(keyEvent, deviceName);
1346     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1347     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1348
1349     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, compose, deviceName, deviceClass, deviceSubclass);
1350
1351     mKeyEventSignal.Emit(keyEvent);
1352   }
1353 }
1354
1355 void WindowBaseEcoreWl2::OnDataSend(void* data, int type, void* event)
1356 {
1357   mSelectionDataSendSignal.Emit(event);
1358 }
1359
1360 void WindowBaseEcoreWl2::OnDataReceive(void* data, int type, void* event)
1361 {
1362   mSelectionDataReceivedSignal.Emit(event);
1363 }
1364
1365 void WindowBaseEcoreWl2::OnFontNameChanged()
1366 {
1367   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_CHANGE);
1368 }
1369
1370 void WindowBaseEcoreWl2::OnFontSizeChanged()
1371 {
1372   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1373 }
1374
1375 #ifdef DALI_ELDBUS_AVAILABLE
1376 void WindowBaseEcoreWl2::OnEcoreElDBusAccessibilityNotification(void* context, const Eldbus_Message* message)
1377 {
1378   AccessibilityInfo info;
1379
1380   // The string defines the arg-list's respective types.
1381   if(!eldbus_message_arguments_get(message, "iiiiiiu", &info.gestureValue, &info.startX, &info.startY, &info.endX, &info.endY, &info.state, &info.eventTime))
1382   {
1383     DALI_LOG_ERROR("OnEcoreElDBusAccessibilityNotification: Error getting arguments\n");
1384   }
1385
1386   mAccessibilitySignal.Emit(info);
1387 }
1388 #endif // DALI_ELDBUS_AVAILABLE
1389
1390 void WindowBaseEcoreWl2::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
1391 {
1392   mTransitionEffectEventSignal.Emit(state, type);
1393 }
1394
1395 void WindowBaseEcoreWl2::OnKeyboardRepeatSettingsChanged()
1396 {
1397   mKeyboardRepeatSettingsChangedSignal.Emit();
1398 }
1399
1400 void WindowBaseEcoreWl2::OnEcoreEventWindowRedrawRequest()
1401 {
1402   mWindowRedrawRequestSignal.Emit();
1403 }
1404
1405 void WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage(void* event)
1406 {
1407   Ecore_Wl2_Event_Aux_Message* message = static_cast<Ecore_Wl2_Event_Aux_Message*>(event);
1408   if(message)
1409   {
1410     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, key:%s, value:%s \n", message->key, message->val);
1411     std::string           key(message->key);
1412     std::string           value(message->val);
1413     Dali::Property::Array options;
1414
1415     if(message->options)
1416     {
1417       Eina_List* l;
1418       void*      data;
1419       EINA_LIST_FOREACH(message->options, l, data)
1420       {
1421         DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, option: %s\n", (char*)data);
1422         std::string option(static_cast<char*>(data));
1423         options.Add(option);
1424       }
1425     }
1426
1427     mAuxiliaryMessageSignal.Emit(key, value, options);
1428   }
1429 }
1430
1431 void WindowBaseEcoreWl2::KeymapChanged(void* data, int type, void* event)
1432 {
1433   Ecore_Wl2_Event_Seat_Keymap_Changed* changed = static_cast<Ecore_Wl2_Event_Seat_Keymap_Changed*>(event);
1434   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::KeymapChanged, keymap id[ %d ]\n", changed->id);
1435   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(changed->display);
1436   if(ecoreWlInput)
1437   {
1438     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
1439   }
1440 }
1441
1442 void WindowBaseEcoreWl2::RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
1443 {
1444   if(strcmp(interface, tizen_policy_interface.name) == 0)
1445   {
1446     uint32_t clientVersion = std::min(version, MAX_TIZEN_CLIENT_VERSION);
1447
1448     mTizenPolicy = static_cast<tizen_policy*>(wl_registry_bind(registry, name, &tizen_policy_interface, clientVersion));
1449     if(!mTizenPolicy)
1450     {
1451       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n");
1452       return;
1453     }
1454
1455     tizen_policy_add_listener(mTizenPolicy, &tizenPolicyListener, data);
1456
1457     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_policy_add_listener is called.\n");
1458   }
1459   else if(strcmp(interface, tizen_display_policy_interface.name) == 0)
1460   {
1461     mTizenDisplayPolicy = static_cast<tizen_display_policy*>(wl_registry_bind(registry, name, &tizen_display_policy_interface, version));
1462     if(!mTizenDisplayPolicy)
1463     {
1464       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n");
1465       return;
1466     }
1467
1468     tizen_display_policy_add_listener(mTizenDisplayPolicy, &tizenDisplayPolicyListener, data);
1469
1470     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n");
1471   }
1472 }
1473
1474 void WindowBaseEcoreWl2::RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
1475 {
1476   mTizenPolicy        = NULL;
1477   mTizenDisplayPolicy = NULL;
1478 }
1479
1480 void WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
1481 {
1482   mNotificationLevel           = level;
1483   mNotificationChangeState     = state;
1484   mNotificationLevelChangeDone = true;
1485
1486   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state);
1487 }
1488
1489 void WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
1490 {
1491   mScreenOffMode            = mode;
1492   mScreenOffModeChangeState = state;
1493   mScreenOffModeChangeDone  = true;
1494
1495   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state);
1496 }
1497
1498 void WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
1499 {
1500   mBrightness            = brightness;
1501   mBrightnessChangeState = state;
1502   mBrightnessChangeDone  = true;
1503
1504   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state);
1505 }
1506
1507 void WindowBaseEcoreWl2::GetKeyCode(std::string keyName, int32_t& keyCode)
1508 {
1509   xkb_keysym_t sym = XKB_KEY_NoSymbol;
1510   KeyCodeMap   foundKeyCode;
1511
1512   sym = xkb_keysym_from_name(keyName.c_str(), XKB_KEYSYM_NO_FLAGS);
1513   if(sym == XKB_KEY_NoSymbol)
1514   {
1515     DALI_LOG_ERROR("Failed to get keysym in WindowBaseEcoreWl2\n");
1516     return;
1517   }
1518
1519   foundKeyCode.keySym    = sym;
1520   foundKeyCode.isKeyCode = false;
1521   xkb_keymap_key_for_each(mKeyMap, FindKeyCode, &foundKeyCode);
1522   keyCode = static_cast<int32_t>(foundKeyCode.keyCode);
1523 }
1524
1525 Any WindowBaseEcoreWl2::GetNativeWindow()
1526 {
1527   return mEcoreWindow;
1528 }
1529
1530 int WindowBaseEcoreWl2::GetNativeWindowId()
1531 {
1532   return ecore_wl2_window_id_get(mEcoreWindow);
1533 }
1534
1535 EGLNativeWindowType WindowBaseEcoreWl2::CreateEglWindow(int width, int height)
1536 {
1537   int totalAngle = (mWindowRotationAngle + mScreenRotationAngle) % 360;
1538   if(totalAngle == 90 || totalAngle == 270)
1539   {
1540     mEglWindow = wl_egl_window_create(mWlSurface, height, width);
1541   }
1542   else
1543   {
1544     mEglWindow = wl_egl_window_create(mWlSurface, width, height);
1545   }
1546
1547   return static_cast<EGLNativeWindowType>(mEglWindow);
1548 }
1549
1550 void WindowBaseEcoreWl2::DestroyEglWindow()
1551 {
1552   if(mEglWindow != NULL)
1553   {
1554     wl_egl_window_destroy(mEglWindow);
1555     mEglWindow = NULL;
1556   }
1557 }
1558
1559 void WindowBaseEcoreWl2::SetEglWindowRotation(int angle)
1560 {
1561   wl_egl_window_tizen_rotation rotation;
1562
1563   switch(angle)
1564   {
1565     case 0:
1566     {
1567       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1568       break;
1569     }
1570     case 90:
1571     {
1572       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_270;
1573       break;
1574     }
1575     case 180:
1576     {
1577       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_180;
1578       break;
1579     }
1580     case 270:
1581     {
1582       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_90;
1583       break;
1584     }
1585     default:
1586     {
1587       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1588       break;
1589     }
1590   }
1591
1592   wl_egl_window_tizen_set_rotation(mEglWindow, rotation);
1593 }
1594
1595 void WindowBaseEcoreWl2::SetEglWindowBufferTransform(int angle)
1596 {
1597   wl_output_transform bufferTransform;
1598
1599   switch(angle)
1600   {
1601     case 0:
1602     {
1603       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1604       break;
1605     }
1606     case 90:
1607     {
1608       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1609       break;
1610     }
1611     case 180:
1612     {
1613       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1614       break;
1615     }
1616     case 270:
1617     {
1618       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1619       break;
1620     }
1621     default:
1622     {
1623       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1624       break;
1625     }
1626   }
1627
1628   wl_egl_window_tizen_set_buffer_transform(mEglWindow, bufferTransform);
1629 }
1630
1631 void WindowBaseEcoreWl2::SetEglWindowTransform(int angle)
1632 {
1633   wl_output_transform windowTransform;
1634
1635   switch(angle)
1636   {
1637     case 0:
1638     {
1639       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1640       break;
1641     }
1642     case 90:
1643     {
1644       windowTransform = WL_OUTPUT_TRANSFORM_90;
1645       break;
1646     }
1647     case 180:
1648     {
1649       windowTransform = WL_OUTPUT_TRANSFORM_180;
1650       break;
1651     }
1652     case 270:
1653     {
1654       windowTransform = WL_OUTPUT_TRANSFORM_270;
1655       break;
1656     }
1657     default:
1658     {
1659       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1660       break;
1661     }
1662   }
1663
1664   wl_egl_window_tizen_set_window_transform(mEglWindow, windowTransform);
1665 }
1666
1667 void WindowBaseEcoreWl2::ResizeEglWindow(PositionSize positionSize)
1668 {
1669   wl_egl_window_resize(mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y);
1670
1671   // Note: Both "Resize" and "MoveResize" cases can reach here, but only "MoveResize" needs to submit serial number
1672   if(mMoveResizeSerial != mLastSubmittedMoveResizeSerial)
1673   {
1674     wl_egl_window_tizen_set_window_serial(mEglWindow, mMoveResizeSerial);
1675     mLastSubmittedMoveResizeSerial = mMoveResizeSerial;
1676   }
1677 }
1678
1679 bool WindowBaseEcoreWl2::IsEglWindowRotationSupported()
1680 {
1681   // Check capability
1682   wl_egl_window_tizen_capability capability = static_cast<wl_egl_window_tizen_capability>(wl_egl_window_tizen_get_capabilities(mEglWindow));
1683   if(capability == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED)
1684   {
1685     mSupportedPreProtation = true;
1686     return true;
1687   }
1688   mSupportedPreProtation = false;
1689   return false;
1690 }
1691
1692 void WindowBaseEcoreWl2::Move(PositionSize positionSize)
1693 {
1694   mWindowPositionSize = positionSize;
1695   ecore_wl2_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1696 }
1697
1698 void WindowBaseEcoreWl2::Resize(PositionSize positionSize)
1699 {
1700   mWindowPositionSize = positionSize;
1701   ecore_wl2_window_geometry_set(mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
1702 }
1703
1704 void WindowBaseEcoreWl2::MoveResize(PositionSize positionSize)
1705 {
1706   mWindowPositionSize = positionSize;
1707   ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
1708 }
1709
1710 void WindowBaseEcoreWl2::SetClass(const std::string& name, const std::string& className)
1711 {
1712   ecore_wl2_window_title_set(mEcoreWindow, name.c_str());
1713   ecore_wl2_window_class_set(mEcoreWindow, className.c_str());
1714 }
1715
1716 void WindowBaseEcoreWl2::Raise()
1717 {
1718   // Use ecore_wl2_window_activate to prevent the window shown without rendering
1719   ecore_wl2_window_activate(mEcoreWindow);
1720 }
1721
1722 void WindowBaseEcoreWl2::Lower()
1723 {
1724   ecore_wl2_window_lower(mEcoreWindow);
1725 }
1726
1727 void WindowBaseEcoreWl2::Activate()
1728 {
1729   ecore_wl2_window_activate(mEcoreWindow);
1730 }
1731
1732 void WindowBaseEcoreWl2::Maximize(bool maximize)
1733 {
1734   ecore_wl2_window_maximized_set(mEcoreWindow, maximize);
1735 }
1736
1737 bool WindowBaseEcoreWl2::IsMaximized() const
1738 {
1739   return ecore_wl2_window_maximized_get(mEcoreWindow);
1740 }
1741
1742 void WindowBaseEcoreWl2::Minimize(bool minimize)
1743 {
1744   ecore_wl2_window_iconified_set(mEcoreWindow, minimize);
1745 }
1746
1747 bool WindowBaseEcoreWl2::IsMinimized() const
1748 {
1749   return ecore_wl2_window_iconified_get(mEcoreWindow);
1750 }
1751
1752 void WindowBaseEcoreWl2::SetAvailableAnlges(const std::vector<int>& angles)
1753 {
1754   int rotations[4] = {0};
1755   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size());
1756   for(std::size_t i = 0; i < angles.size(); ++i)
1757   {
1758     rotations[i] = static_cast<int>(angles[i]);
1759     DALI_LOG_RELEASE_INFO("%d ", rotations[i]);
1760   }
1761   ecore_wl2_window_available_rotations_set(mEcoreWindow, rotations, angles.size());
1762 }
1763
1764 void WindowBaseEcoreWl2::SetPreferredAngle(int angle)
1765 {
1766   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPreferredAngle, angle: %d\n", angle);
1767   ecore_wl2_window_preferred_rotation_set(mEcoreWindow, angle);
1768 }
1769
1770 void WindowBaseEcoreWl2::SetAcceptFocus(bool accept)
1771 {
1772   ecore_wl2_window_focus_skip_set(mEcoreWindow, !accept);
1773 }
1774
1775 void WindowBaseEcoreWl2::Show()
1776 {
1777   if(!mVisible)
1778   {
1779     // Ecore-wl2 has the original window size
1780     // and he always sends the window rotation event with the swapped size.
1781     // So, to restore, dali should set the reswapped size(original window size) to ecore-wl2 for restoring.
1782     if(mWindowRotationAngle == 0 || mWindowRotationAngle == 180)
1783     {
1784       ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height);
1785     }
1786     else
1787     {
1788       ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.height, mWindowPositionSize.width);
1789     }
1790   }
1791   mVisible = true;
1792
1793   ecore_wl2_window_show(mEcoreWindow);
1794 }
1795
1796 void WindowBaseEcoreWl2::Hide()
1797 {
1798   mVisible = false;
1799   ecore_wl2_window_hide(mEcoreWindow);
1800 }
1801
1802 unsigned int WindowBaseEcoreWl2::GetSupportedAuxiliaryHintCount() const
1803 {
1804   return mSupportedAuxiliaryHints.size();
1805 }
1806
1807 std::string WindowBaseEcoreWl2::GetSupportedAuxiliaryHint(unsigned int index) const
1808 {
1809   if(index >= GetSupportedAuxiliaryHintCount())
1810   {
1811     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index);
1812   }
1813
1814   return mSupportedAuxiliaryHints[index];
1815 }
1816
1817 unsigned int WindowBaseEcoreWl2::AddAuxiliaryHint(const std::string& hint, const std::string& value)
1818 {
1819   bool supported = false;
1820
1821   // Check if the hint is suppported
1822   for(std::vector<std::string>::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter)
1823   {
1824     if(*iter == hint)
1825     {
1826       supported = true;
1827       break;
1828     }
1829   }
1830
1831   if(!supported)
1832   {
1833     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str());
1834     return 0;
1835   }
1836
1837   // Check if the hint is already added
1838   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1839   {
1840     if(mAuxiliaryHints[i].first == hint)
1841     {
1842       // Just change the value
1843       mAuxiliaryHints[i].second = value;
1844
1845       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1);
1846
1847       return i + 1; // id is index + 1
1848     }
1849   }
1850
1851   // Add the hint
1852   mAuxiliaryHints.push_back(std::pair<std::string, std::string>(hint, value));
1853
1854   unsigned int id = mAuxiliaryHints.size();
1855
1856   ecore_wl2_window_aux_hint_add(mEcoreWindow, static_cast<int>(id), hint.c_str(), value.c_str());
1857
1858   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id);
1859
1860   return id;
1861 }
1862
1863 bool WindowBaseEcoreWl2::RemoveAuxiliaryHint(unsigned int id)
1864 {
1865   if(id == 0 || id > mAuxiliaryHints.size())
1866   {
1867     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: Invalid id [%d]\n", id);
1868     return false;
1869   }
1870
1871   mAuxiliaryHints[id - 1].second = std::string();
1872
1873   ecore_wl2_window_aux_hint_del(mEcoreWindow, static_cast<int>(id));
1874
1875   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str());
1876
1877   return true;
1878 }
1879
1880 bool WindowBaseEcoreWl2::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
1881 {
1882   if(id == 0 || id > mAuxiliaryHints.size())
1883   {
1884     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: Invalid id [%d]\n", id);
1885     return false;
1886   }
1887
1888   mAuxiliaryHints[id - 1].second = value;
1889
1890   ecore_wl2_window_aux_hint_change(mEcoreWindow, static_cast<int>(id), value.c_str());
1891
1892   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1893
1894   return true;
1895 }
1896
1897 std::string WindowBaseEcoreWl2::GetAuxiliaryHintValue(unsigned int id) const
1898 {
1899   if(id == 0 || id > mAuxiliaryHints.size())
1900   {
1901     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: Invalid id [%d]\n", id);
1902     return std::string();
1903   }
1904
1905   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1906
1907   return mAuxiliaryHints[id - 1].second;
1908 }
1909
1910 unsigned int WindowBaseEcoreWl2::GetAuxiliaryHintId(const std::string& hint) const
1911 {
1912   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1913   {
1914     if(mAuxiliaryHints[i].first == hint)
1915     {
1916       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1);
1917       return i + 1;
1918     }
1919   }
1920
1921   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str());
1922
1923   return 0;
1924 }
1925
1926 void WindowBaseEcoreWl2::SetInputRegion(const Rect<int>& inputRegion)
1927 {
1928   ecore_wl2_window_input_region_set(mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1929 }
1930
1931 void WindowBaseEcoreWl2::SetType(Dali::WindowType type)
1932 {
1933   if(mType != type)
1934   {
1935     mType = type;
1936     Ecore_Wl2_Window_Type windowType;
1937
1938     switch(type)
1939     {
1940       case Dali::WindowType::NORMAL:
1941       {
1942         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1943         break;
1944       }
1945       case Dali::WindowType::NOTIFICATION:
1946       {
1947         windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
1948         break;
1949       }
1950       case Dali::WindowType::UTILITY:
1951       {
1952         windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
1953         break;
1954       }
1955       case Dali::WindowType::DIALOG:
1956       {
1957         windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
1958         break;
1959       }
1960       case Dali::WindowType::IME:
1961       {
1962         windowType = ECORE_WL2_WINDOW_TYPE_NONE;
1963         break;
1964       }
1965       default:
1966       {
1967         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1968         break;
1969       }
1970     }
1971     ecore_wl2_window_type_set(mEcoreWindow, windowType);
1972   }
1973 }
1974
1975 Dali::WindowType WindowBaseEcoreWl2::GetType() const
1976 {
1977   return mType;
1978 }
1979
1980 Dali::WindowOperationResult WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel level)
1981 {
1982   while(!mTizenPolicy)
1983   {
1984     wl_display_dispatch_queue(mDisplay, mEventQueue);
1985   }
1986
1987   int notificationLevel;
1988
1989   switch(level)
1990   {
1991     case Dali::WindowNotificationLevel::NONE:
1992     {
1993       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1994       break;
1995     }
1996     case Dali::WindowNotificationLevel::BASE:
1997     {
1998       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1999       break;
2000     }
2001     case Dali::WindowNotificationLevel::MEDIUM:
2002     {
2003       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
2004       break;
2005     }
2006     case Dali::WindowNotificationLevel::HIGH:
2007     {
2008       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
2009       break;
2010     }
2011     case Dali::WindowNotificationLevel::TOP:
2012     {
2013       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
2014       break;
2015     }
2016     default:
2017     {
2018       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: invalid level [%d]\n", level);
2019       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
2020       break;
2021     }
2022   }
2023
2024   mNotificationLevelChangeDone = false;
2025   mNotificationChangeState     = TIZEN_POLICY_ERROR_STATE_NONE;
2026
2027   tizen_policy_set_notification_level(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), notificationLevel);
2028
2029   int count = 0;
2030
2031   while(!mNotificationLevelChangeDone && count < 3)
2032   {
2033     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2034     wl_display_dispatch_queue(mDisplay, mEventQueue);
2035     count++;
2036   }
2037
2038   if(!mNotificationLevelChangeDone)
2039   {
2040     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
2041     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2042   }
2043   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2044   {
2045     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Permission denied! [%d]\n", level);
2046     return Dali::WindowOperationResult::PERMISSION_DENIED;
2047   }
2048
2049   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
2050
2051   return Dali::WindowOperationResult::SUCCEED;
2052 }
2053
2054 Dali::WindowNotificationLevel WindowBaseEcoreWl2::GetNotificationLevel() const
2055 {
2056   while(!mTizenPolicy)
2057   {
2058     wl_display_dispatch_queue(mDisplay, mEventQueue);
2059   }
2060
2061   int count = 0;
2062
2063   while(!mNotificationLevelChangeDone && count < 3)
2064   {
2065     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2066     wl_display_dispatch_queue(mDisplay, mEventQueue);
2067     count++;
2068   }
2069
2070   if(!mNotificationLevelChangeDone)
2071   {
2072     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState);
2073     return Dali::WindowNotificationLevel::NONE;
2074   }
2075
2076   Dali::WindowNotificationLevel level;
2077
2078   switch(mNotificationLevel)
2079   {
2080     case TIZEN_POLICY_LEVEL_NONE:
2081     {
2082       level = Dali::WindowNotificationLevel::NONE;
2083       break;
2084     }
2085     case TIZEN_POLICY_LEVEL_DEFAULT:
2086     {
2087       level = Dali::WindowNotificationLevel::BASE;
2088       break;
2089     }
2090     case TIZEN_POLICY_LEVEL_MEDIUM:
2091     {
2092       level = Dali::WindowNotificationLevel::MEDIUM;
2093       break;
2094     }
2095     case TIZEN_POLICY_LEVEL_HIGH:
2096     {
2097       level = Dali::WindowNotificationLevel::HIGH;
2098       break;
2099     }
2100     case TIZEN_POLICY_LEVEL_TOP:
2101     {
2102       level = Dali::WindowNotificationLevel::TOP;
2103       break;
2104     }
2105     default:
2106     {
2107       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel);
2108       level = Dali::WindowNotificationLevel::NONE;
2109       break;
2110     }
2111   }
2112
2113   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: level [%d]\n", mNotificationLevel);
2114
2115   return level;
2116 }
2117
2118 void WindowBaseEcoreWl2::SetOpaqueState(bool opaque)
2119 {
2120   while(!mTizenPolicy)
2121   {
2122     wl_display_dispatch_queue(mDisplay, mEventQueue);
2123   }
2124
2125   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
2126 }
2127
2128 Dali::WindowOperationResult WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
2129 {
2130   while(!mTizenPolicy)
2131   {
2132     wl_display_dispatch_queue(mDisplay, mEventQueue);
2133   }
2134
2135   mScreenOffModeChangeDone  = false;
2136   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2137
2138   unsigned int mode = 0;
2139
2140   switch(screenOffMode)
2141   {
2142     case WindowScreenOffMode::TIMEOUT:
2143     {
2144       mode = 0;
2145       break;
2146     }
2147     case WindowScreenOffMode::NEVER:
2148     {
2149       mode = 1;
2150       break;
2151     }
2152   }
2153
2154   tizen_policy_set_window_screen_mode(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), mode);
2155
2156   int count = 0;
2157
2158   while(!mScreenOffModeChangeDone && count < 3)
2159   {
2160     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2161     wl_display_dispatch_queue(mDisplay, mEventQueue);
2162     count++;
2163   }
2164
2165   if(!mScreenOffModeChangeDone)
2166   {
2167     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
2168     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2169   }
2170   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2171   {
2172     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
2173     return Dali::WindowOperationResult::PERMISSION_DENIED;
2174   }
2175
2176   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
2177
2178   return Dali::WindowOperationResult::SUCCEED;
2179 }
2180
2181 WindowScreenOffMode WindowBaseEcoreWl2::GetScreenOffMode() const
2182 {
2183   while(!mTizenPolicy)
2184   {
2185     wl_display_dispatch_queue(mDisplay, mEventQueue);
2186   }
2187
2188   int count = 0;
2189
2190   while(!mScreenOffModeChangeDone && count < 3)
2191   {
2192     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2193     wl_display_dispatch_queue(mDisplay, mEventQueue);
2194     count++;
2195   }
2196
2197   if(!mScreenOffModeChangeDone)
2198   {
2199     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState);
2200     return WindowScreenOffMode::TIMEOUT;
2201   }
2202
2203   WindowScreenOffMode screenMode = WindowScreenOffMode::TIMEOUT;
2204
2205   switch(mScreenOffMode)
2206   {
2207     case 0:
2208     {
2209       screenMode = WindowScreenOffMode::TIMEOUT;
2210       break;
2211     }
2212     case 1:
2213     {
2214       screenMode = WindowScreenOffMode::NEVER;
2215       break;
2216     }
2217   }
2218
2219   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode);
2220
2221   return screenMode;
2222 }
2223
2224 Dali::WindowOperationResult WindowBaseEcoreWl2::SetBrightness(int brightness)
2225 {
2226   while(!mTizenDisplayPolicy)
2227   {
2228     wl_display_dispatch_queue(mDisplay, mEventQueue);
2229   }
2230
2231   mBrightnessChangeDone  = false;
2232   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2233
2234   tizen_display_policy_set_window_brightness(mTizenDisplayPolicy, ecore_wl2_window_surface_get(mEcoreWindow), brightness);
2235
2236   int count = 0;
2237
2238   while(!mBrightnessChangeDone && count < 3)
2239   {
2240     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2241     wl_display_dispatch_queue(mDisplay, mEventQueue);
2242     count++;
2243   }
2244
2245   if(!mBrightnessChangeDone)
2246   {
2247     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
2248     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2249   }
2250   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2251   {
2252     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Permission denied! [%d]\n", brightness);
2253     return Dali::WindowOperationResult::PERMISSION_DENIED;
2254   }
2255
2256   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness is changed [%d]\n", mBrightness);
2257
2258   return Dali::WindowOperationResult::SUCCEED;
2259 }
2260
2261 int WindowBaseEcoreWl2::GetBrightness() const
2262 {
2263   while(!mTizenDisplayPolicy)
2264   {
2265     wl_display_dispatch_queue(mDisplay, mEventQueue);
2266   }
2267
2268   int count = 0;
2269
2270   while(!mBrightnessChangeDone && count < 3)
2271   {
2272     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2273     wl_display_dispatch_queue(mDisplay, mEventQueue);
2274     count++;
2275   }
2276
2277   if(!mBrightnessChangeDone)
2278   {
2279     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Error! [%d]\n", mBrightnessChangeState);
2280     return 0;
2281   }
2282
2283   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Brightness [%d]\n", mBrightness);
2284
2285   return mBrightness;
2286 }
2287
2288 bool WindowBaseEcoreWl2::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
2289 {
2290   Ecore_Wl2_Window_Keygrab_Mode mode;
2291
2292   switch(grabMode)
2293   {
2294     case KeyGrab::TOPMOST:
2295     {
2296       mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2297       break;
2298     }
2299     case KeyGrab::SHARED:
2300     {
2301       mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2302       break;
2303     }
2304     case KeyGrab::OVERRIDE_EXCLUSIVE:
2305     {
2306       mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2307       break;
2308     }
2309     case KeyGrab::EXCLUSIVE:
2310     {
2311       mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2312       break;
2313     }
2314     default:
2315     {
2316       return false;
2317     }
2318   }
2319
2320   return ecore_wl2_window_keygrab_set(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0, 0, mode);
2321 }
2322
2323 bool WindowBaseEcoreWl2::UngrabKey(Dali::KEY key)
2324 {
2325   return ecore_wl2_window_keygrab_unset(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0);
2326 }
2327
2328 bool WindowBaseEcoreWl2::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
2329 {
2330   int keyCount         = key.Count();
2331   int keyGrabModeCount = grabMode.Count();
2332
2333   if(keyCount != keyGrabModeCount || keyCount == 0)
2334   {
2335     return false;
2336   }
2337
2338   eina_init();
2339
2340   Eina_List*                     keyList = NULL;
2341   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2342
2343   for(int index = 0; index < keyCount; ++index)
2344   {
2345     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2346
2347     switch(grabMode[index])
2348     {
2349       case KeyGrab::TOPMOST:
2350       {
2351         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2352         break;
2353       }
2354       case KeyGrab::SHARED:
2355       {
2356         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2357         break;
2358       }
2359       case KeyGrab::OVERRIDE_EXCLUSIVE:
2360       {
2361         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2362         break;
2363       }
2364       case KeyGrab::EXCLUSIVE:
2365       {
2366         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2367         break;
2368       }
2369       default:
2370       {
2371         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_UNKNOWN;
2372         break;
2373       }
2374     }
2375
2376     keyList = eina_list_append(keyList, &info);
2377   }
2378
2379   Eina_List* grabList = ecore_wl2_window_keygrab_list_set(mEcoreWindow, keyList);
2380
2381   result.Resize(keyCount, true);
2382
2383   Eina_List* l        = NULL;
2384   Eina_List* m        = NULL;
2385   void*      listData = NULL;
2386   void*      data     = NULL;
2387   if(grabList != NULL)
2388   {
2389     EINA_LIST_FOREACH(grabList, m, data)
2390     {
2391       int index = 0;
2392       EINA_LIST_FOREACH(keyList, l, listData)
2393       {
2394         if(static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key == NULL)
2395         {
2396           DALI_LOG_ERROR("input key list has null data!");
2397           break;
2398         }
2399
2400         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2401         {
2402           result[index] = false;
2403         }
2404         ++index;
2405       }
2406     }
2407   }
2408
2409   delete[] info;
2410
2411   eina_list_free(keyList);
2412   eina_list_free(grabList);
2413   eina_shutdown();
2414
2415   return true;
2416 }
2417
2418 bool WindowBaseEcoreWl2::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
2419 {
2420   int keyCount = key.Count();
2421   if(keyCount == 0)
2422   {
2423     return false;
2424   }
2425
2426   eina_init();
2427
2428   Eina_List*                     keyList = NULL;
2429   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2430
2431   for(int index = 0; index < keyCount; ++index)
2432   {
2433     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2434     keyList         = eina_list_append(keyList, &info);
2435   }
2436
2437   Eina_List* ungrabList = ecore_wl2_window_keygrab_list_unset(mEcoreWindow, keyList);
2438
2439   result.Resize(keyCount, true);
2440
2441   Eina_List* l        = NULL;
2442   Eina_List* m        = NULL;
2443   void*      listData = NULL;
2444   void*      data     = NULL;
2445
2446   if(ungrabList != NULL)
2447   {
2448     EINA_LIST_FOREACH(ungrabList, m, data)
2449     {
2450       int index = 0;
2451       EINA_LIST_FOREACH(keyList, l, listData)
2452       {
2453         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2454         {
2455           result[index] = false;
2456         }
2457         ++index;
2458       }
2459     }
2460   }
2461
2462   delete[] info;
2463
2464   eina_list_free(keyList);
2465   eina_list_free(ungrabList);
2466   eina_shutdown();
2467
2468   return true;
2469 }
2470
2471 void WindowBaseEcoreWl2::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
2472 {
2473   // calculate DPI
2474   float xres, yres;
2475
2476   Ecore_Wl2_Output* output = ecore_wl2_window_output_find(mEcoreWindow);
2477
2478   // 1 inch = 25.4 millimeters
2479   xres = ecore_wl2_output_dpi_get(output);
2480   yres = ecore_wl2_output_dpi_get(output);
2481
2482   dpiHorizontal = int(xres + 0.5f); // rounding
2483   dpiVertical   = int(yres + 0.5f);
2484 }
2485
2486 int WindowBaseEcoreWl2::GetOrientation() const
2487 {
2488   int orientation = (mScreenRotationAngle + mWindowRotationAngle) % 360;
2489   if(mSupportedPreProtation)
2490   {
2491     orientation = 0;
2492   }
2493   return orientation;
2494 }
2495
2496 int WindowBaseEcoreWl2::GetScreenRotationAngle()
2497 {
2498   int transform = 0;
2499
2500   if(ecore_wl2_window_ignore_output_transform_get(mEcoreWindow))
2501   {
2502     transform = 0;
2503   }
2504   else
2505   {
2506     transform = ecore_wl2_output_transform_get(ecore_wl2_window_output_find(mEcoreWindow));
2507   }
2508   mScreenRotationAngle = transform * 90;
2509   return mScreenRotationAngle;
2510 }
2511
2512 void WindowBaseEcoreWl2::SetWindowRotationAngle(int degree)
2513 {
2514   mWindowRotationAngle = degree;
2515   ecore_wl2_window_rotation_set(mEcoreWindow, degree);
2516 }
2517
2518 void WindowBaseEcoreWl2::WindowRotationCompleted(int degree, int width, int height)
2519 {
2520   ecore_wl2_window_rotation_change_done_send(mEcoreWindow, degree, width, height);
2521 }
2522
2523 void WindowBaseEcoreWl2::SetTransparency(bool transparent)
2524 {
2525   ecore_wl2_window_alpha_set(mEcoreWindow, transparent);
2526 }
2527
2528 void WindowBaseEcoreWl2::InitializeEcoreElDBus()
2529 {
2530 #ifdef DALI_ELDBUS_AVAILABLE
2531   Eldbus_Object* object;
2532   Eldbus_Proxy*  manager;
2533
2534   if(!(mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM)))
2535   {
2536     DALI_LOG_ERROR("Unable to get system bus\n");
2537   }
2538
2539   object = eldbus_object_get(mSystemConnection, BUS, PATH);
2540   if(!object)
2541   {
2542     DALI_LOG_ERROR("Getting object failed\n");
2543     return;
2544   }
2545
2546   manager = eldbus_proxy_get(object, INTERFACE);
2547   if(!manager)
2548   {
2549     DALI_LOG_ERROR("Getting proxy failed\n");
2550     return;
2551   }
2552
2553   if(!eldbus_proxy_signal_handler_add(manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this))
2554   {
2555     DALI_LOG_ERROR("No signal handler returned\n");
2556   }
2557 #endif
2558 }
2559
2560 void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize)
2561 {
2562   Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
2563   if(!display)
2564   {
2565     DALI_ASSERT_ALWAYS(0 && "Failed to get display");
2566   }
2567
2568   ecore_wl2_display_sync(display);
2569
2570   mEcoreWindow = ecore_wl2_window_new(display, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2571
2572   if(mEcoreWindow == 0)
2573   {
2574     DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
2575   }
2576
2577   // Set default type
2578   ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
2579 }
2580
2581 void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent)
2582 {
2583   Ecore_Wl2_Window* ecoreParent = NULL;
2584   if(parentWinBase)
2585   {
2586     WindowBaseEcoreWl2* winBaseEcore2 = static_cast<WindowBaseEcoreWl2*>(parentWinBase);
2587     ecoreParent                       = winBaseEcore2->mEcoreWindow;
2588   }
2589   ecore_wl2_window_transient_parent_set(mEcoreWindow, ecoreParent, belowParent);
2590 }
2591
2592 int WindowBaseEcoreWl2::CreateFrameRenderedSyncFence()
2593 {
2594   return wl_egl_window_tizen_create_commit_sync_fd(mEglWindow);
2595 }
2596
2597 int WindowBaseEcoreWl2::CreateFramePresentedSyncFence()
2598 {
2599   return wl_egl_window_tizen_create_presentation_sync_fd(mEglWindow);
2600 }
2601
2602 void WindowBaseEcoreWl2::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
2603 {
2604   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPositionSizeWithAngle, angle: %d, x: %d, y: %d, w: %d, h: %d\n", angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2605   ecore_wl2_window_rotation_geometry_set(mEcoreWindow, angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2606 }
2607
2608 void WindowBaseEcoreWl2::InitializeIme()
2609 {
2610   Eina_Iterator*      globals;
2611   struct wl_registry* registry;
2612   Ecore_Wl2_Global*   global;
2613   Ecore_Wl2_Display*  ecoreWl2Display;
2614
2615   if(!(ecoreWl2Display = ecore_wl2_connected_display_get(NULL)))
2616   {
2617     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 connected display\n");
2618     return;
2619   }
2620
2621   DALI_LOG_RELEASE_INFO("InitializeIme:  Ecore_Wl2_Display: %p, ecore wl window: %p\n", ecoreWl2Display, mEcoreWindow);
2622
2623   if(!(registry = ecore_wl2_display_registry_get(ecoreWl2Display)))
2624   {
2625     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 display registry\n");
2626     return;
2627   }
2628
2629   if(!(globals = ecore_wl2_display_globals_get(ecoreWl2Display)))
2630   {
2631     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 globals\n");
2632     return;
2633   }
2634
2635   EINA_ITERATOR_FOREACH(globals, global)
2636   {
2637 #ifdef OVER_TIZEN_VERSION_7
2638     if(strcmp(global->interface, "zwp_input_panel_v1") == 0)
2639     {
2640       mWlInputPanel = (zwp_input_panel_v1*)wl_registry_bind(registry, global->id, &zwp_input_panel_v1_interface, 1);
2641     }
2642 #else
2643     if(strcmp(global->interface, "wl_input_panel") == 0)
2644     {
2645       mWlInputPanel = (wl_input_panel*)wl_registry_bind(registry, global->id, &wl_input_panel_interface, 1);
2646     }
2647 #endif
2648     else if(strcmp(global->interface, "wl_output") == 0)
2649     {
2650       mWlOutput = (wl_output*)wl_registry_bind(registry, global->id, &wl_output_interface, 1);
2651     }
2652   }
2653
2654   if(!mWlInputPanel)
2655   {
2656     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel interface\n");
2657     return;
2658   }
2659
2660   if(!mWlOutput)
2661   {
2662     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland output panel interface\n");
2663     return;
2664   }
2665 #ifdef OVER_TIZEN_VERSION_7
2666   mWlInputPanelSurface = zwp_input_panel_v1_get_input_panel_surface(mWlInputPanel, mWlSurface);
2667 #else
2668   mWlInputPanelSurface = wl_input_panel_get_input_panel_surface(mWlInputPanel, mWlSurface);
2669 #endif
2670   if(!mWlInputPanelSurface)
2671   {
2672     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel surface\n");
2673     return;
2674   }
2675 #ifdef OVER_TIZEN_VERSION_7
2676   zwp_input_panel_surface_v1_set_toplevel(mWlInputPanelSurface, mWlOutput, ZWP_INPUT_PANEL_SURFACE_V1_POSITION_CENTER_BOTTOM);
2677 #else
2678   wl_input_panel_surface_set_toplevel(mWlInputPanelSurface, mWlOutput, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM);
2679 #endif
2680 }
2681
2682 void WindowBaseEcoreWl2::ImeWindowReadyToRender()
2683 {
2684   if(!mWlInputPanelSurface)
2685   {
2686     DALI_LOG_ERROR("WindowBaseEcoreWl2::ImeWindowReadyToRender(), wayland input panel surface is null\n");
2687     return;
2688   }
2689 #ifdef OVER_TIZEN_VERSION_7
2690   zwp_input_panel_surface_v1_set_ready(mWlInputPanelSurface, 1);
2691 #else
2692   wl_input_panel_surface_set_ready(mWlInputPanelSurface, 1);
2693 #endif
2694 }
2695
2696 void WindowBaseEcoreWl2::RequestMoveToServer()
2697 {
2698   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
2699   if(!display)
2700   {
2701     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get ecore_wl2_display\n");
2702     return;
2703   }
2704
2705   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
2706   if(!input)
2707   {
2708     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get default Ecore_Wl2_Input\n");
2709     return;
2710   }
2711
2712   ecore_wl2_window_move(mEcoreWindow, input);
2713   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestMoveToServer, starts the window[%p] is moved by server\n", mEcoreWindow);
2714 }
2715
2716 void WindowBaseEcoreWl2::RequestResizeToServer(WindowResizeDirection direction)
2717 {
2718   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
2719   if(!display)
2720   {
2721     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get ecore_wl2_display\n");
2722     return;
2723   }
2724
2725   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
2726   if(!input)
2727   {
2728     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get default Ecore_Wl2_Input\n");
2729     return;
2730   }
2731
2732   int location = 0;
2733   switch(direction)
2734   {
2735     case WindowResizeDirection::TOP_LEFT:
2736     {
2737       location = 5;
2738       break;
2739     }
2740     case WindowResizeDirection::TOP:
2741     {
2742       location = 1;
2743       break;
2744     }
2745     case WindowResizeDirection::TOP_RIGHT:
2746     {
2747       location = 9;
2748       break;
2749     }
2750     case WindowResizeDirection::LEFT:
2751     {
2752       location = 4;
2753       break;
2754     }
2755     case WindowResizeDirection::RIGHT:
2756     {
2757       location = 8;
2758       break;
2759     }
2760     case WindowResizeDirection::BOTTOM_LEFT:
2761     {
2762       location = 6;
2763       break;
2764     }
2765     case WindowResizeDirection::BOTTOM:
2766     {
2767       location = 2;
2768       break;
2769     }
2770     case WindowResizeDirection::BOTTOM_RIGHT:
2771     {
2772       location = 10;
2773       break;
2774     }
2775     default:
2776     {
2777       location = 0;
2778       break;
2779     }
2780   }
2781
2782   ecore_wl2_window_resize(mEcoreWindow, input, location);
2783   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestResizeToServer, starts the window[%p] is resized by server, mode:%d\n", mEcoreWindow, location);
2784 }
2785
2786 void WindowBaseEcoreWl2::EnableFloatingMode(bool enable)
2787 {
2788   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EnableFloatingMode, floating mode flag: [%p], enable [%d]\n", mEcoreWindow, enable);
2789   if(enable == true)
2790   {
2791     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_TRUE);
2792   }
2793   else
2794   {
2795     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_FALSE);
2796   }
2797 }
2798
2799 bool WindowBaseEcoreWl2::IsFloatingModeEnabled() const
2800 {
2801   return ecore_wl2_window_floating_mode_get(mEcoreWindow);
2802 }
2803
2804 void WindowBaseEcoreWl2::IncludeInputRegion(const Rect<int>& inputRegion)
2805 {
2806   Eina_Rectangle rect;
2807   rect.x = inputRegion.x;
2808   rect.y = inputRegion.y;
2809   rect.w = inputRegion.width;
2810   rect.h = inputRegion.height;
2811
2812   ecore_wl2_window_input_rect_add(mEcoreWindow, &rect);
2813   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2814 }
2815
2816 void WindowBaseEcoreWl2::ExcludeInputRegion(const Rect<int>& inputRegion)
2817 {
2818   Eina_Rectangle rect;
2819   rect.x = inputRegion.x;
2820   rect.y = inputRegion.y;
2821   rect.w = inputRegion.width;
2822   rect.h = inputRegion.height;
2823
2824   ecore_wl2_window_input_rect_subtract(mEcoreWindow, &rect);
2825   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2826 }
2827
2828 } // namespace Adaptor
2829
2830 } // namespace Internal
2831
2832 } // namespace Dali
2833
2834 #pragma GCC diagnostic pop