Implement TopAppSurface 01/226701/1
authorDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 5 Mar 2020 04:04:40 +0000 (13:04 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 5 Mar 2020 04:05:06 +0000 (13:05 +0900)
Change-Id: I38617357da4f1897b6414411c6279a7ba561b8f4
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
ambient-viewer/src/top-app-surface.cc
ambient-viewer/src/top-app-surface.hh

index 76aecc94a96a1e193e7e573cf783b11b5885b57c..312d524cf5b2070713d0c90c861afadea40f1158 100644 (file)
@@ -30,7 +30,7 @@ namespace ambient_viewer {
 TopAppSurface::TopAppSurface(
     std::shared_ptr<screen_connector::EvasObject> surface, IAmbientViewer* listener)
     : screen_connector::RemoteSurfaceWatcher(
-          screen_connector::RemoteSurface::UI, surface), listener_(listener) {
+          screen_connector::RemoteSurface::UI, surface, true), listener_(listener) {
 }
 
 TopAppSurface::~TopAppSurface() = default;
@@ -98,25 +98,50 @@ float TopAppSurface::GetOpr() const {
 
 void TopAppSurface::OnWatcherAdded(const std::string& appId,
                             const std::string& instId, const int pid) {
-  app_id_ = appId;
-  inst_id_ = instId;
+  LOGD("WatcherAdded (%s:%s:%d)", appId.c_str(), instId.c_str(), pid);
+  if (app_id_ == "" && inst_id_ == "") {
+    app_id_ = appId;
+    inst_id_ = instId;
+    pid_ = pid;
+  }
 }
 
 void TopAppSurface::OnWatcherChanged(const std::string& appId,
                             const std::string& instId, const int pid,
                             const screen_connector::EvasObject& image) {
-  bool added = (image_ == nullptr);
-  image_ = image.GetRaw();
-  if (added)
-    listener_->OnAdded(*this);
-  else
-    listener_->OnUpdated(*this);
+  LOGD("WatcherChanged (%s:%s:%d)", appId.c_str(), instId.c_str(), pid);
+  if (app_id_ == appId && instId == inst_id_) {
+    bool not_added = image_ == nullptr;
+
+    image_ = image.GetRaw();
+    if (not_added)
+      listener_->OnAdded(*this);
+    else
+      listener_->OnUpdated(*this);
+  }
 }
 
 void TopAppSurface::OnWatcherRemoved(const std::string& appId,
                             const std::string& instId, const int pid) {
-  listener_->OnRemoved(*this);
-  image_ = nullptr;
+  LOGD("WatcherRemoved (%s:%s:%d)", appId.c_str(), instId.c_str(), pid);
+  if (app_id_ == appId && instId == inst_id_) {
+    app_id_ = "";
+    inst_id_ = "";
+    pid_ = 0;
+    listener_->OnRemoved(*this);
+    image_ = nullptr;
+  }
+}
+
+void TopAppSurface::OnWatcherFocusChanged(const std::string& appId,
+                            const std::string& instId, const int pid) {
+  LOGD("WatcherFocusChanged (%s:%s:%d)", appId.c_str(), instId.c_str(), pid);
+  if (app_id_ != appId || instId != inst_id_)
+    OnWatcherRemoved(app_id_, inst_id_, pid_);
+
+  app_id_ = appId;
+  inst_id_ = instId;
+  pid_ = pid;
 }
 
 }  // namespace ambient_viewer
index 0a539c2cef689d88b9676f17cd2b284b66b1ad8a..2c72ee3db81bdc2694909ec7b73031f5c3c43c10 100644 (file)
@@ -49,11 +49,14 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher,
                     const screen_connector::EvasObject& image) override;
   void OnWatcherRemoved(const std::string& appId, const std::string& instId,
                     const int pid) override;
+  void OnWatcherFocusChanged(const std::string& appId,
+                        const std::string& instId, const int pid) override;
 
  private:
   Evas_Object* image_ = nullptr;
   std::string app_id_;
   std::string inst_id_;
+  int pid_;
 
   IAmbientViewer* listener_;
 };