2
// Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc
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.
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.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include "gnashconfig.h"
23
#include <sys/types.h>
27
#include <boost/shared_array.hpp>
29
#include "GnashSleep.h"
31
#include "InputDevice.h"
35
UinputDevice::UinputDevice()
38
// GNASH_REPORT_FUNCTION;
41
UinputDevice::~UinputDevice()
43
// GNASH_REPORT_FUNCTION;
45
if (ioctl(_fd, UI_DEV_DESTROY, 0) < 0) {
46
log_error(_("ioctl(UI_DEV_DESTROY)"));
52
UinputDevice::scanForDevice()
54
// GNASH_REPORT_FUNCTION;
58
// Look for these files for mouse input
60
InputDevice::devicetype_e type;
64
// The Uinput device is found in one of these two locations.
65
const char *mice[] = {
74
if (stat(mice[i], &st) == 0) {
75
// Then see if we can open it, this is a write only device
76
if ((_fd = open(mice[i], O_WRONLY)) < 0) {
77
log_error(_("You don't have the proper permissions to open %s"),
82
log_debug(_("Found a User mode input device at %s"), mice[i]);
95
// GNASH_REPORT_FUNCTION;
98
log_error(_("User Mode Input device not initialized yet!"));
102
if (ioctl(_fd, UI_SET_EVBIT, EV_KEY) < 0) {
103
log_error(_("ioctl(UI_SET_EVBIT, EV_KEY)"));
107
#if 0 // USE_RELATIVE_POINTER
108
if (ioctl(_fd, UI_SET_EVBIT, EV_REL) < 0) {
109
log_error(_("ioctl(UI_SET_EVBIT, EV_REL)"));
112
if (ioctl(_fd, UI_SET_RELBIT, REL_X) < 0) {
113
log_error(_("ioctl(UI_SET_RELBIT, REL_X)"));
116
if (ioctl(_fd, UI_SET_RELBIT, REL_Y) < 0) {
117
log_error(_("ioctl( UI_SET_RELBIT, REL_Y)"));
121
#if 1 // USE_ABSOLUTE_POINTER
122
struct uinput_user_dev uidev;
124
memset(&uidev, 0, sizeof(uidev));
125
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput");
126
uidev.id.bustype = BUS_USB;
127
// uidev.id.vendor = 0x1;
128
// uidev.id.product = 0x1;
129
// uidev.id.version = 1;
131
uidev.absmin[ABS_X] = 0;
132
uidev.absmax[ABS_X] = 1024; //_screen_width;
133
uidev.absfuzz[ABS_X] = 0;
134
uidev.absflat[ABS_X] = 0;
135
uidev.absmin[ABS_Y] = 0;
136
uidev.absmax[ABS_Y] = 768; //_screen_height;
137
uidev.absfuzz[ABS_Y] = 0;
138
uidev.absflat[ABS_Y ] = 0;
139
uidev.absmax[ABS_PRESSURE]=400;
141
if (::write(_fd, (char *)&uidev, sizeof(uidev)) < 0) {
142
log_error(_("write uidev"));
146
if (ioctl(_fd, UI_SET_EVBIT, EV_ABS) < 0) {
147
log_error(_("ioctl(UI_SET_EVBIT, EV_ABS): %s"), strerror(errno));
150
if (ioctl(_fd, UI_SET_ABSBIT,ABS_X) < 0) {
151
log_error(_("ioctl(UI_SET_ABSBIT,ABS_X): %s"), strerror(errno));
154
if (ioctl(_fd, UI_SET_ABSBIT, ABS_Y) < 0) {
155
log_error(_("ioctl(UI_SET_ABSBIT, ABS_Y): %s"), strerror(errno));
160
if (ioctl(_fd, UI_SET_KEYBIT, BTN_LEFT) < 0) {
161
log_error(_("ioctl(UI_SET_KEYBIT, BTN_LEFT)): %s"), strerror(errno));
164
if (ioctl(_fd, UI_SET_KEYBIT, BTN_RIGHT) < 0) {
165
log_error(_("ioctl(UI_SET_KEYBIT, BTN_RIGHT): %s"), strerror(errno));
168
if (ioctl(_fd, UI_SET_EVBIT, ABS_PRESSURE) < 0) {
169
log_error(_("ioctl(UI_SET_EVBIT, ABS_PRESSURE): %s"), strerror(errno));
172
// if (ioctl(_fd, UI_SET_EVBIT, ABS_TOUCH) < 0) {
173
// log_error("ioctl(UI_SET_EVBIT, ABS_TOUCH)");
176
if (ioctl(_fd, UI_SET_KEYBIT, BTN_MOUSE) < 0) {
177
log_error(_("ioctl(UI_SET_KEYBIT, BTN_MOUSE): %s"), strerror(errno));
181
if (ioctl(_fd, UI_DEV_CREATE, 0) < 0) {
182
log_error(_("ioctl(UI_DEV_CREATED) failed!"), strerror(errno));
189
// Move the mouse cursor to a specified location
191
UinputDevice::moveTo(int x, int y)
193
// GNASH_REPORT_FUNCTION;
195
struct input_event ev;
197
memset(&ev, 0, sizeof(ev));
198
gettimeofday(&ev.time, NULL);
202
if (::write(_fd, &ev, sizeof(struct input_event)) < 0) {
203
log_error("write ABS_X");
207
ev.code = SYN_REPORT;
209
if (::write(_fd, &ev, sizeof(struct input_event)) < 0) {
210
log_error("write SYN");
217
if (::write(_fd, &ev, sizeof(struct input_event)) < 0) {
218
log_error("write ABS_Y");
222
ev.code = SYN_REPORT;
224
if (::write(_fd, &ev, sizeof(struct input_event)) < 0) {
225
log_error("write SYN");
237
// indent-tabs-mode: nil