xref: /aosp_15_r20/frameworks/native/services/inputflinger/dispatcher/TouchState.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <bitset>
20 #include <ostream>
21 #include <set>
22 #include "TouchedWindow.h"
23 
24 namespace android {
25 
26 namespace gui {
27 class WindowInfoHandle;
28 }
29 
30 namespace inputdispatcher {
31 
32 struct TouchState {
33     std::vector<TouchedWindow> windows;
34 
35     TouchState() = default;
36     ~TouchState() = default;
37     TouchState& operator=(const TouchState&) = default;
38 
39     void reset();
40     void clearWindowsWithoutPointers();
41 
42     bool hasTouchingPointers(DeviceId deviceId) const;
43     void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
44     void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
45                                          const sp<android::gui::WindowInfoHandle>& windowHandle);
46     android::base::Result<void> addOrUpdateWindow(
47             const sp<android::gui::WindowInfoHandle>& windowHandle,
48             InputTarget::DispatchMode dispatchMode, ftl::Flags<InputTarget::Flags> targetFlags,
49             DeviceId deviceId, const std::vector<PointerProperties>& touchingPointers,
50             std::optional<nsecs_t> firstDownTimeInTarget);
51     void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
52                                     DeviceId deviceId, const PointerProperties& pointer, float x,
53                                     float y);
54     void removeHoveringPointer(DeviceId deviceId, int32_t pointerId);
55     void clearHoveringPointers(DeviceId deviceId);
56 
57     void removeAllPointersForDevice(DeviceId deviceId);
58     void removeWindowByToken(const sp<IBinder>& token);
59 
60     // Cancel pointers for current set of windows except the window with particular binder token.
61     void cancelPointersForWindowsExcept(DeviceId deviceId,
62                                         std::bitset<MAX_POINTER_ID + 1> pointerIds,
63                                         const sp<IBinder>& token);
64     // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow
65     // set to false.
66     void cancelPointersForNonPilferingWindows();
67 
68     sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle(DeviceId deviceId) const;
69     bool isSlippery(DeviceId deviceId) const;
70     sp<android::gui::WindowInfoHandle> getWallpaperWindow(DeviceId deviceId) const;
71     const TouchedWindow& getTouchedWindow(
72             const sp<android::gui::WindowInfoHandle>& windowHandle) const;
73     // Whether any of the windows are currently being touched
74     bool isDown(DeviceId deviceId) const;
75     bool hasHoveringPointers(DeviceId deviceId) const;
76 
77     bool hasActiveStylus() const;
78 
79     std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
80             DeviceId deviceId, int32_t pointerId) const;
81     std::string dump() const;
82 };
83 
84 std::ostream& operator<<(std::ostream& out, const TouchState& state);
85 
86 } // namespace inputdispatcher
87 } // namespace android
88