• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_OS_AAFWK_WINDOW_FOCUS_CONTROLLER_H
17 #define OHOS_OS_AAFWK_WINDOW_FOCUS_CONTROLLER_H
18 
19 #include <shared_mutex>
20 
21 #include "element_name.h"
22 #include "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 using OHOS::Rosen::FocusChangeInfo;
27 using OHOS::Rosen::IFocusChangedListener;
28 using OHOS::Rosen::WindowManager;
29 
30 class WindowFocusController {
31 public:
32     WindowFocusController() = default;
33     virtual ~WindowFocusController() = default;
34     static std::shared_ptr<WindowFocusController> GetInstance();
35 
36     void SubscribeWindowFocus();
37     void UnsubscribeWindowFocus();
38     void GetTopAbility(AppExecFwk::ElementName &elementName);
39 
40     class FocusChangedListener : public Rosen::IFocusChangedListener {
41     public:
42         void OnFocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override;
43         void OnUnfocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override;
44     };
45 
46 private:
47     static std::mutex mutex_;
48     static std::shared_ptr<WindowFocusController> instance_;
49     sptr<FocusChangeInfo> focusChangeInfo_ = nullptr;
50     sptr<IFocusChangedListener> focusChangedListener_;
51 };
52 } // namespace AAFwk
53 } // namespace OHOS
54 #endif // OHOS_OS_AAFWK_WINDOW_FOCUS_CONTROLLER_H
55