Qt 4.8
Public Types | Public Functions | Protected Functions | Properties | List of all members
QWSKeyboardHandler Class Reference

The QWSKeyboardHandler class is a base class for keyboard drivers in Qt for Embedded Linux. More...

#include <qkbd_qws.h>

Inheritance diagram for QWSKeyboardHandler:
QDirectFBKeyboardHandler QVFbKeyboardHandler QWSIntKeyboardHandler QWSLinuxInputKeyboardHandler QWSLinuxInputKeyboardHandler QWSQnxKeyboardHandler QWSTtyKeyboardHandler QWSUmKeyboardHandler

Public Types

enum  KeycodeAction {
  None = 0, CapsLockOff = 0x01000000, CapsLockOn = 0x01000001, NumLockOff = 0x02000000,
  NumLockOn = 0x02000001, ScrollLockOff = 0x03000000, ScrollLockOn = 0x03000001, Reboot = 0x04000000,
  PreviousConsole = 0x05000000, NextConsole = 0x05000001, SwitchConsoleFirst = 0x06000000, SwitchConsoleLast = 0x0600007f,
  SwitchConsoleMask = 0x0000007f
}
 This enum describes the various special actions that actual QWSKeyboardHandler implementations have to take care of. More...
 

Public Functions

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 application. More...
 
