2 // Copyright (C) 2010 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
18 #ifndef GNASH_INPUTDEVICE_H
19 #define GNASH_INPUTDEVICE_H
22 #include "gnashconfig.h"
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>
33 #include <linux/input.h>
37 // Define if you want to support multiple input devices of the same type.
38 // The default is to support the devices we prefer for moluse, keyboard,
40 // #define MULTIPLE_DEVICES 1
42 // Forward declarations
45 // If we have a mouse, but the size isn't specified, then this is the
47 static const int DEFAULT_BUFFER_SIZE
= 256;
49 // This is an InputDevice class to cover the various touchscreens, Mice, or
50 // keyboards supported.
66 InputDevice(Gui
*gui
);
67 virtual ~InputDevice();
70 bool init(devicetype_e type
);
71 bool init(devicetype_e type
, size_t size
);
72 bool init(devicetype_e type
, const std::string
&filespec
);
73 bool init(devicetype_e type
, const std::string
&filespec
, size_t size
);
74 virtual bool init(const std::string
&filespec
, size_t size
) = 0;
75 virtual bool check() = 0;
77 static std::vector
<boost::shared_ptr
<InputDevice
> > scanForDevices(Gui
*gui
);
79 InputDevice::devicetype_e
getType() { return _type
; };
81 // Read data into the Device input buffer.
82 boost::shared_array
<boost::uint8_t> readData(size_t size
);
88 std::string _filespec
;
92 // Touchscreens don't have buttons
95 boost::scoped_array
<boost::uint8_t> _buffer
;
96 // We don't control the memory associated with the Gui, we just use
97 // it to propogate the events from this device.
101 class MouseDevice
: public InputDevice
105 MouseDevice(Gui
*gui
);
107 virtual bool init(const std::string
&filespec
, size_t size
);
108 virtual bool check();
110 static std::vector
<boost::shared_ptr
<InputDevice
> > scanForDevices(Gui
*gui
);
112 /// Sends a command to the mouse and waits for the response
113 bool command(unsigned char cmd
, unsigned char *buf
, int count
);
116 class TouchDevice
: public InputDevice
120 TouchDevice(Gui
*gui
);
121 virtual ~TouchDevice();
123 virtual bool init(const std::string
&filespec
, size_t size
);
124 virtual bool check();
126 void apply_ts_calibration(float* cx
, float* cy
, int rawx
, int rawy
);
128 static std::vector
<boost::shared_ptr
<InputDevice
> > scanForDevices(Gui
*gui
);
130 // Although the value is only set when using a touchscreen, it takes up little
131 // memory to initialize a pointer to avoid lots of messy ifdefs.
132 struct tsdev
*_tsDev
;
135 class EventDevice
: public InputDevice
139 EventDevice(Gui
*gui
);
141 virtual bool init(const std::string
&filespec
, size_t size
);
142 virtual bool check();
144 gnash::key::code
scancode_to_gnash_key(int code
, bool shift
);
146 // This looks for all the input event devices.
147 static std::vector
<boost::shared_ptr
<InputDevice
> > scanForDevices(Gui
*gui
);
150 // Keyboard SHIFT/CTRL/ALT states (left + right)
151 bool keyb_lshift
, keyb_rshift
, keyb_lctrl
, keyb_rctrl
, keyb_lalt
, keyb_ralt
;
152 struct input_id _device_info
;
155 } // end of gnash namespace
157 // end of GNASH_INPUTDEVICE_H
162 // indent-tabs-mode: nil