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

Public Functions

 QWSTtyKbPrivate (QWSTtyKeyboardHandler *handler, const QString &device)
 
 ~QWSTtyKbPrivate ()
 
- 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 handleConsoleSwitch (int sig)
 
void readKeycode ()
 

Private Functions

void switchConsole (int vt)
 
void switchLed (char, bool)
 

Properties

QWSTtyKeyboardHandlerm_handler
 
char m_last_keycode
 
int m_orig_kbmode
 
struct termios m_tty_attr
 
int m_tty_fd
 
int m_vt_qws
 

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 72 of file qkbdtty_qws.cpp.

Constructors and Destructors

◆ QWSTtyKbPrivate()

QWSTtyKbPrivate::QWSTtyKbPrivate ( QWSTtyKeyboardHandler handler,
const QString device 
)

Definition at line 113 of file qkbdtty_qws.cpp.

114  : m_handler(h), m_tty_fd(-1), m_last_keycode(0), m_vt_qws(0), m_orig_kbmode(K_XLATE)
115 {
116  setObjectName(QLatin1String("TTY Keyboard Handler"));
117 #ifndef QT_NO_QWS_SIGNALHANDLER
119 #endif
120 
121  QString dev = QLatin1String("/dev/tty0");
122  int repeat_delay = -1;
123  int repeat_rate = -1;
124 
125  QStringList args = device.split(QLatin1Char(':'));
126  foreach (const QString &arg, args) {
127  if (arg.startsWith(QLatin1String("repeat-delay=")))
128  repeat_delay = arg.mid(13).toInt();
129  else if (arg.startsWith(QLatin1String("repeat-rate=")))
130  repeat_rate = arg.mid(12).toInt();
131  else if (arg.startsWith(QLatin1String("/dev/")))
132  dev = arg;
133  }
134 
136  if (m_tty_fd >= 0) {
137  if (repeat_delay > 0 && repeat_rate > 0) {
138 #if defined(Q_OS_LINUX)
139  struct ::kbd_repeat kbdrep = { repeat_delay, repeat_rate };
140  ::ioctl(m_tty_fd, KDKBDREP, &kbdrep);
141 #endif
142  }
143 
144  QSocketNotifier *notifier;
145  notifier = new QSocketNotifier(m_tty_fd, QSocketNotifier::Read, this);
146  connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode()));
147 
148  // save tty config for restore.
149  tcgetattr(m_tty_fd, &m_tty_attr);
150 
151  struct ::termios termdata;
152  tcgetattr(m_tty_fd, &termdata);
153 
154 #if defined(Q_OS_LINUX)
155  // record the original mode so we can restore it again in the destructor.
156  ::ioctl(m_tty_fd, KDGKBMODE, &m_orig_kbmode);
157 
158  // PLEASE NOTE:
159  // the tty keycode interface can only report keycodes 0x01 .. 0x7f
160  // KEY_MAX is however defined to 0x1ff. In practice this is sufficient
161  // for a PC style keyboard though.
162  // we don't support K_RAW anymore - if you need that, you have to add
163  // a scan- to keycode converter yourself.
164  ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW);
165 #endif
166 
167  // set the tty layer to pass-through
168  termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
169  termdata.c_oflag = 0;
170  termdata.c_cflag = CREAD | CS8;
171  termdata.c_lflag = 0;
172  termdata.c_cc[VTIME]=0;
173  termdata.c_cc[VMIN]=1;
174  cfsetispeed(&termdata, 9600);
175  cfsetospeed(&termdata, 9600);
176  tcsetattr(m_tty_fd, TCSANOW, &termdata);
177 
178 #if defined(Q_OS_LINUX)
179  // VT switching is handled via unix signals
180  connect(QApplication::instance(), SIGNAL(unixSignal(int)), this, SLOT(handleConsoleSwitch(int)));
183 
184  struct ::vt_mode vtMode;
185  if (::ioctl(m_tty_fd, VT_GETMODE, &vtMode) == 0) {
186  vtMode.mode = VT_PROCESS;
187  vtMode.relsig = VTRELSIG;
188  vtMode.acqsig = VTACQSIG;
189 
190  if (::ioctl(m_tty_fd, VT_SETMODE, &vtMode) == 0) {
191  struct ::vt_stat vtStat;
192  ::memset(&vtStat, 0, sizeof(vtStat));
193 
194  if (::ioctl(m_tty_fd, VT_GETSTATE, &vtStat) == 0 ) {
195  m_vt_qws = vtStat.v_active;
196  }
197  }
198  }
199 
200  if (!m_vt_qws)
201  qWarning("Could not initialize virtual console switching");
202 #endif
203  } else {
204  qWarning("Cannot open input device '%s': %s", qPrintable(dev), strerror(errno));
205  return;
206  }
207 
208 }
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 VTACQSIG
Definition: qkbdtty_qws.cpp:65
#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
void addObject(QObject *object)
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
static QWSSignalHandler * instance()
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static void watchUnixSignal(int signal, bool watch)
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
QWSTtyKeyboardHandler * m_handler
Definition: qkbdtty_qws.cpp:88
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
struct termios m_tty_attr
Definition: qkbdtty_qws.cpp:90
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
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
#define VTRELSIG
Definition: qkbdtty_qws.cpp:66
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
void handleConsoleSwitch(int sig)
int errno

