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