1 /*
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
17 #include <source/TouchSink.h>
18
19 #include <https/SafeCallbackable.h>
20 #include <https/Support.h>
21
22 #include <android-base/logging.h>
23
24 #include <linux/input.h>
25
26 #include <sys/socket.h>
27 #include <unistd.h>
28
29 namespace android {
30
TouchSink(std::shared_ptr<RunLoop> runLoop,int serverFd,bool write_virtio_input)31 TouchSink::TouchSink(std::shared_ptr<RunLoop> runLoop, int serverFd,
32 bool write_virtio_input)
33 : sink_(
34 std::make_shared<InputSink>(runLoop, serverFd, write_virtio_input)) {}
35
injectTouchEvent(int32_t x,int32_t y,bool down)36 void TouchSink::injectTouchEvent(int32_t x, int32_t y, bool down) {
37 LOG(VERBOSE)
38 << "Received touch (down="
39 << down
40 << ", x="
41 << x
42 << ", y="
43 << y;
44
45 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));
51 }
52
injectMultiTouchEvent(int32_t,int32_t,int32_t x,int32_t y,bool initialDown)53 void 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);
57 }
58
59 } // namespace android
60
61