blob: 716dc4d351088378bad072b2f5bff85af6a580d7 [file] [log] [blame]
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -08001/*
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 Vishniakoua3c8e512022-02-10 19:46:34 -080019#include <optional>
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080020#include <set>
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -080021#include "InputListener.h"
22
23namespace android {
24
25/**
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080026 * When stylus is down, all touch is ignored.
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -080027 * TODO(b/210159205): delete this when simultaneous stylus and touch is supported
28 */
29class PreferStylusOverTouchBlocker {
30public:
31 /**
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080032 * Process the provided event and emit 0 or more events that should be used instead of it.
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -080033 * 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 Vishniakoua6a660f2022-03-04 15:12:16 -080039 * b) An array of N elements, containing N-1 events with ACTION_CANCEL and the current event.
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -080040 *
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080041 * The returned result is intended to be reinjected into the original event stream in
42 * replacement of the incoming event.
Siarhei Vishniakoua3c8e512022-02-10 19:46:34 -080043 */
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080044 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 Vishniakoua3c8e512022-02-10 19:46:34 -080050
51private:
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -080052 // 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 Vishniakoua3c8e512022-02-10 19:46:34 -080063};
64
65} // namespace android