Steve Kondik | 95027ea | 2017-06-14 17:22:58 -0700 | [diff] [blame] | 1 | // |
| 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 Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 18 | #ifndef INPUT_DEVICE_H |
| 19 | #define INPUT_DEVICE_H |
| 20 | |
| 21 | #include <utils/Errors.h> |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 22 | #include <utils/Mutex.h> |
| 23 | #include <utils/Singleton.h> |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 24 | |
| 25 | #include <rfb/rfb.h> |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 26 | #include <linux/uinput.h> |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 27 | |
| 28 | #define UINPUT_DEVICE "/dev/uinput" |
| 29 | |
| 30 | namespace android { |
| 31 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 32 | class InputDevice : public Singleton<InputDevice> { |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 33 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 34 | friend class Singleton; |
| 35 | |
| 36 | public: |
| 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 Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 49 | 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 Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 56 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 57 | void keyEvent(rfbBool down, rfbKeySym key, rfbClientPtr cl); |
| 58 | void pointerEvent(int buttonMask, int x, int y, rfbClientPtr cl); |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 59 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 60 | int keysym2scancode(rfbKeySym c, rfbClientPtr cl, int* sh, int* alt); |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 61 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame] | 62 | Mutex mLock; |
| 63 | |
| 64 | int mFD; |
| 65 | |
| 66 | struct uinput_user_dev mUserDev; |
Steve Kondik | a890c5e | 2017-06-15 02:46:23 -0700 | [diff] [blame] | 67 | |
| 68 | bool mLeftClicked; |
| 69 | bool mRightClicked; |
| 70 | bool mMiddleClicked; |
| 71 | |
Steve Kondik | 107d2e5 | 2017-06-13 17:34:56 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | }; |
| 75 | #endif |