Add DeviceInfo event 39/294039/6
authorjoogab.yun <joogab.yun@samsung.com>
Mon, 12 Jun 2023 04:03:35 +0000 (13:03 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Mon, 19 Jun 2023 05:52:06 +0000 (14:52 +0900)
this event called when a device such as a mouse or keyboard is connected or disconnected

Change-Id: Ia8d70e87000514b691436732b148666d8a5c1b51

automated-tests/src/dali-adaptor/utc-Dali-Window.cpp
dali/devel-api/adaptor-framework/device-info-event.h [new file with mode: 0644]
dali/devel-api/adaptor-framework/window-devel.cpp
dali/devel-api/adaptor-framework/window-devel.h
dali/devel-api/file.list
dali/internal/window-system/common/window-base.cpp
dali/internal/window-system/common/window-base.h
dali/internal/window-system/common/window-impl.cpp
dali/internal/window-system/common/window-impl.h
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h

index f224d97..bc625e9 100644 (file)
@@ -1637,3 +1637,18 @@ int UtcDaliWindowResizeCompletedSignalNegative(void)
   }
   END_TEST;
 }
+
+int UtcDaliWindowDeviceInfoSignalNegative(void)
+{
+  Dali::Window instance;
+  try
+  {
+    DevelWindow::DeviceInfoEventSignal(instance);
+    DALI_TEST_CHECK(false); // Should not get here
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true); // We expect an assert
+  }
+  END_TEST;
+}
diff --git a/dali/devel-api/adaptor-framework/device-info-event.h b/dali/devel-api/adaptor-framework/device-info-event.h
new file mode 100644 (file)
index 0000000..1d956d2
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef DALI_WINDOW_DEVEL_DEVICE_INFO_EVENT_H
+#define DALI_WINDOW_DEVEL_DEVICE_INFO_EVENT_H
+
+/*
+ * Copyright (c) 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/events/device.h>
+#include <dali/public-api/math/vector2.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/dali-adaptor-common.h>
+
+namespace Dali
+{
+namespace DevelWindow
+{
+/**
+ * @brief DeviceInfoEvent occurs when a device such as a mouse or keyboard is connected or disconnected.
+ *
+ * A signal is emitted whenever when a device such as a mouse or keyboard is connected or disconnected.
+ */
+struct DALI_ADAPTOR_API DeviceInfoEvent
+{
+  enum class Type
+  {
+    NONE = 0,
+    CONNECTED,
+    DISCONNECTED
+  };
+
+  /**
+   * @brief Constructor which creates a DeviceInfoEvent instance
+   * @param[in] type The type of the event.
+   * @param[in] name The device name.
+   * @param[in] identifier The identifier.
+   * @param[in] seatname The seat name.
+   * @param[in] deviceClass The device class the event originated from.
+   * @param[in] deviceSubclass The device subclass the event originated from.
+   */
+  DeviceInfoEvent(Type type, const std::string& name, const std::string& identifier, const std::string& seatname, const Device::Class::Type deviceClass, const Device::Subclass::Type deviceSubclass)
+  : type(type),
+    name(name),
+    identifier(identifier),
+    seatname(seatname),
+    deviceClass(deviceClass),
+    deviceSubclass(deviceSubclass)
+  {
+  }
+
+  Type                         type;
+  const std::string            name;
+  const std::string            identifier;
+  const std::string            seatname;
+  const Device::Class::Type    deviceClass;
+  const Device::Subclass::Type deviceSubclass;
+};
+
+} // namespace DevelWindow
+
+} // namespace Dali
+
+#endif // DALI_WINDOW_DEVEL_DEVICE_INFO_EVENT_H
index 897ea9f..691bc35 100644 (file)
@@ -294,6 +294,11 @@ MouseInOutEventSignalType& MouseInOutEventSignal(Window window)
   return GetImplementation(window).MouseInOutEventSignal();
 }
 
+DeviceInfoEventSignalType& DeviceInfoEventSignal(Window window)
+{
+  return GetImplementation(window).DeviceInfoEventSignal();
+}
+
 } // namespace DevelWindow
 
 } // namespace Dali
index 9cfaa8f..0096167 100644 (file)
@@ -22,6 +22,7 @@
 #include <memory>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/device-info-event.h>
 #include <dali/devel-api/adaptor-framework/mouse-in-out-event.h>
 #include <dali/public-api/adaptor-framework/window-enumerations.h>
 #include <dali/public-api/adaptor-framework/window.h>
