blob: 3f1ff30cb25b0a248d8b729b9477c7ae40299ead [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
2 * Copyright (C) 2014 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
Michael Wrightd02c5b62014-02-10 15:10:22 -080018
Garfield Tan888a6a42020-01-09 11:39:16 -080019#include <input/DisplayViewport.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080020#include <input/Input.h>
21#include <utils/BitSet.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080022
23namespace android {
24
Prabir Pradhan2719e822023-02-28 17:39:36 +000025struct FloatPoint {
26 float x;
27 float y;
28
29 inline FloatPoint(float x, float y) : x(x), y(y) {}
30
31 inline explicit FloatPoint(vec2 p) : x(p.x), y(p.y) {}
32
33 template <typename T, typename U>
34 operator std::tuple<T, U>() {
35 return {x, y};
36 }
37};
38
Michael Wrightd02c5b62014-02-10 15:10:22 -080039/**
40 * Interface for tracking a mouse / touch pad pointer and touch pad spots.
41 *
42 * The spots are sprites on screen that visually represent the positions of
43 * fingers
44 *
45 * The pointer controller is responsible for providing synchronization and for tracking
Prabir Pradhande69f8a2021-11-18 16:40:34 +000046 * display orientation changes if needed. It works in the display panel's coordinate space, which
47 * is the same coordinate space used by InputReader.
Michael Wrightd02c5b62014-02-10 15:10:22 -080048 */
Michael Wright17db18e2020-06-26 20:51:44 +010049class PointerControllerInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -080050protected:
51 PointerControllerInterface() { }
52 virtual ~PointerControllerInterface() { }
53
54public:
55 /* Gets the bounds of the region that the pointer can traverse.
56 * Returns true if the bounds are available. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000057 virtual std::optional<FloatRect> getBounds() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080058
59 /* Move the pointer. */
60 virtual void move(float deltaX, float deltaY) = 0;
61
62 /* Sets a mask that indicates which buttons are pressed. */
63 virtual void setButtonState(int32_t buttonState) = 0;
64
65 /* Gets a mask that indicates which buttons are pressed. */
66 virtual int32_t getButtonState() const = 0;
67
68 /* Sets the absolute location of the pointer. */
69 virtual void setPosition(float x, float y) = 0;
70
71 /* Gets the absolute location of the pointer. */
Prabir Pradhan2719e822023-02-28 17:39:36 +000072 virtual FloatPoint getPosition() const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080073
Michael Wrightca5bede2020-07-02 00:00:29 +010074 enum class Transition {
Michael Wrightd02c5b62014-02-10 15:10:22 -080075 // Fade/unfade immediately.
Michael Wrightca5bede2020-07-02 00:00:29 +010076 IMMEDIATE,
Michael Wrightd02c5b62014-02-10 15:10:22 -080077 // Fade/unfade gradually.
Michael Wrightca5bede2020-07-02 00:00:29 +010078 GRADUAL,
Michael Wrightd02c5b62014-02-10 15:10:22 -080079 };
80
81 /* Fades the pointer out now. */
82 virtual void fade(Transition transition) = 0;
83
84 /* Makes the pointer visible if it has faded out.
85 * The pointer never unfades itself automatically. This method must be called
86 * by the client whenever the pointer is moved or a button is pressed and it
87 * wants to ensure that the pointer becomes visible again. */
88 virtual void unfade(Transition transition) = 0;
89
Michael Wrightca5bede2020-07-02 00:00:29 +010090 enum class Presentation {
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 // Show the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +010092 POINTER,
Michael Wrightd02c5b62014-02-10 15:10:22 -080093 // Show spots and a spot anchor in place of the mouse pointer.
Michael Wrightca5bede2020-07-02 00:00:29 +010094 SPOT,
Seunghwan Choi75789cd2023-01-13 20:31:59 +090095 // Show the stylus hover pointer.
96 STYLUS_HOVER,
Michael Wright08f7a6a2022-10-22 03:14:39 +010097
Seunghwan Choi75789cd2023-01-13 20:31:59 +090098 ftl_last = STYLUS_HOVER,
Michael Wrightd02c5b62014-02-10 15:10:22 -080099 };
100
101 /* Sets the mode of the pointer controller. */
102 virtual void setPresentation(Presentation presentation) = 0;
103
104 /* Sets the spots for the current gesture.
105 * The spots are not subject to the inactivity timeout like the pointer
106 * itself it since they are expected to remain visible for so long as
107 * the fingers are on the touch pad.
108 *
109 * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant.
110 * For spotCoords, pressure != 0 indicates that the spot's location is being
111 * pressed (not hovering).
112 */
113 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
Arthur Hung7c645402019-01-25 17:45:42 +0800114 BitSet32 spotIdBits, int32_t displayId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115
116 /* Removes all spots. */
117 virtual void clearSpots() = 0;
Arthur Hungc7ad2d02018-12-18 17:41:29 +0800118
119 /* Gets the id of the display where the pointer should be shown. */
120 virtual int32_t getDisplayId() const = 0;
Garfield Tan888a6a42020-01-09 11:39:16 -0800121
122 /* Sets the associated display of this pointer. Pointer should show on that display. */
123 virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800124};
125
126} // namespace android