Qt 4.8
Public Functions | Private Slots | Private Functions | Properties | List of all members
QWSLinuxInputKbPrivate Class Reference
Inheritance diagram for QWSLinuxInputKbPrivate:
QObject

Public Functions

 QWSLinuxInputKbPrivate (QWSLinuxInputKeyboardHandler *, const QString &)
 
 ~QWSLinuxInputKbPrivate ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void readKeycode ()
 

Private Functions

void switchLed (int, bool)
 

Properties

int m_fd
 
QWSLinuxInputKeyboardHandlerm_handler
 
int m_orig_kbmode
 
struct termios m_tty_attr
 
int m_tty_fd
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 61 of file qkbdlinuxinput_qws.cpp.

Constructors and Destructors

◆ QWSLinuxInputKbPrivate()

QWSLinuxInputKbPrivate::QWSLinuxInputKbPrivate ( QWSLinuxInputKeyboardHandler h,
const QString device 
)

Definition at line 98 of file qkbdlinuxinput_qws.cpp.

99  : m_handler(h), m_fd(-1), m_tty_fd(-1), m_orig_kbmode(K_XLATE)
100 {
101  setObjectName(QLatin1String("LinuxInputSubsystem Keyboard Handler"));
102 
103  QString dev = QLatin1String("/dev/input/event1");
104  int repeat_delay = -1;
105  int repeat_rate = -1;
106  int grab = 0;
107 
108  QStringList args = device.split(QLatin1Char(':'));
109  foreach (const QString &arg, args) {
110  if (arg.startsWith(QLatin1String("repeat-delay=")))
111  repeat_delay = arg.mid(13).toInt();
112  else if (arg.startsWith(QLatin1String("repeat-rate=")))
113  repeat_rate = arg.mid(12).toInt();
114  else if (arg.startsWith(QLatin1String("grab=")))
115  grab = arg.mid(5).toInt();
116  else if (arg.startsWith(QLatin1String("/dev/")))
117  dev = arg;
118  }
119 
120  m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0);
121  if (m_fd >= 0) {
122  ::ioctl(m_fd, EVIOCGRAB, grab);
123  if (repeat_delay > 0 && repeat_rate > 0) {
124  int kbdrep[2] = { repeat_delay, repeat_rate };
125  ::ioctl(m_fd, EVIOCSREP, kbdrep);
126  }
127 
128  QSocketNotifier *notifier;
129  notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
130  connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode()));
131 
132  // play nice in case we are started from a shell (e.g. for debugging)
133  m_tty_fd = isatty(0) ? 0 : -1;
134 
135  if (m_tty_fd >= 0) {
136  // save tty config for restore.
137  tcgetattr(m_tty_fd, &m_tty_attr);
138 
139  struct ::termios termdata;
140  tcgetattr(m_tty_fd, &termdata);
141 
142  // record the original mode so we can restore it again in the destructor.
143  ::ioctl(m_tty_fd, KDGKBMODE, &m_orig_kbmode);
144 
145  // setting this translation mode is even needed in INPUT mode to prevent
146  // the shell from also interpreting codes, if the process has a tty
147  // attached: e.g. Ctrl+C wouldn't copy, but kill the application.
148  ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW);
149 
150  // set the tty layer to pass-through
151  termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
152  termdata.c_oflag = 0;
153  termdata.c_cflag = CREAD | CS8;
154  termdata.c_lflag = 0;
155  termdata.c_cc[VTIME]=0;
156  termdata.c_cc[VMIN]=1;
157  cfsetispeed(&termdata, 9600);
158  cfsetospeed(&termdata, 9600);
159  tcsetattr(m_tty_fd, TCSANOW, &termdata);
160  }
161  } else {
162  qWarning("Cannot open keyboard input device '%s': %s", qPrintable(dev), strerror(errno));
163  return;
164  }
165 }
QWSLinuxInputKeyboardHandler * m_handler
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
#define SLOT(a)
Definition: qobjectdefs.h:226
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
#define QT_OPEN
Definition: qcore_unix_p.h:186
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
#define qPrintable(string)
Definition: qglobal.h:1750
#define O_RDWR
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int errno

◆ ~QWSLinuxInputKbPrivate()

QWSLinuxInputKbPrivate::~QWSLinuxInputKbPrivate ( )

