Add SetParent in Window
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.cpp
index f54c22b..737f1a9 100644 (file)
@@ -698,6 +698,9 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surf
 : mEcoreEventHandler(),
   mEcoreWindow(nullptr),
   mWlSurface(nullptr),
+  mWlInputPanel(nullptr),
+  mWlOutput(nullptr),
+  mWlInputPanelSurface(nullptr),
   mEglWindow(nullptr),
   mDisplay(nullptr),
   mEventQueue(nullptr),
@@ -705,24 +708,25 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surf
   mTizenDisplayPolicy(nullptr),
   mKeyMap(nullptr),
   mSupportedAuxiliaryHints(),
+  mWindowPositionSize(positionSize),
   mAuxiliaryHints(),
+  mType(WindowType::NORMAL),
   mNotificationLevel(-1),
-  mNotificationChangeState(0),
-  mNotificationLevelChangeDone(true),
   mScreenOffMode(0),
-  mScreenOffModeChangeState(0),
-  mScreenOffModeChangeDone(true),
   mBrightness(0),
+  mWindowRotationAngle(0),
+  mScreenRotationAngle(0),
+  mSupportedPreProtation(0),
+  mNotificationChangeState(0),
+  mScreenOffModeChangeState(0),
   mBrightnessChangeState(0),
-  mBrightnessChangeDone(true),
+  mLastSubmittedMoveResizeSerial(0),
+  mMoveResizeSerial(0),
+  mNotificationLevelChangeDone(true),
+  mScreenOffModeChangeDone(true),
   mVisible(true),
-  mWindowPositionSize(positionSize),
   mOwnSurface(false),
-  mMoveResizeSerial(0),
-  mLastSubmittedMoveResizeSerial(0),
-  mWindowRotationAngle(0),
-  mScreenRotationAngle(0),
-  mSupportedPreProtation(0)
+  mBrightnessChangeDone(true)
 #ifdef DALI_ELDBUS_AVAILABLE
   ,
   mSystemConnection(NULL)
@@ -980,7 +984,23 @@ void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event)
     RotationEvent rotationEvent;
     rotationEvent.angle     = ev->angle;
     rotationEvent.winResize = 0;
-    mWindowRotationAngle    = ev->angle;
+
+    if(ev->w == 0 || ev->h == 0)
+    {
+      // Use previous client side window's size.
+      if(mWindowRotationAngle == 90 || mWindowRotationAngle == 270)
+      {
+        ev->w = mWindowPositionSize.height;
+        ev->h = mWindowPositionSize.width;
+      }
+      else
+      {
+        ev->w = mWindowPositionSize.width;
+        ev->h = mWindowPositionSize.height;
+      }
+    }
+
+    mWindowRotationAngle = ev->angle;
 
     if(ev->angle == 0 || ev->angle == 180)
     {
@@ -1016,8 +1036,8 @@ void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
     // When window is just moved or window is resized by client application,
     // The configure notification event's size will be 0.
     // If new size is 0, the resized work should be skip.
-    int newWidth = mWindowPositionSize.width;
-    int newHeight = mWindowPositionSize.height;
+    int  newWidth    = mWindowPositionSize.width;
+    int  newHeight   = mWindowPositionSize.height;
     bool windowMoved = false, windowResized = false;
 
     if(ev->x != mWindowPositionSize.x || ev->y != mWindowPositionSize.y)
@@ -1028,8 +1048,8 @@ void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
     if(tempWidth != 0 && tempHeight != 0 && (tempWidth != mWindowPositionSize.width || tempHeight != mWindowPositionSize.height))
     {
       windowResized = true;
-      newWidth = tempWidth;
-      newHeight = tempHeight;
+      newWidth      = tempWidth;
+      newHeight     = tempHeight;
     }
 
     if(windowMoved || windowResized)
@@ -1845,41 +1865,54 @@ void WindowBaseEcoreWl2::SetInputRegion(const Rect<int>& inputRegion)
 
 void WindowBaseEcoreWl2::SetType(Dali::WindowType type)
 {
-  Ecore_Wl2_Window_Type windowType;
-
-  switch(type)
+  if(mType != type)
   {
-    case Dali::WindowType::NORMAL:
-    {
-      windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
-      break;
-    }
-    case Dali::WindowType::NOTIFICATION:
-    {
-      windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
-      break;
-    }
-    case Dali::WindowType::UTILITY:
-    {
-      windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
-      break;
-    }
-    case Dali::WindowType::DIALOG:
-    {
-      windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
-      break;
-    }
-    default:
+    mType = type;
+    Ecore_Wl2_Window_Type windowType;
+
+    switch(type)
     {
-      windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
-      break;
+      case Dali::WindowType::NORMAL:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
+        break;
+      }
+      case Dali::WindowType::NOTIFICATION:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
+        break;
+      }
+      case Dali::WindowType::UTILITY:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
+        break;
+      }
+      case Dali::WindowType::DIALOG:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
+        break;
+      }
+      case Dali::WindowType::IME:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_NONE;
+        break;
+      }
+      default:
+      {
+        windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
+        break;
+      }
     }
+    ecore_wl2_window_type_set(mEcoreWindow, windowType);
   }
+}
 
-  ecore_wl2_window_type_set(mEcoreWindow, windowType);
+Dali::WindowType WindowBaseEcoreWl2::GetType() const
+{
+  return mType;
 }
 
-bool WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel level)
+Dali::WindowOperationResult WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel level)
 {
   while(!mTizenPolicy)
   {
@@ -1940,17 +1973,17 @@ bool WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel leve
   if(!mNotificationLevelChangeDone)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
-    return false;
+    return Dali::WindowOperationResult::UNKNOWN_ERROR;
   }
   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Permission denied! [%d]\n", level);
-    return false;
+    return Dali::WindowOperationResult::PERMISSION_DENIED;
   }
 
   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
 
-  return true;
+  return Dali::WindowOperationResult::SUCCEED;
 }
 
 Dali::WindowNotificationLevel WindowBaseEcoreWl2::GetNotificationLevel() const
@@ -2027,7 +2060,7 @@ void WindowBaseEcoreWl2::SetOpaqueState(bool opaque)
   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
 }
 
-bool WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
+Dali::WindowOperationResult WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
 {
   while(!mTizenPolicy)
   {
@@ -2067,17 +2100,17 @@ bool WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
   if(!mScreenOffModeChangeDone)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
-    return false;
+    return Dali::WindowOperationResult::UNKNOWN_ERROR;
   }
   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
-    return false;
+    return Dali::WindowOperationResult::PERMISSION_DENIED;
   }
 
   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
 
-  return true;
+  return Dali::WindowOperationResult::SUCCEED;
 }
 
 WindowScreenOffMode WindowBaseEcoreWl2::GetScreenOffMode() const
@@ -2123,7 +2156,7 @@ WindowScreenOffMode WindowBaseEcoreWl2::GetScreenOffMode() const
   return screenMode;
 }
 
-bool WindowBaseEcoreWl2::SetBrightness(int brightness)
+Dali::WindowOperationResult WindowBaseEcoreWl2::SetBrightness(int brightness)
 {
   while(!mTizenDisplayPolicy)
   {
@@ -2147,17 +2180,17 @@ bool WindowBaseEcoreWl2::SetBrightness(int brightness)
   if(!mBrightnessChangeDone)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
-    return false;
+    return Dali::WindowOperationResult::UNKNOWN_ERROR;
   }
   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
   {
     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Permission denied! [%d]\n", brightness);
-    return false;
+    return Dali::WindowOperationResult::PERMISSION_DENIED;
   }
 
   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness is changed [%d]\n", mBrightness);
 
-  return true;
+  return Dali::WindowOperationResult::SUCCEED;
 }
 
 int WindowBaseEcoreWl2::GetBrightness() const
@@ -2480,7 +2513,7 @@ void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize)
   ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
 }
 
-void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase)
+void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent)
 {
   Ecore_Wl2_Window* ecoreParent = NULL;
   if(parentWinBase)
@@ -2488,7 +2521,7 @@ void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase)
     WindowBaseEcoreWl2* winBaseEcore2 = static_cast<WindowBaseEcoreWl2*>(parentWinBase);
     ecoreParent                       = winBaseEcore2->mEcoreWindow;
   }
-  ecore_wl2_window_parent_set(mEcoreWindow, ecoreParent);
+  ecore_wl2_window_transient_parent_set(mEcoreWindow, ecoreParent, belowParent);
 }
 
 int WindowBaseEcoreWl2::CreateFrameRenderedSyncFence()
@@ -2501,6 +2534,216 @@ int WindowBaseEcoreWl2::CreateFramePresentedSyncFence()
   return wl_egl_window_tizen_create_presentation_sync_fd(mEglWindow);
 }
 
