• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <optional>
20 #include <set>
21 #include "InputListener.h"
22 
23 namespace android {
24 
25 /**
26  * When stylus is down, all touch is ignored.
27  * TODO(b/210159205): delete this when simultaneous stylus and touch is supported
28  */
29 class PreferStylusOverTouchBlocker {
30 public:
31     /**
32      * Process the provided event and emit 0 or more events that should be used instead of it.
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
39      * b) An array of N elements, containing N-1 events with ACTION_CANCEL and the current event.
40      *
41      * The returned result is intended to be reinjected into the original event stream in
42      * replacement of the incoming event.
43      */
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);
50 
51 private:
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;
63 };
64 
65 } // namespace android