Revert "[Tizen] keygrab & ecore-wl-window-handle c# binding"
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / window-impl-ecore-wl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index c564d2e..d0dbdb7
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,9 @@
 #include <window-impl.h>
 
 // EXTERNAL HEADERS
+// Ecore is littered with C style cast
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
 #include <Ecore.h>
 #include <Ecore_Wayland.h>
 #include <tizen-extension-client-protocol.h>
@@ -67,6 +70,7 @@ struct Window::EventHandler
   : mWindow( window ),
     mWindowPropertyHandler( NULL ),
     mWindowIconifyStateHandler( NULL ),
+    mWindowVisibilityStateHandler( NULL ),
     mWindowFocusInHandler( NULL ),
     mWindowFocusOutHandler( NULL ),
     mEcoreWindow( 0 ),
@@ -79,7 +83,10 @@ struct Window::EventHandler
     mNotificationLevelChangeDone( true ),
     mScreenMode( 0 ),
     mScreenModeChangeState( 0 ),
-    mScreenModeChangeDone( true )
+    mScreenModeChangeDone( true ),
+    mBrightness( 0 ),
+    mBrightnessChangeState( 0 ),
+    mBrightnessChangeDone( true )
   {
     // store ecore window handle
     ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
@@ -92,25 +99,29 @@ struct Window::EventHandler
     if( mWindow->mEcoreEventHander )
     {
       mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
+      mWindowVisibilityStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreEventWindowVisibilityChanged, this );
       mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
       mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
     }
 
     mDisplay = ecore_wl_display_get();
 
-    wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
-    if( displayWrapper )
+    if( mDisplay )
     {
-      mEventQueue = wl_display_create_queue( mDisplay );
-      if( mEventQueue )
+      wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
+      if( displayWrapper )
       {
-        wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
+        mEventQueue = wl_display_create_queue( mDisplay );
+        if( mEventQueue )
+        {
+          wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
 
-        wl_registry* registry = wl_display_get_registry( displayWrapper );
-        wl_registry_add_listener( registry, &mRegistryListener, this );
-      }
+          wl_registry* registry = wl_display_get_registry( displayWrapper );
+          wl_registry_add_listener( registry, &mRegistryListener, this );
+        }
 
-      wl_proxy_wrapper_destroy( displayWrapper );
+        wl_proxy_wrapper_destroy( displayWrapper );
+      }
     }
   }
 
@@ -123,18 +134,27 @@ struct Window::EventHandler
     {
       ecore_event_handler_del( mWindowPropertyHandler );
     }
+
     if ( mWindowIconifyStateHandler )
     {
       ecore_event_handler_del( mWindowIconifyStateHandler );
     }
+
+    if ( mWindowVisibilityStateHandler )
+    {
+      ecore_event_handler_del( mWindowVisibilityStateHandler );
+    }
+
     if( mWindowFocusInHandler )
     {
       ecore_event_handler_del( mWindowFocusInHandler );
     }
+
     if( mWindowFocusOutHandler )
     {
       ecore_event_handler_del( mWindowFocusOutHandler );
     }
+
     if( mEventQueue )
     {
       wl_event_queue_destroy( mEventQueue );
@@ -178,6 +198,35 @@ struct Window::EventHandler
     return handled;
   }
 
+  /// Called when the window visibility is changed.
+  static Eina_Bool EcoreEventWindowVisibilityChanged( void* data, int type, void* event )
+  {
+    Ecore_Wl_Event_Window_Visibility_Change* visibilityChangedEvent( static_cast< Ecore_Wl_Event_Window_Visibility_Change* >( event ) );
+    EventHandler* handler( static_cast< EventHandler* >( data ) );
+    Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
+
+    if ( handler && handler->mWindow )
+    {
+      WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
+      if ( observer && ( visibilityChangedEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
+      {
+        if( visibilityChangedEvent->fully_obscured == 1 )
+        {
+          observer->OnWindowHidden();
+          DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) full obscured\n", handler->mEcoreWindow );
+        }
+        else
+        {
+          observer->OnWindowShown();
+          DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
+        }
+        handled = ECORE_CALLBACK_DONE;
+      }
+    }
+
+    return handled;
+  }
+
   /// Called when the window gains focus
   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
   {
@@ -310,6 +359,7 @@ struct Window::EventHandler
   Window* mWindow;
   Ecore_Event_Handler* mWindowPropertyHandler;
   Ecore_Event_Handler* mWindowIconifyStateHandler;
+  Ecore_Event_Handler* mWindowVisibilityStateHandler;
   Ecore_Event_Handler* mWindowFocusInHandler;
   Ecore_Event_Handler* mWindowFocusOutHandler;
   Ecore_Wl_Window* mEcoreWindow;
@@ -1360,11 +1410,10 @@ int Window::GetBrightness()
   return mEventHandler->mBrightness;
 }
 
-void* Window::GetNativeWindowHandler()
-{
-  return mEventHandler->mEcoreWindow;
-}
-
 } // Adaptor
+
 } // Internal
+
 } // Dali
+
+#pragma GCC diagnostic pop