Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QXcbKeyboard Class Reference

#include <qxcbkeyboard.h>

Inheritance diagram for QXcbKeyboard:
QXcbObject

Public Functions

void handleKeyPressEvent (QWidget *widget, const xcb_key_press_event_t *event)
 
void handleKeyReleaseEvent (QWidget *widget, const xcb_key_release_event_t *event)
 
void handleMappingNotifyEvent (const xcb_mapping_notify_event_t *event)
 
 QXcbKeyboard (QXcbConnection *connection)
 
Qt::KeyboardModifiers translateModifiers (int s)
 
 ~QXcbKeyboard ()
 
- Public Functions inherited from QXcbObject
xcb_atom_t atom (QXcbAtom::Atom atom) const
 
QXcbConnectionconnection () const
 
 QXcbObject (QXcbConnection *connection=0)
 
void setConnection (QXcbConnection *connection)
 
xcb_connection_t * xcb_connection () const
 

Private Functions

void handleKeyEvent (QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time)
 
int translateKeySym (uint key) const
 
QString translateKeySym (xcb_keysym_t keysym, uint xmodifiers, int &code, Qt::KeyboardModifiers &modifiers, QByteArray &chars, int &count)
 

Properties

uint m_alt_mask
 
uint m_hyper_mask
 
xcb_key_symbols_t * m_key_symbols
 
uint m_meta_mask
 
uint m_mode_switch_mask
 
uint m_num_lock_mask
 
uint m_super_mask
 

Detailed Description

Definition at line 51 of file qxcbkeyboard.h.

Constructors and Destructors

◆ QXcbKeyboard()

QXcbKeyboard::QXcbKeyboard ( QXcbConnection connection)

Definition at line 899 of file qxcbkeyboard.cpp.

900  : QXcbObject(connection)
901  , m_alt_mask(0)
902  , m_super_mask(0)
903  , m_hyper_mask(0)
904  , m_meta_mask(0)
905 {
906  m_key_symbols = xcb_key_symbols_alloc(xcb_connection());
907 }
xcb_key_symbols_t * m_key_symbols
Definition: qxcbkeyboard.h:79
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
uint m_hyper_mask
Definition: qxcbkeyboard.h:74
uint m_meta_mask
Definition: qxcbkeyboard.h:75
QXcbObject(QXcbConnection *connection=0)
Definition: qxcbobject.h:50
uint m_super_mask
Definition: qxcbkeyboard.h:73

◆ ~QXcbKeyboard()

QXcbKeyboard::~QXcbKeyboard ( )

Definition at line 909 of file qxcbkeyboard.cpp.

910 {
911  xcb_key_symbols_free(m_key_symbols);
912 }
xcb_key_symbols_t * m_key_symbols
Definition: qxcbkeyboard.h:79

Functions

◆ handleKeyEvent()

void QXcbKeyboard::handleKeyEvent ( QWidget widget,
QEvent::Type  type,
xcb_keycode_t  code,
quint16  state,
xcb_timestamp_t  time 
)
private

Definition at line 916 of file qxcbkeyboard.cpp.

Referenced by handleKeyPressEvent(), and handleKeyReleaseEvent().

917 {
918  int col = state & XCB_MOD_MASK_SHIFT ? 1 : 0;
919 
920  const int altGrOffset = 4;
921  if (state & 128)
922  col += altGrOffset;
923 
925 
926 #ifdef XCB_KEYBOARD_DEBUG
927  printf("key code: %d, state: %d, syms: ", code, state);
928  for (int i = 0; i <= 5; ++i) {
929  printf("%d ", xcb_key_symbols_get_keysym(m_key_symbols, code, i));
930  }
931  printf("\n");
932 #endif
933 
935 
936  xcb_keysym_t sym = xcb_key_symbols_get_keysym(m_key_symbols, code, col);
937  if (sym == XCB_NO_SYMBOL)
938  sym = xcb_key_symbols_get_keysym(m_key_symbols, code, col ^ 0x1);
939 
940  if (state & XCB_MOD_MASK_LOCK && sym <= 0x7f && isprint(sym)) {
941  if (isupper(sym))
942  sym = tolower(sym);
943  else
944  sym = toupper(sym);
945  }
946 
948 
949  QByteArray chars;
950 
951  Qt::KeyboardModifiers modifiers;
952  int qtcode = 0;
953  int count = 0;
954 
955  QString string = translateKeySym(sym, state, qtcode, modifiers, chars, count);
956 
957  QWindowSystemInterface::handleExtendedKeyEvent(widget, time, type, qtcode, modifiers, code, 0, state, string.left(count));
958 }
int type
Definition: qmetatype.cpp:239
xcb_key_symbols_t * m_key_symbols
Definition: qxcbkeyboard.h:79
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
QXcbConnection * connection() const
Definition: qxcbobject.h:53
static void handleExtendedKeyEvent(QWidget *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
#define Q_XCB_NOOP(c)
int translateKeySym(uint key) const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ handleKeyPressEvent()

void QXcbKeyboard::handleKeyPressEvent ( QWidget widget,
const xcb_key_press_event_t *  event 
)

Definition at line 960 of file qxcbkeyboard.cpp.

961 {
962  handleKeyEvent(widget, QEvent::KeyPress, event->detail, event->state, event->time);
963 }
EventRef event
void handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time)

