Diffstat (limited to 'libopie2/opiecore/oinputsystem.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiecore/oinputsystem.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp index d1a28f5..a2306ca 100644 --- a/libopie2/opiecore/oinputsystem.cpp +++ b/libopie2/opiecore/oinputsystem.cpp | |||
@@ -21,60 +21,73 @@ | |||
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 <qdir.h> | ||
33 | #include <qfile.h> | 34 | #include <qfile.h> |
34 | 35 | ||
35 | /* STD */ | 36 | /* STD */ |
36 | #include <errno.h> | 37 | #include <errno.h> |
37 | #include <string.h> | 38 | #include <string.h> |
38 | #include <sys/fcntl.h> | 39 | #include <sys/fcntl.h> |
39 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
41 | #include <unistd.h> | ||
40 | 42 | ||
41 | #define BUFSIZE 256 | 43 | #define BUFSIZE 256 |
42 | #define BIT_MASK( name, numbits ) \ | 44 | #define BIT_MASK( name, numbits ) \ |
43 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | 45 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ |
44 | memset( name, 0, sizeof( name ) ) | 46 | memset( name, 0, sizeof( name ) ) |
45 | #define BIT_TEST( bitmask, bit ) \ | 47 | #define BIT_TEST( bitmask, bit ) \ |
46 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | 48 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) |
47 | 49 | ||
48 | /*====================================================================================== | 50 | /*====================================================================================== |
49 | * OInputSystem | 51 | * OInputSystem |
50 | *======================================================================================*/ | 52 | *======================================================================================*/ |
51 | 53 | ||
52 | OInputSystem* OInputSystem::_instance = 0; | 54 | OInputSystem* OInputSystem::_instance = 0; |
53 | 55 | ||
54 | OInputSystem::OInputSystem() : QObject() | 56 | OInputSystem::OInputSystem() : QObject() |
55 | { | 57 | { |
56 | qDebug( "OInputSystem::OInputSystem()" ); | 58 | qDebug( "OInputSystem::OInputSystem()" ); |
57 | synchronize(); | 59 | synchronize(); |
58 | } | 60 | } |
59 | 61 | ||
60 | 62 | ||
61 | void OInputSystem::synchronize() | 63 | void OInputSystem::synchronize() |
62 | { | 64 | { |
63 | qDebug( "OInputSystem::synchronize()" ); | 65 | qDebug( "OInputSystem::synchronize()" ); |
64 | if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) ); | 66 | QDir devInput( "/dev/input/" ); |
65 | if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) ); | 67 | if ( devInput.exists() ) |
66 | if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) ); | 68 | { |
67 | if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) ); | 69 | QStringList devInputFiles = devInput.entryList( QDir::System, QDir::Name ); |
70 | for ( QStringList::Iterator it = devInputFiles.begin(); it != devInputFiles.end(); ++it ) | ||
71 | { | ||
72 | QString absPath = devInput.absFilePath( *it ); | ||
73 | bool isValid = OInputDevice::isValid( absPath ); | ||
74 | qDebug( "OInputSystem::synchronize() - checking if '%s' is a valid input system node... '%s'", | ||
75 | (const char*) absPath, isValid ? "yes" : "no" ); | ||
76 | if ( isValid ) _devices.insert( *it, new OInputDevice( this, absPath ) ); | ||
77 | } | ||
78 | } | ||
68 | qDebug( "OInputSystem::synchronize() done" ); | 79 | qDebug( "OInputSystem::synchronize() done" ); |
80 | if ( !_devices.count() ) | ||
81 | qWarning( "OInputSystem::no devices found" ); | ||
69 | } | 82 | } |
70 | 83 | ||
71 | 84 | ||
72 | OInputSystem::~OInputSystem() | 85 | OInputSystem::~OInputSystem() |
73 | { | 86 | { |
74 | qDebug( "OInputSystem::~OInputSystem()" ); | 87 | qDebug( "OInputSystem::~OInputSystem()" ); |
75 | } | 88 | } |
76 | 89 | ||
77 | 90 | ||
78 | int OInputSystem::count() const | 91 | int OInputSystem::count() const |
79 | { | 92 | { |
80 | return _devices.count(); | 93 | return _devices.count(); |
@@ -186,12 +199,23 @@ QString OInputDevice::globalKeyMask() const | |||
186 | else | 199 | else |
187 | { | 200 | { |
188 | QString keymask; | 201 | QString keymask; |
189 | for ( int i = 0; i < KEY_MAX; ++i ) | 202 | for ( int i = 0; i < KEY_MAX; ++i ) |
190 | { | 203 | { |
191 | if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) ); | 204 | if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) ); |
192 | } | 205 | } |
193 | return keymask; | 206 | return keymask; |
194 | 207 | ||
195 | } | 208 | } |
196 | } | 209 | } |
197 | 210 | ||
211 | |||
212 | bool OInputDevice::isValid( const QString& path ) | ||
213 | { | ||
214 | char buf[BUFSIZE] = "<unknown>"; | ||
215 | int fd = ::open( (const char*) path, O_RDONLY ); | ||
216 | if ( fd < 0 ) return false; | ||
217 | int res = ::ioctl( fd, EVIOCGNAME(sizeof buf), buf ); | ||
218 | ::close( fd ); | ||
219 | return res >= 0; | ||
220 | } | ||
221 | |||