Jorge E. Moreira | 4750e54 | 2020-01-07 14:35:35 -0800 | [diff] [blame] | 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 | |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 17 | #include <source/TouchSink.h> |
| 18 | |
| 19 | #include <https/SafeCallbackable.h> |
| 20 | #include <https/Support.h> |
Jorge E. Moreira | 2a6ab08 | 2019-12-11 18:41:58 -0800 | [diff] [blame] | 21 | |
| 22 | #include <android-base/logging.h> |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 23 | |
| 24 | #include <linux/input.h> |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 25 | |
| 26 | #include <sys/socket.h> |
Jorge E. Moreira | f45e355 | 2019-12-04 17:52:04 -0800 | [diff] [blame] | 27 | #include <unistd.h> |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 31 | TouchSink::TouchSink(std::shared_ptr<RunLoop> runLoop, int serverFd, |
| 32 | bool write_virtio_input) |
Jorge E. Moreira | cfd0840 | 2020-01-13 18:36:33 -0800 | [diff] [blame^] | 33 | : sink_( |
| 34 | std::make_shared<InputSink>(runLoop, serverFd, write_virtio_input)) {} |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 35 | |
Jorge E. Moreira | cfd0840 | 2020-01-13 18:36:33 -0800 | [diff] [blame^] | 36 | void TouchSink::injectTouchEvent(int32_t x, int32_t y, bool down) { |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 37 | LOG(VERBOSE) |
Jorge E. Moreira | 2a6ab08 | 2019-12-11 18:41:58 -0800 | [diff] [blame] | 38 | << "Received touch (down=" |
| 39 | << down |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 40 | << ", x=" |
| 41 | << x |
| 42 | << ", y=" |
Jorge E. Moreira | 2a6ab08 | 2019-12-11 18:41:58 -0800 | [diff] [blame] | 43 | << y; |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 44 | |
Jorge E. Moreira | cfd0840 | 2020-01-13 18:36:33 -0800 | [diff] [blame^] | 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)); |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Jorge E. Moreira | cfd0840 | 2020-01-13 18:36:33 -0800 | [diff] [blame^] | 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); |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace android |
| 60 | |