Diffstat (limited to 'libopie2/opiecore/oinputsystem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oinputsystem.cpp | 38 |
1 files changed, 31 insertions, 7 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 | |||
@@ -32,2 +32,3 @@ using namespace Opie::Core; | |||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qdir.h> | ||
33 | #include <qfile.h> | 34 | #include <qfile.h> |
@@ -39,2 +40,3 @@ using namespace Opie::Core; | |||
39 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
41 | #include <unistd.h> | ||
40 | 42 | ||
@@ -63,7 +65,18 @@ void OInputSystem::synchronize() | |||
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 | } |
@@ -108,3 +121,3 @@ OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( paren | |||
108 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); | 121 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); |
109 | 122 | ||
110 | _fd = ::open( name, O_RDONLY ); | 123 | _fd = ::open( name, O_RDONLY ); |
@@ -150,3 +163,3 @@ bool OInputDevice::hasFeature( Feature bit ) const | |||
150 | BIT_MASK( features, EV_MAX ); | 163 | BIT_MASK( features, EV_MAX ); |
151 | 164 | ||
152 | if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) | 165 | if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) |
@@ -193,3 +206,3 @@ QString OInputDevice::globalKeyMask() const | |||
193 | return keymask; | 206 | return keymask; |
194 | 207 | ||
195 | } | 208 | } |
@@ -197 +210,12 @@ QString OInputDevice::globalKeyMask() const | |||
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 | |||