+void WindowBaseEcoreWl2::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
+{
+  DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPositionSizeWithAngle, angle: %d, x: %d, y: %d, w: %d, h: %d\n", angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
+  ecore_wl2_window_rotation_geometry_set(mEcoreWindow, angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
+}
+
+void WindowBaseEcoreWl2::InitializeIme()
+{
+  Eina_Iterator*      globals;
+  struct wl_registry* registry;
+  Ecore_Wl2_Global*   global;
+  Ecore_Wl2_Display*  ecoreWl2Display;
+
+  if(!(ecoreWl2Display = ecore_wl2_connected_display_get(NULL)))
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 connected display\n");
+    return;
+  }
+
+  DALI_LOG_RELEASE_INFO("InitializeIme:  Ecore_Wl2_Display: %p, ecore wl window: %p\n", ecoreWl2Display, mEcoreWindow);
+
+  if(!(registry = ecore_wl2_display_registry_get(ecoreWl2Display)))
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 display registry\n");
+    return;
+  }
+
+  if(!(globals = ecore_wl2_display_globals_get(ecoreWl2Display)))
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 globals\n");
+    return;
+  }
+
+  EINA_ITERATOR_FOREACH(globals, global)
+  {
+    if(strcmp(global->interface, "wl_input_panel") == 0)
+    {
+      mWlInputPanel = (wl_input_panel*)wl_registry_bind(registry, global->id, &wl_input_panel_interface, 1);
+    }
+    else if(strcmp(global->interface, "wl_output") == 0)
+    {
+      mWlOutput = (wl_output*)wl_registry_bind(registry, global->id, &wl_output_interface, 1);
+    }
+  }
+
+  if(!mWlInputPanel)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel interface\n");
+    return;
+  }
+
+  if(!mWlOutput)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland output panel interface\n");
+    return;
+  }
+
+  mWlInputPanelSurface = wl_input_panel_get_input_panel_surface(mWlInputPanel, mWlSurface);
+  if(!mWlInputPanelSurface)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel surface\n");
+    return;
+  }
+
+  wl_input_panel_surface_set_toplevel(mWlInputPanelSurface, mWlOutput, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM);
+}
+
+void WindowBaseEcoreWl2::ImeWindowReadyToRender()
+{
+  if(!mWlInputPanelSurface)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::ImeWindowReadyToRender(), wayland input panel surface is null\n");
+    return;
+  }
+
+  wl_input_panel_surface_set_ready(mWlInputPanelSurface, 1);
+}
+
+void WindowBaseEcoreWl2::RequestMoveToServer()
+{
+  Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
+  if(!display)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get ecore_wl2_display\n");
+    return;
+  }
+
+  Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+  if(!input)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get default Ecore_Wl2_Input\n");
+    return;
+  }
+
+  ecore_wl2_window_move(mEcoreWindow, input);
+  DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestMoveToServer, starts the window[%p] is moved by server\n", mEcoreWindow);
+}
+
+void WindowBaseEcoreWl2::RequestResizeToServer(WindowResizeDirection direction)
+{
+  Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
+  if(!display)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get ecore_wl2_display\n");
+    return;
+  }
+
+  Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
+  if(!input)
+  {
+    DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get default Ecore_Wl2_Input\n");
+    return;
+  }
+
+  int location = 0;
+  switch(direction)
+  {
+    case WindowResizeDirection::TOP_LEFT:
+    {
+      location = 5;
+      break;
+    }
+    case WindowResizeDirection::TOP:
+    {
+      location = 1;
+      break;
+    }
+    case WindowResizeDirection::TOP_RIGHT:
+    {
+      location = 9;
+      break;
+    }
+    case WindowResizeDirection::LEFT:
+    {
+      location = 4;
+      break;
+    }
+    case WindowResizeDirection::RIGHT:
+    {
+      location = 8;
+      break;
+    }
+    case WindowResizeDirection::BOTTOM_LEFT:
+    {
+      location = 6;
+      break;
+    }
+    case WindowResizeDirection::BOTTOM:
+    {
+      location = 2;
+      break;
+    }
+    case WindowResizeDirection::BOTTOM_RIGHT:
+    {
+      location = 10;
+      break;
+    }
+    default:
+    {
+      location = 0;
+      break;
+    }
+  }
+
+  ecore_wl2_window_resize(mEcoreWindow, input, location);
+  DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestResizeToServer, starts the window[%p] is resized by server, mode:%d\n", mEcoreWindow, location);
+}
+
+void WindowBaseEcoreWl2::EnableFloatingMode(bool enable)
+{
+  DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EnableFloatingMode, floating mode flag: [%p], enable [%d]\n", mEcoreWindow, enable);
+  if(enable == true)
+  {
+    ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_TRUE);
+  }
+  else
+  {
+    ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_FALSE);
+  }
+}
+
+bool WindowBaseEcoreWl2::IsFloatingModeEnabled() const
+{
+  return ecore_wl2_window_floating_mode_get(mEcoreWindow);
+}
+
+void WindowBaseEcoreWl2::IncludeInputRegion(const Rect<int>& inputRegion)
+{
+  Eina_Rectangle rect;
+  rect.x = inputRegion.x;
+  rect.y = inputRegion.y;
+  rect.w = inputRegion.width;
+  rect.h = inputRegion.height;
+
+  ecore_wl2_window_input_rect_add(mEcoreWindow, &rect);
+  ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
+}
+
+void WindowBaseEcoreWl2::ExcludeInputRegion(const Rect<int>& inputRegion)
+{
+  Eina_Rectangle rect;
+  rect.x = inputRegion.x;
+  rect.y = inputRegion.y;
+  rect.w = inputRegion.width;
+  rect.h = inputRegion.height;
+
+  ecore_wl2_window_input_rect_subtract(mEcoreWindow, &rect);
+  ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
+}
+
 } // namespace Adaptor
 
 } // namespace Internal