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