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 | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 20 | #include <set> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 21 | #include "TouchedWindow.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 25 | namespace gui { |
| 26 | class WindowInfoHandle; |
| 27 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 28 | |
| 29 | namespace inputdispatcher { |
| 30 | |
| 31 | struct TouchState { |
Prabir Pradhan | e680f9b | 2022-02-04 04:24:00 -0800 | [diff] [blame] | 32 | // id of the device that is currently down, others are rejected |
| 33 | int32_t deviceId = -1; |
| 34 | // source of the device that is current down, others are rejected |
| 35 | uint32_t source = 0; |
Prabir Pradhan | e680f9b | 2022-02-04 04:24:00 -0800 | [diff] [blame] | 36 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | std::vector<TouchedWindow> windows; |
| 38 | |
Prabir Pradhan | e680f9b | 2022-02-04 04:24:00 -0800 | [diff] [blame] | 39 | TouchState() = default; |
| 40 | ~TouchState() = default; |
| 41 | TouchState& operator=(const TouchState&) = default; |
| 42 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 43 | void reset(); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 44 | void clearWindowsWithoutPointers(); |
| 45 | |
| 46 | void removeTouchedPointer(int32_t pointerId); |
Siarhei Vishniakou | 0026b4c | 2022-11-10 19:33:29 -0800 | [diff] [blame] | 47 | void removeTouchedPointerFromWindow(int32_t pointerId, |
| 48 | const sp<android::gui::WindowInfoHandle>& windowHandle); |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 49 | void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, |
Siarhei Vishniakou | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame^] | 50 | ftl::Flags<InputTarget::Flags> targetFlags, |
| 51 | std::bitset<MAX_POINTER_ID + 1> pointerIds, |
Siarhei Vishniakou | e0431e4 | 2023-01-28 17:01:39 -0800 | [diff] [blame] | 52 | std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt); |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 53 | void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, |
| 54 | int32_t deviceId, int32_t hoveringPointerId); |
| 55 | void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId); |
| 56 | void clearHoveringPointers(); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 57 | void removeWindowByToken(const sp<IBinder>& token); |
| 58 | void filterNonAsIsTouchWindows(); |
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 | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame^] | 61 | void cancelPointersForWindowsExcept(std::bitset<MAX_POINTER_ID + 1> pointerIds, |
| 62 | const sp<IBinder>& token); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 63 | // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow |
| 64 | // set to false. |
Siarhei Vishniakou | 060f82b | 2023-01-27 06:39:14 -0800 | [diff] [blame] | 65 | void cancelPointersForNonPilferingWindows(); |
Vaibhav Devmurari | ff798f3 | 2022-05-09 23:45:04 +0000 | [diff] [blame] | 66 | |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 67 | sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 68 | bool isSlippery() const; |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 69 | sp<android::gui::WindowInfoHandle> getWallpaperWindow() const; |
Siarhei Vishniakou | 0026b4c | 2022-11-10 19:33:29 -0800 | [diff] [blame] | 70 | const TouchedWindow& getTouchedWindow( |
| 71 | const sp<android::gui::WindowInfoHandle>& windowHandle) const; |
Siarhei Vishniakou | 3ad385b | 2022-11-04 10:09:53 -0700 | [diff] [blame] | 72 | // Whether any of the windows are currently being touched |
| 73 | bool isDown() const; |
Siarhei Vishniakou | b581f7f | 2022-12-07 20:23:06 +0000 | [diff] [blame] | 74 | |
| 75 | std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer( |
| 76 | int32_t deviceId, int32_t pointerId) const; |
Siarhei Vishniakou | 6e1e987 | 2022-11-08 17:51:35 -0800 | [diff] [blame] | 77 | std::string dump() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace inputdispatcher |
| 81 | } // namespace android |