summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oinputsystem.cpp25
-rw-r--r--libopie2/opiecore/oinputsystem.h27
2 files changed, 49 insertions, 3 deletions
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/oinputsystem.cpp
index 29de35c..d1a28f5 100644
--- a/libopie2/opiecore/oinputsystem.cpp
+++ b/libopie2/opiecore/oinputsystem.cpp
@@ -57,116 +57,141 @@ OInputSystem::OInputSystem() : QObject()
57 synchronize(); 57 synchronize();
58} 58}
59 59
60 60
61void OInputSystem::synchronize() 61void OInputSystem::synchronize()
62{ 62{
63 qDebug( "OInputSystem::synchronize()" ); 63 qDebug( "OInputSystem::synchronize()" );
64 if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) ); 64 if ( QFile::exists( "/dev/input/event0" ) ) _devices.insert( "0", new OInputDevice( this, "/dev/input/event0" ) );
65 if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) ); 65 if ( QFile::exists( "/dev/input/event1" ) ) _devices.insert( "1", new OInputDevice( this, "/dev/input/event1" ) );
66 if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) ); 66 if ( QFile::exists( "/dev/input/event2" ) ) _devices.insert( "2", new OInputDevice( this, "/dev/input/event2" ) );
67 if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) ); 67 if ( QFile::exists( "/dev/input/event3" ) ) _devices.insert( "3", new OInputDevice( this, "/dev/input/event3" ) );
68 qDebug( "OInputSystem::synchronize() done" ); 68 qDebug( "OInputSystem::synchronize() done" );
69} 69}
70 70
71 71
72OInputSystem::~OInputSystem() 72OInputSystem::~OInputSystem()
73{ 73{
74 qDebug( "OInputSystem::~OInputSystem()" ); 74 qDebug( "OInputSystem::~OInputSystem()" );
75} 75}
76 76
77 77
78int OInputSystem::count() const 78int OInputSystem::count() const
79{ 79{
80 return _devices.count(); 80 return _devices.count();
81} 81}
82 82
83 83
84OInputDevice* OInputSystem::device( const QString& device ) const 84OInputDevice* OInputSystem::device( const QString& device ) const
85{ 85{
86 return _devices[device]; 86 return _devices[device];
87} 87}
88 88
89 89
90OInputSystem* OInputSystem::instance() 90OInputSystem* OInputSystem::instance()
91{ 91{
92 if ( !_instance ) _instance = new OInputSystem(); 92 if ( !_instance ) _instance = new OInputSystem();
93 return _instance; 93 return _instance;
94} 94}
95 95
96 96
97OInputSystem::DeviceIterator OInputSystem::iterator() const 97OInputSystem::DeviceIterator OInputSystem::iterator() const
98{ 98{
99 return OInputSystem::DeviceIterator( _devices ); 99 return OInputSystem::DeviceIterator( _devices );
100} 100}
101 101
102/*====================================================================================== 102/*======================================================================================
103 * OInputDevice 103 * OInputDevice
104 *======================================================================================*/ 104 *======================================================================================*/
105 105
106OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) 106OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name )
107{ 107{
108 qDebug( "OInputDevice::OInputDevice( '%s' )", name ); 108 qDebug( "OInputDevice::OInputDevice( '%s' )", name );
109 109
110 _fd = ::open( name, O_RDONLY ); 110 _fd = ::open( name, O_RDONLY );
111 if ( _fd == -1 ) 111 if ( _fd == -1 )
112 { 112 {
113 qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); 113 qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) );
114 } 114 }
115} 115}
116 116
117 117
118OInputDevice::~OInputDevice() 118OInputDevice::~OInputDevice()
119{ 119{
120 qDebug( "OInputDevice::~OInputDevice()" ); 120 qDebug( "OInputDevice::~OInputDevice()" );
121} 121}
122 122
123 123
124QString OInputDevice::identity() const 124QString OInputDevice::identity() const
125{ 125{
126 char buf[BUFSIZE] = "<unknown>"; 126 char buf[BUFSIZE] = "<unknown>";
127 ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); 127 ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf );
128 return buf; 128 return buf;
129} 129}
130 130
131 131
132QString OInputDevice::path() const 132QString OInputDevice::path() const
133{ 133{
134 char buf[BUFSIZE] = "<unknown>"; 134 char buf[BUFSIZE] = "<unknown>";
135 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); 135 ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf );
136 return buf; 136 return buf;
137} 137}
138 138
139 139
140QString OInputDevice::uniq() const 140QString OInputDevice::uniq() const
141{ 141{
142 char buf[BUFSIZE] = "<unknown>"; 142 char buf[BUFSIZE] = "<unknown>";
143 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); 143 ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf );
144 return buf; 144 return buf;
145} 145}
146 146
147 147
148bool OInputDevice::hasFeature( Feature bit ) const 148bool OInputDevice::hasFeature( Feature bit ) const
149{ 149{
150 BIT_MASK( features, EV_MAX ); 150 BIT_MASK( features, EV_MAX );
151 151
152 if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) 152 if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 )
153 {
154 perror( "EVIOCGBIT" );
153 return false; 155 return false;
156 }
154 else 157 else
155 return BIT_TEST( features, bit ); 158 return BIT_TEST( features, bit );
156} 159}
157 160
158 161
159bool OInputDevice::isHeld( Key bit ) const 162bool OInputDevice::isHeld( Key bit ) const
160{ 163{
161 BIT_MASK( keys, KEY_MAX ); 164 BIT_MASK( keys, KEY_MAX );
162 165
163 if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) 166 if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 )
164 { 167 {
165 perror( "EVIOCGKEY" ); 168 perror( "EVIOCGKEY" );
166 return false; 169 return false;
167 } 170 }
168 else 171 else
169 { 172 {
170 return BIT_TEST( keys, bit ); 173 return BIT_TEST( keys, bit );
171 } 174 }
172} 175}
176
177
178QString OInputDevice::globalKeyMask() const
179{
180 BIT_MASK( keys, KEY_MAX );
181
182 if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 )
183 {
184 perror( "EVIOCGKEY" );
185 }
186 else
187 {
188 QString keymask;
189 for ( int i = 0; i < KEY_MAX; ++i )
190 {
191 if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) );
192 }
193 return keymask;
194
195 }
196}
197
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/oinputsystem.h
index 9020bc1..7919610 100644
--- a/libopie2/opiecore/oinputsystem.h
+++ b/libopie2/opiecore/oinputsystem.h
@@ -1,116 +1,137 @@
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#include "linux_input.h" 32#include "linux_input.h"
33 33
34/* QT */ 34/* QT */
35#include <qobject.h> 35#include <qobject.h>
36#include <qdict.h> 36#include <qdict.h>
37 37
38namespace Opie { 38namespace Opie {
39namespace Core { 39namespace Core {
40 40
41class OInputDevice; 41class OInputDevice;
42 42
43/** 43/**
44 * @brief A container class for all input devices 44 * @brief A container class for all input devices
45 * 45 *
46 * This class provides access to all available input system devices of your computer. 46 * This class provides access to all available input system devices of your computer.
47 * 47 *
48 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 48 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
49 */ 49 */
50class OInputSystem : public QObject 50class OInputSystem : public QObject
51{ 51{
52 public: 52 public:
53 typedef QDict<OInputDevice> DeviceMap; 53 typedef QDict<OInputDevice> DeviceMap;
54 typedef QDictIterator<OInputDevice> DeviceIterator; 54 typedef QDictIterator<OInputDevice> DeviceIterator;
55 55
56 /** 56 /**
57 * @returns the number of available input devices 57 * @returns the number of available input devices
58 */ 58 */
59 int count() const; 59 int count() const;
60 /** 60 /**
61 * @returns a pointer to the (one and only) @ref OInputSystem instance. 61 * @returns a pointer to the (one and only) @ref OInputSystem instance.
62 */ 62 */
63 static OInputSystem* instance(); 63 static OInputSystem* instance();
64 /** 64 /**
65 * @returns an iterator usable for iterating through all network interfaces. 65 * @returns an iterator usable for iterating through all network interfaces.
66 */ 66 */
67 DeviceIterator iterator() const; 67 DeviceIterator iterator() const;
68 /** 68 /**
69 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found 69 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
70 * @see OAudioInterface 70 * @see OAudioInterface
71 */ 71 */
72 OInputDevice* device( const QString& interface ) const; 72 OInputDevice* device( const QString& interface ) const;
73 /** 73 /**
74 * @internal Rebuild the internal interface database 74 * @internal Rebuild the internal interface database
75 * @note Sometimes it might be useful to call this from client code, 75 * @note Sometimes it might be useful to call this from client code,
76 */ 76 */
77 void synchronize(); 77 void synchronize();
78 /** 78 /**
79 * @internal desctructor 79 * @internal destructor
80 */ 80 */
81 ~OInputSystem(); 81 ~OInputSystem();
82 82
83 protected: 83 protected:
84 OInputSystem(); 84 OInputSystem();
85 85
86 static OInputSystem* _instance; 86 static OInputSystem* _instance;
87 DeviceMap _devices; 87 DeviceMap _devices;
88}; 88};
89 89
90 90
91class OInputDevice : public QObject 91class OInputDevice : public QObject
92{ 92{
93 public: 93 public:
94 OInputDevice( QObject* parent, const char* name = 0 ); 94 OInputDevice( QObject* parent, const char* name = 0 );
95 ~OInputDevice(); 95 ~OInputDevice();
96 96
97 #include "oinputsystemenums.h" 97 #include "oinputsystemenums.h"
98 98
99 public: 99 public:
100 /**
101 * @returns the identity string of this input device
102 */
100 QString identity() const; 103 QString identity() const;
104 /**
105 * @returns the path of this input device
106 */
101 QString path() const; 107 QString path() const;
108 /**
109 * @returns a unique identifier for this input device
110 * @note Only a few devices support this
111 */
102 QString uniq() const; 112 QString uniq() const;
103 bool hasFeature( Feature ) const; 113 /**
104 bool isHeld( Key ) const; 114 * @returns whether a certain @a Feature is being supported by this device
115 */
116 bool hasFeature( Feature ) const;
117 /**
118 * @returns whether a given @a Key or Button is being held at the moment
119 */
120 bool isHeld( Key ) const;
121 /**
122 * @internal
123 * @returns a string containing a printable form of the global keymask
124 */
125 QString globalKeyMask() const;
105 126
106 private: 127 private:
107 int _fd; 128 int _fd;
108 input_id _id; 129 input_id _id;
109 130
110}; 131};
111 132
112} 133}
113} 134}
114 135
115#endif // OINPUTSYSTEM_H 136#endif // OINPUTSYSTEM_H
116 137