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;
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