◆ handleKeyReleaseEvent()

void QXcbKeyboard::handleKeyReleaseEvent ( QWidget widget,
const xcb_key_release_event_t *  event 
)

Definition at line 965 of file qxcbkeyboard.cpp.

966 {
967  handleKeyEvent(widget, QEvent::KeyRelease, event->detail, event->state, event->time);
968 }
EventRef event
void handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time)

◆ handleMappingNotifyEvent()

void QXcbKeyboard::handleMappingNotifyEvent ( const xcb_mapping_notify_event_t *  event)

Definition at line 970 of file qxcbkeyboard.cpp.

Referenced by QXcbConnection::processXcbEvents().

971 {
972  xcb_refresh_keyboard_mapping(m_key_symbols, const_cast<xcb_mapping_notify_event_t *>(event));
973 }
EventRef event
xcb_key_symbols_t * m_key_symbols
Definition: qxcbkeyboard.h:79

◆ translateKeySym() [1/2]

int QXcbKeyboard::translateKeySym ( uint  key) const
private

Definition at line 760 of file qxcbkeyboard.cpp.

Referenced by handleKeyEvent(), and translateKeySym().

761 {
762  int code = -1;
763  int i = 0; // any other keys
764  while (KeyTbl[i]) {
765  if (key == KeyTbl[i]) {
766  code = (int)KeyTbl[i+1];
767  break;
768  }
769  i += 2;
770  }
771  if (m_meta_mask) {
772  // translate Super/Hyper keys to Meta if we're using them as the MetaModifier
773  if (m_meta_mask == m_super_mask && (code == Qt::Key_Super_L || code == Qt::Key_Super_R)) {
774  code = Qt::Key_Meta;
775  } else if (m_meta_mask == m_hyper_mask && (code == Qt::Key_Hyper_L || code == Qt::Key_Hyper_R)) {
776  code = Qt::Key_Meta;
777  }
778  }
779  return code;
780 }
static const unsigned int KeyTbl[]
uint m_hyper_mask
Definition: qxcbkeyboard.h:74
uint m_meta_mask
Definition: qxcbkeyboard.h:75
int key
uint m_super_mask
Definition: qxcbkeyboard.h:73

◆ translateKeySym() [2/2]

QString QXcbKeyboard::translateKeySym ( xcb_keysym_t  keysym,
uint  xmodifiers,
int &  code,
Qt::KeyboardModifiers &  modifiers,
QByteArray chars,
int &  count 
)
private

Definition at line 782 of file qxcbkeyboard.cpp.

