1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2019 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <bitset> 20*38e8c45fSAndroid Build Coastguard Worker #include <ostream> 21*38e8c45fSAndroid Build Coastguard Worker #include <set> 22*38e8c45fSAndroid Build Coastguard Worker #include "TouchedWindow.h" 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker namespace android { 25*38e8c45fSAndroid Build Coastguard Worker 26*38e8c45fSAndroid Build Coastguard Worker namespace gui { 27*38e8c45fSAndroid Build Coastguard Worker class WindowInfoHandle; 28*38e8c45fSAndroid Build Coastguard Worker } 29*38e8c45fSAndroid Build Coastguard Worker 30*38e8c45fSAndroid Build Coastguard Worker namespace inputdispatcher { 31*38e8c45fSAndroid Build Coastguard Worker 32*38e8c45fSAndroid Build Coastguard Worker struct TouchState { 33*38e8c45fSAndroid Build Coastguard Worker std::vector<TouchedWindow> windows; 34*38e8c45fSAndroid Build Coastguard Worker 35*38e8c45fSAndroid Build Coastguard Worker TouchState() = default; 36*38e8c45fSAndroid Build Coastguard Worker ~TouchState() = default; 37*38e8c45fSAndroid Build Coastguard Worker TouchState& operator=(const TouchState&) = default; 38*38e8c45fSAndroid Build Coastguard Worker 39*38e8c45fSAndroid Build Coastguard Worker void reset(); 40*38e8c45fSAndroid Build Coastguard Worker void clearWindowsWithoutPointers(); 41*38e8c45fSAndroid Build Coastguard Worker 42*38e8c45fSAndroid Build Coastguard Worker bool hasTouchingPointers(DeviceId deviceId) const; 43*38e8c45fSAndroid Build Coastguard Worker void removeTouchingPointer(DeviceId deviceId, int32_t pointerId); 44*38e8c45fSAndroid Build Coastguard Worker void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId, 45*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle); 46*38e8c45fSAndroid Build Coastguard Worker android::base::Result<void> addOrUpdateWindow( 47*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle, 48*38e8c45fSAndroid Build Coastguard Worker InputTarget::DispatchMode dispatchMode, ftl::Flags<InputTarget::Flags> targetFlags, 49*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId, const std::vector<PointerProperties>& touchingPointers, 50*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> firstDownTimeInTarget); 51*38e8c45fSAndroid Build Coastguard Worker void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle, 52*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId, const PointerProperties& pointer, float x, 53*38e8c45fSAndroid Build Coastguard Worker float y); 54*38e8c45fSAndroid Build Coastguard Worker void removeHoveringPointer(DeviceId deviceId, int32_t pointerId); 55*38e8c45fSAndroid Build Coastguard Worker void clearHoveringPointers(DeviceId deviceId); 56*38e8c45fSAndroid Build Coastguard Worker 57*38e8c45fSAndroid Build Coastguard Worker void removeAllPointersForDevice(DeviceId deviceId); 58*38e8c45fSAndroid Build Coastguard Worker void removeWindowByToken(const sp<IBinder>& token); 59*38e8c45fSAndroid Build Coastguard Worker 60*38e8c45fSAndroid Build Coastguard Worker // Cancel pointers for current set of windows except the window with particular binder token. 61*38e8c45fSAndroid Build Coastguard Worker void cancelPointersForWindowsExcept(DeviceId deviceId, 62*38e8c45fSAndroid Build Coastguard Worker std::bitset<MAX_POINTER_ID + 1> pointerIds, 63*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& token); 64*38e8c45fSAndroid Build Coastguard Worker // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow 65*38e8c45fSAndroid Build Coastguard Worker // set to false. 66*38e8c45fSAndroid Build Coastguard Worker void cancelPointersForNonPilferingWindows(); 67*38e8c45fSAndroid Build Coastguard Worker 68*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle(DeviceId deviceId) const; 69*38e8c45fSAndroid Build Coastguard Worker bool isSlippery(DeviceId deviceId) const; 70*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> getWallpaperWindow(DeviceId deviceId) const; 71*38e8c45fSAndroid Build Coastguard Worker const TouchedWindow& getTouchedWindow( 72*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle) const; 73*38e8c45fSAndroid Build Coastguard Worker // Whether any of the windows are currently being touched 74*38e8c45fSAndroid Build Coastguard Worker bool isDown(DeviceId deviceId) const; 75*38e8c45fSAndroid Build Coastguard Worker bool hasHoveringPointers(DeviceId deviceId) const; 76*38e8c45fSAndroid Build Coastguard Worker 77*38e8c45fSAndroid Build Coastguard Worker bool hasActiveStylus() const; 78*38e8c45fSAndroid Build Coastguard Worker 79*38e8c45fSAndroid Build Coastguard Worker std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer( 80*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId, int32_t pointerId) const; 81*38e8c45fSAndroid Build Coastguard Worker std::string dump() const; 82*38e8c45fSAndroid Build Coastguard Worker }; 83*38e8c45fSAndroid Build Coastguard Worker 84*38e8c45fSAndroid Build Coastguard Worker std::ostream& operator<<(std::ostream& out, const TouchState& state); 85*38e8c45fSAndroid Build Coastguard Worker 86*38e8c45fSAndroid Build Coastguard Worker } // namespace inputdispatcher 87*38e8c45fSAndroid Build Coastguard Worker } // namespace android 88