author | mickeyl <mickeyl> | 2005-02-02 16:37:12 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-02-02 16:37:12 (UTC) |
commit | 8ea35f618c5811b59f4460d0f2198b9818db281e (patch) (unidiff) | |
tree | 0ef5a73e14c9b236dde77cb866401ab0ad3a103f /libopie2 | |
parent | 896b1f8f0855feec3bb6cb9944c5f7a7b2d6cd1f (diff) | |
download | opie-8ea35f618c5811b59f4460d0f2198b9818db281e.zip opie-8ea35f618c5811b59f4460d0f2198b9818db281e.tar.gz opie-8ea35f618c5811b59f4460d0f2198b9818db281e.tar.bz2 |
more input system stuff
-rw-r--r-- | libopie2/opiecore/oinputsystem.cpp | 17 | ||||
-rw-r--r-- | libopie2/opiecore/oinputsystem.h | 7 |
2 files changed, 20 insertions, 4 deletions
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp index bfdc31f..fde36c3 100644 --- a/libopie2/opiecore/oinputsystem.cpp +++ b/libopie2/opiecore/oinputsystem.cpp | |||
@@ -1,142 +1,157 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "oinputsystem.h" | 29 | #include "oinputsystem.h" |
30 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | 34 | ||
35 | /* STD */ | 35 | /* STD */ |
36 | #include <errno.h> | 36 | #include <errno.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <linux/input.h> | 38 | #include <linux/input.h> |
39 | #include <sys/fcntl.h> | 39 | #include <sys/fcntl.h> |
40 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
41 | 41 | ||
42 | #define BUFSIZE 256 | 42 | #define BUFSIZE 256 |
43 | #define BIT_MASK( name, numbits ) \ | ||
44 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | ||
45 | memset( name, 0, sizeof( name ) ) | ||
46 | #define BIT_TEST( bitmask, bit ) \ | ||
47 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | ||
43 | 48 | ||
44 | /*====================================================================================== | 49 | /*====================================================================================== |
45 | * OInputSystem | 50 | * OInputSystem |
46 | *======================================================================================*/ | 51 | *======================================================================================*/ |
47 | 52 | ||
48 | OInputSystem* OInputSystem::_instance = 0; | 53 | OInputSystem* OInputSystem::_instance = 0; |
49 | 54 | ||
50 | OInputSystem::OInputSystem() : QObject() | 55 | OInputSystem::OInputSystem() : QObject() |
51 | { | 56 | { |
52 | qDebug( "OInputSystem::OInputSystem()" ); | 57 | qDebug( "OInputSystem::OInputSystem()" ); |
53 | synchronize(); | 58 | synchronize(); |
54 | } | 59 | } |
55 | 60 | ||
56 | 61 | ||
57 | void OInputSystem::synchronize() | 62 | void OInputSystem::synchronize() |
58 | { | 63 | { |
59 | qDebug( "OInputSystem::synchronize()" ); | 64 | qDebug( "OInputSystem::synchronize()" ); |
60 | if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) ); | 65 | if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) ); |
61 | if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) ); | 66 | if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) ); |
62 | if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) ); | 67 | if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) ); |
63 | if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) ); | 68 | if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) ); |
64 | qDebug( "OInputSystem::synchronize() done" ); | 69 | qDebug( "OInputSystem::synchronize() done" ); |
65 | } | 70 | } |
66 | 71 | ||
67 | 72 | ||
68 | OInputSystem::~OInputSystem() | 73 | OInputSystem::~OInputSystem() |
69 | { | 74 | { |
70 | qDebug( "OInputSystem::~OInputSystem()" ); | 75 | qDebug( "OInputSystem::~OInputSystem()" ); |
71 | } | 76 | } |
72 | 77 | ||
73 | 78 | ||
74 | int OInputSystem::count() const | 79 | int OInputSystem::count() const |
75 | { | 80 | { |
76 | return _devices.count(); | 81 | return _devices.count(); |
77 | } | 82 | } |
78 | 83 | ||
79 | 84 | ||
80 | OInputDevice* OInputSystem::device( const QString& device ) const | 85 | OInputDevice* OInputSystem::device( const QString& device ) const |
81 | { | 86 | { |
82 | return _devices[device]; | 87 | return _devices[device]; |
83 | } | 88 | } |
84 | 89 | ||
85 | 90 | ||
86 | OInputSystem* OInputSystem::instance() | 91 | OInputSystem* OInputSystem::instance() |
87 | { | 92 | { |
88 | if ( !_instance ) _instance = new OInputSystem(); | 93 | if ( !_instance ) _instance = new OInputSystem(); |
89 | return _instance; | 94 | return _instance; |
90 | } | 95 | } |
91 | 96 | ||
92 | 97 | ||
93 | OInputSystem::DeviceIterator OInputSystem::iterator() const | 98 | OInputSystem::DeviceIterator OInputSystem::iterator() const |
94 | { | 99 | { |
95 | return OInputSystem::DeviceIterator( _devices ); | 100 | return OInputSystem::DeviceIterator( _devices ); |
96 | } | 101 | } |
97 | 102 | ||
98 | /*====================================================================================== | 103 | /*====================================================================================== |
99 | * OInputDevice | 104 | * OInputDevice |
100 | *======================================================================================*/ | 105 | *======================================================================================*/ |
101 | 106 | ||
102 | OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) | 107 | OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) |
103 | { | 108 | { |
104 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); | 109 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); |
105 | 110 | ||
106 | _fd = ::open( name, O_RDONLY ); | 111 | _fd = ::open( name, O_RDONLY ); |
107 | if ( _fd == -1 ) | 112 | if ( _fd == -1 ) |
108 | { | 113 | { |
109 | qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); | 114 | qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); |
110 | } | 115 | } |
111 | } | 116 | } |
112 | 117 | ||
113 | 118 | ||
114 | OInputDevice::~OInputDevice() | 119 | OInputDevice::~OInputDevice() |
115 | { | 120 | { |
116 | qDebug( "OInputDevice::~OInputDevice()" ); | 121 | qDebug( "OInputDevice::~OInputDevice()" ); |
117 | } | 122 | } |
118 | 123 | ||
119 | 124 | ||
120 | QString OInputDevice::identity() const | 125 | QString OInputDevice::identity() const |
121 | { | 126 | { |
122 | char buf[BUFSIZE] = "<unknown>"; | 127 | char buf[BUFSIZE] = "<unknown>"; |
123 | ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); | 128 | ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); |
124 | return buf; | 129 | return buf; |
125 | } | 130 | } |
126 | 131 | ||
127 | 132 | ||
128 | QString OInputDevice::path() const | 133 | QString OInputDevice::path() const |
129 | { | 134 | { |
130 | char buf[BUFSIZE] = "<unknown>"; | 135 | char buf[BUFSIZE] = "<unknown>"; |
131 | ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); | 136 | ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); |
132 | return buf; | 137 | return buf; |
133 | } | 138 | } |
134 | 139 | ||
135 | 140 | ||
136 | QString OInputDevice::uniq() const | 141 | QString OInputDevice::uniq() const |
137 | { | 142 | { |
138 | char buf[BUFSIZE] = "<unknown>"; | 143 | char buf[BUFSIZE] = "<unknown>"; |
139 | ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); | 144 | ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); |
140 | return buf; | 145 | return buf; |
141 | } | 146 | } |
142 | 147 | ||
148 | bool OInputDevice::hasFeature( Feature bit ) const | ||
149 | { | ||
150 | BIT_MASK( features, EV_MAX ); | ||
151 | |||
152 | if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) | ||
153 | return false; | ||
154 | else | ||
155 | return BIT_TEST( features, bit ); | ||
156 | } | ||
157 | |||
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/oinputsystem.h index 350656b..4d913a1 100644 --- a/libopie2/opiecore/oinputsystem.h +++ b/libopie2/opiecore/oinputsystem.h | |||
@@ -1,148 +1,149 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef OINPUTSYSTEM_H | 29 | #ifndef OINPUTSYSTEM_H |
30 | #define OINPUTSYSTEM_H | 30 | #define OINPUTSYSTEM_H |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qobject.h> | 33 | #include <qobject.h> |
34 | #include <qdict.h> | 34 | #include <qdict.h> |
35 | 35 | ||
36 | /* STD */ | 36 | /* STD */ |
37 | #include <linux/input.h> | 37 | #include <linux/input.h> |
38 | 38 | ||
39 | namespace Opie { | 39 | namespace Opie { |
40 | namespace Core { | 40 | namespace Core { |
41 | 41 | ||
42 | class OInputDevice; | 42 | class OInputDevice; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * @brief A container class for all input devices | 45 | * @brief A container class for all input devices |
46 | * | 46 | * |
47 | * This class provides access to all available input system devices of your computer. | 47 | * This class provides access to all available input system devices of your computer. |
48 | * | 48 | * |
49 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 49 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
50 | */ | 50 | */ |
51 | class OInputSystem : public QObject | 51 | class OInputSystem : public QObject |
52 | { | 52 | { |
53 | public: | 53 | public: |
54 | typedef QDict<OInputDevice> DeviceMap; | 54 | typedef QDict<OInputDevice> DeviceMap; |
55 | typedef QDictIterator<OInputDevice> DeviceIterator; | 55 | typedef QDictIterator<OInputDevice> DeviceIterator; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * @returns the number of available input devices | 58 | * @returns the number of available input devices |
59 | */ | 59 | */ |
60 | int count() const; | 60 | int count() const; |
61 | /** | 61 | /** |
62 | * @returns a pointer to the (one and only) @ref OInputSystem instance. | 62 | * @returns a pointer to the (one and only) @ref OInputSystem instance. |
63 | */ | 63 | */ |
64 | static OInputSystem* instance(); | 64 | static OInputSystem* instance(); |
65 | /** | 65 | /** |
66 | * @returns an iterator usable for iterating through all network interfaces. | 66 | * @returns an iterator usable for iterating through all network interfaces. |
67 | */ | 67 | */ |
68 | DeviceIterator iterator() const; | 68 | DeviceIterator iterator() const; |
69 | /** | 69 | /** |
70 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 70 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found |
71 | * @see OAudioInterface | 71 | * @see OAudioInterface |
72 | */ | 72 | */ |
73 | OInputDevice* device( const QString& interface ) const; | 73 | OInputDevice* device( const QString& interface ) const; |
74 | /** | 74 | /** |
75 | * @internal Rebuild the internal interface database | 75 | * @internal Rebuild the internal interface database |
76 | * @note Sometimes it might be useful to call this from client code, | 76 | * @note Sometimes it might be useful to call this from client code, |
77 | */ | 77 | */ |
78 | void synchronize(); | 78 | void synchronize(); |
79 | /** | 79 | /** |
80 | * @internal desctructor | 80 | * @internal desctructor |
81 | */ | 81 | */ |
82 | ~OInputSystem(); | 82 | ~OInputSystem(); |
83 | 83 | ||
84 | protected: | 84 | protected: |
85 | OInputSystem(); | 85 | OInputSystem(); |
86 | 86 | ||
87 | static OInputSystem* _instance; | 87 | static OInputSystem* _instance; |
88 | DeviceMap _devices; | 88 | DeviceMap _devices; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | class OInputDevice : public QObject | 92 | class OInputDevice : public QObject |
93 | { | 93 | { |
94 | public: | 94 | public: |
95 | 95 | ||
96 | enum EventType | 96 | enum Feature |
97 | { | 97 | { |
98 | Synchronous = EV_SYN, | 98 | Synchronous = EV_SYN, |
99 | Keyboard = EV_KEY, | 99 | Keys = EV_KEY, |
100 | Relative = EV_REL, | 100 | Relative = EV_REL, |
101 | Absolute = EV_ABS, | 101 | Absolute = EV_ABS, |
102 | Miscellaneous = EV_MSC, | 102 | Miscellaneous = EV_MSC, |
103 | Led = EV_LED, | 103 | Leds = EV_LED, |
104 | Sound = EV_SND, | 104 | Sound = EV_SND, |
105 | AutoRepeat = EV_REP, | 105 | AutoRepeat = EV_REP, |
106 | ForceFeedback = EV_FF, | 106 | ForceFeedback = EV_FF, |
107 | PowerManagement = EV_PWR, | 107 | PowerManagement = EV_PWR, |
108 | ForceFeedbackStatus = EV_FF_STATUS, | 108 | ForceFeedbackStatus = EV_FF_STATUS, |
109 | }; | 109 | }; |
110 | 110 | ||
111 | enum Bus | 111 | enum Bus |
112 | { | 112 | { |
113 | PCI = BUS_PCI, | 113 | PCI = BUS_PCI, |
114 | ISAPNP = BUS_ISAPNP, | 114 | ISAPNP = BUS_ISAPNP, |
115 | HIL = BUS_HIL, | 115 | HIL = BUS_HIL, |
116 | BLUETOOTH = BUS_BLUETOOTH, | 116 | BLUETOOTH = BUS_BLUETOOTH, |
117 | ISA = BUS_ISA, | 117 | ISA = BUS_ISA, |
118 | I8042 = BUS_I8042, | 118 | I8042 = BUS_I8042, |
119 | XTKBD = BUS_XTKBD, | 119 | XTKBD = BUS_XTKBD, |
120 | RS232 = BUS_RS232, | 120 | RS232 = BUS_RS232, |
121 | GAMEPORT = BUS_GAMEPORT, | 121 | GAMEPORT = BUS_GAMEPORT, |
122 | PARPORT = BUS_PARPORT, | 122 | PARPORT = BUS_PARPORT, |
123 | AMIGA = BUS_AMIGA, | 123 | AMIGA = BUS_AMIGA, |
124 | ADB = BUS_ADB, | 124 | ADB = BUS_ADB, |
125 | I2C = BUS_I2C, | 125 | I2C = BUS_I2C, |
126 | HOST = BUS_HOST, | 126 | HOST = BUS_HOST, |
127 | }; | 127 | }; |
128 | 128 | ||
129 | public: | 129 | public: |
130 | OInputDevice( QObject* parent, const char* name = 0 ); | 130 | OInputDevice( QObject* parent, const char* name = 0 ); |
131 | ~OInputDevice(); | 131 | ~OInputDevice(); |
132 | 132 | ||
133 | public: | 133 | public: |
134 | QString identity() const; | 134 | QString identity() const; |
135 | QString path() const; | 135 | QString path() const; |
136 | QString uniq() const; | 136 | QString uniq() const; |
137 | bool hasFeature( Feature ) const; | ||
137 | 138 | ||
138 | private: | 139 | private: |
139 | int _fd; | 140 | int _fd; |
140 | input_id _id; | 141 | input_id _id; |
141 | 142 | ||
142 | }; | 143 | }; |
143 | 144 | ||
144 | } | 145 | } |
145 | } | 146 | } |
146 | 147 | ||
147 | #endif // OINPUTSYSTEM_H | 148 | #endif // OINPUTSYSTEM_H |
148 | 149 | ||