WindowRenderSurface and EventHandler refactoring
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / window-base-ecore-x.cpp
1 /*
2  * Copyright (c) 2018 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/ubuntu-x11/window-base-ecore-x.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/window-system/common/window-impl.h>
27 #include <dali/internal/window-system/common/window-render-surface.h>
28 #include <dali/internal/window-system/ubuntu-x11/ecore-x-types.h>
29
30 // EXTERNAL_HEADERS
31 #include <dali/public-api/object/any.h>
32 #include <dali/integration-api/debug.h>
33 #include <Ecore_Input.h>
34
35 namespace Dali
36 {
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 namespace
45 {
46
47 const std::string DEFAULT_DEVICE_NAME = "";
48 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
49 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
50
51 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
55 #endif
56
57 /////////////////////////////////////////////////////////////////////////////////////////////////
58 // Window Callbacks
59 /////////////////////////////////////////////////////////////////////////////////////////////////
60
61 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
62 {
63   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
64   if( windowBase )
65   {
66     return windowBase->OnWindowPropertyChanged( data, type, event );
67   }
68
69   return ECORE_CALLBACK_PASS_ON;
70 }
71
72 /**
73  * Called when the window receives a delete request
74  */
75 static Eina_Bool EcoreEventWindowDeleteRequest( void* data, int type, void* event )
76 {
77   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
78   if( windowBase )
79   {
80     windowBase->OnDeleteRequest();
81   }
82   return ECORE_CALLBACK_DONE;
83 }
84
85 /**
86  * Called when the window gains focus.
87  */
88 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
89 {
90   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
91   if( windowBase )
92   {
93     windowBase->OnFocusIn( data, type, event );
94   }
95   return ECORE_CALLBACK_PASS_ON;
96 }
97
98 /**
99  * Called when the window loses focus.
100  */
101 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
102 {
103   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
104   if( windowBase )
105   {
106     windowBase->OnFocusOut( data, type, event );
107   }
108   return ECORE_CALLBACK_PASS_ON;
109 }
110
111 /**
112  * Called when the window is damaged.
113  */
114 static Eina_Bool EcoreEventWindowDamaged( void* data, int type, void* event )
115 {
116   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
117   if( windowBase )
118   {
119     windowBase->OnWindowDamaged( data, type, event );
120   }
121
122   return ECORE_CALLBACK_PASS_ON;
123 }
124
125 /////////////////////////////////////////////////////////////////////////////////////////////////
126 // Selection Callbacks
127 /////////////////////////////////////////////////////////////////////////////////////////////////
128
129 /**
130  * Called when the source window notifies us the content in clipboard is selected.
131  */
132 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
133 {
134   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
135   if( windowBase )
136   {
137     windowBase->OnSelectionClear( data, type, event );
138   }
139   return ECORE_CALLBACK_PASS_ON;
140 }
141
142 /**
143  * Called when the source window sends us about the selected content.
144  * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
145  */
146 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
147 {
148   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
149   if( windowBase )
150   {
151     windowBase->OnSelectionNotify( data, type, event );
152   }
153   return ECORE_CALLBACK_PASS_ON;
154 }
155
156 /////////////////////////////////////////////////////////////////////////////////////////////////
157 // Touch Callbacks
158 /////////////////////////////////////////////////////////////////////////////////////////////////
159
160 /**
161  * Called when a touch down is received.
162  */
163 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
164 {
165   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
166   if( windowBase )
167   {
168     windowBase->OnMouseButtonDown( data, type, event );
169   }
170   return ECORE_CALLBACK_PASS_ON;
171 }
172
173 /**
174  * Called when a touch up is received.
175  */
176 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
177 {
178   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
179   if( windowBase )
180   {
181     windowBase->OnMouseButtonUp( data, type, event );
182   }
183   return ECORE_CALLBACK_PASS_ON;
184 }
185
186 /**
187  * Called when a touch motion is received.
188  */
189 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
190 {
191   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
192   if( windowBase )
193   {
194     windowBase->OnMouseButtonMove( data, type, event );
195   }
196   return ECORE_CALLBACK_PASS_ON;
197 }
198
199 /////////////////////////////////////////////////////////////////////////////////////////////////
200 // Wheel Callbacks
201 /////////////////////////////////////////////////////////////////////////////////////////////////
202
203 /**
204  * Called when a mouse wheel is received.
205  */
206 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
207 {
208   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
209   if( windowBase )
210   {
211     windowBase->OnMouseWheel( data, type, event );
212   }
213   return ECORE_CALLBACK_PASS_ON;
214 }
215
216 /////////////////////////////////////////////////////////////////////////////////////////////////
217 // Key Callbacks
218 /////////////////////////////////////////////////////////////////////////////////////////////////
219
220 /**
221  * Called when a key down is received.
222  */
223 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
224 {
225   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
226   if( windowBase )
227   {
228     windowBase->OnKeyDown( data, type, event );
229   }
230   return ECORE_CALLBACK_PASS_ON;
231 }
232
233 /**
234  * Called when a key up is received.
235  */
236 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
237 {
238   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
239   if( windowBase )
240   {
241     windowBase->OnKeyUp( data, type, event );
242   }
243   return ECORE_CALLBACK_PASS_ON;
244 }
245
246 } // unnamed namespace
247
248 WindowBaseEcoreX::WindowBaseEcoreX( Dali::PositionSize positionSize, Any surface, bool isTransparent )
249 : mEcoreEventHandler(),
250   mEcoreWindow( 0 ),
251   mOwnSurface( false ),
252   mRotationAppSet( false )
253 {
254   Initialize( positionSize, surface, isTransparent );
255 }
256
257 WindowBaseEcoreX::~WindowBaseEcoreX()
258 {
259   for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
260   {
261     ecore_event_handler_del( *iter );
262   }
263   mEcoreEventHandler.Clear();
264
265   if( mOwnSurface )
266   {
267     ecore_x_window_free( mEcoreWindow );
268   }
269 }
270
271 void WindowBaseEcoreX::Initialize( PositionSize positionSize, Any surface, bool isTransparent )
272 {
273   // see if there is a surface in Any surface
274   unsigned int surfaceId = GetSurfaceId( surface );
275
276   // if the surface is empty, create a new one.
277   if( surfaceId == 0 )
278   {
279     // we own the surface about to created
280     mOwnSurface = true;
281     CreateWindow( positionSize, isTransparent );
282   }
283   else
284   {
285     // XLib should already be initialized so no point in calling XInitThreads
286     mEcoreWindow = static_cast< Ecore_X_Window >( surfaceId );
287   }
288
289   // set up etc properties to match with ecore-evas
290   char *id = NULL;
291   if( ( id = getenv("DESKTOP_STARTUP_ID") ) )
292   {
293     ecore_x_netwm_startup_id_set( mEcoreWindow, id );
294   }
295
296   ecore_x_icccm_hints_set( mEcoreWindow,
297                            1,                                // accepts_focus
298                            ECORE_X_WINDOW_STATE_HINT_NORMAL, // initial_state
299                            0,                                // icon_pixmap
300                            0,                                // icon_mask
301                            0,                                // icon_window
302                            0,                                // window_group
303                            0 );                              // is_urgent
304
305   // we SHOULD guarantee the x11 window was created in x server.
306   ecore_x_sync();
307
308   ecore_x_input_multi_select( mEcoreWindow );
309
310   // This ensures that we catch the window close (or delete) request
311   ecore_x_icccm_protocol_set( mEcoreWindow, ECORE_X_WM_PROTOCOL_DELETE_REQUEST, EINA_TRUE );
312
313   // Enable Drag & Drop
314   ecore_x_dnd_aware_set( mEcoreWindow, EINA_TRUE );
315
316   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_PROPERTY,       EcoreEventWindowPropertyChanged, this ) );
317   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DELETE_REQUEST, EcoreEventWindowDeleteRequest,   this ) );
318
319   // Register window focus events
320   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN,       EcoreEventWindowFocusIn,   this ) );
321   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT,      EcoreEventWindowFocusOut,  this ) );
322
323   // Register Window damage events
324   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE,         EcoreEventWindowDamaged,   this ) );
325
326   // Register Touch events
327   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,       EcoreEventMouseButtonDown, this ) );
328   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,         EcoreEventMouseButtonUp,   this ) );
329   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,              EcoreEventMouseButtonMove, this ) );
330   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT,               EcoreEventMouseButtonUp,   this ) ); // process mouse out event like up event
331
332   // Register Mouse wheel events
333   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,             EcoreEventMouseWheel,      this ) );
334
335   // Register Key events
336   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,                EcoreEventKeyDown,         this ) );
337   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_UP,                  EcoreEventKeyUp,           this ) );
338
339   // Register Selection event
340   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR,       EcoreEventSelectionClear,  this ) );
341   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY,      EcoreEventSelectionNotify, this ) );
342 }
343
344 Eina_Bool WindowBaseEcoreX::OnWindowPropertyChanged( void* data, int type, void* event )
345 {
346   Ecore_X_Event_Window_Property* propertyChangedEvent = static_cast< Ecore_X_Event_Window_Property* >( event );
347   Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
348
349   if( propertyChangedEvent->win == mEcoreWindow )
350   {
351     Ecore_X_Window_State_Hint state( ecore_x_icccm_state_get( propertyChangedEvent->win ) );
352
353     switch( state )
354     {
355       case ECORE_X_WINDOW_STATE_HINT_WITHDRAWN:
356       {
357         // Window was hidden.
358         mIconifyChangedSignal.Emit( true );
359         handled = ECORE_CALLBACK_DONE;
360         break;
361       }
362       case ECORE_X_WINDOW_STATE_HINT_ICONIC:
363       {
364         // Window was iconified (minimised).
365         mIconifyChangedSignal.Emit( true );
366         handled = ECORE_CALLBACK_DONE;
367         break;
368       }
369       case ECORE_X_WINDOW_STATE_HINT_NORMAL:
370       {
371         // Window was shown.
372         mIconifyChangedSignal.Emit( false );
373         handled = ECORE_CALLBACK_DONE;
374         break;
375       }
376       default:
377       {
378         // Ignore
379         break;
380       }
381     }
382   }
383
384   return handled;
385 }
386
387 void WindowBaseEcoreX::OnDeleteRequest()
388 {
389   mDeleteRequestSignal.Emit();
390 }
391
392 void WindowBaseEcoreX::OnFocusIn( void* data, int type, void* event )
393 {
394   Ecore_X_Event_Window_Focus_In* focusInEvent = static_cast< Ecore_X_Event_Window_Focus_In* >( event );
395
396   if( focusInEvent->win == mEcoreWindow )
397   {
398     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
399
400     mFocusChangedSignal.Emit( true );
401   }
402 }
403
404 void WindowBaseEcoreX::OnFocusOut( void* data, int type, void* event )
405 {
406   Ecore_X_Event_Window_Focus_Out* focusOutEvent = static_cast< Ecore_X_Event_Window_Focus_Out* >( event );
407
408   // If the window loses focus then hide the keyboard.
409   if( focusOutEvent->win == mEcoreWindow )
410   {
411     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
412
413     mFocusChangedSignal.Emit( false );
414   }
415 }
416
417 void WindowBaseEcoreX::OnWindowDamaged( void* data, int type, void* event )
418 {
419   Ecore_X_Event_Window_Damage* windowDamagedEvent = static_cast< Ecore_X_Event_Window_Damage* >( event );
420
421   if( windowDamagedEvent->win == mEcoreWindow )
422   {
423     DamageArea area;
424     area.x = windowDamagedEvent->x;
425     area.y = windowDamagedEvent->y;
426     area.width = windowDamagedEvent->w;
427     area.height = windowDamagedEvent->h;
428
429     mWindowDamagedSignal.Emit( area );
430   }
431 }
432
433 void WindowBaseEcoreX::OnMouseButtonDown( void* data, int type, void* event )
434 {
435   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
436
437   if( touchEvent->window == mEcoreWindow )
438   {
439     PointState::Type state ( PointState::DOWN );
440
441     // Check if the buttons field is set and ensure it's the primary touch button.
442     // If this event was triggered by buttons other than the primary button (used for touch), then
443     // just send an interrupted event to Core.
444     if( touchEvent->buttons && ( touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
445     {
446       state = PointState::INTERRUPTED;
447     }
448
449     Integration::Point point;
450     point.SetDeviceId( touchEvent->multi.device );
451     point.SetState( state );
452     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
453     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
454     point.SetPressure( touchEvent->multi.pressure );
455     point.SetAngle( Degree( touchEvent->multi.angle ) );
456
457     mTouchEventSignal.Emit( point, touchEvent->timestamp );
458   }
459 }
460
461 void WindowBaseEcoreX::OnMouseButtonUp( void* data, int type, void* event )
462 {
463   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
464
465   if( touchEvent->window == mEcoreWindow )
466   {
467     Integration::Point point;
468     point.SetDeviceId( touchEvent->multi.device );
469     point.SetState( PointState::UP );
470     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
471     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
472     point.SetPressure( touchEvent->multi.pressure );
473     point.SetAngle( Degree( touchEvent->multi.angle ) );
474
475     mTouchEventSignal.Emit( point, touchEvent->timestamp );
476   }
477 }
478
479 void WindowBaseEcoreX::OnMouseButtonMove( void* data, int type, void* event )
480 {
481   Ecore_Event_Mouse_Move* touchEvent = static_cast< Ecore_Event_Mouse_Move* >( event );
482
483   if( touchEvent->window == mEcoreWindow )
484   {
485     Integration::Point point;
486     point.SetDeviceId( touchEvent->multi.device );
487     point.SetState( PointState::MOTION );
488     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
489     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
490     point.SetPressure( touchEvent->multi.pressure );
491     point.SetAngle( Degree( touchEvent->multi.angle ) );
492
493     mTouchEventSignal.Emit( point, touchEvent->timestamp );
494   }
495 }
496
497 void WindowBaseEcoreX::OnMouseWheel( void* data, int type, void* event )
498 {
499   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast< Ecore_Event_Mouse_Wheel* >( event );
500
501   if( mouseWheelEvent->window == mEcoreWindow )
502   {
503     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreX::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z );
504
505     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2( mouseWheelEvent->x, mouseWheelEvent->y ), mouseWheelEvent->z, mouseWheelEvent->timestamp );
506
507     mWheelEventSignal.Emit( wheelEvent );
508   }
509 }
510
511 void WindowBaseEcoreX::OnKeyDown( void* data, int type, void* event )
512 {
513   Ecore_Event_Key* keyEvent = static_cast< Ecore_Event_Key* >( event );
514
515   if( keyEvent->window == mEcoreWindow )
516   {
517     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreX::OnKeyDown\n" );
518
519     std::string keyName( keyEvent->keyname );
520     std::string keyString( "" );
521     std::string compose( "" );
522
523     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
524     if( keyEvent->compose )
525     {
526       compose = keyEvent->compose;
527     }
528
529     int keyCode = ecore_x_keysym_keycode_get( keyEvent->keyname );
530     int modifier( keyEvent->modifiers );
531     unsigned long time = keyEvent->timestamp;
532
533     // Ensure key event string is not NULL as keys like SHIFT have a null string.
534     if( keyEvent->string )
535     {
536       keyString = keyEvent->string;
537     }
538
539     Integration::KeyEvent keyEvent( keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
540
541     mKeyEventSignal.Emit( keyEvent );
542   }
543 }
544
545 void WindowBaseEcoreX::OnKeyUp( void* data, int type, void* event )
546 {
547   Ecore_Event_Key* keyEvent = static_cast< Ecore_Event_Key* >( event );
548
549   if ( keyEvent->window == mEcoreWindow )
550   {
551     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, " WindowBaseEcoreX::OnKeyUp\n" );
552
553     std::string keyName( keyEvent->keyname );
554     std::string keyString( "" );
555     std::string compose( "" );
556
557     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
558     if( keyEvent->compose )
559     {
560       compose = keyEvent->compose;
561     }
562     int keyCode = ecore_x_keysym_keycode_get( keyEvent->keyname );
563     int modifier( keyEvent->modifiers );
564     unsigned long time( keyEvent->timestamp );
565
566     // Ensure key event string is not NULL as keys like SHIFT have a null string.
567     if( keyEvent->string )
568     {
569       keyString = keyEvent->string;
570     }
571
572     Integration::KeyEvent keyEvent( keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
573
574     mKeyEventSignal.Emit( keyEvent );
575   }
576 }
577
578 void WindowBaseEcoreX::OnSelectionClear( void* data, int type, void* event )
579 {
580   Ecore_X_Event_Selection_Clear* selectionClearEvent = static_cast< Ecore_X_Event_Selection_Clear* >( event );
581
582   if( selectionClearEvent->win == mEcoreWindow )
583   {
584     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, " WindowBaseEcoreX::OnSelectionClear\n" );
585
586     if( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
587     {
588       // Request to get the content from Ecore.
589       ecore_x_selection_secondary_request( selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT );
590     }
591   }
592 }
593
594 void WindowBaseEcoreX::OnSelectionNotify( void* data, int type, void* event )
595 {
596   Ecore_X_Event_Selection_Notify* selectionNotifyEvent = static_cast< Ecore_X_Event_Selection_Notify* >( event );
597
598   if( selectionNotifyEvent->win == mEcoreWindow )
599   {
600     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, " WindowBaseEcoreX::OnSelectionNotify\n" );
601
602     Ecore_X_Selection_Data* selectionData = static_cast< Ecore_X_Selection_Data* >( selectionNotifyEvent->data );
603     if( selectionData->data )
604     {
605       if( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
606       {
607         mSelectionDataReceivedSignal.Emit( event  );
608       }
609     }
610   }
611 }
612
613 Any WindowBaseEcoreX::GetNativeWindow()
614 {
615   return mEcoreWindow;
616 }
617
618 int WindowBaseEcoreX::GetNativeWindowId()
619 {
620   return mEcoreWindow;
621 }
622
623 EGLNativeWindowType WindowBaseEcoreX::CreateEglWindow( int width, int height )
624 {
625   // need to create X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
626   XWindow window( mEcoreWindow );
627   return reinterpret_cast< EGLNativeWindowType >( window );
628 }
629
630 void WindowBaseEcoreX::DestroyEglWindow()
631 {
632 }
633
634 void WindowBaseEcoreX::SetEglWindowRotation( int angle )
635 {
636 }
637
638 void WindowBaseEcoreX::SetEglWindowBufferTransform( int angle )
639 {
640 }
641
642 void WindowBaseEcoreX::SetEglWindowTransform( int angle )
643 {
644 }
645
646 void WindowBaseEcoreX::ResizeEglWindow( PositionSize positionSize )
647 {
648 }
649
650 bool WindowBaseEcoreX::IsEglWindowRotationSupported()
651 {
652   return false;
653 }
654
655 void WindowBaseEcoreX::Move( PositionSize positionSize )
656 {
657   ecore_x_window_move( mEcoreWindow, positionSize.x, positionSize.y );
658 }
659
660 void WindowBaseEcoreX::Resize( PositionSize positionSize )
661 {
662   ecore_x_window_resize( mEcoreWindow, positionSize.width, positionSize.height );
663 }
664
665 void WindowBaseEcoreX::MoveResize( PositionSize positionSize )
666 {
667   ecore_x_window_move_resize( mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
668 }
669
670 void WindowBaseEcoreX::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
671 {
672   DALI_LOG_TRACE_METHOD_FMT( gWindowBaseLogFilter, "visible : %d\n", visibleMode );
673
674   if( visibleMode == Dali::Window::VISIBLE )
675   {
676     // when the indicator is visible, set proper mode for indicator server according to bg mode
677     if( opacityMode == Dali::Window::OPAQUE )
678     {
679       ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_OPAQUE );
680     }
681     else if( opacityMode == Dali::Window::TRANSLUCENT )
682     {
683       ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT );
684     }
685   }
686   else
687   {
688     // when the indicator is not visible, set TRANSPARENT mode for indicator server
689     ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_TRANSPARENT ); // it means hidden indicator
690   }
691 }
692
693 void WindowBaseEcoreX::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
694 {
695   int show_state = static_cast< int >( isShow );
696   ecore_x_window_prop_property_set( mEcoreWindow, ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE,
697                                     ECORE_X_ATOM_CARDINAL, 32, &show_state, 1 );
698
699   if( isShow )
700   {
701     ecore_x_e_illume_indicator_state_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_STATE_ON );
702   }
703   else
704   {
705     ecore_x_e_illume_indicator_state_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_STATE_OFF );
706   }
707 }
708
709 void WindowBaseEcoreX::IndicatorTypeChanged( IndicatorInterface::Type type )
710 {
711 }
712
713 void WindowBaseEcoreX::SetClass( const std::string& name, const std::string& className )
714 {
715   ecore_x_icccm_title_set( mEcoreWindow, name.c_str() );
716   ecore_x_netwm_name_set( mEcoreWindow, name.c_str() );
717   ecore_x_icccm_name_class_set( mEcoreWindow, name.c_str(), className.c_str() );
718 }
719
720 void WindowBaseEcoreX::Raise()
721 {
722   ecore_x_window_raise( mEcoreWindow );
723 }
724
725 void WindowBaseEcoreX::Lower()
726 {
727   ecore_x_window_lower( mEcoreWindow );
728 }
729
730 void WindowBaseEcoreX::Activate()
731 {
732   ecore_x_netwm_client_active_request( ecore_x_window_root_get( mEcoreWindow ), mEcoreWindow, 1 /* request type, 1:application, 2:pager */, 0 );
733 }
734
735 void WindowBaseEcoreX::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
736 {
737 }
738
739 void WindowBaseEcoreX::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
740 {
741 }
742
743 void WindowBaseEcoreX::SetAcceptFocus( bool accept )
744 {
745 }
746
747 void WindowBaseEcoreX::Show()
748 {
749   ecore_x_window_show( mEcoreWindow );
750 }
751
752 void WindowBaseEcoreX::Hide()
753 {
754   ecore_x_window_hide( mEcoreWindow );
755 }
756
757 unsigned int WindowBaseEcoreX::GetSupportedAuxiliaryHintCount() const
758 {
759   return 0;
760 }
761
762 std::string WindowBaseEcoreX::GetSupportedAuxiliaryHint( unsigned int index ) const
763 {
764   return std::string();
765 }
766
767 unsigned int WindowBaseEcoreX::AddAuxiliaryHint( const std::string& hint, const std::string& value )
768 {
769   return 0;
770 }
771
772 bool WindowBaseEcoreX::RemoveAuxiliaryHint( unsigned int id )
773 {
774   return false;
775 }
776
777 bool WindowBaseEcoreX::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
778 {
779   return false;
780 }
781
782 std::string WindowBaseEcoreX::GetAuxiliaryHintValue( unsigned int id ) const
783 {
784   return std::string();
785 }
786
787 unsigned int WindowBaseEcoreX::GetAuxiliaryHintId( const std::string& hint ) const
788 {
789   return 0;
790 }
791
792 void WindowBaseEcoreX::SetInputRegion( const Rect< int >& inputRegion )
793 {
794 }
795
796 void WindowBaseEcoreX::SetType( Dali::Window::Type type )
797 {
798 }
799
800 bool WindowBaseEcoreX::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
801 {
802   return false;
803 }
804
805 Dali::Window::NotificationLevel::Type WindowBaseEcoreX::GetNotificationLevel() const
806 {
807   return Dali::Window::NotificationLevel::NONE;
808 }
809
810 void WindowBaseEcoreX::SetOpaqueState( bool opaque )
811 {
812 }
813
814 bool WindowBaseEcoreX::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
815 {
816   return false;
817 }
818
819 Dali::Window::ScreenOffMode::Type WindowBaseEcoreX::GetScreenOffMode() const
820 {
821   return Dali::Window::ScreenOffMode::TIMEOUT;
822 }
823
824 bool WindowBaseEcoreX::SetBrightness( int brightness )
825 {
826   return false;
827 }
828
829 int WindowBaseEcoreX::GetBrightness() const
830 {
831   return 0;
832 }
833
834 bool WindowBaseEcoreX::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
835 {
836   return false;
837 }
838
839 bool WindowBaseEcoreX::UngrabKey( Dali::KEY key )
840 {
841   return false;
842 }
843
844 bool WindowBaseEcoreX::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
845 {
846   return false;
847 }
848
849 bool WindowBaseEcoreX::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
850 {
851   return false;
852 }
853
854 void WindowBaseEcoreX::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
855 {
856   // calculate DPI
857   float xres, yres;
858
859   // 1 inch = 25.4 millimeters
860   xres = ecore_x_dpi_get();
861   yres = ecore_x_dpi_get();
862
863   dpiHorizontal = int( xres + 0.5f );  // rounding
864   dpiVertical   = int( yres + 0.5f );
865 }
866
867 void WindowBaseEcoreX::SetViewMode( ViewMode viewMode )
868 {
869   Ecore_X_Atom viewModeAtom( ecore_x_atom_get( "_E_COMP_3D_APP_WIN" ) );
870
871   if( viewModeAtom != None )
872   {
873     unsigned int value( static_cast< unsigned int >( viewMode ) );
874     ecore_x_window_prop_card32_set( mEcoreWindow, viewModeAtom, &value, 1 );
875   }
876 }
877
878 int WindowBaseEcoreX::GetScreenRotationAngle()
879 {
880   return 0;
881 }
882
883 void WindowBaseEcoreX::SetWindowRotationAngle( int degree )
884 {
885 }
886
887 void WindowBaseEcoreX::WindowRotationCompleted( int degree, int width, int height )
888 {
889 }
890
891 void WindowBaseEcoreX::SetTransparency( bool transparent )
892 {
893 }
894
895 unsigned int WindowBaseEcoreX::GetSurfaceId( Any surface ) const
896 {
897   unsigned int surfaceId = 0;
898
899   if ( surface.Empty() == false )
900   {
901     // check we have a valid type
902     DALI_ASSERT_ALWAYS( ( (surface.GetType() == typeid (XWindow) ) || (surface.GetType() == typeid (Ecore_X_Window) ) )
903                         && "Surface type is invalid" );
904
905     if ( surface.GetType() == typeid (Ecore_X_Window) )
906     {
907       surfaceId = AnyCast< Ecore_X_Window >( surface );
908     }
909     else
910     {
911       surfaceId = AnyCast< XWindow >( surface );
912     }
913   }
914   return surfaceId;
915 }
916
917 void WindowBaseEcoreX::CreateWindow( PositionSize positionSize, bool isTransparent )
918 {
919  if( isTransparent )
920  {
921    // create 32 bit window
922    mEcoreWindow = ecore_x_window_argb_new( 0, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
923  }
924  else
925  {
926    // create 24 bit window
927    mEcoreWindow = ecore_x_window_new( 0, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
928  }
929
930  if ( mEcoreWindow == 0 )
931  {
932    DALI_ASSERT_ALWAYS( 0 && "Failed to create X window" );
933  }
934 }
935
936 } // namespace Adaptor
937
938 } // namespace Internal
939
940 } // namespace Dali
941
942 #pragma GCC diagnostic pop