@@ -52,6 +53,7 @@ typedef Signal<void(Window, Dali::WindowOrientation)>
 typedef Signal<void(Window, const Dali::DevelWindow::MouseInOutEvent&)>              MouseInOutEventSignalType;               ///< MouseInOutEvent signal type
 typedef Signal<void(Window, Dali::Window::WindowPosition)>                           MoveCompletedSignalType;                 ///< Window Moved by Server signal type
 typedef Signal<void(Window, Dali::Window::WindowSize)>                               ResizeCompletedSignalType;               ///< Window Resized by Server signal type
+typedef Signal<void(Window, const Dali::DevelWindow::DeviceInfoEvent&)>              DeviceInfoEventSignalType;               ///< DeviceInfoEvent signal type
 
 /**
  * @brief Creates an initialized handle to a new Window.
@@ -610,6 +612,19 @@ DALI_ADAPTOR_API MoveCompletedSignalType& MoveCompletedSignal(Window window);
  */
 DALI_ADAPTOR_API ResizeCompletedSignalType& ResizeCompletedSignal(Window window);
 
+/**
+ * @brief This signal is emitted when the device info event is received.
+ *
+ * A callback of the following type may be connected:
+ * @code
+ *   void YourCallbackName( Window window, Dali::DeviceInfoEvent event );
+ * @endcode
+ *
+ * @param[in] window The window instance.
+ * @return The signal to connect to
+ */
+DALI_ADAPTOR_API DeviceInfoEventSignalType& DeviceInfoEventSignal(Window window);
+
 } // namespace DevelWindow
 
 } // namespace Dali
index 1b9c636..4dbcc9c 100755 (executable)
@@ -68,6 +68,7 @@ SET( devel_api_adaptor_framework_header_files
   ${adaptor_devel_api_dir}/adaptor-framework/capture-devel.h
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.h
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard.h
+  ${adaptor_devel_api_dir}/adaptor-framework/device-info-event.h
   ${adaptor_devel_api_dir}/adaptor-framework/drag-and-drop.h
   ${adaptor_devel_api_dir}/adaptor-framework/color-controller-plugin.h
   ${adaptor_devel_api_dir}/adaptor-framework/color-controller.h
index a0a89dc..9aa3177 100644 (file)
@@ -44,7 +44,8 @@ WindowBase::WindowBase()
   mAuxiliaryMessageSignal(),
   mMouseInOutEventSignal(),
   mMoveCompletedSignal(),
-  mResizeCompletedSignal()
+  mResizeCompletedSignal(),
+  mDeviceInfoEventSignal()
 {
 }
 
@@ -157,6 +158,11 @@ WindowBase::ResizeCompletedSignalType& WindowBase::ResizeCompletedSignal()
   return mResizeCompletedSignal;
 }
 
+WindowBase::DeviceInfoEventSignalType& WindowBase::DeviceInfoEventSignal()
+{
+  return mDeviceInfoEventSignal;
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 699461a..48ed76e 100644 (file)
@@ -27,6 +27,7 @@
 #include <vector>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/device-info-event.h>
 #include <dali/devel-api/adaptor-framework/mouse-in-out-event.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/internal/graphics/gles/egl-implementation.h>
@@ -79,6 +80,7 @@ public:
   typedef Signal<void(const Dali::DevelWindow::MouseInOutEvent&)>                      MouseInOutEventSignalType;
   typedef Signal<void(Dali::Int32Pair&)>                                               MoveCompletedSignalType;
   typedef Signal<void(Dali::Uint16Pair&)>                                              ResizeCompletedSignalType;
+  typedef Signal<void(const Dali::DevelWindow::DeviceInfoEvent&)>                      DeviceInfoEventSignalType;
 
   // Input events
   typedef Signal<void(Integration::Point&, uint32_t)> TouchEventSignalType;
@@ -577,6 +579,11 @@ public:
    */
   ResizeCompletedSignalType& ResizeCompletedSignal();
 
+  /**
+   * @brief This signal is emitted when a device info event is recevied.
+   */
+  DeviceInfoEventSignalType& DeviceInfoEventSignal();
+
 protected:
   // Undefined
   WindowBase(const WindowBase&) = delete;
@@ -606,6 +613,7 @@ protected:
   MouseInOutEventSignalType               mMouseInOutEventSignal;
   MoveCompletedSignalType                 mMoveCompletedSignal;
   ResizeCompletedSignalType               mResizeCompletedSignal;
+  DeviceInfoEventSignalType               mDeviceInfoEventSignal;
 };
 
 } // namespace Adaptor
index dd75c39..aa82ad2 100644 (file)
@@ -94,6 +94,7 @@ Window::Window()
   mMouseInOutEventSignal(),
   mMoveCompletedSignal(),
   mResizeCompletedSignal(),
