blob: 25b96435282da3f557c7bc57fb45bd1448cbefe2 [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 Vishniakoub581f7f2022-12-07 20:23:06 +000020#include <set>
Garfield Tane84e6f92019-08-29 17:28:41 -070021#include "TouchedWindow.h"
22
23namespace android {
24
chaviw98318de2021-05-19 16:45:23 -050025namespace gui {
26class WindowInfoHandle;
27}
Garfield Tane84e6f92019-08-29 17:28:41 -070028
29namespace inputdispatcher {
30
31struct TouchState {
Garfield Tane84e6f92019-08-29 17:28:41 -070032 std::vector<TouchedWindow> windows;
33
Prabir Pradhane680f9b2022-02-04 04:24:00 -080034 TouchState() = default;
35 ~TouchState() = default;
36 TouchState& operator=(const TouchState&) = default;
37
Garfield Tane84e6f92019-08-29 17:28:41 -070038 void reset();
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000039 void clearWindowsWithoutPointers();
40
Siarhei Vishniakou45504fe2023-05-05 16:05:10 -070041 std::set<int32_t> getActiveDeviceIds() const;
42
43 bool hasTouchingPointers(int32_t device) const;
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070044 void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
45 void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070046 const sp<android::gui::WindowInfoHandle>& windowHandle);
chaviw98318de2021-05-19 16:45:23 -050047 void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070048 ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
Siarhei Vishniakou0836a302023-05-03 13:54:30 -070049 std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
Siarhei Vishniakoue0431e42023-01-28 17:01:39 -080050 std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000051 void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070052 DeviceId deviceId, int32_t hoveringPointerId);
53 void removeHoveringPointer(DeviceId deviceId, int32_t hoveringPointerId);
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000054 void clearHoveringPointers();
Siarhei Vishniakou0686f0c2023-05-02 11:56:15 -070055
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070056 void removeAllPointersForDevice(DeviceId deviceId);
Garfield Tane84e6f92019-08-29 17:28:41 -070057 void removeWindowByToken(const sp<IBinder>& token);
58 void filterNonAsIsTouchWindows();
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
chaviw98318de2021-05-19 16:45:23 -050068 sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070069 bool isSlippery() const;
Siarhei Vishniakouca205502021-07-16 21:31:58 +000070 sp<android::gui::WindowInfoHandle> getWallpaperWindow() 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
74 bool isDown() const;
Siarhei Vishniakouf372b812023-02-14 18:06:51 -080075 bool hasHoveringPointers() const;
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000076
77 std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
Siarhei Vishniakou7e2f8f12023-07-11 10:51:20 -070078 DeviceId deviceId, int32_t pointerId) const;
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080079 std::string dump() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070080};
81
82} // namespace inputdispatcher
83} // namespace android