blob: 451d91704cb6153effb29159ade565e079da4e0b [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 Vishniakou8a878352023-01-30 14:05:01 -080019#include <bitset>
Siarhei Vishniakou72945a02023-09-18 18:30:25 -070020#include <ostream>
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000021#include <set>
Garfield Tane84e6f92019-08-29 17:28:41 -070022#include "TouchedWindow.h"
23
24namespace android {
25
chaviw98318de2021-05-19 16:45:23 -050026namespace gui {
27class WindowInfoHandle;
28}
Garfield Tane84e6f92019-08-29 17:28:41 -070029
30namespace inputdispatcher {
31
32struct TouchState {
Garfield Tane84e6f92019-08-29 17:28:41 -070033 std::vector<TouchedWindow> windows;
34
Prabir Pradhane680f9b2022-02-04 04:24:00 -080035 TouchState() = default;
36 ~TouchState() = default;
37 TouchState& operator=(const TouchState&) = default;
38
Garfield Tane84e6f92019-08-29 17:28:41 -070039 void reset();
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000040 void clearWindowsWithoutPointers();
41
Siarhei Vishniakou5b9766d2023-07-18 14:06:29 -070042 bool hasTouchingPointers(DeviceId deviceId) const;
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070043 void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
44 void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070045 const sp<android::gui::WindowInfoHandle>& windowHandle);
Siarhei Vishniakoue535f972024-03-29 14:55:21 -070046 android::base::Result<void> addOrUpdateWindow(
47 const sp<android::gui::WindowInfoHandle>& windowHandle,
48 InputTarget::DispatchMode dispatchMode, ftl::Flags<InputTarget::Flags> targetFlags,
49 DeviceId deviceId, const std::vector<PointerProperties>& touchingPointers,
Siarhei Vishniakoufe346982024-08-07 00:17:19 +000050 std::optional<nsecs_t> firstDownTimeInTarget);
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000051 void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
Siarhei Vishniakoub711e652024-08-12 12:00:28 -070052 DeviceId deviceId, const PointerProperties& pointer, float x,
53 float y);
Siarhei Vishniakou1ff00cc2023-12-13 16:12:13 -080054 void removeHoveringPointer(DeviceId deviceId, int32_t pointerId);
Siarhei Vishniakou2899c552023-07-10 18:20:46 -070055 void clearHoveringPointers(DeviceId deviceId);
Siarhei Vishniakou0686f0c2023-05-02 11:56:15 -070056
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070057 void removeAllPointersForDevice(DeviceId deviceId);
Garfield Tane84e6f92019-08-29 17:28:41 -070058 void removeWindowByToken(const sp<IBinder>& token);
Vaibhav Devmurariff798f32022-05-09 23:45:04 +000059
60 // Cancel pointers for current set of windows except the window with particular binder token.
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070061 void cancelPointersForWindowsExcept(DeviceId deviceId,
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070062 std::bitset<MAX_POINTER_ID + 1> pointerIds,
Siarhei Vishniakou8a878352023-01-30 14:05:01 -080063 const sp<IBinder>& token);
Vaibhav Devmurariff798f32022-05-09 23:45:04 +000064 // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow
65 // set to false.
Siarhei Vishniakou060f82b2023-01-27 06:39:14 -080066 void cancelPointersForNonPilferingWindows();
Vaibhav Devmurariff798f32022-05-09 23:45:04 +000067
Linnan Liccf6ce32024-04-11 20:32:13 +080068 sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle(DeviceId deviceId) const;
Linnan Li49b2b202024-04-12 12:46:40 +080069 bool isSlippery(DeviceId deviceId) const;
Linnan Li72352222024-04-12 18:55:57 +080070 sp<android::gui::WindowInfoHandle> getWallpaperWindow(DeviceId deviceId) const;
Siarhei Vishniakou0026b4c2022-11-10 19:33:29 -080071 const TouchedWindow& getTouchedWindow(
72 const sp<android::gui::WindowInfoHandle>& windowHandle) const;
Siarhei Vishniakou3ad385b2022-11-04 10:09:53 -070073 // Whether any of the windows are currently being touched
Siarhei Vishniakou2899c552023-07-10 18:20:46 -070074 bool isDown(DeviceId deviceId) const;
75 bool hasHoveringPointers(DeviceId deviceId) const;
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000076
Siarhei Vishniakouf77f60a2023-10-23 17:26:05 -070077 bool hasActiveStylus() const;
78
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000079 std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070080 DeviceId deviceId, int32_t pointerId) const;
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080081 std::string dump() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070082};
83
Siarhei Vishniakou72945a02023-09-18 18:30:25 -070084std::ostream& operator<<(std::ostream& out, const TouchState& state);
85
Garfield Tane84e6f92019-08-29 17:28:41 -070086} // namespace inputdispatcher
87} // namespace android