/* * Copyright (c) 2025 Huawei Device 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. */ #ifndef OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H #define OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H #include #include #include #include #include "dm_common.h" #include "wm_common.h" #include "ws_common.h" #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { class FocusGroup : public RefBase { public: explicit FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} int32_t GetFocusedSessionId() const { return focusedSessionId_; } int32_t GetLastFocusedSessionId() const { return lastFocusedSessionId_; } int32_t GetLastFocusedAppSessionId() const { return lastFocusedAppSessionId_; } bool GetNeedBlockNotifyFocusStatusUntilForeground() const { return needBlockNotifyFocusStatusUntilForeground_; } bool GetNeedBlockNotifyUnfocusStatus() const { return needBlockNotifyUnfocusStatus_; } DisplayId GetDisplayGroupId() const { return displayGroupId_; } void SetFocusedSessionId(int32_t persistentId) { focusedSessionId_ = persistentId; } void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId_ = persistentId; } void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId_ = persistentId; } void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) { needBlockNotifyFocusStatusUntilForeground_ = needBlock; } void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus_ = needBlock; } WSError UpdateFocusedSessionId(int32_t persistentId); WSError UpdateFocusedAppSessionId(int32_t persistentId); std::unordered_set displayIds_; private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; bool needBlockNotifyFocusStatusUntilForeground_ { false }; bool needBlockNotifyUnfocusStatus_ { false }; DisplayId displayGroupId_ = DISPLAY_ID_INVALID; }; class WindowFocusController : public RefBase { public: WindowFocusController() noexcept; ~WindowFocusController() = default; DisplayId GetDisplayGroupId(DisplayId displayId); WSError AddFocusGroup(DisplayGroupId displayGroupId, DisplayId displayId); WSError RemoveFocusGroup(DisplayGroupId displayGroupId, DisplayId displayId); int32_t GetFocusedSessionId(DisplayId displayId); sptr GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID); std::vector> GetAllFocusedSessionList() const; WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId); WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); void LogDisplayIds(); private: sptr GetFocusGroupInner(DisplayId displayId); std::unordered_map> focusGroupMap_; std::unordered_map displayId2GroupIdMap_; std::unordered_map deletedDisplayId2GroupIdMap_; }; } } #endif // OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H