1 /* 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 17 #pragma once 18 19 #include <bitset> 20 #include <ostream> 21 #include <set> 22 #include "TouchedWindow.h" 23 24 namespace android { 25 26 namespace gui { 27 class WindowInfoHandle; 28 } 29 30 namespace inputdispatcher { 31 32 struct TouchState { 33 std::vector<TouchedWindow> windows; 34 35 TouchState() = default; 36 ~TouchState() = default; 37 TouchState& operator=(const TouchState&) = default; 38 39 void reset(); 40 void clearWindowsWithoutPointers(); 41 42 bool hasTouchingPointers(DeviceId deviceId) const; 43 void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); 44 void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId, 45 const sp<android::gui::WindowInfoHandle>& windowHandle); 46 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, 50 std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt); 51 void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, 52 DeviceId deviceId, const PointerProperties& pointer); 53 void removeHoveringPointer(DeviceId deviceId, int32_t pointerId); 54 void clearHoveringPointers(DeviceId deviceId); 55 56 void removeAllPointersForDevice(DeviceId deviceId); 57 void removeWindowByToken(const sp<IBinder>& token); 58 59 // Cancel pointers for current set of windows except the window with particular binder token. 60 void cancelPointersForWindowsExcept(DeviceId deviceId, 61 std::bitset<MAX_POINTER_ID + 1> pointerIds, 62 const sp<IBinder>& token); 63 // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow 64 // set to false. 65 void cancelPointersForNonPilferingWindows(); 66 67 sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle(DeviceId deviceId) const; 68 bool isSlippery(DeviceId deviceId) const; 69 sp<android::gui::WindowInfoHandle> getWallpaperWindow(DeviceId deviceId) const; 70 const TouchedWindow& getTouchedWindow( 71 const sp<android::gui::WindowInfoHandle>& windowHandle) const; 72 // Whether any of the windows are currently being touched 73 bool isDown(DeviceId deviceId) const; 74 bool hasHoveringPointers(DeviceId deviceId) const; 75 76 bool hasActiveStylus() const; 77 78 std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer( 79 DeviceId deviceId, int32_t pointerId) const; 80 std::string dump() const; 81 }; 82 83 std::ostream& operator<<(std::ostream& out, const TouchState& state); 84 85 } // namespace inputdispatcher 86 } // namespace android 87