blob: be4367f832ef87ad45288a594cef4ae18f9d4495 [file] [log] [blame]
Steve Kondik95027ea2017-06-14 17:22:58 -07001//
2// vncflinger - Copyright (C) 2017 Steve Kondik
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
Steve Kondik107d2e52017-06-13 17:34:56 -070018#ifndef INPUT_DEVICE_H
19#define INPUT_DEVICE_H
20
21#include <utils/Errors.h>
Steve Kondik6ec5bc82017-06-15 01:31:51 -070022#include <utils/Mutex.h>
Steve Kondik961b4cc2017-06-22 18:10:50 -070023#include <utils/RefBase.h>
Steve Kondik107d2e52017-06-13 17:34:56 -070024
Steve Kondik6ec5bc82017-06-15 01:31:51 -070025#include <linux/uinput.h>
Steve Kondik961b4cc2017-06-22 18:10:50 -070026
Steve Kondik107d2e52017-06-13 17:34:56 -070027
28#define UINPUT_DEVICE "/dev/uinput"
29
30namespace android {
31
Steve Kondik961b4cc2017-06-22 18:10:50 -070032class InputDevice : public RefBase {
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070033 public:
Steve Kondik6ec5bc82017-06-15 01:31:51 -070034 virtual status_t start(uint32_t width, uint32_t height);
Steve Kondik961b4cc2017-06-22 18:10:50 -070035 virtual status_t start_async(uint32_t width, uint32_t height);
Steve Kondik6ec5bc82017-06-15 01:31:51 -070036 virtual status_t stop();
37 virtual status_t reconfigure(uint32_t width, uint32_t height);
38
Steve Kondik961b4cc2017-06-22 18:10:50 -070039 virtual void keyEvent(bool down, uint32_t key);
40 virtual void pointerEvent(int buttonMask, int x, int y);
Steve Kondik6ec5bc82017-06-15 01:31:51 -070041
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070042 InputDevice() : mFD(-1) {
43 }
44 virtual ~InputDevice() {
Steve Kondik961b4cc2017-06-22 18:10:50 -070045 stop();
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070046 }
Steve Kondik107d2e52017-06-13 17:34:56 -070047
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070048 private:
Steve Kondik961b4cc2017-06-22 18:10:50 -070049
Steve Kondik6ec5bc82017-06-15 01:31:51 -070050 status_t inject(uint16_t type, uint16_t code, int32_t value);
51 status_t injectSyn(uint16_t type, uint16_t code, int32_t value);
52 status_t movePointer(int32_t x, int32_t y);
53 status_t setPointer(int32_t x, int32_t y);
54 status_t press(uint16_t code);
55 status_t release(uint16_t code);
56 status_t click(uint16_t code);
Steve Kondik107d2e52017-06-13 17:34:56 -070057
Steve Kondik961b4cc2017-06-22 18:10:50 -070058 int keysym2scancode(uint32_t c, int* sh, int* alt);
Steve Kondik107d2e52017-06-13 17:34:56 -070059
Steve Kondik6ec5bc82017-06-15 01:31:51 -070060 Mutex mLock;
61
62 int mFD;
Steve Kondik961b4cc2017-06-22 18:10:50 -070063 bool mOpened;
Steve Kondik6ec5bc82017-06-15 01:31:51 -070064
65 struct uinput_user_dev mUserDev;
Steve Kondika890c5e2017-06-15 02:46:23 -070066
67 bool mLeftClicked;
68 bool mRightClicked;
69 bool mMiddleClicked;
Steve Kondik107d2e52017-06-13 17:34:56 -070070};
Steve Kondik107d2e52017-06-13 17:34:56 -070071};
72#endif