kkeynative_x11.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qnamespace.h>
00021 #include <qwindowdefs.h>
00022
00023 #ifdef Q_WS_X11 // Only compile this module if we're compiling for X11
00024
00025 #include "kkeynative.h"
00026 #include "kkeyserver_x11.h"
00027
00028 #include <qmap.h>
00029 #include <qstringlist.h>
00030 #include <kckey.h>
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033
00034 #define XK_MISCELLANY
00035 #define XK_XKB_KEYS
00036 #include <X11/X.h>
00037 #include <X11/Xlib.h>
00038 #include <X11/Xutil.h>
00039 #include <X11/keysymdef.h>
00040 #include <ctype.h>
00041 #undef NONE
00042
00043 #ifdef Q_WS_X11
00044 #ifndef KDE_USE_FINAL
00045
00046 const int XKeyPress = KeyPress;
00047 const int XKeyRelease = KeyRelease;
00048 #undef KeyPress
00049 #endif
00050 #endif
00051
00052
00053
00054 static KKeyNative* gx_pkey = 0;
00055
00056
00057
00058
00059
00060 KKeyNative::KKeyNative() { clear(); }
00061 KKeyNative::KKeyNative( const KKey& key ) { init( key ); }
00062 KKeyNative::KKeyNative( const KKeyNative& key ) { init( key ); }
00063 KKeyNative::KKeyNative( const XEvent* pEvent ) { init( pEvent ); }
00064
00065 KKeyNative::KKeyNative( uint code, uint mod, uint sym )
00066 {
00067 m_code = code;
00068 m_mod = mod;
00069 m_sym = sym;
00070 }
00071
00072 KKeyNative::~KKeyNative()
00073 { }
00074
00075 void KKeyNative::clear()
00076 {
00077 m_code = 0;
00078 m_mod = 0;
00079 m_sym = 0;
00080 }
00081
00082 bool KKeyNative::init( const XEvent* pEvent )
00083 {
00084 m_code = pEvent->xkey.keycode;
00085 m_mod = pEvent->xkey.state;
00086 XLookupString( (XKeyEvent*) pEvent, 0, 0, (KeySym*) &m_sym, 0 );
00087 return true;
00088 }
00089
00090 bool KKeyNative::init( const KKey& key )
00091 {
00092
00093
00094 m_sym = key.sym();
00095 uint modExtra = KKeyServer::Sym(m_sym).getModsRequired();
00096
00097 if( !m_sym || !KKeyServer::modToModX( key.modFlags() | modExtra, m_mod ) ) {
00098 m_sym = m_mod = 0;
00099 m_code = 0;
00100 return false;
00101 }
00102
00103
00104
00105
00106 if( m_sym == XK_Print && !(m_mod & Mod1Mask) )
00107 m_code = 111;
00108 else if( m_sym == XK_Break || (m_sym == XK_Pause && (m_mod & ControlMask)) )
00109 m_code = 114;
00110 else
00111 m_code = XKeysymToKeycode( qt_xdisplay(), m_sym );
00112
00113 if( !m_code && m_sym )
00114 kdDebug(125) << "Couldn't get code for sym" << endl;
00115
00116
00117 if( key.modFlags() )
00118 KKeyServer::codeXToSym( m_code, m_mod, m_sym );
00119
00120 return true;
00121 }
00122
00123 bool KKeyNative::init( const KKeyNative& key )
00124 {
00125 m_code = key.m_code;
00126 m_mod = key.m_mod;
00127 m_sym = key.m_sym;
00128 return true;
00129 }
00130
00131 uint KKeyNative::code() const { return m_code; }
00132 uint KKeyNative::mod() const { return m_mod; }
00133 uint KKeyNative::sym() const { return m_sym; }
00134
00135 bool KKeyNative::isNull() const
00136 {
00137 return m_sym == 0;
00138 }
00139
00140 int KKeyNative::compare( const KKeyNative& key ) const
00141 {
00142 if( m_sym != key.m_sym ) return m_sym - key.m_sym;
00143 if( m_mod != key.m_mod ) return m_mod - key.m_mod;
00144 if( m_code != key.m_code ) return m_code - key.m_code;
00145 return 0;
00146 }
00147
00148 KKeyNative& KKeyNative::null()
00149 {
00150 if( !gx_pkey )
00151 gx_pkey = new KKeyNative;
00152 if( !gx_pkey->isNull() )
00153 gx_pkey->clear();
00154 return *gx_pkey;
00155 }
00156
00157 KKey KKeyNative::key() const
00158 {
00159 uint modSpec;
00160 if( KKeyServer::modXToMod( m_mod, modSpec ) )
00161 return KKey( m_sym, modSpec );
00162 else
00163 return KKey();
00164 }
00165
00166 int KKeyNative::keyCodeQt() const
00167 {
00168 int keyQt = KKeyServer::Sym(m_sym).qt(), modQt;
00169
00170 if( keyQt != Qt::Key_unknown && KKeyServer::modXToModQt( m_mod, modQt ) )
00171 return keyQt | modQt;
00172
00173 return 0;
00174 }
00175
00176 uint KKeyNative::modX( KKey::ModFlag modFlag ) { return KKeyServer::modX( modFlag ); }
00177 bool KKeyNative::keyboardHasWinKey() { return KKeyServer::keyboardHasWinKey(); }
00178 uint KKeyNative::accelModMaskX() { return KKeyServer::accelModMaskX(); }
00179
00180 #endif // Q_WS_X11
This file is part of the documentation for kdelibs Version 3.1.0.