◆ ~QWSTtyKbPrivate()

QWSTtyKbPrivate::~QWSTtyKbPrivate ( )

Definition at line 210 of file qkbdtty_qws.cpp.

211 {
212  if (m_tty_fd >= 0) {
213 #if defined(Q_OS_LINUX)
214  ::ioctl(m_tty_fd, KDSKBMODE, m_orig_kbmode);
215 #endif
216  tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr);
218  }
219 }
struct termios m_tty_attr
Definition: qkbdtty_qws.cpp:90
#define QT_CLOSE
Definition: qcore_unix_p.h:304

Functions

◆ handleConsoleSwitch

void QWSTtyKbPrivate::handleConsoleSwitch ( int  sig)
privateslot

Definition at line 308 of file qkbdtty_qws.cpp.

Referenced by QWSTtyKbPrivate().

309 {
310 #if defined(Q_OS_LINUX)
311  // received a notification from the kernel that the current VT is
312  // changing: either enable or disable QWS painting accordingly.
313 
314  if (sig == VTACQSIG) {
315  if (::ioctl(m_tty_fd, VT_RELDISP, VT_ACKACQ) == 0) {
316  qwsServer->enablePainting(true);
317  qt_screen->restore();
319  qwsServer->refresh();
320  }
321  } else if (sig == VTRELSIG) {
322  qwsServer->enablePainting(false);
323 
324  // Check for reserved surfaces which might still do painting
325  bool allWindowsHidden = true;
327  for (int i = 0; i < windows.size(); ++i) {
328  const QWSWindow *w = windows.at(i);
330  if (s && s->isRegionReserved() && !w->allocatedRegion().isEmpty()) {
331  allWindowsHidden = false;
332  break;
333  }
334  }
335 
336  if (!allWindowsHidden) {
337  ::ioctl(m_tty_fd, VT_RELDISP, 0); // abort console switch
338  qwsServer->enablePainting(true);
339  } else if (::ioctl(m_tty_fd, VT_RELDISP, 1) == 0) {
340  qt_screen->save();
342  } else {
343  qwsServer->enablePainting(true);
344  }
345  }
346 #endif
347 }
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
static QWSServer * instance()
void refresh()
Refreshes the display by making the screen driver update the entire display.
#define VTACQSIG
Definition: qkbdtty_qws.cpp:65
virtual void restore()
Restores the previously saved state of the graphics card.
QRegion allocatedRegion() const
Returns the region that the window is allowed to draw onto, including any window decorations but excl...
The QWSWindow class encapsulates a top-level window in Qt for Embedded Linux.
void enablePainting(bool)
Enables painting onto the screen if enable is true; otherwise painting is disabled.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
void resumeMouse()
Resumes pointer handling by reactivating all the mouse drivers registered by the QWS_MOUSE_PROTO envi...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void suspendMouse()
Suspends pointer handling by deactivating all the mouse drivers registered by the QWS_MOUSE_PROTO env...
virtual void save()
Saves the current state of the graphics card.
#define VTRELSIG
Definition: qkbdtty_qws.cpp:66
bool isRegionReserved() const
Returns true if the QWSWindowSurface::RegionReserved is set; otherwise returns false.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QWSWindowSurface * windowSurface() const
QWSServer Q_GUI_EXPORT * qwsServer
const QList< QWSWindow * > & clientWindows()
Returns the list of current top-level windows.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ readKeycode

