blob: 0092f1d8a08e39a50da1b5736144d0ad2cc4077e [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 Vishniakoub581f7f2022-12-07 20:23:06 +000019#include <set>
Garfield Tane84e6f92019-08-29 17:28:41 -070020#include "TouchedWindow.h"
21
22namespace android {
23
chaviw98318de2021-05-19 16:45:23 -050024namespace gui {
25class WindowInfoHandle;
26}
Garfield Tane84e6f92019-08-29 17:28:41 -070027
28namespace inputdispatcher {
29
30struct TouchState {
Prabir Pradhane680f9b2022-02-04 04:24:00 -080031 // id of the device that is currently down, others are rejected
32 int32_t deviceId = -1;
33 // source of the device that is current down, others are rejected
34 uint32_t source = 0;
Prabir Pradhane680f9b2022-02-04 04:24:00 -080035
Garfield Tane84e6f92019-08-29 17:28:41 -070036 std::vector<TouchedWindow> windows;
37
Prabir Pradhane680f9b2022-02-04 04:24:00 -080038 TouchState() = default;
39 ~TouchState() = default;
40 TouchState& operator=(const TouchState&) = default;
41
Garfield Tane84e6f92019-08-29 17:28:41 -070042 void reset();
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000043 void clearWindowsWithoutPointers();
44
45 void removeTouchedPointer(int32_t pointerId);
Siarhei Vishniakou0026b4c2022-11-10 19:33:29 -080046 void removeTouchedPointerFromWindow(int32_t pointerId,
47 const sp<android::gui::WindowInfoHandle>& windowHandle);
chaviw98318de2021-05-19 16:45:23 -050048 void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080049 ftl::Flags<InputTarget::Flags> targetFlags, BitSet32 pointerIds,
Vaibhav Devmurari882bd9b2022-06-23 14:54:54 +000050 std::optional<nsecs_t> eventTime = std::nullopt);
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000051 void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
52 int32_t deviceId, int32_t hoveringPointerId);
53 void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId);
54 void clearHoveringPointers();
Garfield Tane84e6f92019-08-29 17:28:41 -070055 void removeWindowByToken(const sp<IBinder>& token);
56 void filterNonAsIsTouchWindows();
Vaibhav Devmurariff798f32022-05-09 23:45:04 +000057
58 // Cancel pointers for current set of windows except the window with particular binder token.
59 void cancelPointersForWindowsExcept(const BitSet32 pointerIds, const sp<IBinder>& token);
60 // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow
61 // set to false.
Siarhei Vishniakou060f82b2023-01-27 06:39:14 -080062 void cancelPointersForNonPilferingWindows();
Vaibhav Devmurariff798f32022-05-09 23:45:04 +000063
chaviw98318de2021-05-19 16:45:23 -050064 sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070065 bool isSlippery() const;
Siarhei Vishniakouca205502021-07-16 21:31:58 +000066 sp<android::gui::WindowInfoHandle> getWallpaperWindow() const;
Siarhei Vishniakou0026b4c2022-11-10 19:33:29 -080067 const TouchedWindow& getTouchedWindow(
68 const sp<android::gui::WindowInfoHandle>& windowHandle) const;
Siarhei Vishniakou3ad385b2022-11-04 10:09:53 -070069 // Whether any of the windows are currently being touched
70 bool isDown() const;
Siarhei Vishniakoub581f7f2022-12-07 20:23:06 +000071
72 std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
73 int32_t deviceId, int32_t pointerId) const;
Siarhei Vishniakou6e1e9872022-11-08 17:51:35 -080074 std::string dump() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070075};
76
77} // namespace inputdispatcher
78} // namespace android