Definition at line 167 of file qkbdlinuxinput_qws.cpp.

168 {
169  if (m_tty_fd >= 0) {
170  ::ioctl(m_tty_fd, KDSKBMODE, m_orig_kbmode);
171  tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr);
172  }
173  if (m_fd >= 0)
174  QT_CLOSE(m_fd);
175 }
#define QT_CLOSE
Definition: qcore_unix_p.h:304

Functions

◆ readKeycode

void QWSLinuxInputKbPrivate::readKeycode ( )
privateslot

Definition at line 188 of file qkbdlinuxinput_qws.cpp.

Referenced by QWSLinuxInputKbPrivate().

189 {
190  struct ::input_event buffer[32];
191  int n = 0;
192 
193  forever {
194  n = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);
195 
196  if (n == 0) {
197  qWarning("Got EOF from the input device.");
198  return;
199  } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) {
200  qWarning("Could not read from input device: %s", strerror(errno));
201  return;
202  } else if (n % sizeof(buffer[0]) == 0) {
203  break;
204  }
205  }
206 
207  n /= sizeof(buffer[0]);
208 
209  for (int i = 0; i < n; ++i) {
210  if (buffer[i].type != EV_KEY)
211  continue;
212 
213  quint16 code = buffer[i].code;
214  qint32 value = buffer[i].value;
215 
216  if (m_handler->filterInputEvent(code, value))
217  continue;
218 
220  ka = m_handler->processKeycode(code, value != 0, value == 2);
221 
222  switch (ka) {
225  switchLed(LED_CAPSL, ka == QWSKeyboardHandler::CapsLockOn);
226  break;
227 
230  switchLed(LED_NUML, ka == QWSKeyboardHandler::NumLockOn);
231  break;
232 
235  switchLed(LED_SCROLLL, ka == QWSKeyboardHandler::ScrollLockOn);
236  break;
237 
238  default:
239  // ignore console switching and reboot
240  break;
241  }
242  }
243 }
int type
Definition: qmetatype.cpp:239
QWSLinuxInputKeyboardHandler * m_handler
int qint32
Definition: qglobal.h:937
#define QT_READ
Definition: qcore_unix_p.h:280
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
virtual bool filterInputEvent(quint16 &input_code, qint32 &input_value)
KeycodeAction
This enum describes the various special actions that actual QWSKeyboardHandler implementations have t...
Definition: qkbd_qws.h:67
KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat)
Maps keycode according to a keymap and sends that key event to the Qt for Embedded Linux server appli...
Definition: qkbd_qws.cpp:521
int errno
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ switchLed()

void QWSLinuxInputKbPrivate::switchLed ( int  led,
bool  state 
)
private

Definition at line 177 of file qkbdlinuxinput_qws.cpp.

Referenced by readKeycode().

178 {
179  struct ::input_event led_ie;
180  ::gettimeofday(&led_ie.time, 0);
181  led_ie.type = EV_LED;
182  led_ie.code = led;
183  led_ie.value = state;
184 
185  QT_WRITE(m_fd, &led_ie, sizeof(led_ie));
186 }
#define QT_WRITE
Definition: qcore_unix_p.h:289

Properties

◆ m_fd

int QWSLinuxInputKbPrivate::m_fd
private

◆ m_handler

QWSLinuxInputKeyboardHandler* QWSLinuxInputKbPrivate::m_handler
private

Definition at line 75 of file qkbdlinuxinput_qws.cpp.

Referenced by readKeycode().

◆ m_orig_kbmode

int QWSLinuxInputKbPrivate::m_orig_kbmode
private

Definition at line 79 of file qkbdlinuxinput_qws.cpp.

Referenced by QWSLinuxInputKbPrivate(), and ~QWSLinuxInputKbPrivate().

◆ m_tty_attr

struct termios QWSLinuxInputKbPrivate::m_tty_attr
private

Definition at line 78 of file qkbdlinuxinput_qws.cpp.

Referenced by QWSLinuxInputKbPrivate(), and ~QWSLinuxInputKbPrivate().

◆ m_tty_fd

int QWSLinuxInputKbPrivate::m_tty_fd
private

Definition at line 77 of file qkbdlinuxinput_qws.cpp.

Referenced by QWSLinuxInputKbPrivate(), and ~QWSLinuxInputKbPrivate().


The documentation for this class was generated from the following file: