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