• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

kkeynative_x11.cpp

00001 /*
00002     Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
00003 
00004     Win32 port:
00005     Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <tqnamespace.h>
00024 #include <tqwindowdefs.h>
00025 
00026 #if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_MACX) // Only compile this module if we're compiling for X11, mac or win32
00027 
00028 #include "kkeynative.h"
00029 #include "kkeyserver_x11.h"
00030 
00031 #include <tqmap.h>
00032 #include <tqstringlist.h>
00033 #include "kckey.h"
00034 #include <kdebug.h>
00035 #include <tdelocale.h>
00036 
00037 #ifdef Q_WS_X11
00038 #define XK_MISCELLANY
00039 #define XK_XKB_KEYS
00040 #include <X11/X.h>
00041 #include <X11/Xlib.h>
00042 #include <X11/Xutil.h>
00043 #include <X11/XKBlib.h>
00044 #include <X11/keysymdef.h>
00045 #include <ctype.h>
00046 #endif
00047 
00048 //---------------------------------------------------------------------
00049 
00050 static KKeyNative* gx_pkey = 0;
00051 
00052 //---------------------------------------------------------------------
00053 // KKeyNative
00054 //---------------------------------------------------------------------
00055 
00056 KKeyNative::KKeyNative()                           { clear(); }
00057 KKeyNative::KKeyNative( const KKey& key )          { init( key ); }
00058 KKeyNative::KKeyNative( const KKeyNative& key )    { init( key ); }
00059 #ifdef Q_WS_X11
00060 KKeyNative::KKeyNative( const XEvent* pEvent )     { init( pEvent ); }
00061 #endif
00062 
00063 KKeyNative::KKeyNative( uint code, uint mod, uint sym )
00064 {
00065     m_code = code;
00066     m_mod = mod;
00067     m_sym = sym;
00068 }
00069 
00070 KKeyNative::~KKeyNative()
00071     { }
00072 
00073 void KKeyNative::clear()
00074 {
00075     m_code = 0;
00076     m_mod = 0;
00077     m_sym = 0;
00078 }
00079 
00080 #ifdef Q_WS_X11
00081 bool KKeyNative::init( const XEvent* pEvent )
00082 {
00083     KeySym keySym;
00084     m_code = pEvent->xkey.keycode;
00085     m_mod = pEvent->xkey.state;
00086     XLookupString( (XKeyEvent*) pEvent, 0, 0, &keySym, 0 );
00087     m_sym = (uint) keySym;
00088     return true;
00089 }
00090 #endif
00091 
00092 bool KKeyNative::init( const KKey& key )
00093 {
00094 #ifdef Q_WS_WIN
00095     m_sym = key.sym();
00096     m_code = m_sym; //key.keyCodeQt();
00097     m_mod = key.m_mod;
00098 #elif !defined(Q_WS_WIN) && !defined(Q_WS_MACX)
00099     // Get any extra mods required by the sym.
00100     //  E.g., XK_Plus requires SHIFT on the en layout.
00101     m_sym = key.sym();
00102     uint modExtra = KKeyServer::Sym(m_sym).getModsRequired();
00103     // Get the X modifier equivalent.
00104     if( !m_sym || !KKeyServer::modToModX( key.modFlags() | modExtra, m_mod ) ) {
00105         m_sym = m_mod = 0;
00106         m_code = 0;
00107         return false;
00108     }
00109 
00110     // XKeysymToKeycode returns the wrong keycode for XK_Print and XK_Break.
00111     // Specifically, it returns the code for SysReq instead of Print
00112     // Only do this for the default Xorg layout, other keycode mappings
00113     // (e.g. evdev) don't need or want it.
00114     if( m_sym == XK_Print && !(m_mod & Mod1Mask) &&
00115                 XkbKeycodeToKeysym( tqt_xdisplay(), 111, 0, 0 ) == XK_Print )
00116         m_code = 111; // code for Print
00117     else if( m_sym == XK_Break || (m_sym == XK_Pause && (m_mod & ControlMask)) &&
00118                 XkbKeycodeToKeysym( tqt_xdisplay(), 114, 0, 0 ) == XK_Pause )
00119         m_code = 114;
00120     else
00121         m_code = XKeysymToKeycode( tqt_xdisplay(), m_sym );
00122 
00123     if( !m_code && m_sym )
00124         kdDebug(125) << "Couldn't get code for sym" << endl;
00125     // Now get the true sym formed by the modifiers
00126     //  E.g., Shift+Equal => Plus on the en layout.
00127     if( key.modFlags() && ( ( m_sym < XK_Home || m_sym > XK_Begin ) && 
00128                   m_sym != XK_Insert && m_sym != XK_Delete ))
00129         KKeyServer::codeXToSym( m_code, m_mod, m_sym );
00130 #endif
00131     return true;
00132 }
00133 
00134 bool KKeyNative::init( const KKeyNative& key )
00135 {
00136     m_code = key.m_code;
00137     m_mod = key.m_mod;
00138     m_sym = key.m_sym;
00139     return true;
00140 }
00141 
00142 uint KKeyNative::code() const { return m_code; }
00143 uint KKeyNative::mod() const  { return m_mod; }
00144 uint KKeyNative::sym() const  { return m_sym; }
00145 
00146 bool KKeyNative::isNull() const
00147 {
00148     return m_sym == 0;
00149 }
00150 
00151 int KKeyNative::compare( const KKeyNative& key ) const
00152 {
00153     if( m_sym != key.m_sym )   return m_sym - key.m_sym;
00154     if( m_mod != key.m_mod )   return m_mod - key.m_mod;
00155     if( m_code != key.m_code ) return m_code - key.m_code;
00156     return 0;
00157 }
00158 
00159 KKeyNative& KKeyNative::null()
00160 {
00161     if( !gx_pkey )
00162         gx_pkey = new KKeyNative;
00163     if( !gx_pkey->isNull() )
00164         gx_pkey->clear();
00165     return *gx_pkey;
00166 }
00167 
00168 KKey KKeyNative::key() const
00169 {
00170 #ifdef Q_WS_WIN
00171     return KKey( m_sym, m_mod );
00172 #else
00173     uint modSpec;
00174     if( KKeyServer::modXToMod( m_mod, modSpec ) )
00175         return KKey( m_sym, modSpec );
00176     else
00177         return KKey();
00178 #endif
00179 }
00180 
00181 int KKeyNative::keyCodeQt() const
00182 {
00183     int keyQt = KKeyServer::Sym(m_sym).qt();
00184     int modQt;
00185 
00186     if( (keyQt != TQt::Key_unknown) && (KKeyServer::modXToModQt( m_mod, modQt )) ) {
00187         return keyQt | modQt;
00188     }
00189 
00190     return 0;
00191 }
00192 
00193 bool KKeyNative::keyboardHasWinKey()           { return KKeyServer::keyboardHasWinKey(); }
00194 
00195 #ifdef Q_WS_X11
00196 uint KKeyNative::modX( KKey::ModFlag modFlag ) { return KKeyServer::modX( modFlag ); }
00197 uint KKeyNative::accelModMaskX()               { return KKeyServer::accelModMaskX(); }
00198 uint KKeyNative::modXNumLock()                 { return KKeyServer::modXNumLock(); }
00199 uint KKeyNative::modXLock()                    { return KKeyServer::modXLock(); }
00200 uint KKeyNative::modXScrollLock()              { return KKeyServer::modXScrollLock(); }
00201 uint KKeyNative::modXModeSwitch()              { return KKeyServer::modXModeSwitch(); }
00202 #endif
00203 
00204 #endif // Q_WS_X11

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.6.3
This website is maintained by Timothy Pearson.