blob: a66744f6d4a3c7668d9306f0a54ede7dce021519 [file] [log] [blame]
Jorge E. Moreira4750e542020-01-07 14:35:35 -08001/*
2 * Copyright (C) 2019 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
Jorge E. Moreirae049b792019-12-18 18:17:48 -080017#include <source/TouchSink.h>
18
19#include <https/SafeCallbackable.h>
20#include <https/Support.h>
Jorge E. Moreira2a6ab082019-12-11 18:41:58 -080021
22#include <android-base/logging.h>
Jorge E. Moreirae049b792019-12-18 18:17:48 -080023
24#include <linux/input.h>
Jorge E. Moreirae049b792019-12-18 18:17:48 -080025
26#include <sys/socket.h>
Jorge E. Moreiraf45e3552019-12-04 17:52:04 -080027#include <unistd.h>
Jorge E. Moreirae049b792019-12-18 18:17:48 -080028
29namespace android {
30
Jorge E. Moreirae049b792019-12-18 18:17:48 -080031TouchSink::TouchSink(std::shared_ptr<RunLoop> runLoop, int serverFd,
32 bool write_virtio_input)
Jorge E. Moreiracfd08402020-01-13 18:36:33 -080033 : sink_(
34 std::make_shared<InputSink>(runLoop, serverFd, write_virtio_input)) {}
Jorge E. Moreirae049b792019-12-18 18:17:48 -080035
Jorge E. Moreiracfd08402020-01-13 18:36:33 -080036void TouchSink::injectTouchEvent(int32_t x, int32_t y, bool down) {
Jorge E. Moreirae049b792019-12-18 18:17:48 -080037 LOG(VERBOSE)
Jorge E. Moreira2a6ab082019-12-11 18:41:58 -080038 << "Received touch (down="
39 << down
Jorge E. Moreirae049b792019-12-18 18:17:48 -080040 << ", x="
41 << x
42 << ", y="
Jorge E. Moreira2a6ab082019-12-11 18:41:58 -080043 << y;
Jorge E. Moreirae049b792019-12-18 18:17:48 -080044
Jorge E. Moreiracfd08402020-01-13 18:36:33 -080045 auto buffer = sink_->getEventBuffer();
46 buffer->addEvent(EV_ABS, ABS_X, x);
47 buffer->addEvent(EV_ABS, ABS_Y, y);
48 buffer->addEvent(EV_KEY, BTN_TOUCH, down);
49 buffer->addEvent(EV_SYN, 0, 0);
50 sink_->SendEvents(std::move(buffer));
Jorge E. Moreirae049b792019-12-18 18:17:48 -080051}
52
Jorge E. Moreiracfd08402020-01-13 18:36:33 -080053void TouchSink::injectMultiTouchEvent(int32_t /*id*/, int32_t /*slot*/,
54 int32_t x, int32_t y, bool initialDown) {
55 // TODO (muntsinger): Enable multitouch
56 return injectTouchEvent(x, y, initialDown);
Jorge E. Moreirae049b792019-12-18 18:17:48 -080057}
58
59} // namespace android
60