virtual void processKeyEvent (int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
 Sends a key event to the Qt for Embedded Linux server application. More...
 
 QWSKeyboardHandler ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
 QWSKeyboardHandler (const QString &device)
 Constructs a keyboard driver. More...
 
virtual ~QWSKeyboardHandler ()
 Destroys this keyboard driver. More...
 

Protected Functions

void beginAutoRepeat (int uni, int code, Qt::KeyboardModifiers mod)
 Begins auto-repeating the specified key press; after a short delay the key press is sent periodically until the endAutoRepeat() function is called. More...
 
void endAutoRepeat ()
 Stops auto-repeating a key press. More...
 
int transformDirKey (int key)
 Transforms the arrow key specified by the given keycode, to the orientation of the display and returns the transformed keycode. More...
 

Properties

QWSKbPrivated
 

Detailed Description

The QWSKeyboardHandler class is a base class for keyboard drivers in Qt for Embedded Linux.

Note that this class is only available in Qt for Embedded Linux.

Qt for Embedded Linux provides ready-made drivers for several keyboard protocols, see the Qt for Embedded Linux Character Input{character input} documentation for details. Custom keyboard drivers can be implemented by subclassing the QWSKeyboardHandler class and creating a keyboard driver plugin (derived from QKbdDriverPlugin). The default implementation of the QKbdDriverFactory class will automatically detect the plugin, and load the driver into the server application at run-time using Qt's How to Create Qt Plugins{plugin system}.

The keyboard driver receives keyboard events from the system device and encapsulates each event with an instance of the QWSEvent class which it then passes to the server application (the server is responsible for propagating the event to the appropriate client). To receive keyboard events, a QWSKeyboardHandler object will usually create a QSocketNotifier object for the given device. The QSocketNotifier class provides support for monitoring activity on a file descriptor. When the socket notifier receives data, it will call the keyboard driver's processKeyEvent() function to send the event to the Qt for Embedded Linux server application for relaying to clients.

QWSKeyboardHandler also provides functions to control auto-repetion of key sequences, beginAutoRepeat() and endAutoRepeat(), and the transformDirKey() function enabling transformation of arrow keys according to the display orientation.

See also
QKbdDriverPlugin, QKbdDriverFactory, {Qt for Embedded Linux Character Input}

Definition at line 57 of file qkbd_qws.h.

Enumerations

◆ KeycodeAction

This enum describes the various special actions that actual QWSKeyboardHandler implementations have to take care of.

  • None No further action required.
  • CapsLockOn Set the state of the Caps lock LED to on.
  • CapsLockOff Set the state of the Caps lock LED to off.
  • NumLockOn Set the state of the Num lock LED to on.
  • NumLockOff Set the state of the Num lock LED to off.
  • ScrollLockOn Set the state of the Scroll lock LED to on.
  • ScrollLockOff Set the state of the Scroll lock LED to off.
  • PreviousConsole Switch to the previous virtual console (by default Ctrl+Alt+Left on Linux).
  • NextConsole Switch to the next virtual console (by default Ctrl+Alt+Right on Linux).
  • SwitchConsoleFirst Switch to the first virtual console (0).
  • SwitchConsoleLast Switch to the last virtual console (255).
  • SwitchConsoleMask If the KeyAction value is between SwitchConsoleFirst and SwitchConsoleLast, you can use this mask to get the specific virtual console number to switch to.
  • Reboot Reboot the machine - this is ignored in both the TTY and LinuxInput handlers though (by default Ctrl+Alt+Del on Linux).
See also
processKeycode()
Enumerator
None 
CapsLockOff 
CapsLockOn 
NumLockOff 
NumLockOn 
ScrollLockOff 
ScrollLockOn 
Reboot 
PreviousConsole 
NextConsole 
SwitchConsoleFirst 
SwitchConsoleLast 
SwitchConsoleMask 

Definition at line 67 of file qkbd_qws.h.

Constructors and Destructors

◆ QWSKeyboardHandler() [1/2]

QWSKeyboardHandler::QWSKeyboardHandler ( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 323 of file qkbd_qws.cpp.

324 {
325  d = new QWSKbPrivate(this, QString());
326 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QWSKbPrivate * d
Definition: qkbd_qws.h:94

◆ QWSKeyboardHandler() [2/2]

QWSKeyboardHandler::QWSKeyboardHandler ( const QString device)

Constructs a keyboard driver.

The device argument is passed by the QWS_KEYBOARD environment variable.

Call the QWSServer::setKeyboardHandler() function to make the newly created keyboard driver, the primary driver. Note that the primary driver is controlled by the system, i.e., the system will delete it upon exit.

Definition at line 315 of file qkbd_qws.cpp.

316 {
317  d = new QWSKbPrivate(this, device);
318 }
QWSKbPrivate * d
Definition: qkbd_qws.h:94

◆ ~QWSKeyboardHandler()

QWSKeyboardHandler::~QWSKeyboardHandler ( )
virtual

Destroys this keyboard driver.

Do not call this function if this driver is the primary keyboard handler, i.e., if QWSServer::setKeyboardHandler() function has been called passing this driver as argument. The primary keyboard driver is deleted by the system.

Definition at line 338 of file qkbd_qws.cpp.

339 {
340  delete d;
341 }
QWSKbPrivate * d
Definition: qkbd_qws.h:94

Functions

◆ beginAutoRepeat()

void QWSKeyboardHandler::beginAutoRepeat ( int  unicode,
int  keycode,
Qt::KeyboardModifiers  modifier 
)
protected

Begins auto-repeating the specified key press; after a short delay the key press is sent periodically until the endAutoRepeat() function is called.

The key press is specified by its unicode, keycode and modifier state.

See also
endAutoRepeat(), processKeyEvent()

Definition at line 433 of file qkbd_qws.cpp.

434 {
435  d->beginAutoRepeat(uni, code, mod);
436 }
void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod)
Definition: qkbd_qws.cpp:110
QWSKbPrivate * d
Definition: qkbd_qws.h:94

◆ endAutoRepeat()

void QWSKeyboardHandler::endAutoRepeat ( )
protected

Stops auto-repeating a key press.

See also
beginAutoRepeat(), processKeyEvent()

Definition at line 443 of file qkbd_qws.cpp.

444 {
445  d->endAutoRepeat();
446 }
void endAutoRepeat()
Definition: qkbd_qws.cpp:118
QWSKbPrivate * d
Definition: qkbd_qws.h:94

◆ processKeycode()

QWSKeyboardHandler::KeycodeAction QWSKeyboardHandler::processKeycode ( quint16  keycode,
bool  isPress,
bool  autoRepeat 
)

Maps keycode according to a keymap and sends that key event to the Qt for Embedded Linux server application.

Since
4.6

Please see the Qt for Embedded Linux Character Input and the kmap2qmap documentations for a description on how to create and use keymap files.

The key event is identified by its keycode value and the isPress and autoRepeat parameters.

The keycode parameter is NOT the Qt keycode value as defined by the Qt::Key enum. This functions expects a standard Linux 16 bit kernel keycode as it is used in the Linux Input Event sub-system. This keycode is transformed to a Qt::Key code by using either a compiled-in US keyboard layout or by dynamically loading a keymap at startup which can be specified via the QWS_KEYBOARD environment variable.

The isPress parameter is true if the event is a key press event and autoRepeat is true if the event is caused by an auto-repeat mechanism and not an actual key press.

The return value indicates if the actual QWSKeyboardHandler implementation needs to take care of a special action, like console switching or LED handling.

If standard Linux console keymaps are used, keycode must be one of the standardized values defined in /usr/include/linux/input.h

See also
processKeyEvent(), KeycodeAction

Definition at line 521 of file qkbd_qws.cpp.

Referenced by QWSLinuxInputKbPrivate::readKeycode(), QWSTtyKbPrivate::readKeycode(), and QLinuxInputKeyboardHandler::readKeycode().

522 {
523  KeycodeAction result = None;
524  bool first_press = pressed && !autorepeat;
525 
526  const QWSKeyboard::Mapping *map_plain = 0;
527  const QWSKeyboard::Mapping *map_withmod = 0;
528 
529  // get a specific and plain mapping for the keycode and the current modifiers
530  for (int i = 0; i < d->m_keymap_size && !(map_plain && map_withmod); ++i) {
531  const QWSKeyboard::Mapping *m = d->m_keymap + i;
532  if (m->keycode == keycode) {
533  if (m->modifiers == 0)
534  map_plain = m;
535 
536  quint8 testmods = d->m_modifiers;
537  if (d->m_locks[0] /*CapsLock*/ && (m->flags & QWSKeyboard::IsLetter))
538  testmods ^= QWSKeyboard::ModShift;
539  if (m->modifiers == testmods)
540  map_withmod = m;
541  }
542  }
543 
544 #ifdef QT_DEBUG_KEYMAP
545  qWarning("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", \
546  keycode, d->m_modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, \
547  map_plain ? map_plain - d->m_keymap : -1, \
548  map_withmod ? map_withmod - d->m_keymap : -1, \
549  d->m_keymap_size);
550 #endif
551 
552  const QWSKeyboard::Mapping *it = map_withmod ? map_withmod : map_plain;
553 
554  if (!it) {
555 #ifdef QT_DEBUG_KEYMAP
556  // we couldn't even find a plain mapping
557  qWarning("Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, d->m_modifiers);
558 #endif
559  return result;
560  }
561 
562  bool skip = false;
563  quint16 unicode = it->unicode;
564  quint32 qtcode = it->qtcode;
565 
566  if ((it->flags & QWSKeyboard::IsModifier) && it->special) {
567  // this is a modifier, i.e. Shift, Alt, ...
568  if (pressed)
569  d->m_modifiers |= quint8(it->special);
570  else
571  d->m_modifiers &= ~quint8(it->special);
572  } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) {
573  // (Caps|Num|Scroll)Lock
574  if (first_press) {
575  quint8 &lock = d->m_locks[qtcode - Qt::Key_CapsLock];
576  lock ^= 1;
577 
578  switch (qtcode) {
579  case Qt::Key_CapsLock : result = lock ? CapsLockOn : CapsLockOff; break;
580  case Qt::Key_NumLock : result = lock ? NumLockOn : NumLockOff; break;
581  case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break;
582  default : break;
583  }
584  }
585  } else if ((it->flags & QWSKeyboard::IsSystem) && it->special && first_press) {
586  switch (it->special) {
588  result = Reboot;
589  break;
590 
592  if (!d->m_no_zap)
593  qApp->quit();
594  break;
595 
597  result = PreviousConsole;
598  break;
599 
601  result = NextConsole;
602  break;
603 
604  default:
608  }
609  break;
610  }
611 
612  skip = true; // no need to tell QWS about it
613  } else if ((qtcode == Qt::Key_Multi_key) && d->m_do_compose) {
614  // the Compose key was pressed
615  if (first_press)
616  d->m_composing = 2;
617  skip = true;
618  } else if ((it->flags & QWSKeyboard::IsDead) && d->m_do_compose) {
619  // a Dead key was pressed
620  if (first_press && d->m_composing == 1 && d->m_dead_unicode == unicode) { // twice
621  d->m_composing = 0;
622  qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead...
623  } else if (first_press && unicode != 0xffff) {
624  d->m_dead_unicode = unicode;
625  d->m_composing = 1;
626  skip = true;
627  } else {
628  skip = true;
629  }
630  }
631 
632  if (!skip) {
633  // a normal key was pressed
635 
636  // we couldn't find a specific mapping for the current modifiers,
637  // or that mapping didn't have special modifiers:
638  // so just report the plain mapping with additional modifiers.
639  if ((it == map_plain && it != map_withmod) ||
640  (map_withmod && !(map_withmod->qtcode & modmask))) {
642  }
643 
644  if (d->m_composing == 2 && first_press && !(it->flags & QWSKeyboard::IsModifier)) {
645  // the last key press was the Compose key
646  if (unicode != 0xffff) {
647  int idx = 0;
648  // check if this code is in the compose table at all
649  for ( ; idx < d->m_keycompose_size; ++idx) {
650  if (d->m_keycompose[idx].first == unicode)
651  break;
652  }
653  if (idx < d->m_keycompose_size) {
654  // found it -> simulate a Dead key press
655  d->m_dead_unicode = unicode;
656  unicode = 0xffff;
657  d->m_composing = 1;
658  skip = true;
659  } else {
660  d->m_composing = 0;
661  }
662  } else {
663  d->m_composing = 0;
664  }
665  } else if (d->m_composing == 1 && first_press && !(it->flags & QWSKeyboard::IsModifier)) {
666  // the last key press was a Dead key
667  bool valid = false;
668  if (unicode != 0xffff) {
669  int idx = 0;
670  // check if this code is in the compose table at all
671  for ( ; idx < d->m_keycompose_size; ++idx) {
672  if (d->m_keycompose[idx].first == d->m_dead_unicode && d->m_keycompose[idx].second == unicode)
673  break;
674  }
675  if (idx < d->m_keycompose_size) {
676  quint16 composed = d->m_keycompose[idx].result;
677  if (composed != 0xffff) {
678  unicode = composed;
679  qtcode = Qt::Key_unknown;
680  valid = true;
681  }
682  }
683  }
684  if (!valid) {
685  unicode = d->m_dead_unicode;
686  qtcode = Qt::Key_unknown;
687  }
688  d->m_composing = 0;
689  }
690 
691  if (!skip) {
692 #ifdef QT_DEBUG_KEYMAP
693  qWarning("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask));
694 #endif
695 
696  // send the result to the QWS server
697  processKeyEvent(unicode, qtcode & ~modmask, Qt::KeyboardModifiers(qtcode & modmask), pressed, autorepeat);
698  }
699  }
700  return result;
701 }
int keycode
#define it(className, varName)
unsigned char quint8
Definition: qglobal.h:934
quint8 m_locks[3]
Definition: qkbd_qws.cpp:161
bool m_do_compose
Definition: qkbd_qws.cpp:166
quint16 m_dead_unicode
Definition: qkbd_qws.cpp:163
#define qApp
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
const QWSKeyboard::Mapping * m_keymap
Definition: qkbd_qws.cpp:168
int m_keycompose_size
Definition: qkbd_qws.cpp:171
static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
Definition: qkbd_qws.cpp:123
KeycodeAction
This enum describes the various special actions that actual QWSKeyboardHandler implementations have t...
Definition: qkbd_qws.h:67
const QWSKeyboard::Composing * m_keycompose
Definition: qkbd_qws.cpp:170
int m_keymap_size
Definition: qkbd_qws.cpp:169
unsigned int quint32
Definition: qglobal.h:938
static QReadWriteLock lock
Definition: proxyconf.cpp:399
virtual void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
Sends a key event to the Qt for Embedded Linux server application.
Definition: qkbd_qws.cpp:363
quint8 m_modifiers
Definition: qkbd_qws.cpp:160
QWSKbPrivate * d
Definition: qkbd_qws.h:94

◆ processKeyEvent()

void QWSKeyboardHandler::processKeyEvent ( int  unicode,
int  keycode,
Qt::KeyboardModifiers  modifiers,
bool  isPress,
bool  autoRepeat 
)
virtual

Sends a key event to the Qt for Embedded Linux server application.

The key event is identified by its unicode value and the keycode, modifiers, isPress and autoRepeat parameters.

The keycode parameter is the Qt keycode value as defined by the Qt::Key enum. The modifiers is an OR combination of Qt::KeyboardModifier values, indicating whether Shift/Alt/Ctrl keys are pressed. The isPress parameter is true if the event is a key press event and autoRepeat is true if the event is caused by an auto-repeat mechanism and not an actual key press.

Note that this function does not handle key mapping. Please use processKeycode() if you need that functionality.

See also
processKeycode(), beginAutoRepeat(), endAutoRepeat(), transformDirKey()

Definition at line 363 of file qkbd_qws.cpp.

Referenced by QWSKbPrivate::autoRepeat(), processKeycode(), QDirectFBKeyboardHandlerPrivate::readKeyboardData(), and QWSQnxKeyboardHandler::socketActivated().

365 {
366 #if defined(Q_WS_QWS)
367  qwsServer->processKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat);
368 #elif defined(Q_WS_QPA)
370  QString str;
371  if (unicode != 0xffff)
372  str = QString(unicode);
373  QWindowSystemInterface::handleKeyEvent(0, type, keycode, modifiers, str, autoRepeat);
374 #endif
375 }
int type
Definition: qmetatype.cpp:239
int keycode
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
Processes the given key event.
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QWSServer Q_GUI_EXPORT * qwsServer

◆ transformDirKey()

int QWSKeyboardHandler::transformDirKey ( int  keycode)
protected

Transforms the arrow key specified by the given keycode, to the orientation of the display and returns the transformed keycode.

The keycode is a Qt::Key value. The values identifying arrow keys are:

See also
processKeyEvent()

Definition at line 398 of file qkbd_qws.cpp.

399 {
400 #ifdef Q_WS_QWS
401  static int dir_keyrot = -1;
402  if (dir_keyrot < 0) {
403  // get the rotation
404  switch (qgetenv("QWS_CURSOR_ROTATION").toInt()) {
405  case 90: dir_keyrot = 1; break;
406  case 180: dir_keyrot = 2; break;
407  case 270: dir_keyrot = 3; break;
408  default: dir_keyrot = 0; break;
409  }
410  }
411  int xf = qt_screen->transformOrientation() + dir_keyrot;
412  return (key-Qt::Key_Left+xf)%4+Qt::Key_Left;
413 #else
414  return 0;
415 #endif
416 }
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
int key
virtual int transformOrientation() const
Returns the current rotation as an integer value.

Properties

◆ d

QWSKbPrivate* QWSKeyboardHandler::d
private

Definition at line 94 of file qkbd_qws.h.


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