• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H
17 #define OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <shared_mutex>
23 
24 #include "dm_common.h"
25 #include "wm_common.h"
26 #include "ws_common.h"
27 #include "window_manager_hilog.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 class FocusGroup : public RefBase {
32 public:
FocusGroup(DisplayId displayGroupId)33     explicit FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {}
34 
GetFocusedSessionId()35     int32_t GetFocusedSessionId() const { return focusedSessionId_; }
GetLastFocusedSessionId()36     int32_t GetLastFocusedSessionId() const { return lastFocusedSessionId_; }
GetLastFocusedAppSessionId()37     int32_t GetLastFocusedAppSessionId() const { return lastFocusedAppSessionId_; }
GetNeedBlockNotifyFocusStatusUntilForeground()38     bool GetNeedBlockNotifyFocusStatusUntilForeground() const { return needBlockNotifyFocusStatusUntilForeground_; }
GetNeedBlockNotifyUnfocusStatus()39     bool GetNeedBlockNotifyUnfocusStatus() const { return needBlockNotifyUnfocusStatus_; }
GetDisplayGroupId()40     DisplayId GetDisplayGroupId() const { return displayGroupId_; }
SetFocusedSessionId(int32_t persistentId)41     void SetFocusedSessionId(int32_t persistentId) { focusedSessionId_ = persistentId; }
SetLastFocusedSessionId(int32_t persistentId)42     void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId_ = persistentId; }
SetLastFocusedAppSessionId(int32_t persistentId)43     void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId_ = persistentId; }
SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock)44     void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock)
45     {
46         needBlockNotifyFocusStatusUntilForeground_ = needBlock;
47     }
SetNeedBlockNotifyUnfocusStatus(bool needBlock)48     void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus_ = needBlock; }
49     WSError UpdateFocusedSessionId(int32_t persistentId);
50     WSError UpdateFocusedAppSessionId(int32_t persistentId);
51     std::unordered_set<DisplayId> displayIds_;
52 
53 private:
54     int32_t focusedSessionId_ = INVALID_SESSION_ID;
55     int32_t lastFocusedSessionId_ = INVALID_SESSION_ID;
56     int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID;
57     bool needBlockNotifyFocusStatusUntilForeground_ { false };
58     bool needBlockNotifyUnfocusStatus_ { false };
59     DisplayId displayGroupId_ = DISPLAY_ID_INVALID;
60 };
61 
62 class WindowFocusController : public RefBase {
63 public:
64     WindowFocusController() noexcept;
65     ~WindowFocusController() = default;
66 
67     DisplayId GetDisplayGroupId(DisplayId displayId);
68     WSError AddFocusGroup(DisplayGroupId displayGroupId, DisplayId displayId);
69     WSError RemoveFocusGroup(DisplayGroupId displayGroupId, DisplayId displayId);
70     int32_t GetFocusedSessionId(DisplayId displayId);
71     sptr<FocusGroup> GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID);
72     std::vector<std::pair<DisplayId, int32_t>> GetAllFocusedSessionList() const;
73     WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId);
74     WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId);
75     void LogDisplayIds();
76 
77 private:
78     sptr<FocusGroup> GetFocusGroupInner(DisplayId displayId);
79 
80     std::unordered_map<DisplayId, sptr<FocusGroup>> focusGroupMap_;
81     std::unordered_map<DisplayId, DisplayGroupId> displayId2GroupIdMap_;
82     std::unordered_map<DisplayId, DisplayGroupId> deletedDisplayId2GroupIdMap_;
83 };
84 }
85 }
86 #endif // OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H
87