blob: aef866baaf2a148b2d0fc11e4a13a826436f7512 [file] [log] [blame]
Garfield Tane84e6f92019-08-29 17:28:41 -07001/*
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 Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Garfield Tane84e6f92019-08-29 17:28:41 -070018
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080019#include <ftl/flags.h>
Prabir Pradhan8ede1d12023-05-08 19:37:44 +000020#include <gui/WindowInfo.h>
chaviw3277faf2021-05-19 16:45:23 -050021#include <gui/constants.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070022#include <input/InputTransport.h>
chaviw1ff3d1e2020-07-01 15:53:47 -070023#include <ui/Transform.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070024#include <utils/BitSet.h>
Siarhei Vishniakou8a878352023-01-30 14:05:01 -080025#include <bitset>
Garfield Tane84e6f92019-08-29 17:28:41 -070026
27namespace 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 */
35struct InputTarget {
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080036 enum class Flags : uint32_t {
Garfield Tane84e6f92019-08-29 17:28:41 -070037 /* This flag indicates that the event is being delivered to a foreground application. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080038 FOREGROUND = 1 << 0,
Garfield Tane84e6f92019-08-29 17:28:41 -070039
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 Vishniakou253f4642022-11-09 13:42:06 -080043 WINDOW_IS_OBSCURED = 1 << 1,
Garfield Tane84e6f92019-08-29 17:28:41 -070044
45 /* This flag indicates that a motion event is being split across multiple windows. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080046 SPLIT = 1 << 2,
Garfield Tane84e6f92019-08-29 17:28:41 -070047
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 Vishniakou253f4642022-11-09 13:42:06 -080052 ZERO_COORDS = 1 << 3,
Garfield Tane84e6f92019-08-29 17:28:41 -070053
Garfield Tane84e6f92019-08-29 17:28:41 -070054 /* This flag indicates that the target of a MotionEvent is partly or wholly
55 * obscured by another visible window above it. The motion event should be
56 * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080057 WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
Garfield Tane84e6f92019-08-29 17:28:41 -070058 };
59
Prabir Pradhan4b09c1f2023-11-17 03:16:25 +000060 enum class DispatchMode {
61 /* This flag indicates that the event should be sent as is.
62 * Should always be set unless the event is to be transmuted. */
63 AS_IS,
64 /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside
65 * of the area of this target and so should instead be delivered as an
66 * AMOTION_EVENT_ACTION_OUTSIDE to this target. */
67 OUTSIDE,
68 /* This flag indicates that a hover sequence is starting in the given window.
69 * The event is transmuted into ACTION_HOVER_ENTER. */
70 HOVER_ENTER,
71 /* This flag indicates that a hover event happened outside of a window which handled
72 * previous hover events, signifying the end of the current hover sequence for that
73 * window.
74 * The event is transmuted into ACTION_HOVER_ENTER. */
75 HOVER_EXIT,
76 /* This flag indicates that the event should be canceled.
77 * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
78 * outside of a window. */
79 SLIPPERY_EXIT,
80 /* This flag indicates that the event should be dispatched as an initial down.
81 * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
82 * into a new window. */
83 SLIPPERY_ENTER,
84
85 ftl_last = SLIPPERY_ENTER,
86 };
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080087
Garfield Tane84e6f92019-08-29 17:28:41 -070088 // The input channel to be targeted.
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050089 std::shared_ptr<InputChannel> inputChannel;
Garfield Tane84e6f92019-08-29 17:28:41 -070090
91 // Flags for the input target.
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080092 ftl::Flags<Flags> flags;
Garfield Tane84e6f92019-08-29 17:28:41 -070093
Prabir Pradhan4b09c1f2023-11-17 03:16:25 +000094 // The dispatch mode that should be used for this target.
95 DispatchMode dispatchMode = DispatchMode::AS_IS;
96
Garfield Tane84e6f92019-08-29 17:28:41 -070097 // Scaling factor to apply to MotionEvent as it is delivered.
98 // (ignored for KeyEvents)
Siarhei Vishniakou240f8312019-11-27 17:09:07 -080099 float globalScaleFactor = 1.0f;
Garfield Tane84e6f92019-08-29 17:28:41 -0700100
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700101 // Current display transform. Used for compatibility for raw coordinates.
102 ui::Transform displayTransform;
Evan Rosky84f07f02021-04-16 10:42:42 -0700103
Garfield Tane84e6f92019-08-29 17:28:41 -0700104 // The subset of pointer ids to include in motion events dispatched to this input target
105 // if FLAG_SPLIT is set.
Siarhei Vishniakou8a878352023-01-30 14:05:01 -0800106 std::bitset<MAX_POINTER_ID + 1> pointerIds;
Vaibhav Devmurari882bd9b2022-06-23 14:54:54 +0000107 // Event time for the first motion event (ACTION_DOWN) dispatched to this input target if
108 // FLAG_SPLIT is set.
109 std::optional<nsecs_t> firstDownTimeInTarget;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000110 // The data is stored by the pointerId. Use the bit position of pointerIds to look up
chaviw1ff3d1e2020-07-01 15:53:47 -0700111 // Transform per pointerId.
112 ui::Transform pointerTransforms[MAX_POINTERS];
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000113
Prabir Pradhan8ede1d12023-05-08 19:37:44 +0000114 // The window that this input target is being dispatched to. It is possible for this to be
115 // null for cases like global monitors.
116 sp<gui::WindowInfoHandle> windowHandle;
117
Siarhei Vishniakou8a878352023-01-30 14:05:01 -0800118 void addPointers(std::bitset<MAX_POINTER_ID + 1> pointerIds, const ui::Transform& transform);
chaviw1ff3d1e2020-07-01 15:53:47 -0700119 void setDefaultPointerTransform(const ui::Transform& transform);
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000120
121 /**
122 * Returns whether the default pointer information should be used. This will be true when the
123 * InputTarget doesn't have any bits set in the pointerIds bitset. This can happen for monitors
124 * and non splittable windows since we want all pointers for the EventEntry to go to this
125 * target.
126 */
chaviw1ff3d1e2020-07-01 15:53:47 -0700127 bool useDefaultPointerTransform() const;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000128
129 /**
chaviw1ff3d1e2020-07-01 15:53:47 -0700130 * Returns the default Transform object. This should be used when useDefaultPointerTransform is
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000131 * true.
132 */
chaviw1ff3d1e2020-07-01 15:53:47 -0700133 const ui::Transform& getDefaultPointerTransform() const;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000134
135 std::string getPointerInfoString() const;
Garfield Tane84e6f92019-08-29 17:28:41 -0700136};
137
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -0700138std::ostream& operator<<(std::ostream& out, const InputTarget& target);
Garfield Tane84e6f92019-08-29 17:28:41 -0700139
140} // namespace android::inputdispatcher