2 * Copyright (C) 2015 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
25UInput::UInput(QObject *parent) :
28 m_devName = QStringLiteral("unity8-simulated-mouse");
29 m_uinput.setFileName("/dev/uinput");
31 memset(&m_uinput_mouse_dev, 0, sizeof(m_uinput_mouse_dev));
32 m_uinput_mouse_dev.id.bustype = BUS_USB;
33 m_uinput_mouse_dev.id.version = 1;
34 strncpy(m_uinput_mouse_dev.name, m_devName.toLocal8Bit().data(), m_devName.length());
44void UInput::createMouse()
47 qDebug() << "Already have a virtual device. Not creating another one.";
51 if (!m_uinput.isOpen() && !m_uinput.open(QFile::WriteOnly)) {
55 ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_REL);
56 ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_X);
57 ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_Y);
58 ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_HWHEEL);
59 ioctl(m_uinput.handle(), UI_SET_RELBIT, REL_WHEEL);
61 ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_KEY);
62 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_MOUSE);
63 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_LEFT);
64 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_MIDDLE);
65 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_RIGHT);
66 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_FORWARD);
67 ioctl(m_uinput.handle(), UI_SET_KEYBIT, BTN_BACK);
69 ioctl(m_uinput.handle(), UI_SET_EVBIT, EV_SYN);
71 int len = write(m_uinput.handle(), &m_uinput_mouse_dev, sizeof(m_uinput_mouse_dev));
73 qWarning() << "Failed to write to uinput. Cannot create virtual uinput mouse.";
77 int err = ioctl(m_uinput.handle(), UI_DEV_CREATE);
79 qWarning() << "Cannot create virtual uinput device. Create ioctl failed:" << err;
82 m_mouseCreated = true;
83 qDebug() << "Virtual uinput mouse device created.";
86void UInput::removeMouse()
88 if (!m_mouseCreated) {
92 if (!m_uinput.isOpen() && !m_uinput.open(QFile::WriteOnly)) {
93 qWarning() << "cannot open uinput... ";
97 int err = ioctl(m_uinput.handle(), UI_DEV_DESTROY);
99 qWarning() << "Failed to destroy virtual uinput device. Destroy ioctl failed:" << err;
101 qDebug() << "Virtual uinput mouse device removed.";
104 m_mouseCreated = false;
107void UInput::moveMouse(int dx, int dy)
109 struct input_event event;
110 memset(&event, 0, sizeof(event));
111 gettimeofday(&event.time, 0);
115 write(m_uinput.handle(), &event, sizeof(event));
119 write(m_uinput.handle(), &event, sizeof(event));
122 event.code = SYN_REPORT;
124 write(m_uinput.handle(), &event, sizeof(event));
127void UInput::pressMouse(Button button)
129 injectMouse(button, 1);
132void UInput::releaseMouse(Button button)
134 injectMouse(button, 0);
137void UInput::scrollMouse(int dh, int dv)
139 struct input_event event;
140 memset(&event, 0, sizeof(event));
141 gettimeofday(&event.time, 0);
143 event.code = REL_HWHEEL;
145 write(m_uinput.handle(), &event, sizeof(event));
147 event.code = REL_WHEEL;
149 write(m_uinput.handle(), &event, sizeof(event));
152 event.code = SYN_REPORT;
154 write(m_uinput.handle(), &event, sizeof(event));
157void UInput::injectMouse(Button button, int down)
159 struct input_event event;
160 memset(&event, 0, sizeof(event));
161 gettimeofday(&event.time, 0);
165 event.code = BTN_LEFT;
168 event.code = BTN_RIGHT;
171 event.code = BTN_MIDDLE;
175 write(m_uinput.handle(), &event, sizeof(event));
178 event.code = SYN_REPORT;
180 write(m_uinput.handle(), &event, sizeof(event));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list