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