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 | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame] | 19 | #include <bitset> |
Siarhei Vishniakou | 72945a0 | 2023-09-18 18:30:25 -0700 | [diff] [blame] | 20 | #include <ostream> |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 21 | #include <set> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 22 | #include "TouchedWindow.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 26 | namespace gui { |
| 27 | class WindowInfoHandle; |
| 28 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 29 | |
| 30 | namespace inputdispatcher { |
| 31 | |
| 32 | struct TouchState { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 33 | std::vector<TouchedWindow> windows; |
| 34 | |
Prabir Pradhan | e680f9b | 2022-02-04 04:24:00 -0800 | [diff] [blame] | 35 | TouchState() = default; |
| 36 | ~TouchState() = default; |
| 37 | TouchState& operator=(const TouchState&) = default; |
| 38 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 39 | void reset(); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 40 | void clearWindowsWithoutPointers(); |
| 41 | |
Siarhei Vishniakou | 5b9766d | 2023-07-18 14:06:29 -0700 | [diff] [blame] | 42 | bool hasTouchingPointers(DeviceId deviceId) const; |
Siarhei Vishniakou | 7e2f8f1 | 2023-07-11 10:51:20 -0700 | [diff] [blame] | 43 | void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); |
| 44 | void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId, |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 45 | const sp<android::gui::WindowInfoHandle>& windowHandle); |
Siarhei Vishniakou | e535f97 | 2024-03-29 14:55:21 -0700 | [diff] [blame] | 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 = std::nullopt); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 51 | void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, |
Siarhei Vishniakou | a8aaeb8 | 2024-08-12 12:00:28 -0700 | [diff] [blame] | 52 | DeviceId deviceId, const PointerProperties& pointer, float x, |
| 53 | float y); |
Siarhei Vishniakou | 1ff00cc | 2023-12-13 16:12:13 -0800 | [diff] [blame] | 54 | void removeHoveringPointer(DeviceId deviceId, int32_t pointerId); |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 55 | void clearHoveringPointers(DeviceId deviceId); |
Siarhei Vishniakou | 0686f0c | 2023-05-02 11:56:15 -0700 | [diff] [blame] | 56 | |
Siarhei Vishniakou | 7e2f8f1 | 2023-07-11 10:51:20 -0700 | [diff] [blame] | 57 | void removeAllPointersForDevice(DeviceId deviceId); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 58 | void removeWindowByToken(const sp<IBinder>& token); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 59 | |
| 60 | // Cancel pointers for current set of windows except the window with particular binder token. |
Siarhei Vishniakou | 7e2f8f1 | 2023-07-11 10:51:20 -0700 | [diff] [blame] | 61 | void cancelPointersForWindowsExcept(DeviceId deviceId, |
Siarhei Vishniakou | 0836a30 | 2023-05-03 13:54:30 -0700 | [diff] [blame] | 62 | std::bitset<MAX_POINTER_ID + 1> pointerIds, |
Siarhei Vishniakou | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame] | 63 | const sp<IBinder>& token); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 64 | // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow |
| 65 | // set to false. |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 66 | void cancelPointersForNonPilferingWindows(); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 67 | |
Linnan Li | ccf6ce3 | 2024-04-11 20:32:13 +0800 | [diff] [blame] | 68 | sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle(DeviceId deviceId) const; |
Linnan Li | 49b2b20 | 2024-04-12 12:46:40 +0800 | [diff] [blame] | 69 | bool isSlippery(DeviceId deviceId) const; |
Linnan Li | 7235222 | 2024-04-12 18:55:57 +0800 | [diff] [blame] | 70 | sp<android::gui::WindowInfoHandle> getWallpaperWindow(DeviceId deviceId) const; |
Siarhei Vishniakou | 0026b4c | 2022-11-10 19:33:29 -0800 | [diff] [blame] | 71 | const TouchedWindow& getTouchedWindow( |
| 72 | const sp<android::gui::WindowInfoHandle>& windowHandle) const; |
Siarhei Vishniakou | 3ad385b | 2022-11-04 10:09:53 -0700 | [diff] [blame] | 73 | // Whether any of the windows are currently being touched |
Siarhei Vishniakou | 2899c55 | 2023-07-10 18:20:46 -0700 | [diff] [blame] | 74 | bool isDown(DeviceId deviceId) const; |
| 75 | bool hasHoveringPointers(DeviceId deviceId) const; |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 76 | |
Siarhei Vishniakou | f77f60a | 2023-10-23 17:26:05 -0700 | [diff] [blame] | 77 | bool hasActiveStylus() const; |
| 78 | |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 79 | std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer( |
Siarhei Vishniakou | 7e2f8f1 | 2023-07-11 10:51:20 -0700 | [diff] [blame] | 80 | DeviceId deviceId, int32_t pointerId) const; |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 81 | std::string dump() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Siarhei Vishniakou | 72945a0 | 2023-09-18 18:30:25 -0700 | [diff] [blame] | 84 | std::ostream& operator<<(std::ostream& out, const TouchState& state); |
| 85 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 86 | } // namespace inputdispatcher |
| 87 | } // namespace android |