+  mDeviceInfoEventSignal(),
   mLastKeyEvent(),
   mLastTouchEvent(),
   mIsTransparent(false),
@@ -164,6 +165,7 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
   mWindowBase->MouseInOutEventSignal().Connect(this, &Window::OnMouseInOutEvent);
   mWindowBase->MoveCompletedSignal().Connect(this, &Window::OnMoveCompleted);
   mWindowBase->ResizeCompletedSignal().Connect(this, &Window::OnResizeCompleted);
+  mWindowBase->DeviceInfoEventSignal().Connect(this, &Window::OnDeviceInfoEvent);
 
   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
   mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
@@ -190,8 +192,8 @@ void Window::Initialize(Any surface, const PositionSize& positionSize, const std
   bool isSetWithScreenSize = false;
   if(mWindowWidth <= 0 || mWindowHeight <= 0)
   {
-    mWindowWidth         = screenWidth;
-    mWindowHeight        = screenHeight;
+    mWindowWidth        = screenWidth;
+    mWindowHeight       = screenHeight;
     isSetWithScreenSize = true;
     DALI_LOG_RELEASE_INFO("Window size is set with screen size(%d x %d)\n", mWindowWidth, mWindowHeight);
   }
@@ -1157,6 +1159,13 @@ void Window::OnMoveCompleted(Dali::Window::WindowPosition& position)
   mMoveCompletedSignal.Emit(handle, position);
 }
 
+void Window::OnDeviceInfoEvent(const Dali::DevelWindow::DeviceInfoEvent& deviceInfoEvent)
+{
+  Dali::Window handle(this);
+
+  mDeviceInfoEventSignal.Emit(handle, deviceInfoEvent);
+}
+
 void Window::OnResizeCompleted(Dali::Window::WindowSize& size)
 {
   Dali::Window handle(this);
index da9336d..6d3fc3b 100644 (file)
@@ -52,6 +52,7 @@ class Window;
 using WindowPtr          = IntrusivePtr<Window>;
 using OrientationPtr     = IntrusivePtr<Orientation>;
 using MouseInOutEventPtr = IntrusivePtr<Dali::DevelWindow::MouseInOutEvent>;
+using DeviceInfoEventPtr = IntrusivePtr<Dali::DevelWindow::DeviceInfoEvent>;
 using EventHandlerPtr    = IntrusivePtr<EventHandler>;
 
 /**
@@ -72,6 +73,7 @@ public:
   typedef Dali::DevelWindow::MouseInOutEventSignalType               MouseInOutEventSignalType;
   typedef Dali::DevelWindow::MoveCompletedSignalType                 MoveCompletedSignalType;
   typedef Dali::DevelWindow::ResizeCompletedSignalType               ResizeCompletedSignalType;
+  typedef Dali::DevelWindow::DeviceInfoEventSignalType               DeviceInfoEventSignalType;
   typedef Signal<void()>                                             SignalType;
 
   /**
@@ -625,6 +627,12 @@ private:
   void OnResizeCompleted(Dali::Window::WindowSize& size);
 
   /**
+   * @brief Called when a device such as a mouse or keyboard is connected or disconnected.
+   * @param[in] deviceInfoEvent the device info event
+   */
+  void OnDeviceInfoEvent(const Dali::DevelWindow::DeviceInfoEvent& deviceInfoEvent);
+
+  /**
    * @brief Set available orientation to window base.
    */
   void SetAvailableAnlges(const std::vector<int>& angles);
@@ -812,6 +820,14 @@ public: // Signals
     return mResizeCompletedSignal;
   }
 
+  /**
+   * @copydoc Dali::DevelWindow::DeviceInfoEventSignal()
+   */
+  DeviceInfoEventSignalType& DeviceInfoEventSignal()
+  {
+    return mDeviceInfoEventSignal;
+  }
+
 private:
   WindowRenderSurface* mWindowSurface; ///< The window rendering surface
   WindowBase*          mWindowBase;
@@ -823,10 +839,10 @@ private:
   std::vector<int> mAvailableAngles;
   int              mPreferredAngle;
 
-  int mRotationAngle;               ///< The angle of the rotation
-  int mWindowWidth;                 ///< The width of the window
-  int mWindowHeight;                ///< The height of the window
-  int mNativeWindowId;              ///< The Native Window Id
+  int mRotationAngle;  ///< The angle of the rotation
+  int mWindowWidth;    ///< The width of the window
+  int mWindowHeight;   ///< The height of the window
+  int mNativeWindowId; ///< The Native Window Id
 
   EventHandlerPtr mEventHandler;    ///< The window events handler
   OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
