1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2022 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 <optional> 20*38e8c45fSAndroid Build Coastguard Worker #include <set> 21*38e8c45fSAndroid Build Coastguard Worker #include "InputListener.h" 22*38e8c45fSAndroid Build Coastguard Worker 23*38e8c45fSAndroid Build Coastguard Worker namespace android { 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker /** 26*38e8c45fSAndroid Build Coastguard Worker * When stylus is down, all touch is ignored. 27*38e8c45fSAndroid Build Coastguard Worker * TODO(b/210159205): delete this when simultaneous stylus and touch is supported 28*38e8c45fSAndroid Build Coastguard Worker */ 29*38e8c45fSAndroid Build Coastguard Worker class PreferStylusOverTouchBlocker { 30*38e8c45fSAndroid Build Coastguard Worker public: 31*38e8c45fSAndroid Build Coastguard Worker /** 32*38e8c45fSAndroid Build Coastguard Worker * Process the provided event and emit 0 or more events that should be used instead of it. 33*38e8c45fSAndroid Build Coastguard Worker * In the majority of cases, the returned result will just be the provided args (array with 34*38e8c45fSAndroid Build Coastguard Worker * only 1 element), unmodified. 35*38e8c45fSAndroid Build Coastguard Worker * 36*38e8c45fSAndroid Build Coastguard Worker * If the gesture should be blocked, the returned result may be: 37*38e8c45fSAndroid Build Coastguard Worker * 38*38e8c45fSAndroid Build Coastguard Worker * a) An empty array, if the current event should just be ignored completely 39*38e8c45fSAndroid Build Coastguard Worker * b) An array of N elements, containing N-1 events with ACTION_CANCEL and the current event. 40*38e8c45fSAndroid Build Coastguard Worker * 41*38e8c45fSAndroid Build Coastguard Worker * The returned result is intended to be reinjected into the original event stream in 42*38e8c45fSAndroid Build Coastguard Worker * replacement of the incoming event. 43*38e8c45fSAndroid Build Coastguard Worker */ 44*38e8c45fSAndroid Build Coastguard Worker std::vector<NotifyMotionArgs> processMotion(const NotifyMotionArgs& args); 45*38e8c45fSAndroid Build Coastguard Worker std::string dump() const; 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices); 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker void notifyDeviceReset(const NotifyDeviceResetArgs& args); 50*38e8c45fSAndroid Build Coastguard Worker 51*38e8c45fSAndroid Build Coastguard Worker private: 52*38e8c45fSAndroid Build Coastguard Worker // Stores the device id's of styli that are currently down. 53*38e8c45fSAndroid Build Coastguard Worker std::set<int32_t /*deviceId*/> mActiveStyli; 54*38e8c45fSAndroid Build Coastguard Worker // For each device, store the last touch event as long as the touch is down. Upon liftoff, 55*38e8c45fSAndroid Build Coastguard Worker // the entry is erased. 56*38e8c45fSAndroid Build Coastguard Worker std::map<int32_t /*deviceId*/, NotifyMotionArgs> mLastTouchEvents; 57*38e8c45fSAndroid Build Coastguard Worker // Device ids of devices for which the current touch gesture is canceled. 58*38e8c45fSAndroid Build Coastguard Worker std::set<int32_t /*deviceId*/> mCanceledDevices; 59*38e8c45fSAndroid Build Coastguard Worker 60*38e8c45fSAndroid Build Coastguard Worker // Device ids of input devices where we encountered simultaneous touch and stylus 61*38e8c45fSAndroid Build Coastguard Worker // events. For these devices, we don't do any event processing (nothing is blocked or altered). 62*38e8c45fSAndroid Build Coastguard Worker std::set<int32_t /*deviceId*/> mDevicesWithMixedToolType; 63*38e8c45fSAndroid Build Coastguard Worker }; 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker } // namespace android