Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 18 | |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 19 | #include <gui/WindowInfo.h> |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 20 | #include <input/Input.h> |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 21 | #include <utils/BitSet.h> |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 22 | #include <bitset> |
Siarhei Vishniakou | 72945a0 | 2023-09-18 18:30:25 -0700 | [diff] [blame] | 23 | #include <ostream> |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 24 | #include <set> |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 25 | #include "InputTarget.h" |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 26 | |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 27 | namespace android { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 28 | |
| 29 | namespace inputdispatcher { |
| 30 | |
| 31 | // Focus tracking for touch. |
| 32 | struct TouchedWindow { |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 33 | sp<gui::WindowInfoHandle> windowHandle; |
Prabir Pradhan | 4b09c1f | 2023-11-17 03:16:25 +0000 | [diff] [blame] | 34 | InputTarget::DispatchMode dispatchMode = InputTarget::DispatchMode::AS_IS; |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 35 | ftl::Flags<InputTarget::Flags> targetFlags; |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 36 | |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 37 | // Hovering |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 38 | bool hasHoveringPointers() const; |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 39 | bool hasHoveringPointers(DeviceId deviceId) const; |
| 40 | bool hasHoveringPointer(DeviceId deviceId, int32_t pointerId) const; |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 41 | void addHoveringPointer(DeviceId deviceId, const PointerProperties& pointer); |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 42 | void removeHoveringPointer(DeviceId deviceId, int32_t pointerId); |
Siarhei Vishniakou | 0686f0c | 2023-05-02 11:56:15 -0700 | [diff] [blame] | 43 | |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 44 | // Touching |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 45 | bool hasTouchingPointer(DeviceId deviceId, int32_t pointerId) const; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 46 | bool hasTouchingPointers() const; |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 47 | bool hasTouchingPointers(DeviceId deviceId) const; |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 48 | std::vector<PointerProperties> getTouchingPointers(DeviceId deviceId) const; |
| 49 | void addTouchingPointers(DeviceId deviceId, const std::vector<PointerProperties>& pointers); |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 50 | void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); |
| 51 | void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers); |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame^] | 52 | bool hasActiveStylus() const; |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 53 | std::set<DeviceId> getTouchingDeviceIds() const; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 54 | |
| 55 | // Pilfering pointers |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 56 | bool hasPilferingPointers(DeviceId deviceId) const; |
| 57 | void addPilferingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointerIds); |
| 58 | void addPilferingPointer(DeviceId deviceId, int32_t pointerId); |
| 59 | std::bitset<MAX_POINTER_ID + 1> getPilferingPointers(DeviceId deviceId) const; |
| 60 | std::map<DeviceId, std::bitset<MAX_POINTER_ID + 1>> getPilferingPointers() const; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 61 | |
| 62 | // Down time |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 63 | std::optional<nsecs_t> getDownTimeInTarget(DeviceId deviceId) const; |
| 64 | void trySetDownTimeInTarget(DeviceId deviceId, nsecs_t downTime); |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 65 | |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 66 | void removeAllTouchingPointersForDevice(DeviceId deviceId); |
| 67 | void removeAllHoveringPointersForDevice(DeviceId deviceId); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 68 | void clearHoveringPointers(DeviceId deviceId); |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 69 | std::string dump() const; |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 70 | |
| 71 | private: |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 72 | struct DeviceState { |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 73 | std::vector<PointerProperties> touchingPointers; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 74 | // The pointer ids of the pointers that this window is currently pilfering, by device |
| 75 | std::bitset<MAX_POINTER_ID + 1> pilferingPointerIds; |
| 76 | // Time at which the first action down occurred on this window, for each device |
| 77 | // NOTE: This is not initialized in case of HOVER entry/exit and DISPATCH_AS_OUTSIDE |
| 78 | // scenario. |
| 79 | std::optional<nsecs_t> downTimeInTarget; |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 80 | std::vector<PointerProperties> hoveringPointers; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 81 | |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 82 | bool hasPointers() const { return !touchingPointers.empty() || !hoveringPointers.empty(); }; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame] | 85 | std::map<DeviceId, DeviceState> mDeviceStates; |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 86 | |
| 87 | static std::string deviceStateToString(const TouchedWindow::DeviceState& state); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Siarhei Vishniakou | 72945a0 | 2023-09-18 18:30:25 -0700 | [diff] [blame] | 90 | std::ostream& operator<<(std::ostream& out, const TouchedWindow& window); |
| 91 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 92 | } // namespace inputdispatcher |
| 93 | } // namespace android |