blob: 20f506308420e37ac43df527ffe45daa222ce02e [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>
23#include <utils/Singleton.h>
Steve Kondik107d2e52017-06-13 17:34:56 -070024
25#include <rfb/rfb.h>
Steve Kondik6ec5bc82017-06-15 01:31:51 -070026#include <linux/uinput.h>
Steve Kondik107d2e52017-06-13 17:34:56 -070027
28#define UINPUT_DEVICE "/dev/uinput"
29
30namespace android {
31
Steve Kondik6ec5bc82017-06-15 01:31:51 -070032class InputDevice : public Singleton<InputDevice> {
Steve Kondik107d2e52017-06-13 17:34:56 -070033
Steve Kondik6ec5bc82017-06-15 01:31:51 -070034friend class Singleton;
35
36public:
37 virtual status_t start(uint32_t width, uint32_t height);
38 virtual status_t stop();
39 virtual status_t reconfigure(uint32_t width, uint32_t height);
40
41 static void onKeyEvent(rfbBool down, rfbKeySym key, rfbClientPtr cl);
42 static void onPointerEvent(int buttonMask, int x, int y, rfbClientPtr cl);
43
44 InputDevice() : mFD(-1) {}
45 virtual ~InputDevice() {}
Steve Kondik107d2e52017-06-13 17:34:56 -070046
47private:
48
Steve Kondik6ec5bc82017-06-15 01:31:51 -070049 status_t inject(uint16_t type, uint16_t code, int32_t value);
50 status_t injectSyn(uint16_t type, uint16_t code, int32_t value);
51 status_t movePointer(int32_t x, int32_t y);
52 status_t setPointer(int32_t x, int32_t y);
53 status_t press(uint16_t code);
54 status_t release(uint16_t code);
55 status_t click(uint16_t code);
Steve Kondik107d2e52017-06-13 17:34:56 -070056
Steve Kondik6ec5bc82017-06-15 01:31:51 -070057 void keyEvent(rfbBool down, rfbKeySym key, rfbClientPtr cl);
58 void pointerEvent(int buttonMask, int x, int y, rfbClientPtr cl);
Steve Kondik107d2e52017-06-13 17:34:56 -070059
Steve Kondik6ec5bc82017-06-15 01:31:51 -070060 int keysym2scancode(rfbKeySym c, rfbClientPtr cl, int* sh, int* alt);
Steve Kondik107d2e52017-06-13 17:34:56 -070061
Steve Kondik6ec5bc82017-06-15 01:31:51 -070062 Mutex mLock;
63
64 int mFD;
65
66 struct uinput_user_dev mUserDev;
Steve Kondik107d2e52017-06-13 17:34:56 -070067};
68
69};
70#endif