kkeynative_x11.cpp Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kkeynative_x11.cpp

    00001 /*
    00002     Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    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 // defined by X11 headers
    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 // KKeyNative
    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         // Get any extra mods required by the sym.
    00093         //  E.g., XK_Plus requires SHIFT on the en layout.
    00094         m_sym = key.sym();
    00095         uint modExtra = KKeyServer::Sym(m_sym).getModsRequired();
    00096         // Get the X modifier equivalent.
    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         // FIXME: Accomadate non-standard layouts
    00104         // XKeysymToKeycode returns the wrong keycode for XK_Print and XK_Break.
    00105         // Specifically, it returns the code for SysReq instead of Print
    00106         if( m_sym == XK_Print && !(m_mod & Mod1Mask) )
    00107                 m_code = 111; // code for Print
    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         // Now get the true sym formed by the modifiers
    00116         //  E.g., Shift+Equal => Plus on the en layout.
    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 uint KKeyNative::modXNumLock()                 { return KKeyServer::modXNumLock(); }
    00180 uint KKeyNative::modXLock()                    { return KKeyServer::modXLock(); }
    00181 uint KKeyNative::modXScrollLock()              { return KKeyServer::modXScrollLock(); }
    00182
    00183 #endif // Q_WS_X11

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:34 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001