Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 // Define if you want to support multiple input devices of the same type. 00040 // The default is to support the devices we prefer for mouse, keyboard, 00041 // and touchscreen. 00042 // #define MULTIPLE_DEVICES 1 00043 00044 // If we have a mouse, but the size isn't specified, then this is the 00045 // default size. 00046 static const int DEFAULT_BUFFER_SIZE = 256; 00047 00048 00049 // The Uinput device is write only, and is used to control the mouse movements. 00050 // It's not really an input device, but uses the same subsystem. 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 // Move the mouse cursor to a specified location 00062 bool moveTo(int x, int y); 00063 private: 00064 int _fd; 00065 std::string _filespec; 00066 }; 00067 00068 // This is an InputDevice class to cover the various touchscreens, Mice, or 00069 // keyboards supported. 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 // Instantiate with the screen size 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 // Read data into the Device input buffer. 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 // std::cerr << "FIXME: " <<_data.size() << std::endl; 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 // These hold the data queue 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 // Although the value is only set when using a touchscreen, it takes up little 00202 // memory to initialize a pointer to avoid lots of messy ifdefs. 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 // This looks for all the input event devices. 00218 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(); 00219 00220 private: 00221 // Keyboard SHIFT/CTRL/ALT states (left + right) 00222 bool keyb_lshift, keyb_rshift, keyb_lctrl, keyb_rctrl, keyb_lalt, keyb_ralt; 00223 struct input_id _device_info; 00224 }; 00225 00226 } // end of gnash namespace 00227 00228 // end of GNASH_INPUTDEVICE_H 00229 #endif 00230 00231 // Local Variables: 00232 // mode: C++ 00233 // indent-tabs-mode: nil 00234 // End: