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 | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 19 | #include <ftl/flags.h> |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 20 | #include <gui/WindowInfo.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 21 | #include <gui/constants.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 22 | #include <input/InputTransport.h> |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 23 | #include <ui/Transform.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 24 | #include <utils/BitSet.h> |
Siarhei Vishniakou | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame] | 25 | #include <bitset> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android::inputdispatcher { |
| 28 | |
| 29 | /* |
| 30 | * An input target specifies how an input event is to be dispatched to a particular window |
| 31 | * including the window's input channel, control flags, a timeout, and an X / Y offset to |
| 32 | * be added to input event coordinates to compensate for the absolute position of the |
| 33 | * window area. |
| 34 | */ |
| 35 | struct InputTarget { |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 36 | enum class Flags : uint32_t { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | /* This flag indicates that the event is being delivered to a foreground application. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 38 | FOREGROUND = 1 << 0, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 39 | |
| 40 | /* This flag indicates that the MotionEvent falls within the area of the target |
| 41 | * obscured by another visible window above it. The motion event should be |
| 42 | * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 43 | WINDOW_IS_OBSCURED = 1 << 1, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 44 | |
| 45 | /* This flag indicates that a motion event is being split across multiple windows. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 46 | SPLIT = 1 << 2, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 47 | |
| 48 | /* This flag indicates that the pointer coordinates dispatched to the application |
| 49 | * will be zeroed out to avoid revealing information to an application. This is |
| 50 | * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing |
| 51 | * the same UID from watching all touches. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 52 | ZERO_COORDS = 1 << 3, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 53 | |
| 54 | /* This flag indicates that the event should be sent as is. |
| 55 | * Should always be set unless the event is to be transmuted. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 56 | DISPATCH_AS_IS = 1 << 8, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 57 | |
| 58 | /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside |
| 59 | * of the area of this target and so should instead be delivered as an |
| 60 | * AMOTION_EVENT_ACTION_OUTSIDE to this target. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 61 | DISPATCH_AS_OUTSIDE = 1 << 9, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 62 | |
| 63 | /* This flag indicates that a hover sequence is starting in the given window. |
| 64 | * The event is transmuted into ACTION_HOVER_ENTER. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 65 | DISPATCH_AS_HOVER_ENTER = 1 << 10, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 66 | |
| 67 | /* This flag indicates that a hover event happened outside of a window which handled |
| 68 | * previous hover events, signifying the end of the current hover sequence for that |
| 69 | * window. |
| 70 | * The event is transmuted into ACTION_HOVER_ENTER. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 71 | DISPATCH_AS_HOVER_EXIT = 1 << 11, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 72 | |
| 73 | /* This flag indicates that the event should be canceled. |
| 74 | * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips |
| 75 | * outside of a window. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 76 | DISPATCH_AS_SLIPPERY_EXIT = 1 << 12, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 77 | |
| 78 | /* This flag indicates that the event should be dispatched as an initial down. |
| 79 | * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips |
| 80 | * into a new window. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 81 | DISPATCH_AS_SLIPPERY_ENTER = 1 << 13, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 82 | |
| 83 | /* This flag indicates that the target of a MotionEvent is partly or wholly |
| 84 | * obscured by another visible window above it. The motion event should be |
| 85 | * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */ |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 86 | WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 89 | /* Mask for all dispatch modes. */ |
| 90 | static constexpr const ftl::Flags<InputTarget::Flags> DISPATCH_MASK = |
| 91 | ftl::Flags<InputTarget::Flags>() | Flags::DISPATCH_AS_IS | Flags::DISPATCH_AS_OUTSIDE | |
| 92 | Flags::DISPATCH_AS_HOVER_ENTER | Flags::DISPATCH_AS_HOVER_EXIT | |
| 93 | Flags::DISPATCH_AS_SLIPPERY_EXIT | Flags::DISPATCH_AS_SLIPPERY_ENTER; |
| 94 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 95 | // The input channel to be targeted. |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 96 | std::shared_ptr<InputChannel> inputChannel; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 97 | |
| 98 | // Flags for the input target. |
Siarhei Vishniakou | 253f464 | 2022-11-09 13:42:06 -0800 | [diff] [blame] | 99 | ftl::Flags<Flags> flags; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 100 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 101 | // Scaling factor to apply to MotionEvent as it is delivered. |
| 102 | // (ignored for KeyEvents) |
Siarhei Vishniakou | 240f831 | 2019-11-27 17:09:07 -0800 | [diff] [blame] | 103 | float globalScaleFactor = 1.0f; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 104 | |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 105 | // Current display transform. Used for compatibility for raw coordinates. |
| 106 | ui::Transform displayTransform; |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 107 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 108 | // The subset of pointer ids to include in motion events dispatched to this input target |
| 109 | // if FLAG_SPLIT is set. |
Siarhei Vishniakou | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame] | 110 | std::bitset<MAX_POINTER_ID + 1> pointerIds; |
Vaibhav Devmurari | 882bd9b | 2022-06-23 14:54:54 +0000 | [diff] [blame] | 111 | // Event time for the first motion event (ACTION_DOWN) dispatched to this input target if |
| 112 | // FLAG_SPLIT is set. |
| 113 | std::optional<nsecs_t> firstDownTimeInTarget; |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 114 | // The data is stored by the pointerId. Use the bit position of pointerIds to look up |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 115 | // Transform per pointerId. |
| 116 | ui::Transform pointerTransforms[MAX_POINTERS]; |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 117 | |
Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 118 | // The window that this input target is being dispatched to. It is possible for this to be |
| 119 | // null for cases like global monitors. |
| 120 | sp<gui::WindowInfoHandle> windowHandle; |
| 121 | |
Siarhei Vishniakou | 8a87835 | 2023-01-30 14:05:01 -0800 | [diff] [blame] | 122 | void addPointers(std::bitset<MAX_POINTER_ID + 1> pointerIds, const ui::Transform& transform); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 123 | void setDefaultPointerTransform(const ui::Transform& transform); |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Returns whether the default pointer information should be used. This will be true when the |
| 127 | * InputTarget doesn't have any bits set in the pointerIds bitset. This can happen for monitors |
| 128 | * and non splittable windows since we want all pointers for the EventEntry to go to this |
| 129 | * target. |
| 130 | */ |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 131 | bool useDefaultPointerTransform() const; |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 134 | * Returns the default Transform object. This should be used when useDefaultPointerTransform is |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 135 | * true. |
| 136 | */ |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 137 | const ui::Transform& getDefaultPointerTransform() const; |
Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 138 | |
| 139 | std::string getPointerInfoString() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Siarhei Vishniakou | d38a1e0 | 2023-07-18 11:55:17 -0700 | [diff] [blame^] | 142 | std::ostream& operator<<(std::ostream& out, const InputTarget& target); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 143 | |
| 144 | } // namespace android::inputdispatcher |