Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GNASH_INPUTDEVICE_H
00019 #define GNASH_INPUTDEVICE_H
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include "gnashconfig.h"
00023 #endif
00024
00025 #include <boost/scoped_array.hpp>
00026 #include <boost/shared_array.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/cstdint.hpp>
00030 #include <vector>
00031 #include <queue>
00032 #include <linux/input.h>
00033 #include <linux/uinput.h>
00034
00035 #include "GnashKey.h"
00036
00037 namespace gnash {
00038
00039
00040
00041
00042
00043
00044
00045
00046 static const int DEFAULT_BUFFER_SIZE = 256;
00047
00048
00049
00050
00051 class UinputDevice
00052 {
00053 public:
00054 UinputDevice();
00055 ~UinputDevice();
00056 const char *id() { return "Uinput"; };
00057 bool init();
00058
00059 bool scanForDevice();
00060
00061
00062 bool moveTo(int x, int y);
00063 private:
00064 int _fd;
00065 std::string _filespec;
00066 };
00067
00068
00069
00070 class InputDevice
00071 {
00072 public:
00073 typedef struct {
00074 bool pressed;
00075 gnash::key::code key;
00076 int modifier;
00077 int x;
00078 int y;
00079 int z;
00080 int button;
00081 int position;
00082 int pressure;
00083 int volumne;
00084 int distance;
00085 int rx;
00086 int ry;
00087 int rz;
00088 int throttle;
00089 int rudder;
00090 int gas;
00091 int brake;
00092 int tiltX;
00093 int tiltY;
00094 } input_data_t;
00095 typedef enum {
00096 UNKNOWN,
00097 KEYBOARD,
00098 UMOUSE,
00099 MOUSE,
00100 TABLET,
00101 TOUCHSCREEN,
00102 TOUCHMOUSE,
00103 POWERBUTTON,
00104 SLEEPBUTTON,
00105 SERIALUSB,
00106 INFRARED,
00107 UINPUT,
00108 TSLIB
00109 } devicetype_e;
00110 InputDevice();
00111
00112 InputDevice(int x, int y);
00113 virtual ~InputDevice();
00114
00115 virtual const char *id() = 0;
00116
00117 virtual bool init();
00118 bool init(devicetype_e type);
00119 bool init(devicetype_e type, size_t size);
00120 bool init(devicetype_e type, const std::string &filespec);
00121 bool init(devicetype_e type, const std::string &filespec, size_t size);
00122 virtual bool init(const std::string &filespec, size_t size) = 0;
00123 virtual bool check() = 0;
00124
00125 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
00126
00127 InputDevice::devicetype_e getType() { return _type; };
00128 void setType(InputDevice::devicetype_e x) { _type = x; };
00129
00130
00131 boost::shared_array<boost::uint8_t> readData(size_t size);
00132 boost::shared_ptr<input_data_t> popData()
00133 {
00134 boost::shared_ptr<InputDevice::input_data_t> input;
00135 if (_data.size()) {
00136
00137 input = _data.front();
00138 _data.pop();
00139 }
00140 return input;
00141 }
00142
00143 static boost::shared_array<int> convertAbsCoords(int x, int y,
00144 int width, int height);
00145
00146 void setScreenSize(int x, int y)
00147 {
00148 _screen_width = x;
00149 _screen_height = y;
00150 }
00151 void dump() const;
00152
00153 protected:
00154 void addData(bool pressed, key::code key, int modifier, int x, int y);
00155
00156 devicetype_e _type;
00157 std::string _filespec;
00158 int _fd;
00159 input_data_t _input_data;
00160
00161 boost::scoped_array<boost::uint8_t> _buffer;
00162 std::queue<boost::shared_ptr<input_data_t> > _data;
00163 int _screen_width;
00164 int _screen_height;
00165 };
00166
00167 class MouseDevice : public InputDevice
00168 {
00169 public:
00170 MouseDevice();
00171 ~MouseDevice();
00172 const char *id() { return "Mouse"; };
00173 bool init();
00174 bool init(const std::string &filespec, size_t size);
00175 bool check();
00176
00177 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
00178
00180 bool command(unsigned char cmd, unsigned char *buf, int count);
00181
00182 private:
00183 int _previous_x;
00184 int _previous_y;
00185 };
00186
00187 class TouchDevice : public InputDevice
00188 {
00189 public:
00190 const char *id() { return "TouchScreen"; };
00191 TouchDevice();
00192 virtual ~TouchDevice();
00193 bool init();
00194 bool init(const std::string &filespec, size_t size);
00195 bool check();
00196
00197 void apply_ts_calibration(float* cx, float* cy, int rawx, int rawy);
00198
00199 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
00200 private:
00201
00202
00203 struct tsdev *_tsDev;
00204 };
00205
00206 class EventDevice : public InputDevice
00207 {
00208 public:
00209 EventDevice();
00210 const char *id() { return "InputEvent"; };
00211 virtual bool init();
00212 virtual bool init(const std::string &filespec, size_t size);
00213 virtual bool check();
00214
00215 gnash::key::code scancode_to_gnash_key(int code, bool shift);
00216
00217
00218 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices();
00219
00220 private:
00221
00222 bool keyb_lshift, keyb_rshift, keyb_lctrl, keyb_rctrl, keyb_lalt, keyb_ralt;
00223 struct input_id _device_info;
00224 };
00225
00226 }
00227
00228
00229 #endif
00230
00231
00232
00233
00234