785 {
786  // all keysyms smaller than 0xff00 are actally keys that can be mapped to unicode chars
787 
789  QChar converted;
790 
791  if (/*count == 0 &&*/ keysym < 0xff00) {
792  unsigned char byte3 = (unsigned char)(keysym >> 8);
793  int mib = -1;
794  switch(byte3) {
795  case 0: // Latin 1
796  case 1: // Latin 2
797  case 2: //latin 3
798  case 3: // latin4
799  mib = byte3 + 4; break;
800  case 5: // arabic
801  mib = 82; break;
802  case 12: // Hebrew
803  mib = 85; break;
804  case 13: // Thai
805  mib = 2259; break;
806  case 4: // kana
807  case 6: // cyrillic
808  case 7: // greek
809  case 8: // technical, no mapping here at the moment
810  case 9: // Special
811  case 10: // Publishing
812  case 11: // APL
813  case 14: // Korean, no mapping
814  mib = -1; // manual conversion
815  mapper= 0;
816 #if !defined(QT_NO_XIM)
817  converted = keysymToUnicode(byte3, keysym & 0xff);
818 #endif
819  case 0x20:
820  // currency symbols
821  if (keysym >= 0x20a0 && keysym <= 0x20ac) {
822  mib = -1; // manual conversion
823  mapper = 0;
824  converted = (uint)keysym;
825  }
826  break;
827  default:
828  break;
829  }
830  if (mib != -1) {
831  mapper = QTextCodec::codecForMib(mib);
832  if (chars.isEmpty())
833  chars.resize(1);
834  chars[0] = (unsigned char) (keysym & 0xff); // get only the fourth bit for conversion later
835  count = 1;
836  }
837  } else if (keysym >= 0x1000000 && keysym <= 0x100ffff) {
838  converted = (ushort) (keysym - 0x1000000);
839  mapper = 0;
840  }
841  if (count < (int)chars.size()-1)
842  chars[count] = '\0';
843 
844  QString text;
845  if (!mapper && converted.unicode() != 0x0) {
846  text = converted;
847  } else if (!chars.isEmpty()) {
848  // convert chars (8bit) to text (unicode).
849  if (mapper)
850  text = mapper->toUnicode(chars.data(), count, 0);
851  if (text.isEmpty()) {
852  // no mapper, or codec couldn't convert to unicode (this
853  // can happen when running in the C locale or with no LANG
854  // set). try converting from latin-1
855  text = QString::fromLatin1(chars);
856  }
857  }
858 
859  modifiers = translateModifiers(xmodifiers);
860 
861  // Commentary in X11/keysymdef says that X codes match ASCII, so it
862  // is safe to use the locale functions to process X codes in ISO8859-1.
863  //
864  // This is mainly for compatibility - applications should not use the
865  // Qt keycodes between 128 and 255, but should rather use the
866  // QKeyEvent::text().
867  //
868  if (keysym < 128 || (keysym < 256 && (!mapper || mapper->mibEnum()==4))) {
869  // upper-case key, if known
870  code = isprint((int)keysym) ? toupper((int)keysym) : 0;
871  } else if (keysym >= XK_F1 && keysym <= XK_F35) {
872  // function keys
873  code = Qt::Key_F1 + ((int)keysym - XK_F1);
874  } else if (keysym >= XK_KP_Space && keysym <= XK_KP_9) {
875  if (keysym >= XK_KP_0) {
876  // numeric keypad keys
877  code = Qt::Key_0 + ((int)keysym - XK_KP_0);
878  } else {
879  code = translateKeySym(keysym);
880  }
881  modifiers |= Qt::KeypadModifier;
882  } else if (text.length() == 1 && text.unicode()->unicode() > 0x1f && text.unicode()->unicode() != 0x7f && !(keysym >= XK_dead_grave && keysym <= XK_dead_horn)) {
883  code = text.unicode()->toUpper().unicode();
884  } else {
885  // any other keys
886  code = translateKeySym(keysym);
887 
888  if (code == Qt::Key_Tab && (modifiers & Qt::ShiftModifier)) {
889  // map shift+tab to shift+backtab, QShortcutMap knows about it
890  // and will handle it.
891  code = Qt::Key_Backtab;
892  text = QString();
893  }
894  }
895 
896  return text;
897 }
static QTextCodec * codecForLocale()
Returns a pointer to the codec most suitable for this locale.
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
int keysym
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual int mibEnum() const =0
Subclasses of QTextCodec must reimplement this function.
unsigned int uint
Definition: qglobal.h:996
int mib
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
#define XK_dead_horn
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
static QChar keysymToUnicode(unsigned char byte3, unsigned char byte4)
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
Qt::KeyboardModifiers translateModifiers(int s)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
int translateKeySym(uint key) const
#define text
Definition: qobjectdefs.h:80

◆ translateModifiers()

Qt::KeyboardModifiers QXcbKeyboard::translateModifiers ( int  s)

Definition at line 746 of file qxcbkeyboard.cpp.

Referenced by translateKeySym().

747 {
748  Qt::KeyboardModifiers ret = 0;
749  if (s & XCB_MOD_MASK_SHIFT)
750  ret |= Qt::ShiftModifier;
751  if (s & XCB_MOD_MASK_CONTROL)
752  ret |= Qt::ControlModifier;
753  if (s & m_alt_mask)
754  ret |= Qt::AltModifier;
755  if (s & m_meta_mask)
756  ret |= Qt::MetaModifier;
757  return ret;
758 }
uint m_meta_mask
Definition: qxcbkeyboard.h:75

Properties

◆ m_alt_mask

uint QXcbKeyboard::m_alt_mask
private

Definition at line 72 of file qxcbkeyboard.h.

Referenced by translateModifiers().

◆ m_hyper_mask

uint QXcbKeyboard::m_hyper_mask
private

Definition at line 74 of file qxcbkeyboard.h.

Referenced by translateKeySym().

◆ m_key_symbols

xcb_key_symbols_t* QXcbKeyboard::m_key_symbols
private

◆ m_meta_mask

uint QXcbKeyboard::m_meta_mask
private

Definition at line 75 of file qxcbkeyboard.h.

Referenced by translateKeySym(), and translateModifiers().

◆ m_mode_switch_mask

uint QXcbKeyboard::m_mode_switch_mask
private

Definition at line 76 of file qxcbkeyboard.h.

◆ m_num_lock_mask

uint QXcbKeyboard::m_num_lock_mask
private

Definition at line 77 of file qxcbkeyboard.h.

◆ m_super_mask

uint QXcbKeyboard::m_super_mask
private

Definition at line 73 of file qxcbkeyboard.h.

Referenced by translateKeySym().


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