void QWSTtyKbPrivate::readKeycode ( )
privateslot

Definition at line 237 of file qkbdtty_qws.cpp.

Referenced by QWSTtyKbPrivate().

238 {
239  char buffer[32];
240  int n = 0;
241 
242  forever {
243  n = QT_READ(m_tty_fd, buffer + n, 32 - n);
244 
245  if (n == 0) {
246  qWarning("Got EOF from the input device.");
247  return;
248  } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) {
249  qWarning("Could not read from input device: %s", strerror(errno));
250  return;
251  } else {
252  break;
253  }
254  }
255 
256  for (int i = 0; i < n; ++i) {
257  if (m_handler->filterKeycode(buffer[i]))
258  continue;
259 
261  ka = m_handler->processKeycode(buffer[i] & 0x7f, (buffer[i] & 0x80) == 0x00, buffer[i] == m_last_keycode);
262  m_last_keycode = buffer[i];
263 
264  switch (ka) {
268  break;
269 
273  break;
274 
278  break;
279 
281  switchConsole(qBound(1, m_vt_qws - 1, 10));
282  break;
283 
285  switchConsole(qBound(1, m_vt_qws + 1, 10));
286  break;
287 
288  default:
292  }
293  //ignore reboot
294  break;
295  }
296  }
297 }
void switchConsole(int vt)
#define QT_READ
Definition: qcore_unix_p.h:280
void switchLed(char, bool)
Q_CORE_EXPORT void qWarning(const char *,...)
KeycodeAction
This enum describes the various special actions that actual QWSKeyboardHandler implementations have t...
Definition: qkbd_qws.h:67
virtual bool filterKeycode(char &code)
QWSTtyKeyboardHandler * m_handler
Definition: qkbdtty_qws.cpp:88
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
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

◆ switchConsole()

void QWSTtyKbPrivate::switchConsole ( int  vt)
private

Definition at line 300 of file qkbdtty_qws.cpp.

Referenced by readKeycode().

301 {
302 #if defined(Q_OS_LINUX)
303  if (m_vt_qws && vt && (m_tty_fd >= 0 ))
304  ::ioctl(m_tty_fd, VT_ACTIVATE, vt);
305 #endif
306 }

◆ switchLed()

void QWSTtyKbPrivate::switchLed ( char  led,
bool  state 
)
private

Definition at line 223 of file qkbdtty_qws.cpp.

Referenced by readKeycode().

224 {
225 #if defined(Q_OS_LINUX)
226  char ledstate;
227 
228  ::ioctl(m_tty_fd, KDGETLED, &ledstate);
229  if (state)
230  ledstate |= led;
231  else
232  ledstate &= ~led;
233  ::ioctl(m_tty_fd, KDSETLED, ledstate);
234 #endif
235 }

Properties

◆ m_handler

QWSTtyKeyboardHandler* QWSTtyKbPrivate::m_handler
private

Definition at line 88 of file qkbdtty_qws.cpp.

Referenced by readKeycode().

◆ m_last_keycode

char QWSTtyKbPrivate::m_last_keycode
private

Definition at line 91 of file qkbdtty_qws.cpp.

Referenced by readKeycode().

◆ m_orig_kbmode

int QWSTtyKbPrivate::m_orig_kbmode
private

Definition at line 93 of file qkbdtty_qws.cpp.

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

◆ m_tty_attr

struct termios QWSTtyKbPrivate::m_tty_attr
private

Definition at line 90 of file qkbdtty_qws.cpp.

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

◆ m_tty_fd

int QWSTtyKbPrivate::m_tty_fd
private

◆ m_vt_qws

int QWSTtyKbPrivate::m_vt_qws
private

Definition at line 92 of file qkbdtty_qws.cpp.

Referenced by QWSTtyKbPrivate(), readKeycode(), and switchConsole().


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