Gnash  0.8.11dev
InputDevice.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc
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, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 #ifndef GNASH_INPUTDEVICE_H
19 #define GNASH_INPUTDEVICE_H
20 
21 #ifdef HAVE_CONFIG_H
22 #include "gnashconfig.h"
23 #endif
24 
25 #include <boost/scoped_array.hpp>
26 #include <boost/shared_array.hpp>
27 #include <boost/scoped_ptr.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/cstdint.hpp>
30 #include <vector>
31 #include <queue>
32 #include <linux/input.h>
33 #ifdef HAVE_LINUX_UINPUT_H
34 #include <linux/uinput.h>
35 #endif
36 
37 #include "GnashKey.h"
38 
39 namespace gnash {
40 
41 // Define if you want to support multiple input devices of the same type.
42 // The default is to support the devices we prefer for mouse, keyboard,
43 // and touchscreen.
44 // #define MULTIPLE_DEVICES 1
45 
46 // If we have a mouse, but the size isn't specified, then this is the
47 // default size.
48 static const int DEFAULT_BUFFER_SIZE = 256;
49 
50 
51 // The Uinput device is write only, and is used to control the mouse movements.
52 // It's not really an input device, but uses the same subsystem.
54 {
55 public:
56  UinputDevice();
57  ~UinputDevice();
58  const char *id() { return "Uinput"; };
59  bool init();
60 
61  bool scanForDevice();
62 
63  // Move the mouse cursor to a specified location
64  bool moveTo(int x, int y);
65 private:
66  int _fd;
67  std::string _filespec;
68 };
69 
70 // This is an InputDevice class to cover the various touchscreens, Mice, or
71 // keyboards supported.
73 {
74 public:
75  typedef struct {
76  bool pressed;
78  int modifier;
79  int x;
80  int y;
81  int z;
82  int button;
83  int position;
84  int pressure;
85  int volumne;
86  int distance;
87  int rx;
88  int ry;
89  int rz;
90  int throttle;
91  int rudder;
92  int gas;
93  int brake;
94  int tiltX;
95  int tiltY;
96  } input_data_t;
97  typedef enum {
111  } devicetype_e;
112  InputDevice();
113  // Instantiate with the screen size
114  InputDevice(int x, int y);
115  virtual ~InputDevice();
116 
117  virtual const char *id() = 0;
118 
119  virtual bool init();
120  bool init(devicetype_e type);
121  bool init(devicetype_e type, size_t size);
122  bool init(devicetype_e type, const std::string &filespec);
123  bool init(devicetype_e type, const std::string &filespec, size_t size);
124  virtual bool init(const std::string &filespec, size_t size) = 0;
125  virtual bool check() = 0;
126 
127  static DSOEXPORT std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
128 
131 
132  // Read data into the Device input buffer.
133  boost::shared_array<boost::uint8_t> readData(size_t size);
134  boost::shared_ptr<input_data_t> popData()
135  {
136  boost::shared_ptr<InputDevice::input_data_t> input;
137  if (_data.size()) {
138  // std::cerr << "FIXME: " <<_data.size() << std::endl;
139  input = _data.front();
140  _data.pop();
141  }
142  return input;
143  }
144 
145  static DSOEXPORT boost::shared_array<int> convertAbsCoords(int x, int y,
146  int width, int height);
147 
148  void setScreenSize(int x, int y)
149  {
150  _screen_width = x;
151  _screen_height = y;
152  }
153  void dump() const;
154 
155 protected:
156  void addData(bool pressed, key::code key, int modifier, int x, int y);
157 
159  std::string _filespec;
160  int _fd;
162  // These hold the data queue
163  boost::scoped_array<boost::uint8_t> _buffer;
164  std::queue<boost::shared_ptr<input_data_t> > _data;
167 };
168 
169 class MouseDevice : public InputDevice
170 {
171 public:
172  MouseDevice();
173  ~MouseDevice();
174  const char *id() { return "Mouse"; };
175  bool init();
176  bool init(const std::string &filespec, size_t size);
177  bool check();
178 
179  static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
180 
182  bool command(unsigned char cmd, unsigned char *buf, int count);
183 
184 private:
185  int _previous_x;
186  int _previous_y;
187 };
188 
189 class TouchDevice : public InputDevice
190 {
191 public:
192  const char *id() { return "TouchScreen"; };
193  TouchDevice();
194  virtual ~TouchDevice();
195  bool init();
196  bool init(const std::string &filespec, size_t size);
197  bool check();
198 
199  void apply_ts_calibration(float* cx, float* cy, int rawx, int rawy);
200 
201  static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
202 private:
203  // Although the value is only set when using a touchscreen, it takes up little
204  // memory to initialize a pointer to avoid lots of messy ifdefs.
205  struct tsdev *_tsDev;
206 };
207 
208 class EventDevice : public InputDevice
209 {
210 public:
211  EventDevice();
212  const char *id() { return "InputEvent"; };
213  virtual bool init();
214  virtual bool init(const std::string &filespec, size_t size);
215  virtual bool check();
216 
218 
219  // This looks for all the input event devices.
220  static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
221 
222 private:
223  // Keyboard SHIFT/CTRL/ALT states (left + right)
224  bool keyb_lshift, keyb_rshift, keyb_lctrl, keyb_rctrl, keyb_lalt, keyb_ralt;
225  struct input_id _device_info;
226 };
227 
228 } // end of gnash namespace
229 
230 // end of GNASH_INPUTDEVICE_H
231 #endif
232 
233 // Local Variables:
234 // mode: C++
235 // indent-tabs-mode: nil
236 // End:
const char * id()
Definition: InputDevice.h:174
Definition: InputDevice.h:108
Definition: InputDevice.h:103
const char * id()
Definition: InputDevice.h:192
modifier
Definition: GnashKey.h:33
int y
Definition: InputDevice.h:80
bool check()
Definition: TouchDevice.cpp:109
Definition: InputDevice.h:75
Definition: InputDevice.h:98
void setType(InputDevice::devicetype_e x)
Definition: InputDevice.h:130
virtual bool check()=0
Definition: InputDevice.h:53
InputDevice()
Definition: InputDevice.cpp:31
virtual bool init()
Definition: InputDevice.cpp:57
int tiltY
Definition: InputDevice.h:95
bool init()
Definition: MouseDevice.cpp:128
Definition: InputDevice.h:169
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
int _screen_height
Definition: InputDevice.h:166
static DSOEXPORT std::vector< boost::shared_ptr< InputDevice > > scanForDevices()
Definition: InputDevice.cpp:191
boost::shared_ptr< input_data_t > popData()
Definition: InputDevice.h:134
devicetype_e _type
Definition: InputDevice.h:158
Definition: InputDevice.h:99
static std::vector< boost::shared_ptr< InputDevice > > scanForDevices()
Definition: EventDevice.cpp:676
type
Definition: GnashKey.h:329
int tiltX
Definition: InputDevice.h:94
gnash::key::code key
Definition: InputDevice.h:77
int volumne
Definition: InputDevice.h:85
int position
Definition: InputDevice.h:83
Definition: klash_part.cpp:329
int distance
Definition: InputDevice.h:86
Definition: InputDevice.h:106
int _screen_width
Definition: InputDevice.h:165
virtual bool init()
Definition: EventDevice.cpp:54
void setScreenSize(int x, int y)
Definition: InputDevice.h:148
Definition: InputDevice.h:105
~MouseDevice()
Definition: MouseDevice.cpp:44
TouchDevice()
Definition: TouchDevice.cpp:50
Definition: InputDevice.h:208
input_data_t _input_data
Definition: InputDevice.h:161
code
Definition: GnashKey.h:43
bool check()
Definition: MouseDevice.cpp:237
int x
Definition: InputDevice.h:79
EventDevice()
Definition: EventDevice.cpp:40
virtual ~TouchDevice()
Definition: TouchDevice.cpp:55
static std::vector< boost::shared_ptr< InputDevice > > scanForDevices()
Definition: MouseDevice.cpp:50
Definition: InputDevice.h:101
int rz
Definition: InputDevice.h:89
int z
Definition: InputDevice.h:81
Definition: klash_part.cpp:329
boost::shared_array< boost::uint8_t > readData(size_t size)
Definition: InputDevice.cpp:112
virtual const char * id()=0
Definition: InputDevice.h:100
Definition: InputDevice.h:107
std::queue< boost::shared_ptr< input_data_t > > _data
Definition: InputDevice.h:164
int pressure
Definition: InputDevice.h:84
boost::int32_t x
Definition: BitmapData_as.cpp:434
#define DSOEXPORT
Definition: dsodefs.h:55
Definition: InputDevice.h:72
int throttle
Definition: InputDevice.h:90
void dump() const
Definition: InputDevice.cpp:152
int rudder
Definition: InputDevice.h:91
Definition: InputDevice.h:189
int gas
Definition: InputDevice.h:92
int ry
Definition: InputDevice.h:88
virtual bool check()
Definition: EventDevice.cpp:254
Definition: InputDevice.h:104
InputDevice::devicetype_e getType()
Definition: InputDevice.h:129
static std::vector< boost::shared_ptr< InputDevice > > scanForDevices()
Definition: TouchDevice.cpp:271
bool pressed
Definition: InputDevice.h:76
const char * id()
Definition: InputDevice.h:212
Definition: InputDevice.h:109
boost::int32_t y
Definition: BitmapData_as.cpp:435
MouseDevice()
Definition: MouseDevice.cpp:37
boost::scoped_array< boost::uint8_t > _buffer
Definition: InputDevice.h:163
bool command(unsigned char cmd, unsigned char *buf, int count)
Sends a command to the mouse and waits for the response.
Definition: MouseDevice.cpp:369
gnash::key::code scancode_to_gnash_key(int code, bool shift)
Definition: EventDevice.cpp:556
std::string _filespec
Definition: InputDevice.h:159
Definition: InputDevice.h:102
int modifier
Definition: InputDevice.h:78
int _fd
Definition: InputDevice.h:160
devicetype_e
Definition: InputDevice.h:97
static DSOEXPORT boost::shared_array< int > convertAbsCoords(int x, int y, int width, int height)
Definition: InputDevice.cpp:179
bool init()
Definition: TouchDevice.cpp:65
Definition: InputDevice.h:110
void apply_ts_calibration(float *cx, float *cy, int rawx, int rawy)
Definition: TouchDevice.cpp:149
int brake
Definition: InputDevice.h:93
const char * id()
Definition: InputDevice.h:58
void addData(bool pressed, key::code key, int modifier, int x, int y)
Definition: InputDevice.cpp:92
virtual ~InputDevice()
Definition: InputDevice.cpp:51
int rx
Definition: InputDevice.h:87
int button
Definition: InputDevice.h:82