blob: 0d1531f8ff674e906bdcda5e7299365874d9eb87 [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 Vishniakou6e1e9872022-11-08 17:51:35 -080019#include <gui/WindowInfo.h>
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000020#include <input/Input.h>
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080021#include <utils/BitSet.h>
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000022#include <bitset>
Siarhei Vishniakou72945a02023-09-18 18:30:25 -070023#include <ostream>
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070024#include <set>
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080025#include "InputTarget.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070026
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080027namespace android {
Garfield Tane84e6f92019-08-29 17:28:41 -070028
29namespace inputdispatcher {
30
31// Focus tracking for touch.
32struct TouchedWindow {
chaviw98318de2021-05-19 16:45:23 -050033 sp<gui::WindowInfoHandle> windowHandle;
Prabir Pradhan4b09c1f2023-11-17 03:16:25 +000034 InputTarget::DispatchMode dispatchMode = InputTarget::DispatchMode::AS_IS;
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080035 ftl::Flags<InputTarget::Flags> targetFlags;
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000036
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070037 // Hovering
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000038 bool hasHoveringPointers() const;
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070039 bool hasHoveringPointers(DeviceId deviceId) const;
40 bool hasHoveringPointer(DeviceId deviceId, int32_t pointerId) const;
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080041 void addHoveringPointer(DeviceId deviceId, const PointerProperties& pointer);
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070042 void removeHoveringPointer(DeviceId deviceId, int32_t pointerId);
Siarhei Vishniakou0686f0c2023-05-02 11:56:15 -070043
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070044 // Touching
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070045 bool hasTouchingPointer(DeviceId deviceId, int32_t pointerId) const;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070046 bool hasTouchingPointers() const;
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070047 bool hasTouchingPointers(DeviceId deviceId) const;
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080048 std::vector<PointerProperties> getTouchingPointers(DeviceId deviceId) const;
49 void addTouchingPointers(DeviceId deviceId, const std::vector<PointerProperties>& pointers);
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070050 void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
51 void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
Siarhei Vishniakouf77f60a2023-10-23 17:26:05 -070052 bool hasActiveStylus() const;
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070053 std::set<DeviceId> getTouchingDeviceIds() const;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070054
55 // Pilfering pointers
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070056 bool hasPilferingPointers(DeviceId deviceId) const;
57 void addPilferingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointerIds);
58 void addPilferingPointer(DeviceId deviceId, int32_t pointerId);
59 std::bitset<MAX_POINTER_ID + 1> getPilferingPointers(DeviceId deviceId) const;
60 std::map<DeviceId, std::bitset<MAX_POINTER_ID + 1>> getPilferingPointers() const;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070061
62 // Down time
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070063 std::optional<nsecs_t> getDownTimeInTarget(DeviceId deviceId) const;
64 void trySetDownTimeInTarget(DeviceId deviceId, nsecs_t downTime);
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070065
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070066 void removeAllTouchingPointersForDevice(DeviceId deviceId);
67 void removeAllHoveringPointersForDevice(DeviceId deviceId);
Siarhei Vishniakou2899c552023-07-10 18:20:46 -070068 void clearHoveringPointers(DeviceId deviceId);
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080069 std::string dump() const;
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000070
71private:
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070072 struct DeviceState {
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080073 std::vector<PointerProperties> touchingPointers;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070074 // The pointer ids of the pointers that this window is currently pilfering, by device
75 std::bitset<MAX_POINTER_ID + 1> pilferingPointerIds;
76 // Time at which the first action down occurred on this window, for each device
77 // NOTE: This is not initialized in case of HOVER entry/exit and DISPATCH_AS_OUTSIDE
78 // scenario.
79 std::optional<nsecs_t> downTimeInTarget;
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080080 std::vector<PointerProperties> hoveringPointers;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070081
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080082 bool hasPointers() const { return !touchingPointers.empty() || !hoveringPointers.empty(); };
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070083 };
84
Siarhei Vishniakoud38a1e02023-07-18 11:55:17 -070085 std::map<DeviceId, DeviceState> mDeviceStates;
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070086
87 static std::string deviceStateToString(const TouchedWindow::DeviceState& state);
Garfield Tane84e6f92019-08-29 17:28:41 -070088};
89
Siarhei Vishniakou72945a02023-09-18 18:30:25 -070090std::ostream& operator<<(std::ostream& out, const TouchedWindow& window);
91
Garfield Tane84e6f92019-08-29 17:28:41 -070092} // namespace inputdispatcher
93} // namespace android