• 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 
52 private:
53     int32_t focusedSessionId_ = INVALID_SESSION_ID;
54     int32_t lastFocusedSessionId_ = INVALID_SESSION_ID;
55     int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID;
56     bool needBlockNotifyFocusStatusUntilForeground_ { false };
57     bool needBlockNotifyUnfocusStatus_ { false };
58     DisplayId displayGroupId_ = DISPLAY_ID_INVALID;
59 };
60 
61 class WindowFocusController : public RefBase {
62 public:
63     WindowFocusController() noexcept;
64     ~WindowFocusController() = default;
65 
66     DisplayId GetDisplayGroupId(DisplayId displayId);
67     WSError AddFocusGroup(DisplayId displayId);
68     WSError RemoveFocusGroup(DisplayId displayId);
69     int32_t GetFocusedSessionId(DisplayId displayId);
70     sptr<FocusGroup> GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID);
71     std::vector<std::pair<DisplayId, int32_t>> GetAllFocusedSessionList() const;
72     WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId);
73     WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId);
74 
75 private:
76     sptr<FocusGroup> GetFocusGroupInner(DisplayId displayId);
77 
78     std::unordered_map<DisplayId, sptr<FocusGroup>> focusGroupMap_;
79     std::unordered_set<DisplayId> virtualScreenDisplayIdSet_;
80 };
81 }
82 }
83 #endif // OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H
84