@@ -845,6 +861,7 @@ private:
   MouseInOutEventSignalType               mMouseInOutEventSignal;
   MoveCompletedSignalType                 mMoveCompletedSignal;
   ResizeCompletedSignalType               mResizeCompletedSignal;
+  DeviceInfoEventSignalType               mDeviceInfoEventSignal;
 
   Dali::KeyEvent   mLastKeyEvent;
   Dali::TouchEvent mLastTouchEvent;
@@ -856,7 +873,7 @@ private:
   bool mOpaqueState : 1;
   bool mWindowRotationAcknowledgement : 1;
   bool mFocused : 1;
-  bool mIsWindowRotating : 1;     ///< The window rotating flag.
+  bool mIsWindowRotating : 1;      ///< The window rotating flag.
   bool mIsEnabledUserGeometry : 1; ///< The user geometry enable flag.
 };
 
index 1e64164..6d5cd11 100644 (file)
@@ -739,6 +739,35 @@ static Eina_Bool EcoreEventWindowResizeCompleted(void* data, int type, void* eve
   return ECORE_CALLBACK_RENEW;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// Window Device Info Callbacks
+/////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Called when a device is added.
+ */
+static Eina_Bool EcoreEventDeviceAdd(void* data, int type, void* event)
+{
+  WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
+  if(windowBase)
+  {
+    windowBase->OnDeviceInfo(data, type, event, Dali::DevelWindow::DeviceInfoEvent::Type::CONNECTED);
+  }
+  return ECORE_CALLBACK_PASS_ON;
+}
+
+/**
+ * Called when a device is removed
+ */
+static Eina_Bool EcoreEventDeviceDel(void* data, int type, void* event)
+{
+  WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
+  if(windowBase)
+  {
+    windowBase->OnDeviceInfo(data, type, event, Dali::DevelWindow::DeviceInfoEvent::Type::DISCONNECTED);
+  }
+  return ECORE_CALLBACK_PASS_ON;
+}
+
 static void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
 {
   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
@@ -989,6 +1018,10 @@ void WindowBaseEcoreWl2::Initialize(PositionSize positionSize, Any surface, bool
   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_INTERACTIVE_MOVE_DONE, EcoreEventWindowMoveCompleted, this));
   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_INTERACTIVE_RESIZE_DONE, EcoreEventWindowResizeCompleted, this));
 
+  // Register Device Info
+  mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DEVICE_ADD, EcoreEventDeviceAdd, this));
+  mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DEVICE_DEL, EcoreEventDeviceDel, this));
+
   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
   mDisplay                   = ecore_wl2_display_get(display);
 
@@ -1604,6 +1637,32 @@ void WindowBaseEcoreWl2::OnResizeCompleted(void* event)
   }
 }
 
+void WindowBaseEcoreWl2::OnDeviceInfo(void* data, int type, void* event, Dali::DevelWindow::DeviceInfoEvent::Type action)
+{
+  Ecore_Event_Device_Info* deviceInfo = static_cast<Ecore_Event_Device_Info*>(event);
+
+  if(deviceInfo->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
+  {
+    DALI_TRACE_SCOPE(gTraceFilter, "DALI_ON_DEVICE_INFO");
+
+    DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnDeviceInfo: name: %s, identifier: %s, seatname: %s\n", deviceInfo->name, deviceInfo->identifier, deviceInfo->seatname);
+
+    std::string name(deviceInfo->name);
+    std::string identifier(deviceInfo->identifier);
+    std::string seatname(deviceInfo->seatname);
+
+    Device::Class::Type    deviceClass;
+    Device::Subclass::Type deviceSubclass;
+
+    GetDeviceClass(deviceInfo->clas, deviceClass);
+    GetDeviceSubclass(deviceInfo->subclas, deviceSubclass);
+
+    Dali::DevelWindow::DeviceInfoEvent deviceInfoEvent(action, name, identifier, seatname, deviceClass, deviceSubclass);
+
+    mDeviceInfoEventSignal.Emit(deviceInfoEvent);
+  }
+}
+
 void WindowBaseEcoreWl2::RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
 {
   if(strcmp(interface, tizen_policy_interface.name) == 0)
index b70afbc..e368c16 100644 (file)
@@ -201,6 +201,11 @@ public:
   void KeymapChanged(void* data, int type, void* event);
 
   /**
+   * @brief Called when a device info changed.
+   */
+  void OnDeviceInfo(void* data, int type, void* event, Dali::DevelWindow::DeviceInfoEvent::Type action);
+
+  /**
    * @brief RegistryGlobalCallback
    */
   void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);