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