985f36ea554fe25200a3d6f19afacbc102e1e19c
[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 static void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
720 {
721   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
722   if(windowBase)
723   {
724     windowBase->RegistryGlobalCallback(data, registry, name, interface, version);
725   }
726 }
727
728 static void RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
729 {
730   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
731   if(windowBase)
732   {
733     windowBase->RegistryGlobalCallbackRemove(data, registry, id);
734   }
735 }
736
737 static void TizenPolicyConformant(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant)
738 {
739 }
740
741 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)
742 {
743 }
744
745 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
746 {
747   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
748   if(windowBase)
749   {
750     windowBase->TizenPolicyNotificationChangeDone(data, tizenPolicy, surface, level, state);
751   }
752 }
753
754 static void TizenPolicyTransientForDone(void* data, struct tizen_policy* tizenPolicy, uint32_t childId)
755 {
756 }
757
758 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
759 {
760   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
761   if(windowBase)
762   {
763     windowBase->TizenPolicyScreenModeChangeDone(data, tizenPolicy, surface, mode, state);
764   }
765 }
766
767 static void TizenPolicyIconifyStateChanged(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force)
768 {
769 }
770
771 static void TizenPolicySupportedAuxiliaryHints(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints)
772 {
773 }
774
775 static void TizenPolicyAllowedAuxiliaryHint(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id)
776 {
777 }
778
779 static void TizenPolicyAuxiliaryMessage(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options)
780 {
781 }
782
783 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)
784 {
785 }
786
787 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
788 {
789   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
790   if(windowBase)
791   {
792     windowBase->DisplayPolicyBrightnessChangeDone(data, displayPolicy, surface, brightness, state);
793   }
794 }
795
796 const struct wl_registry_listener registryListener =
797   {
798     RegistryGlobalCallback,
799     RegistryGlobalCallbackRemove};
800
801 const struct tizen_policy_listener tizenPolicyListener =
802   {
803     TizenPolicyConformant,
804     TizenPolicyConformantArea,
805     TizenPolicyNotificationChangeDone,
806     TizenPolicyTransientForDone,
807     TizenPolicyScreenModeChangeDone,
808     TizenPolicyIconifyStateChanged,
809     TizenPolicySupportedAuxiliaryHints,
810     TizenPolicyAllowedAuxiliaryHint,
811     TizenPolicyAuxiliaryMessage,
812     TizenPolicyConformantRegion};
813
814 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
815   {
816     DisplayPolicyBrightnessChangeDone};
817
818 } // unnamed namespace
819
820 WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surface, bool isTransparent)
821 : mEcoreEventHandler(),
822   mEcoreWindow(nullptr),
823   mWlSurface(nullptr),
824   mWlInputPanel(nullptr),
825   mWlOutput(nullptr),
826   mWlInputPanelSurface(nullptr),
827   mEglWindow(nullptr),
828   mDisplay(nullptr),
829   mEventQueue(nullptr),
830   mTizenPolicy(nullptr),
831   mTizenDisplayPolicy(nullptr),
832   mKeyMap(nullptr),
833   mSupportedAuxiliaryHints(),
834   mWindowPositionSize(positionSize),
835   mAuxiliaryHints(),
836   mType(WindowType::NORMAL),
837   mNotificationLevel(-1),
838   mScreenOffMode(0),
839   mBrightness(0),
840   mWindowRotationAngle(0),
841   mScreenRotationAngle(0),
842   mSupportedPreProtation(0),
843   mNotificationChangeState(0),
844   mScreenOffModeChangeState(0),
845   mBrightnessChangeState(0),
846   mLastSubmittedMoveResizeSerial(0),
847   mMoveResizeSerial(0),
848   mNotificationLevelChangeDone(true),
849   mScreenOffModeChangeDone(true),
850   mVisible(true),
851   mOwnSurface(false),
852   mBrightnessChangeDone(true)
853 {
854   Initialize(positionSize, surface, isTransparent);
855 }
856
857 WindowBaseEcoreWl2::~WindowBaseEcoreWl2()
858 {
859 #if defined(VCONF_ENABLED)
860   vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged);
861   vconf_ignore_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged);
862 #endif
863
864   for(Dali::Vector<Ecore_Event_Handler*>::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter)
865   {
866     ecore_event_handler_del(*iter);
867   }
868   mEcoreEventHandler.Clear();
869
870   if(mEventQueue)
871   {
872     wl_event_queue_destroy(mEventQueue);
873   }
874
875   mSupportedAuxiliaryHints.clear();
876   mAuxiliaryHints.clear();
877
878   if(mEglWindow != NULL)
879   {
880     wl_egl_window_destroy(mEglWindow);
881     mEglWindow = NULL;
882   }
883
884   if(mOwnSurface)
885   {
886     ecore_wl2_window_free(mEcoreWindow);
887
888     WindowSystem::Shutdown();
889   }
890 }
891
892 void WindowBaseEcoreWl2::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
893 {
894   if(surface.Empty() == false)
895   {
896     // check we have a valid type
897     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(Ecore_Wl2_Window*)) && "Surface type is invalid");
898
899     mEcoreWindow = AnyCast<Ecore_Wl2_Window*>(surface);
900   }
901   else
902   {
903     // we own the surface about to created
904     WindowSystem::Initialize();
905
906     mOwnSurface = true;
907     CreateWindow(positionSize);
908   }
909
910   mWlSurface = ecore_wl2_window_surface_get(mEcoreWindow);
911
912   SetTransparency(isTransparent);
913
914   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this));
915   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this));
916   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this));
917   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this));
918   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this));
919
920   // Register Rotate event
921   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE, EcoreEventRotate, this));
922
923   // Register Configure event
924   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE, EcoreEventConfigure, this));
925
926   // Register Touch events
927   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, this));
928   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, this));
929   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, this));
930   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, this));
931
932   // Register Mouse wheel events
933   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, this));
934
935   // Register Mouse IO events
936   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_IN, EcoreEventMouseIn, this));
937   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT, EcoreEventMouseOut, this));
938
939   // Register Detent event
940   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DETENT_ROTATE, EcoreEventDetentRotation, this));
941
942   // Register Key events
943   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this));
944   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this));
945
946   // Register Selection event - clipboard selection
947   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this));
948   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, this));
949
950   // Register Effect Start/End event
951   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_START, EcoreEventEffectStart, this));
952   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_END, EcoreEventEffectEnd, this));
953
954   // Register Keyboard repeat event
955   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYBOARD_REPEAT_CHANGED, EcoreEventSeatKeyboardRepeatChanged, this));
956
957   // Register Window redraw request event
958   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_REDRAW_REQUEST, EcoreEventWindowRedrawRequest, this));
959
960   // Register Window auxiliary event
961   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_AUX_MESSAGE, EcoreEventWindowAuxiliaryMessage, this));
962
963 #if defined(VCONF_ENABLED)
964   // Register Vconf notify - font name and size
965   vconf_notify_key_changed_for_ui_thread(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this);
966   vconf_notify_key_changed_for_ui_thread(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, this);
967 #endif
968
969   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
970   mDisplay                   = ecore_wl2_display_get(display);
971
972   if(mDisplay)
973   {
974     wl_display* displayWrapper = static_cast<wl_display*>(wl_proxy_create_wrapper(mDisplay));
975     if(displayWrapper)
976     {
977       mEventQueue = wl_display_create_queue(mDisplay);
978       if(mEventQueue)
979       {
980         wl_proxy_set_queue(reinterpret_cast<wl_proxy*>(displayWrapper), mEventQueue);
981
982         wl_registry* registry = wl_display_get_registry(displayWrapper);
983         wl_registry_add_listener(registry, &registryListener, this);
984       }
985
986       wl_proxy_wrapper_destroy(displayWrapper);
987     }
988   }
989
990   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(display);
991
992   if(ecoreWlInput)
993   {
994     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
995
996     mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYMAP_CHANGED, EcoreEventSeatKeymapChanged, this));
997   }
998
999   // get auxiliary hint
1000   Eina_List* hints = ecore_wl2_window_aux_hints_supported_get(mEcoreWindow);
1001   if(hints)
1002   {
1003     Eina_List* l    = NULL;
1004     char*      hint = NULL;
1005
1006     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))))
1007     {
1008       mSupportedAuxiliaryHints.push_back(hint);
1009
1010       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::Initialize: %s\n", hint);
1011     }
1012   }
1013 }
1014
1015 Eina_Bool WindowBaseEcoreWl2::OnIconifyStateChanged(void* data, int type, void* event)
1016 {
1017   Ecore_Wl2_Event_Window_Iconify_State_Change* iconifyChangedEvent(static_cast<Ecore_Wl2_Event_Window_Iconify_State_Change*>(event));
1018   Eina_Bool                                    handled(ECORE_CALLBACK_PASS_ON);
1019
1020   if(iconifyChangedEvent->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1021   {
1022     if(iconifyChangedEvent->iconified == EINA_TRUE)
1023     {
1024       mIconifyChangedSignal.Emit(true);
1025     }
1026     else
1027     {
1028       mIconifyChangedSignal.Emit(false);
1029     }
1030     handled = ECORE_CALLBACK_DONE;
1031   }
1032
1033   return handled;
1034 }
1035
1036 Eina_Bool WindowBaseEcoreWl2::OnFocusIn(void* data, int type, void* event)
1037 {
1038   Ecore_Wl2_Event_Focus_In* focusInEvent(static_cast<Ecore_Wl2_Event_Focus_In*>(event));
1039
1040   if(focusInEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1041   {
1042     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n");
1043
1044     mFocusChangedSignal.Emit(true);
1045   }
1046
1047   return ECORE_CALLBACK_PASS_ON;
1048 }
1049
1050 Eina_Bool WindowBaseEcoreWl2::OnFocusOut(void* data, int type, void* event)
1051 {
1052   Ecore_Wl2_Event_Focus_Out* focusOutEvent(static_cast<Ecore_Wl2_Event_Focus_Out*>(event));
1053
1054   if(focusOutEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1055   {
1056     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n");
1057
1058     mFocusChangedSignal.Emit(false);
1059   }
1060
1061   return ECORE_CALLBACK_PASS_ON;
1062 }
1063
1064 Eina_Bool WindowBaseEcoreWl2::OnOutputTransform(void* data, int type, void* event)
1065 {
1066   Ecore_Wl2_Event_Output_Transform* transformEvent(static_cast<Ecore_Wl2_Event_Output_Transform*>(event));
1067
1068   if(transformEvent->output == ecore_wl2_window_output_find(mEcoreWindow))
1069   {
1070     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow);
1071
1072     mScreenRotationAngle = GetScreenRotationAngle();
1073
1074     mOutputTransformedSignal.Emit();
1075   }
1076
1077   return ECORE_CALLBACK_PASS_ON;
1078 }
1079
1080 Eina_Bool WindowBaseEcoreWl2::OnIgnoreOutputTransform(void* data, int type, void* event)
1081 {
1082   Ecore_Wl2_Event_Ignore_Output_Transform* ignoreTransformEvent(static_cast<Ecore_Wl2_Event_Ignore_Output_Transform*>(event));
1083
1084   if(ignoreTransformEvent->win == mEcoreWindow)
1085   {
1086     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow);
1087
1088     mScreenRotationAngle = GetScreenRotationAngle();
1089
1090     mOutputTransformedSignal.Emit();
1091   }
1092
1093   return ECORE_CALLBACK_PASS_ON;
1094 }
1095
1096 void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event)
1097 {
1098   Ecore_Wl2_Event_Window_Rotation* ev(static_cast<Ecore_Wl2_Event_Window_Rotation*>(event));
1099
1100   if(ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1101   {
1102     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h);
1103
1104     RotationEvent rotationEvent;
1105     rotationEvent.angle     = ev->angle;
1106     rotationEvent.winResize = 0;
1107
1108     if(ev->w == 0 || ev->h == 0)
1109     {
1110       // When rotation event does not have the window width or height,
1111       // previous DALi side window's size are used.
1112       ev->w = mWindowPositionSize.width;
1113       ev->h = mWindowPositionSize.height;
1114     }
1115
1116     mWindowRotationAngle = ev->angle;
1117
1118     mWindowPositionSize.width  = ev->w;
1119     mWindowPositionSize.height = ev->h;
1120
1121     PositionSize newPositionSize = RecalculatePositionSizeToCurrentOrientation(mWindowPositionSize);
1122
1123     rotationEvent.x      = newPositionSize.x;
1124     rotationEvent.y      = newPositionSize.y;
1125     rotationEvent.width  = newPositionSize.width;
1126     rotationEvent.height = newPositionSize.height;
1127
1128     mRotationSignal.Emit(rotationEvent);
1129   }
1130 }
1131
1132 void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
1133 {
1134   Ecore_Wl2_Event_Window_Configure* ev(static_cast<Ecore_Wl2_Event_Window_Configure*>(event));
1135
1136   if(ev && ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1137   {
1138     // Note: To comply with the wayland protocol, Dali should make an ack_configure
1139     // by calling ecore_wl2_window_commit
1140
1141     int tempWidth  = static_cast<int>(ev->w);
1142     int tempHeight = static_cast<int>(ev->h);
1143
1144     // Initialize with previous size for skip resize when new size is 0.
1145     // When window is just moved or window is resized by client application,
1146     // The configure notification event's size will be 0.
1147     // If new size is 0, the resized work should be skip.
1148     int  newWidth    = mWindowPositionSize.width;
1149     int  newHeight   = mWindowPositionSize.height;
1150     bool windowMoved = false, windowResized = false;
1151
1152     if(ev->x != mWindowPositionSize.x || ev->y != mWindowPositionSize.y)
1153     {
1154       windowMoved = true;
1155     }
1156
1157     if(tempWidth != 0 && tempHeight != 0 && (tempWidth != mWindowPositionSize.width || tempHeight != mWindowPositionSize.height))
1158     {
1159       windowResized = true;
1160       newWidth      = tempWidth;
1161       newHeight     = tempHeight;
1162     }
1163
1164     if(windowMoved || windowResized)
1165     {
1166       mWindowPositionSize.x      = ev->x;
1167       mWindowPositionSize.y      = ev->y;
1168       mWindowPositionSize.width  = newWidth;
1169       mWindowPositionSize.height = newHeight;
1170       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);
1171
1172       ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height);
1173
1174       Dali::PositionSize newPositionSize = RecalculatePositionSizeToCurrentOrientation(mWindowPositionSize);
1175       mUpdatePositionSizeSignal.Emit(newPositionSize);
1176     }
1177
1178     ecore_wl2_window_commit(mEcoreWindow, EINA_FALSE);
1179   }
1180 }
1181
1182 void WindowBaseEcoreWl2::OnMouseButtonDown(void* data, int type, void* event)
1183 {
1184   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1185
1186   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1187   {
1188     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_DOWN");
1189
1190     Device::Class::Type    deviceClass;
1191     Device::Subclass::Type deviceSubclass;
1192
1193     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1194     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1195
1196     PointState::Type state(PointState::DOWN);
1197
1198     if(deviceClass != Device::Class::Type::MOUSE)
1199     {
1200       // Check if the buttons field is set and ensure it's the primary touch button.
1201       // If this event was triggered by buttons other than the primary button (used for touch), then
1202       // just send an interrupted event to Core.
1203       if(touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID))
1204       {
1205         state = PointState::INTERRUPTED;
1206       }
1207     }
1208
1209     Integration::Point point;
1210     point.SetDeviceId(touchEvent->multi.device);
1211     point.SetState(state);
1212     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1213     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1214     point.SetPressure(touchEvent->multi.pressure);
1215     point.SetAngle(Degree(touchEvent->multi.angle));
1216     point.SetDeviceClass(deviceClass);
1217     point.SetDeviceSubclass(deviceSubclass);
1218     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1219
1220     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1221   }
1222 }
1223
1224 void WindowBaseEcoreWl2::OnMouseButtonUp(void* data, int type, void* event)
1225 {
1226   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1227
1228   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1229   {
1230     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_UP");
1231
1232     Device::Class::Type    deviceClass;
1233     Device::Subclass::Type deviceSubclass;
1234
1235     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1236     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1237
1238     Integration::Point point;
1239     point.SetDeviceId(touchEvent->multi.device);
1240     point.SetState(PointState::UP);
1241     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1242     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1243     point.SetPressure(touchEvent->multi.pressure);
1244     point.SetAngle(Degree(touchEvent->multi.angle));
1245     point.SetDeviceClass(deviceClass);
1246     point.SetDeviceSubclass(deviceSubclass);
1247     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1248
1249     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1250   }
1251 }
1252
1253 void WindowBaseEcoreWl2::OnMouseButtonMove(void* data, int type, void* event)
1254 {
1255   Ecore_Event_Mouse_Move* touchEvent = static_cast<Ecore_Event_Mouse_Move*>(event);
1256
1257   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1258   {
1259     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_MOVE");
1260
1261     Device::Class::Type    deviceClass;
1262     Device::Subclass::Type deviceSubclass;
1263
1264     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1265     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1266
1267     Integration::Point point;
1268     point.SetDeviceId(touchEvent->multi.device);
1269     point.SetState(PointState::MOTION);
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
1277     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1278   }
1279 }
1280
1281 void WindowBaseEcoreWl2::OnMouseButtonCancel(void* data, int type, void* event)
1282 {
1283   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1284
1285   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1286   {
1287     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_CANCEL");
1288
1289     Integration::Point point;
1290     point.SetDeviceId(touchEvent->multi.device);
1291     point.SetState(PointState::INTERRUPTED);
1292     point.SetScreenPosition(Vector2(0.0f, 0.0f));
1293
1294     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1295
1296     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseButtonCancel\n");
1297   }
1298 }
1299
1300 void WindowBaseEcoreWl2::OnMouseWheel(void* data, int type, void* event)
1301 {
1302   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast<Ecore_Event_Mouse_Wheel*>(event);
1303
1304   if(mouseWheelEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1305   {
1306     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_WHEEL");
1307
1308     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);
1309
1310     Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
1311
1312     mWheelEventSignal.Emit(wheelEvent);
1313   }
1314 }
1315
1316 void WindowBaseEcoreWl2::OnMouseInOut(void* data, int type, void* event, Dali::DevelWindow::MouseInOutEvent::Type action)
1317 {
1318   Ecore_Event_Mouse_IO* mouseInOutEvent = static_cast<Ecore_Event_Mouse_IO*>(event);
1319
1320   if(mouseInOutEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1321   {
1322     DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_MOUSE_IN_OUT");
1323
1324     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);
1325
1326     Device::Class::Type    deviceClass;
1327     Device::Subclass::Type deviceSubclass;
1328
1329     GetDeviceClass(ecore_device_class_get(mouseInOutEvent->dev), deviceClass);
1330     GetDeviceSubclass(ecore_device_subclass_get(mouseInOutEvent->dev), deviceSubclass);
1331
1332     Dali::DevelWindow::MouseInOutEvent inOutEvent(action, mouseInOutEvent->modifiers, Vector2(mouseInOutEvent->x, mouseInOutEvent->y), mouseInOutEvent->timestamp, deviceClass, deviceSubclass);
1333
1334     mMouseInOutEventSignal.Emit(inOutEvent);
1335   }
1336 }
1337
1338 void WindowBaseEcoreWl2::OnDetentRotation(void* data, int type, void* event)
1339 {
1340   Ecore_Event_Detent_Rotate* detentEvent = static_cast<Ecore_Event_Detent_Rotate*>(event);
1341
1342   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::OnDetentRotation\n");
1343
1344   int32_t clockwise = (detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1345
1346   Integration::WheelEvent wheelEvent(Integration::WheelEvent::CUSTOM_WHEEL, detentEvent->direction, 0, Vector2(0.0f, 0.0f), clockwise, detentEvent->timestamp);
1347
1348   mWheelEventSignal.Emit(wheelEvent);
1349 }
1350
1351 void WindowBaseEcoreWl2::OnKeyDown(void* data, int type, void* event)
1352 {
1353   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1354
1355   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1356   {
1357     std::string keyName(keyEvent->keyname);
1358     std::string logicalKey("");
1359     std::string keyString("");
1360     std::string compose("");
1361
1362     DALI_TRACE_BEGIN(gTraceFilter, "DALI_ON_KEY_DOWN");
1363
1364     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1365     if(keyEvent->compose)
1366     {
1367       compose = keyEvent->compose;
1368     }
1369
1370     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1371     if(keyEvent->key)
1372     {
1373       logicalKey = keyEvent->key;
1374     }
1375
1376     int keyCode = 0;
1377     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1378
1379     if(keyCode == 0)
1380     {
1381       // Get a specific key code from dali key look up table.
1382       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1383     }
1384
1385     keyCode = (keyCode == -1) ? 0 : keyCode;
1386     int           modifier(keyEvent->modifiers);
1387     unsigned long time = keyEvent->timestamp;
1388     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1389     {
1390       keyCode = atoi(keyEvent->keyname + 8);
1391     }
1392
1393     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1394     if(keyEvent->string)
1395     {
1396       keyString = keyEvent->string;
1397     }
1398
1399     std::string            deviceName;
1400     Device::Class::Type    deviceClass;
1401     Device::Subclass::Type deviceSubclass;
1402
1403     GetDeviceName(keyEvent, deviceName);
1404     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1405     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1406
1407     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::DOWN, compose, deviceName, deviceClass, deviceSubclass);
1408
1409     mKeyEventSignal.Emit(keyEvent);
1410
1411     DALI_TRACE_END(gTraceFilter, "DALI_ON_KEY_DOWN");
1412   }
1413 }
1414
1415 void WindowBaseEcoreWl2::OnKeyUp(void* data, int type, void* event)
1416 {
1417   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1418
1419   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1420   {
1421 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
1422     // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
1423     if(keyEvent->event_flags & ECORE_EVENT_FLAG_CANCEL)
1424     {
1425       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp: This event flag indicates the event is canceled. \n");
1426       return;
1427     }
1428 #endif // Since ecore 1.23 version
1429
1430     std::string keyName(keyEvent->keyname);
1431     std::string logicalKey("");
1432     std::string keyString("");
1433     std::string compose("");
1434
1435     DALI_TRACE_BEGIN(gTraceFilter, "DALI_ON_KEY_UP");
1436
1437     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1438     if(keyEvent->compose)
1439     {
1440       compose = keyEvent->compose;
1441     }
1442
1443     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1444     if(keyEvent->key)
1445     {
1446       logicalKey = keyEvent->key;
1447     }
1448
1449     int keyCode = 0;
1450     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1451
1452     if(keyCode == 0)
1453     {
1454       // Get a specific key code from dali key look up table.
1455       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1456     }
1457
1458     keyCode = (keyCode == -1) ? 0 : keyCode;
1459     int           modifier(keyEvent->modifiers);
1460     unsigned long time = keyEvent->timestamp;
1461     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1462     {
1463       keyCode = atoi(keyEvent->keyname + 8);
1464     }
1465
1466     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1467     if(keyEvent->string)
1468     {
1469       keyString = keyEvent->string;
1470     }
1471
1472     std::string            deviceName;
1473     Device::Class::Type    deviceClass;
1474     Device::Subclass::Type deviceSubclass;
1475
1476     GetDeviceName(keyEvent, deviceName);
1477     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1478     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1479
1480     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, compose, deviceName, deviceClass, deviceSubclass);
1481
1482     mKeyEventSignal.Emit(keyEvent);
1483
1484     DALI_TRACE_END(gTraceFilter, "DALI_ON_KEY_UP");
1485   }
1486 }
1487
1488 void WindowBaseEcoreWl2::OnDataSend(void* data, int type, void* event)
1489 {
1490   mSelectionDataSendSignal.Emit(event);
1491 }
1492
1493 void WindowBaseEcoreWl2::OnDataReceive(void* data, int type, void* event)
1494 {
1495   mSelectionDataReceivedSignal.Emit(event);
1496 }
1497
1498 void WindowBaseEcoreWl2::OnFontNameChanged()
1499 {
1500   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_CHANGE);
1501 }
1502
1503 void WindowBaseEcoreWl2::OnFontSizeChanged()
1504 {
1505   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1506 }
1507
1508 void WindowBaseEcoreWl2::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
1509 {
1510   mTransitionEffectEventSignal.Emit(state, type);
1511 }
1512
1513 void WindowBaseEcoreWl2::OnKeyboardRepeatSettingsChanged()
1514 {
1515   mKeyboardRepeatSettingsChangedSignal.Emit();
1516 }
1517
1518 void WindowBaseEcoreWl2::OnEcoreEventWindowRedrawRequest()
1519 {
1520   mWindowRedrawRequestSignal.Emit();
1521 }
1522
1523 void WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage(void* event)
1524 {
1525   Ecore_Wl2_Event_Aux_Message* message = static_cast<Ecore_Wl2_Event_Aux_Message*>(event);
1526   if(message)
1527   {
1528     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, key:%s, value:%s \n", message->key, message->val);
1529     std::string           key(message->key);
1530     std::string           value(message->val);
1531     Dali::Property::Array options;
1532
1533     if(message->options)
1534     {
1535       Eina_List* l;
1536       void*      data;
1537       EINA_LIST_FOREACH(message->options, l, data)
1538       {
1539         DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, option: %s\n", (char*)data);
1540         std::string option(static_cast<char*>(data));
1541         options.Add(option);
1542       }
1543     }
1544
1545     mAuxiliaryMessageSignal.Emit(key, value, options);
1546   }
1547 }
1548
1549 void WindowBaseEcoreWl2::KeymapChanged(void* data, int type, void* event)
1550 {
1551   Ecore_Wl2_Event_Seat_Keymap_Changed* changed = static_cast<Ecore_Wl2_Event_Seat_Keymap_Changed*>(event);
1552   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::KeymapChanged, keymap id[ %d ]\n", changed->id);
1553   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(changed->display);
1554   if(ecoreWlInput)
1555   {
1556     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
1557   }
1558 }
1559
1560 void WindowBaseEcoreWl2::RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
1561 {
1562   if(strcmp(interface, tizen_policy_interface.name) == 0)
1563   {
1564     uint32_t clientVersion = std::min(version, MAX_TIZEN_CLIENT_VERSION);
1565
1566     mTizenPolicy = static_cast<tizen_policy*>(wl_registry_bind(registry, name, &tizen_policy_interface, clientVersion));
1567     if(!mTizenPolicy)
1568     {
1569       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n");
1570       return;
1571     }
1572
1573     tizen_policy_add_listener(mTizenPolicy, &tizenPolicyListener, data);
1574
1575     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_policy_add_listener is called.\n");
1576   }
1577   else if(strcmp(interface, tizen_display_policy_interface.name) == 0)
1578   {
1579     mTizenDisplayPolicy = static_cast<tizen_display_policy*>(wl_registry_bind(registry, name, &tizen_display_policy_interface, version));
1580     if(!mTizenDisplayPolicy)
1581     {
1582       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n");
1583       return;
1584     }
1585
1586     tizen_display_policy_add_listener(mTizenDisplayPolicy, &tizenDisplayPolicyListener, data);
1587
1588     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n");
1589   }
1590 }
1591
1592 void WindowBaseEcoreWl2::RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
1593 {
1594   mTizenPolicy        = NULL;
1595   mTizenDisplayPolicy = NULL;
1596 }
1597
1598 void WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
1599 {
1600   mNotificationLevel           = level;
1601   mNotificationChangeState     = state;
1602   mNotificationLevelChangeDone = true;
1603
1604   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state);
1605 }
1606
1607 void WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
1608 {
1609   mScreenOffMode            = mode;
1610   mScreenOffModeChangeState = state;
1611   mScreenOffModeChangeDone  = true;
1612
1613   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state);
1614 }
1615
1616 void WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
1617 {
1618   mBrightness            = brightness;
1619   mBrightnessChangeState = state;
1620   mBrightnessChangeDone  = true;
1621
1622   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state);
1623 }
1624
1625 void WindowBaseEcoreWl2::GetKeyCode(std::string keyName, int32_t& keyCode)
1626 {
1627   xkb_keysym_t sym = XKB_KEY_NoSymbol;
1628   KeyCodeMap   foundKeyCode;
1629
1630   sym = xkb_keysym_from_name(keyName.c_str(), XKB_KEYSYM_NO_FLAGS);
1631   if(sym == XKB_KEY_NoSymbol)
1632   {
1633     DALI_LOG_ERROR("Failed to get keysym in WindowBaseEcoreWl2\n");
1634     return;
1635   }
1636
1637   foundKeyCode.keySym    = sym;
1638   foundKeyCode.isKeyCode = false;
1639   xkb_keymap_key_for_each(mKeyMap, FindKeyCode, &foundKeyCode);
1640   keyCode = static_cast<int32_t>(foundKeyCode.keyCode);
1641 }
1642
1643 Any WindowBaseEcoreWl2::GetNativeWindow()
1644 {
1645   return mEcoreWindow;
1646 }
1647
1648 int WindowBaseEcoreWl2::GetNativeWindowId()
1649 {
1650   return ecore_wl2_window_id_get(mEcoreWindow);
1651 }
1652
1653 std::string WindowBaseEcoreWl2::GetNativeWindowResourceId()
1654 {
1655 #ifdef OVER_TIZEN_VERSION_7
1656   return std::to_string(ecore_wl2_window_resource_id_get(mEcoreWindow));
1657 #else
1658   return std::string();
1659 #endif
1660 }
1661
1662 EGLNativeWindowType WindowBaseEcoreWl2::CreateEglWindow(int width, int height)
1663 {
1664   int totalAngle = (mWindowRotationAngle + mScreenRotationAngle) % 360;
1665
1666   START_DURATION_CHECK();
1667   if(totalAngle == 90 || totalAngle == 270)
1668   {
1669     mEglWindow = wl_egl_window_create(mWlSurface, height, width);
1670   }
1671   else
1672   {
1673     mEglWindow = wl_egl_window_create(mWlSurface, width, height);
1674   }
1675   FINISH_DURATION_CHECK("wl_egl_window_create");
1676
1677   return static_cast<EGLNativeWindowType>(mEglWindow);
1678 }
1679
1680 void WindowBaseEcoreWl2::DestroyEglWindow()
1681 {
1682   if(mEglWindow != NULL)
1683   {
1684     START_DURATION_CHECK();
1685     wl_egl_window_destroy(mEglWindow);
1686     FINISH_DURATION_CHECK("wl_egl_window_destroy");
1687
1688     mEglWindow = NULL;
1689   }
1690 }
1691
1692 void WindowBaseEcoreWl2::SetEglWindowRotation(int angle)
1693 {
1694   wl_egl_window_tizen_rotation rotation;
1695
1696   switch(angle)
1697   {
1698     case 0:
1699     {
1700       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1701       break;
1702     }
1703     case 90:
1704     {
1705       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_270;
1706       break;
1707     }
1708     case 180:
1709     {
1710       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_180;
1711       break;
1712     }
1713     case 270:
1714     {
1715       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_90;
1716       break;
1717     }
1718     default:
1719     {
1720       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1721       break;
1722     }
1723   }
1724
1725   START_DURATION_CHECK();
1726   wl_egl_window_tizen_set_rotation(mEglWindow, rotation);
1727   FINISH_DURATION_CHECK("wl_egl_window_tizen_set_rotation");
1728 }
1729
1730 void WindowBaseEcoreWl2::SetEglWindowBufferTransform(int angle)
1731 {
1732   wl_output_transform bufferTransform;
1733
1734   switch(angle)
1735   {
1736     case 0:
1737     {
1738       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1739       break;
1740     }
1741     case 90:
1742     {
1743       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1744       break;
1745     }
1746     case 180:
1747     {
1748       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1749       break;
1750     }
1751     case 270:
1752     {
1753       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1754       break;
1755     }
1756     default:
1757     {
1758       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1759       break;
1760     }
1761   }
1762
1763   DALI_LOG_RELEASE_INFO("wl_egl_window_tizen_set_buffer_transform() with buffer Transform [%d]\n", bufferTransform);
1764   START_DURATION_CHECK();
1765   wl_egl_window_tizen_set_buffer_transform(mEglWindow, bufferTransform);
1766   FINISH_DURATION_CHECK("wl_egl_window_tizen_set_buffer_transform");
1767 }
1768
1769 void WindowBaseEcoreWl2::SetEglWindowTransform(int angle)
1770 {
1771   wl_output_transform windowTransform;
1772
1773   switch(angle)
1774   {
1775     case 0:
1776     {
1777       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1778       break;
1779     }
1780     case 90:
1781     {
1782       windowTransform = WL_OUTPUT_TRANSFORM_90;
1783       break;
1784     }
1785     case 180:
1786     {
1787       windowTransform = WL_OUTPUT_TRANSFORM_180;
1788       break;
1789     }
1790     case 270:
1791     {
1792       windowTransform = WL_OUTPUT_TRANSFORM_270;
1793       break;
1794     }
1795     default:
1796     {
1797       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1798       break;
1799     }
1800   }
1801
1802   DALI_LOG_RELEASE_INFO("wl_egl_window_tizen_set_window_transform() with window Transform [%d]\n", windowTransform);
1803   START_DURATION_CHECK();
1804   wl_egl_window_tizen_set_window_transform(mEglWindow, windowTransform);
1805   FINISH_DURATION_CHECK("wl_egl_window_tizen_set_window_transform");
1806 }
1807
1808 void WindowBaseEcoreWl2::ResizeEglWindow(PositionSize positionSize)
1809 {
1810   DALI_LOG_RELEASE_INFO("wl_egl_window_resize(), (%d, %d) [%d x %d]\n", positionSize.x, positionSize.y, positionSize.width, positionSize.height);
1811   START_DURATION_CHECK();
1812   wl_egl_window_resize(mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y);
1813
1814   // Note: Both "Resize" and "MoveResize" cases can reach here, but only "MoveResize" needs to submit serial number
1815   if(mMoveResizeSerial != mLastSubmittedMoveResizeSerial)
1816   {
1817     wl_egl_window_tizen_set_window_serial(mEglWindow, mMoveResizeSerial);
1818     mLastSubmittedMoveResizeSerial = mMoveResizeSerial;
1819   }
1820   FINISH_DURATION_CHECK("wl_egl_window functions");
1821 }
1822
1823 bool WindowBaseEcoreWl2::IsEglWindowRotationSupported()
1824 {
1825   START_DURATION_CHECK();
1826   // Check capability
1827   wl_egl_window_tizen_capability capability = static_cast<wl_egl_window_tizen_capability>(wl_egl_window_tizen_get_capabilities(mEglWindow));
1828   FINISH_DURATION_CHECK("wl_egl_window_tizen_get_capabilities");
1829
1830   if(capability == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED)
1831   {
1832     mSupportedPreProtation = true;
1833     return true;
1834   }
1835   mSupportedPreProtation = false;
1836   return false;
1837 }
1838
1839 PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToSystem(PositionSize positionSize)
1840 {
1841   PositionSize newPositionSize;
1842   int32_t      screenWidth, screenHeight;
1843   WindowSystem::GetScreenSize(screenWidth, screenHeight);
1844
1845   if(mWindowRotationAngle == 90)
1846   {
1847     newPositionSize.x      = positionSize.y;
1848     newPositionSize.y      = screenHeight - (positionSize.x + positionSize.width);
1849     newPositionSize.width  = positionSize.height;
1850     newPositionSize.height = positionSize.width;
1851   }
1852   else if(mWindowRotationAngle == 180)
1853   {
1854     newPositionSize.x      = screenWidth - (positionSize.x + positionSize.width);
1855     newPositionSize.y      = screenHeight - (positionSize.y + positionSize.height);
1856     newPositionSize.width  = positionSize.width;
1857     newPositionSize.height = positionSize.height;
1858   }
1859   else if(mWindowRotationAngle == 270)
1860   {
1861     newPositionSize.x      = screenWidth - (positionSize.y + positionSize.height);
1862     newPositionSize.y      = positionSize.x;
1863     newPositionSize.width  = positionSize.height;
1864     newPositionSize.height = positionSize.width;
1865   }
1866   else
1867   {
1868     newPositionSize.x      = positionSize.x;
1869     newPositionSize.y      = positionSize.y;
1870     newPositionSize.width  = positionSize.width;
1871     newPositionSize.height = positionSize.height;
1872   }
1873
1874   return newPositionSize;
1875 }
1876
1877 PositionSize WindowBaseEcoreWl2::RecalculatePositionSizeToCurrentOrientation(PositionSize positionSize)
1878 {
1879   PositionSize newPositionSize;
1880   int32_t      screenWidth, screenHeight;
1881   WindowSystem::GetScreenSize(screenWidth, screenHeight);
1882
1883   if(mWindowRotationAngle == 90)
1884   {
1885     newPositionSize.x      = screenHeight - (positionSize.y + positionSize.height);
1886     newPositionSize.y      = positionSize.x;
1887     newPositionSize.width  = positionSize.height;
1888     newPositionSize.height = positionSize.width;
1889   }
1890   else if(mWindowRotationAngle == 180)
1891   {
1892     newPositionSize.x      = screenWidth - (positionSize.x + positionSize.width);
1893     newPositionSize.y      = screenHeight - (positionSize.y + positionSize.height);
1894     newPositionSize.width  = positionSize.width;
1895     newPositionSize.height = positionSize.height;
1896   }
1897   else if(mWindowRotationAngle == 270)
1898   {
1899     newPositionSize.x      = positionSize.y;
1900     newPositionSize.y      = screenWidth - (positionSize.x + positionSize.width);
1901     newPositionSize.width  = positionSize.height;
1902     newPositionSize.height = positionSize.width;
1903   }
1904   else
1905   {
1906     newPositionSize.x      = positionSize.x;
1907     newPositionSize.y      = positionSize.y;
1908     newPositionSize.width  = positionSize.width;
1909     newPositionSize.height = positionSize.height;
1910   }
1911
1912   return newPositionSize;
1913 }
1914
1915 void WindowBaseEcoreWl2::Move(PositionSize positionSize)
1916 {
1917   PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize);
1918
1919   mWindowPositionSize = newPositionSize;
1920   DALI_LOG_RELEASE_INFO("ecore_wl2_window_position_set x[%d], y[%d]\n", newPositionSize.x, newPositionSize.y);
1921   START_DURATION_CHECK();
1922   ecore_wl2_window_position_set(mEcoreWindow, newPositionSize.x, newPositionSize.y);
1923   FINISH_DURATION_CHECK("ecore_wl2_window_position_set");
1924 }
1925
1926 void WindowBaseEcoreWl2::Resize(PositionSize positionSize)
1927 {
1928   PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize);
1929
1930   mWindowPositionSize = newPositionSize;
1931   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);
1932   START_DURATION_CHECK();
1933   ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height);
1934   FINISH_DURATION_CHECK("ecore_wl2_window_sync_geometry_set");
1935 }
1936
1937 void WindowBaseEcoreWl2::MoveResize(PositionSize positionSize)
1938 {
1939   PositionSize newPositionSize = RecalculatePositionSizeToSystem(positionSize);
1940
1941   mWindowPositionSize = newPositionSize;
1942   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);
1943   START_DURATION_CHECK();
1944   ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, newPositionSize.x, newPositionSize.y, newPositionSize.width, newPositionSize.height);
1945   FINISH_DURATION_CHECK("ecore_wl2_window_sync_geometry_set");
1946 }
1947
1948 void WindowBaseEcoreWl2::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
1949 {
1950   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);
1951   START_DURATION_CHECK();
1952   ecore_wl2_window_layout_set(mEcoreWindow, numCols, numRows, column, row, colSpan, rowSpan);
1953   FINISH_DURATION_CHECK("ecore_wl2_window_layout_set");
1954 }
1955
1956 void WindowBaseEcoreWl2::SetClass(const std::string& name, const std::string& className)
1957 {
1958   ecore_wl2_window_title_set(mEcoreWindow, name.c_str());
1959   ecore_wl2_window_class_set(mEcoreWindow, className.c_str());
1960 }
1961
1962 void WindowBaseEcoreWl2::Raise()
1963 {
1964   START_DURATION_CHECK();
1965   // Use ecore_wl2_window_activate to prevent the window shown without rendering
1966   ecore_wl2_window_activate(mEcoreWindow);
1967   FINISH_DURATION_CHECK("ecore_wl2_window_activate");
1968 }
1969
1970 void WindowBaseEcoreWl2::Lower()
1971 {
1972   START_DURATION_CHECK();
1973   ecore_wl2_window_lower(mEcoreWindow);
1974   FINISH_DURATION_CHECK("ecore_wl2_window_lower");
1975 }
1976
1977 void WindowBaseEcoreWl2::Activate()
1978 {
1979   START_DURATION_CHECK();
1980   ecore_wl2_window_activate(mEcoreWindow);
1981   FINISH_DURATION_CHECK("ecore_wl2_window_activate");
1982 }
1983
1984 void WindowBaseEcoreWl2::Maximize(bool maximize)
1985 {
1986   START_DURATION_CHECK();
1987   ecore_wl2_window_maximized_set(mEcoreWindow, maximize);
1988   FINISH_DURATION_CHECK("ecore_wl2_window_maximized_set");
1989 }
1990
1991 bool WindowBaseEcoreWl2::IsMaximized() const
1992 {
1993   return ecore_wl2_window_maximized_get(mEcoreWindow);
1994 }
1995
1996 void WindowBaseEcoreWl2::SetMaximumSize(Dali::Window::WindowSize size)
1997 {
1998   DALI_LOG_RELEASE_INFO("ecore_wl2_window_maximum_size_set, width: %d, height: %d\n", size.GetWidth(), size.GetHeight());
1999   START_DURATION_CHECK();
2000   ecore_wl2_window_maximum_size_set(mEcoreWindow, size.GetWidth(), size.GetHeight());
2001   FINISH_DURATION_CHECK("ecore_wl2_window_maximum_size_set");
2002   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2003 }
2004
2005 void WindowBaseEcoreWl2::Minimize(bool minimize)
2006 {
2007   START_DURATION_CHECK();
2008   ecore_wl2_window_iconified_set(mEcoreWindow, minimize);
2009   FINISH_DURATION_CHECK("ecore_wl2_window_iconified_set");
2010 }
2011
2012 bool WindowBaseEcoreWl2::IsMinimized() const
2013 {
2014   return ecore_wl2_window_iconified_get(mEcoreWindow);
2015 }
2016
2017 void WindowBaseEcoreWl2::SetMimimumSize(Dali::Window::WindowSize size)
2018 {
2019   DALI_LOG_RELEASE_INFO("ecore_wl2_window_minimum_size_set, width: %d, height: %d\n", size.GetWidth(), size.GetHeight());
2020   START_DURATION_CHECK();
2021   ecore_wl2_window_minimum_size_set(mEcoreWindow, size.GetWidth(), size.GetHeight());
2022   FINISH_DURATION_CHECK("ecore_wl2_window_minimum_size_set");
2023   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2024 }
2025
2026 void WindowBaseEcoreWl2::SetAvailableAnlges(const std::vector<int>& angles)
2027 {
2028   int rotations[4] = {0};
2029   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size());
2030   for(std::size_t i = 0; i < angles.size(); ++i)
2031   {
2032     rotations[i] = static_cast<int>(angles[i]);
2033     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "%d ", rotations[i]);
2034   }
2035
2036   START_DURATION_CHECK();
2037   ecore_wl2_window_available_rotations_set(mEcoreWindow, rotations, angles.size());
2038   FINISH_DURATION_CHECK("ecore_wl2_window_available_rotations_set");
2039 }
2040
2041 void WindowBaseEcoreWl2::SetPreferredAngle(int angle)
2042 {
2043   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPreferredAngle, angle: %d\n", angle);
2044   START_DURATION_CHECK();
2045   ecore_wl2_window_preferred_rotation_set(mEcoreWindow, angle);
2046   FINISH_DURATION_CHECK("ecore_wl2_window_preferred_rotation_set");
2047 }
2048
2049 void WindowBaseEcoreWl2::SetAcceptFocus(bool accept)
2050 {
2051   START_DURATION_CHECK();
2052   ecore_wl2_window_focus_skip_set(mEcoreWindow, !accept);
2053   FINISH_DURATION_CHECK("ecore_wl2_window_focus_skip_set");
2054 }
2055
2056 void WindowBaseEcoreWl2::Show()
2057 {
2058   if(!mVisible)
2059   {
2060     START_DURATION_CHECK();
2061     ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height);
2062     FINISH_DURATION_CHECK("ecore_wl2_window_geometry_set");
2063   }
2064   mVisible = true;
2065
2066   ecore_wl2_window_show(mEcoreWindow);
2067 }
2068
2069 void WindowBaseEcoreWl2::Hide()
2070 {
2071   mVisible = false;
2072   ecore_wl2_window_hide(mEcoreWindow);
2073 }
2074
2075 unsigned int WindowBaseEcoreWl2::GetSupportedAuxiliaryHintCount() const
2076 {
2077   return mSupportedAuxiliaryHints.size();
2078 }
2079
2080 std::string WindowBaseEcoreWl2::GetSupportedAuxiliaryHint(unsigned int index) const
2081 {
2082   if(index >= GetSupportedAuxiliaryHintCount())
2083   {
2084     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index);
2085   }
2086
2087   return mSupportedAuxiliaryHints[index];
2088 }
2089
2090 unsigned int WindowBaseEcoreWl2::AddAuxiliaryHint(const std::string& hint, const std::string& value)
2091 {
2092   bool supported = false;
2093
2094   // Check if the hint is suppported
2095   for(std::vector<std::string>::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter)
2096   {
2097     if(*iter == hint)
2098     {
2099       supported = true;
2100       break;
2101     }
2102   }
2103
2104   if(!supported)
2105   {
2106     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str());
2107     return 0;
2108   }
2109
2110   // Check if the hint is already added
2111   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
2112   {
2113     if(mAuxiliaryHints[i].first == hint)
2114     {
2115       // Just change the value
2116       mAuxiliaryHints[i].second = value;
2117
2118       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1);
2119
2120       return i + 1; // id is index + 1
2121     }
2122   }
2123
2124   // Add the hint
2125   mAuxiliaryHints.push_back(std::pair<std::string, std::string>(hint, value));
2126
2127   unsigned int id = mAuxiliaryHints.size();
2128
2129   START_DURATION_CHECK();
2130   ecore_wl2_window_aux_hint_add(mEcoreWindow, static_cast<int>(id), hint.c_str(), value.c_str());
2131   FINISH_DURATION_CHECK("ecore_wl2_window_aux_hint_add");
2132
2133   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id);
2134
2135   return id;
2136 }
2137
2138 bool WindowBaseEcoreWl2::RemoveAuxiliaryHint(unsigned int id)
2139 {
2140   if(id == 0 || id > mAuxiliaryHints.size())
2141   {
2142     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: Invalid id [%d]\n", id);
2143     return false;
2144   }
2145
2146   mAuxiliaryHints[id - 1].second = std::string();
2147
2148   START_DURATION_CHECK();
2149   ecore_wl2_window_aux_hint_del(mEcoreWindow, static_cast<int>(id));
2150   FINISH_DURATION_CHECK("ecore_wl2_window_aux_hint_del");
2151
2152   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str());
2153
2154   return true;
2155 }
2156
2157 bool WindowBaseEcoreWl2::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
2158 {
2159   if(id == 0 || id > mAuxiliaryHints.size())
2160   {
2161     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: Invalid id [%d]\n", id);
2162     return false;
2163   }
2164
2165   mAuxiliaryHints[id - 1].second = value;
2166
2167   START_DURATION_CHECK();
2168   ecore_wl2_window_aux_hint_change(mEcoreWindow, static_cast<int>(id), value.c_str());
2169   FINISH_DURATION_CHECK("ecore_wl2_window_aux_hint_change");
2170
2171   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());
2172
2173   return true;
2174 }
2175
2176 std::string WindowBaseEcoreWl2::GetAuxiliaryHintValue(unsigned int id) const
2177 {
2178   if(id == 0 || id > mAuxiliaryHints.size())
2179   {
2180     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: Invalid id [%d]\n", id);
2181     return std::string();
2182   }
2183
2184   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());
2185
2186   return mAuxiliaryHints[id - 1].second;
2187 }
2188
2189 unsigned int WindowBaseEcoreWl2::GetAuxiliaryHintId(const std::string& hint) const
2190 {
2191   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
2192   {
2193     if(mAuxiliaryHints[i].first == hint)
2194     {
2195       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1);
2196       return i + 1;
2197     }
2198   }
2199
2200   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str());
2201
2202   return 0;
2203 }
2204
2205 Rect<int> WindowBaseEcoreWl2::RecalculateInputRect(const Rect<int>& rect)
2206 {
2207   Rect<int> newRect;
2208
2209   if(mWindowRotationAngle == 90)
2210   {
2211     newRect.x      = rect.y;
2212     newRect.y      = mWindowPositionSize.height - (rect.x + rect.width);
2213     newRect.width  = rect.height;
2214     newRect.height = rect.width;
2215   }
2216   else if(mWindowRotationAngle == 180)
2217   {
2218     newRect.x      = mWindowPositionSize.width - (rect.x + rect.width);
2219     newRect.y      = mWindowPositionSize.height - (rect.y + rect.height);
2220     newRect.width  = rect.width;
2221     newRect.height = rect.height;
2222   }
2223   else if(mWindowRotationAngle == 270)
2224   {
2225     newRect.x      = mWindowPositionSize.width - (rect.y + rect.height);
2226     newRect.y      = rect.x;
2227     newRect.width  = rect.height;
2228     newRect.height = rect.width;
2229   }
2230   else
2231   {
2232     newRect.x      = rect.x;
2233     newRect.y      = rect.y;
2234     newRect.width  = rect.width;
2235     newRect.height = rect.height;
2236   }
2237   return newRect;
2238 }
2239
2240 void WindowBaseEcoreWl2::SetInputRegion(const Rect<int>& inputRegion)
2241 {
2242   Rect<int> convertRegion = RecalculateInputRect(inputRegion);
2243
2244   Eina_Rectangle rect;
2245   rect.x = convertRegion.x;
2246   rect.y = convertRegion.y;
2247   rect.w = convertRegion.width;
2248   rect.h = convertRegion.height;
2249
2250   DALI_LOG_RELEASE_INFO("%p, Set input rect (%d, %d, %d x %d)\n", mEcoreWindow, rect.x, rect.y, rect.w, rect.h);
2251   START_DURATION_CHECK();
2252   ecore_wl2_window_input_rect_set(mEcoreWindow, &rect);
2253   FINISH_DURATION_CHECK("ecore_wl2_window_input_rect_set");
2254   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2255 }
2256
2257 void WindowBaseEcoreWl2::SetType(Dali::WindowType type)
2258 {
2259   if(mType != type)
2260   {
2261     mType = type;
2262     Ecore_Wl2_Window_Type windowType;
2263
2264     switch(type)
2265     {
2266       case Dali::WindowType::NORMAL:
2267       {
2268         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
2269         break;
2270       }
2271       case Dali::WindowType::NOTIFICATION:
2272       {
2273         windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
2274         break;
2275       }
2276       case Dali::WindowType::UTILITY:
2277       {
2278         windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
2279         break;
2280       }
2281       case Dali::WindowType::DIALOG:
2282       {
2283         windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
2284         break;
2285       }
2286       case Dali::WindowType::IME:
2287       {
2288         windowType = ECORE_WL2_WINDOW_TYPE_NONE;
2289         break;
2290       }
2291       case Dali::WindowType::DESKTOP:
2292       {
2293         windowType = ECORE_WL2_WINDOW_TYPE_DESKTOP;
2294         break;
2295       }
2296       default:
2297       {
2298         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
2299         break;
2300       }
2301     }
2302
2303     START_DURATION_CHECK();
2304     ecore_wl2_window_type_set(mEcoreWindow, windowType);
2305     FINISH_DURATION_CHECK("ecore_wl2_window_type_set");
2306   }
2307 }
2308
2309 Dali::WindowType WindowBaseEcoreWl2::GetType() const
2310 {
2311   return mType;
2312 }
2313
2314 Dali::WindowOperationResult WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel level)
2315 {
2316   START_DURATION_CHECK();
2317   while(!mTizenPolicy)
2318   {
2319     wl_display_dispatch_queue(mDisplay, mEventQueue);
2320   }
2321
2322   int notificationLevel;
2323
2324   switch(level)
2325   {
2326     case Dali::WindowNotificationLevel::NONE:
2327     {
2328       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
2329       break;
2330     }
2331     case Dali::WindowNotificationLevel::BASE:
2332     {
2333       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
2334       break;
2335     }
2336     case Dali::WindowNotificationLevel::MEDIUM:
2337     {
2338       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
2339       break;
2340     }
2341     case Dali::WindowNotificationLevel::HIGH:
2342     {
2343       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
2344       break;
2345     }
2346     case Dali::WindowNotificationLevel::TOP:
2347     {
2348       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
2349       break;
2350     }
2351     default:
2352     {
2353       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: invalid level [%d]\n", level);
2354       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
2355       break;
2356     }
2357   }
2358
2359   mNotificationLevelChangeDone = false;
2360   mNotificationChangeState     = TIZEN_POLICY_ERROR_STATE_NONE;
2361
2362   tizen_policy_set_notification_level(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), notificationLevel);
2363
2364   int count = 0;
2365
2366   while(!mNotificationLevelChangeDone && count < 3)
2367   {
2368     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2369     wl_display_dispatch_queue(mDisplay, mEventQueue);
2370     count++;
2371   }
2372   FINISH_DURATION_CHECK("ecore_wl2 & wl_display");
2373
2374   if(!mNotificationLevelChangeDone)
2375   {
2376     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
2377     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2378   }
2379   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2380   {
2381     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Permission denied! [%d]\n", level);
2382     return Dali::WindowOperationResult::PERMISSION_DENIED;
2383   }
2384
2385   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
2386
2387   return Dali::WindowOperationResult::SUCCEED;
2388 }
2389
2390 Dali::WindowNotificationLevel WindowBaseEcoreWl2::GetNotificationLevel() const
2391 {
2392   while(!mTizenPolicy)
2393   {
2394     wl_display_dispatch_queue(mDisplay, mEventQueue);
2395   }
2396
2397   int count = 0;
2398
2399   while(!mNotificationLevelChangeDone && count < 3)
2400   {
2401     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2402     wl_display_dispatch_queue(mDisplay, mEventQueue);
2403     count++;
2404   }
2405
2406   if(!mNotificationLevelChangeDone)
2407   {
2408     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState);
2409     return Dali::WindowNotificationLevel::NONE;
2410   }
2411
2412   Dali::WindowNotificationLevel level;
2413
2414   switch(mNotificationLevel)
2415   {
2416     case TIZEN_POLICY_LEVEL_NONE:
2417     {
2418       level = Dali::WindowNotificationLevel::NONE;
2419       break;
2420     }
2421     case TIZEN_POLICY_LEVEL_DEFAULT:
2422     {
2423       level = Dali::WindowNotificationLevel::BASE;
2424       break;
2425     }
2426     case TIZEN_POLICY_LEVEL_MEDIUM:
2427     {
2428       level = Dali::WindowNotificationLevel::MEDIUM;
2429       break;
2430     }
2431     case TIZEN_POLICY_LEVEL_HIGH:
2432     {
2433       level = Dali::WindowNotificationLevel::HIGH;
2434       break;
2435     }
2436     case TIZEN_POLICY_LEVEL_TOP:
2437     {
2438       level = Dali::WindowNotificationLevel::TOP;
2439       break;
2440     }
2441     default:
2442     {
2443       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel);
2444       level = Dali::WindowNotificationLevel::NONE;
2445       break;
2446     }
2447   }
2448
2449   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: level [%d]\n", mNotificationLevel);
2450
2451   return level;
2452 }
2453
2454 void WindowBaseEcoreWl2::SetOpaqueState(bool opaque)
2455 {
2456   while(!mTizenPolicy)
2457   {
2458     wl_display_dispatch_queue(mDisplay, mEventQueue);
2459   }
2460
2461   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
2462 }
2463
2464 Dali::WindowOperationResult WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
2465 {
2466   while(!mTizenPolicy)
2467   {
2468     wl_display_dispatch_queue(mDisplay, mEventQueue);
2469   }
2470
2471   mScreenOffModeChangeDone  = false;
2472   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2473
2474   unsigned int mode = 0;
2475
2476   switch(screenOffMode)
2477   {
2478     case WindowScreenOffMode::TIMEOUT:
2479     {
2480       mode = 0;
2481       break;
2482     }
2483     case WindowScreenOffMode::NEVER:
2484     {
2485       mode = 1;
2486       break;
2487     }
2488   }
2489
2490   tizen_policy_set_window_screen_mode(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), mode);
2491
2492   int count = 0;
2493
2494   while(!mScreenOffModeChangeDone && count < 3)
2495   {
2496     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2497     wl_display_dispatch_queue(mDisplay, mEventQueue);
2498     count++;
2499   }
2500
2501   if(!mScreenOffModeChangeDone)
2502   {
2503     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
2504     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2505   }
2506   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2507   {
2508     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
2509     return Dali::WindowOperationResult::PERMISSION_DENIED;
2510   }
2511
2512   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
2513
2514   return Dali::WindowOperationResult::SUCCEED;
2515 }
2516
2517 WindowScreenOffMode WindowBaseEcoreWl2::GetScreenOffMode() const
2518 {
2519   while(!mTizenPolicy)
2520   {
2521     wl_display_dispatch_queue(mDisplay, mEventQueue);
2522   }
2523
2524   int count = 0;
2525
2526   while(!mScreenOffModeChangeDone && count < 3)
2527   {
2528     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2529     wl_display_dispatch_queue(mDisplay, mEventQueue);
2530     count++;
2531   }
2532
2533   if(!mScreenOffModeChangeDone)
2534   {
2535     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState);
2536     return WindowScreenOffMode::TIMEOUT;
2537   }
2538
2539   WindowScreenOffMode screenMode = WindowScreenOffMode::TIMEOUT;
2540
2541   switch(mScreenOffMode)
2542   {
2543     case 0:
2544     {
2545       screenMode = WindowScreenOffMode::TIMEOUT;
2546       break;
2547     }
2548     case 1:
2549     {
2550       screenMode = WindowScreenOffMode::NEVER;
2551       break;
2552     }
2553   }
2554
2555   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode);
2556
2557   return screenMode;
2558 }
2559
2560 Dali::WindowOperationResult WindowBaseEcoreWl2::SetBrightness(int brightness)
2561 {
2562   START_DURATION_CHECK();
2563   while(!mTizenDisplayPolicy)
2564   {
2565     wl_display_dispatch_queue(mDisplay, mEventQueue);
2566   }
2567
2568   mBrightnessChangeDone  = false;
2569   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2570
2571   tizen_display_policy_set_window_brightness(mTizenDisplayPolicy, ecore_wl2_window_surface_get(mEcoreWindow), brightness);
2572
2573   int count = 0;
2574
2575   while(!mBrightnessChangeDone && count < 3)
2576   {
2577     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2578     wl_display_dispatch_queue(mDisplay, mEventQueue);
2579     count++;
2580   }
2581   FINISH_DURATION_CHECK("ecore_wl2_display_flush");
2582
2583   if(!mBrightnessChangeDone)
2584   {
2585     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
2586     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2587   }
2588   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2589   {
2590     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Permission denied! [%d]\n", brightness);
2591     return Dali::WindowOperationResult::PERMISSION_DENIED;
2592   }
2593
2594   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness is changed [%d]\n", mBrightness);
2595
2596   return Dali::WindowOperationResult::SUCCEED;
2597 }
2598
2599 int WindowBaseEcoreWl2::GetBrightness() const
2600 {
2601   START_DURATION_CHECK();
2602   while(!mTizenDisplayPolicy)
2603   {
2604     wl_display_dispatch_queue(mDisplay, mEventQueue);
2605   }
2606
2607   int count = 0;
2608
2609   while(!mBrightnessChangeDone && count < 3)
2610   {
2611     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2612     wl_display_dispatch_queue(mDisplay, mEventQueue);
2613     count++;
2614   }
2615   FINISH_DURATION_CHECK("ecore_wl2_display_flush");
2616
2617   if(!mBrightnessChangeDone)
2618   {
2619     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Error! [%d]\n", mBrightnessChangeState);
2620     return 0;
2621   }
2622
2623   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Brightness [%d]\n", mBrightness);
2624
2625   return mBrightness;
2626 }
2627
2628 bool WindowBaseEcoreWl2::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
2629 {
2630   Ecore_Wl2_Window_Keygrab_Mode mode;
2631
2632   switch(grabMode)
2633   {
2634     case KeyGrab::TOPMOST:
2635     {
2636       mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2637       break;
2638     }
2639     case KeyGrab::SHARED:
2640     {
2641       mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2642       break;
2643     }
2644     case KeyGrab::OVERRIDE_EXCLUSIVE:
2645     {
2646       mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2647       break;
2648     }
2649     case KeyGrab::EXCLUSIVE:
2650     {
2651       mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2652       break;
2653     }
2654     default:
2655     {
2656       return false;
2657     }
2658   }
2659
2660   return ecore_wl2_window_keygrab_set(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0, 0, mode);
2661 }
2662
2663 bool WindowBaseEcoreWl2::UngrabKey(Dali::KEY key)
2664 {
2665   return ecore_wl2_window_keygrab_unset(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0);
2666 }
2667
2668 bool WindowBaseEcoreWl2::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
2669 {
2670   int keyCount         = key.Count();
2671   int keyGrabModeCount = grabMode.Count();
2672
2673   if(keyCount != keyGrabModeCount || keyCount == 0)
2674   {
2675     return false;
2676   }
2677
2678   eina_init();
2679
2680   Eina_List*                     keyList = NULL;
2681   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2682
2683   for(int index = 0; index < keyCount; ++index)
2684   {
2685     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2686
2687     switch(grabMode[index])
2688     {
2689       case KeyGrab::TOPMOST:
2690       {
2691         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2692         break;
2693       }
2694       case KeyGrab::SHARED:
2695       {
2696         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2697         break;
2698       }
2699       case KeyGrab::OVERRIDE_EXCLUSIVE:
2700       {
2701         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2702         break;
2703       }
2704       case KeyGrab::EXCLUSIVE:
2705       {
2706         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2707         break;
2708       }
2709       default:
2710       {
2711         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_UNKNOWN;
2712         break;
2713       }
2714     }
2715
2716     keyList = eina_list_append(keyList, &info);
2717   }
2718
2719   START_DURATION_CHECK();
2720   Eina_List* grabList = ecore_wl2_window_keygrab_list_set(mEcoreWindow, keyList);
2721   FINISH_DURATION_CHECK("ecore_wl2_window_keygrab_list_set");
2722
2723   result.Resize(keyCount, true);
2724
2725   Eina_List* l        = NULL;
2726   Eina_List* m        = NULL;
2727   void*      listData = NULL;
2728   void*      data     = NULL;
2729   if(grabList != NULL)
2730   {
2731     EINA_LIST_FOREACH(grabList, m, data)
2732     {
2733       int index = 0;
2734       EINA_LIST_FOREACH(keyList, l, listData)
2735       {
2736         if(static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key == NULL)
2737         {
2738           DALI_LOG_ERROR("input key list has null data!");
2739           break;
2740         }
2741
2742         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2743         {
2744           result[index] = false;
2745         }
2746         ++index;
2747       }
2748     }
2749   }
2750
2751   delete[] info;
2752
2753   eina_list_free(keyList);
2754   eina_list_free(grabList);
2755   eina_shutdown();
2756
2757   return true;
2758 }
2759
2760 bool WindowBaseEcoreWl2::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
2761 {
2762   int keyCount = key.Count();
2763   if(keyCount == 0)
2764   {
2765     return false;
2766   }
2767
2768   eina_init();
2769
2770   Eina_List*                     keyList = NULL;
2771   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2772
2773   for(int index = 0; index < keyCount; ++index)
2774   {
2775     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2776     keyList         = eina_list_append(keyList, &info);
2777   }
2778
2779   START_DURATION_CHECK();
2780   Eina_List* ungrabList = ecore_wl2_window_keygrab_list_unset(mEcoreWindow, keyList);
2781   FINISH_DURATION_CHECK("ecore_wl2_window_keygrab_list_unset");
2782
2783   result.Resize(keyCount, true);
2784
2785   Eina_List* l        = NULL;
2786   Eina_List* m        = NULL;
2787   void*      listData = NULL;
2788   void*      data     = NULL;
2789
2790   if(ungrabList != NULL)
2791   {
2792     EINA_LIST_FOREACH(ungrabList, m, data)
2793     {
2794       int index = 0;
2795       EINA_LIST_FOREACH(keyList, l, listData)
2796       {
2797         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2798         {
2799           result[index] = false;
2800         }
2801         ++index;
2802       }
2803     }
2804   }
2805
2806   delete[] info;
2807
2808   eina_list_free(keyList);
2809   eina_list_free(ungrabList);
2810   eina_shutdown();
2811
2812   return true;
2813 }
2814
2815 void WindowBaseEcoreWl2::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
2816 {
2817   // calculate DPI
2818   float xres, yres;
2819
2820   Ecore_Wl2_Output* output = ecore_wl2_window_output_find(mEcoreWindow);
2821
2822   // 1 inch = 25.4 millimeters
2823   xres = ecore_wl2_output_dpi_get(output);
2824   yres = ecore_wl2_output_dpi_get(output);
2825
2826   dpiHorizontal = int(xres + 0.5f); // rounding
2827   dpiVertical   = int(yres + 0.5f);
2828 }
2829
2830 int WindowBaseEcoreWl2::GetWindowRotationAngle() const
2831 {
2832   int orientation = mWindowRotationAngle;
2833   if(mSupportedPreProtation)
2834   {
2835     orientation = 0;
2836   }
2837   return orientation;
2838 }
2839
2840 int WindowBaseEcoreWl2::GetScreenRotationAngle()
2841 {
2842   if(mSupportedPreProtation)
2843   {
2844     DALI_LOG_RELEASE_INFO("Support PreRotation and return 0\n");
2845     return 0;
2846   }
2847   int transform;
2848   if(ecore_wl2_window_ignore_output_transform_get(mEcoreWindow))
2849   {
2850     transform = 0;
2851   }
2852   else
2853   {
2854     transform = ecore_wl2_output_transform_get(ecore_wl2_window_output_find(mEcoreWindow));
2855   }
2856   mScreenRotationAngle = transform * 90;
2857   return mScreenRotationAngle;
2858 }
2859
2860 void WindowBaseEcoreWl2::SetWindowRotationAngle(int degree)
2861 {
2862   mWindowRotationAngle = degree;
2863   ecore_wl2_window_rotation_set(mEcoreWindow, degree);
2864 }
2865
2866 void WindowBaseEcoreWl2::WindowRotationCompleted(int degree, int width, int height)
2867 {
2868   START_DURATION_CHECK();
2869   ecore_wl2_window_rotation_change_done_send(mEcoreWindow, degree, width, height);
2870   FINISH_DURATION_CHECK("ecore_wl2_window_rotation_change_done_send");
2871 }
2872
2873 void WindowBaseEcoreWl2::SetTransparency(bool transparent)
2874 {
2875   START_DURATION_CHECK();
2876   ecore_wl2_window_alpha_set(mEcoreWindow, transparent);
2877   FINISH_DURATION_CHECK("ecore_wl2_window_alpha_set");
2878 }
2879
2880 void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize)
2881 {
2882   Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
2883   if(!display)
2884   {
2885     DALI_ASSERT_ALWAYS(0 && "Failed to get display");
2886   }
2887
2888   START_DURATION_CHECK();
2889   ecore_wl2_display_sync(display);
2890
2891   mEcoreWindow = ecore_wl2_window_new(display, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2892
2893   if(mEcoreWindow == 0)
2894   {
2895     DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
2896   }
2897
2898   // Set default type
2899   ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
2900   FINISH_DURATION_CHECK("ecore_wl2 functions");
2901 }
2902
2903 void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent)
2904 {
2905   Ecore_Wl2_Window* ecoreParent = NULL;
2906   if(parentWinBase)
2907   {
2908     WindowBaseEcoreWl2* winBaseEcore2 = static_cast<WindowBaseEcoreWl2*>(parentWinBase);
2909     ecoreParent                       = winBaseEcore2->mEcoreWindow;
2910   }
2911
2912   START_DURATION_CHECK();
2913   ecore_wl2_window_transient_parent_set(mEcoreWindow, ecoreParent, belowParent);
2914   FINISH_DURATION_CHECK("ecore_wl2_window_transient_parent_set");
2915 }
2916
2917 int WindowBaseEcoreWl2::CreateFrameRenderedSyncFence()
2918 {
2919   return wl_egl_window_tizen_create_commit_sync_fd(mEglWindow);
2920 }
2921
2922 int WindowBaseEcoreWl2::CreateFramePresentedSyncFence()
2923 {
2924   return wl_egl_window_tizen_create_presentation_sync_fd(mEglWindow);
2925 }
2926
2927 void WindowBaseEcoreWl2::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
2928 {
2929   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);
2930   START_DURATION_CHECK();
2931   ecore_wl2_window_rotation_geometry_set(mEcoreWindow, angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2932   FINISH_DURATION_CHECK("ecore_wl2_window_rotation_geometry_set");
2933 }
2934
2935 void WindowBaseEcoreWl2::InitializeIme()
2936 {
2937   Eina_Iterator*      globals;
2938   struct wl_registry* registry;
2939   Ecore_Wl2_Global*   global;
2940   Ecore_Wl2_Display*  ecoreWl2Display;
2941
2942   if(!(ecoreWl2Display = ecore_wl2_connected_display_get(NULL)))
2943   {
2944     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 connected display\n");
2945     return;
2946   }
2947
2948   DALI_LOG_RELEASE_INFO("InitializeIme:  Ecore_Wl2_Display: %p, ecore wl window: %p\n", ecoreWl2Display, mEcoreWindow);
2949
2950   if(!(registry = ecore_wl2_display_registry_get(ecoreWl2Display)))
2951   {
2952     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 display registry\n");
2953     return;
2954   }
2955
2956   if(!(globals = ecore_wl2_display_globals_get(ecoreWl2Display)))
2957   {
2958     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 globals\n");
2959     return;
2960   }
2961
2962   START_DURATION_CHECK();
2963   EINA_ITERATOR_FOREACH(globals, global)
2964   {
2965 #ifdef OVER_TIZEN_VERSION_7
2966     if(strcmp(global->interface, "zwp_input_panel_v1") == 0)
2967     {
2968       mWlInputPanel = (zwp_input_panel_v1*)wl_registry_bind(registry, global->id, &zwp_input_panel_v1_interface, 1);
2969     }
2970 #else
2971     if(strcmp(global->interface, "wl_input_panel") == 0)
2972     {
2973       mWlInputPanel = (wl_input_panel*)wl_registry_bind(registry, global->id, &wl_input_panel_interface, 1);
2974     }
2975 #endif
2976     else if(strcmp(global->interface, "wl_output") == 0)
2977     {
2978       mWlOutput = (wl_output*)wl_registry_bind(registry, global->id, &wl_output_interface, 1);
2979     }
2980   }
2981
2982   if(!mWlInputPanel)
2983   {
2984     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel interface\n");
2985     return;
2986   }
2987
2988   if(!mWlOutput)
2989   {
2990     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland output panel interface\n");
2991     return;
2992   }
2993 #ifdef OVER_TIZEN_VERSION_7
2994   mWlInputPanelSurface = zwp_input_panel_v1_get_input_panel_surface(mWlInputPanel, mWlSurface);
2995 #else
2996   mWlInputPanelSurface = wl_input_panel_get_input_panel_surface(mWlInputPanel, mWlSurface);
2997 #endif
2998   if(!mWlInputPanelSurface)
2999   {
3000     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel surface\n");
3001     return;
3002   }
3003 #ifdef OVER_TIZEN_VERSION_7
3004   zwp_input_panel_surface_v1_set_toplevel(mWlInputPanelSurface, mWlOutput, ZWP_INPUT_PANEL_SURFACE_V1_POSITION_CENTER_BOTTOM);
3005 #else
3006   wl_input_panel_surface_set_toplevel(mWlInputPanelSurface, mWlOutput, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM);
3007 #endif
3008   FINISH_DURATION_CHECK("zwp_input_panel_surface_v1_set_toplevel");
3009 }
3010
3011 void WindowBaseEcoreWl2::ImeWindowReadyToRender()
3012 {
3013   if(!mWlInputPanelSurface)
3014   {
3015     DALI_LOG_ERROR("WindowBaseEcoreWl2::ImeWindowReadyToRender(), wayland input panel surface is null\n");
3016     return;
3017   }
3018
3019   START_DURATION_CHECK();
3020 #ifdef OVER_TIZEN_VERSION_7
3021   zwp_input_panel_surface_v1_set_ready(mWlInputPanelSurface, 1);
3022 #else
3023   wl_input_panel_surface_set_ready(mWlInputPanelSurface, 1);
3024 #endif
3025   FINISH_DURATION_CHECK("zwp_input_panel_surface_v1_set_ready");
3026 }
3027
3028 void WindowBaseEcoreWl2::RequestMoveToServer()
3029 {
3030   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
3031   if(!display)
3032   {
3033     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get ecore_wl2_display\n");
3034     return;
3035   }
3036
3037   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
3038   if(!input)
3039   {
3040     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get default Ecore_Wl2_Input\n");
3041     return;
3042   }
3043
3044   START_DURATION_CHECK();
3045   ecore_wl2_window_move(mEcoreWindow, input);
3046   FINISH_DURATION_CHECK("ecore_wl2_window_move");
3047   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestMoveToServer, starts the window[%p] is moved by server\n", mEcoreWindow);
3048 }
3049
3050 void WindowBaseEcoreWl2::RequestResizeToServer(WindowResizeDirection direction)
3051 {
3052   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
3053   if(!display)
3054   {
3055     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get ecore_wl2_display\n");
3056     return;
3057   }
3058
3059   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
3060   if(!input)
3061   {
3062     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get default Ecore_Wl2_Input\n");
3063     return;
3064   }
3065
3066   ResizeLocation location = RecalculateLocationToCurrentOrientation(direction, mWindowRotationAngle);
3067
3068   START_DURATION_CHECK();
3069   ecore_wl2_window_resize(mEcoreWindow, input, static_cast<int>(location));
3070   FINISH_DURATION_CHECK("ecore_wl2_window_resize");
3071   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);
3072 }
3073
3074 void WindowBaseEcoreWl2::EnableFloatingMode(bool enable)
3075 {
3076   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EnableFloatingMode, floating mode flag: [%p], enable [%d]\n", mEcoreWindow, enable);
3077   START_DURATION_CHECK();
3078   if(enable == true)
3079   {
3080     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_TRUE);
3081   }
3082   else
3083   {
3084     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_FALSE);
3085   }
3086   FINISH_DURATION_CHECK("ecore_wl2_window_floating_mode_set");
3087 }
3088
3089 bool WindowBaseEcoreWl2::IsFloatingModeEnabled() const
3090 {
3091   return ecore_wl2_window_floating_mode_get(mEcoreWindow);
3092 }
3093
3094 void WindowBaseEcoreWl2::IncludeInputRegion(const Rect<int>& inputRegion)
3095 {
3096   Rect<int>      convertRegion = RecalculateInputRect(inputRegion);
3097   Eina_Rectangle rect;
3098
3099   rect.x = convertRegion.x;
3100   rect.y = convertRegion.y;
3101   rect.w = convertRegion.width;
3102   rect.h = convertRegion.height;
3103
3104   DALI_LOG_RELEASE_INFO("%p, Add input_rect(%d, %d, %d x %d)\n", mEcoreWindow, rect.x, rect.y, rect.w, rect.h);
3105   START_DURATION_CHECK();
3106   ecore_wl2_window_input_rect_add(mEcoreWindow, &rect);
3107   FINISH_DURATION_CHECK("ecore_wl2_window_input_rect_add");
3108   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
3109 }
3110
3111 void WindowBaseEcoreWl2::ExcludeInputRegion(const Rect<int>& inputRegion)
3112 {
3113   Rect<int>      convertRegion = RecalculateInputRect(inputRegion);
3114   Eina_Rectangle rect;
3115
3116   rect.x = convertRegion.x;
3117   rect.y = convertRegion.y;
3118   rect.w = convertRegion.width;
3119   rect.h = convertRegion.height;
3120
3121   DALI_LOG_RELEASE_INFO("%p, Subtract input_rect(%d, %d, %d x %d)\n", mEcoreWindow, rect.x, rect.y, rect.w, rect.h);
3122   START_DURATION_CHECK();
3123   ecore_wl2_window_input_rect_subtract(mEcoreWindow, &rect);
3124   FINISH_DURATION_CHECK("ecore_wl2_window_input_rect_subtract");
3125   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
3126 }
3127
3128 } // namespace Adaptor
3129
3130 } // namespace Internal
3131
3132 } // namespace Dali
3133
3134 #pragma GCC diagnostic pop