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

kdecore

  • kdecore
kkeynative_x11.cpp
1 /*
2  Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
3 
4  Win32 port:
5  Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include <tqnamespace.h>
24 #include <tqwindowdefs.h>
25 
26 #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
27 
28 #include "kkeynative.h"
29 #include "kkeyserver_x11.h"
30 
31 #include <tqmap.h>
32 #include <tqstringlist.h>
33 #include "kckey.h"
34 #include <kdebug.h>
35 #include <klocale.h>
36 
37 #ifdef Q_WS_X11
38 #define XK_MISCELLANY
39 #define XK_XKB_KEYS
40 #include <X11/X.h>
41 #include <X11/Xlib.h>
42 #include <X11/Xutil.h>
43 #include <X11/keysymdef.h>
44 #include <ctype.h>
45 #endif
46 
47 //---------------------------------------------------------------------
48 
49 static KKeyNative* gx_pkey = 0;
50 
51 //---------------------------------------------------------------------
52 // KKeyNative
53 //---------------------------------------------------------------------
54 
55 KKeyNative::KKeyNative() { clear(); }
56 KKeyNative::KKeyNative( const KKey& key ) { init( key ); }
57 KKeyNative::KKeyNative( const KKeyNative& key ) { init( key ); }
58 #ifdef Q_WS_X11
59 KKeyNative::KKeyNative( const XEvent* pEvent ) { init( pEvent ); }
60 #endif
61 
62 KKeyNative::KKeyNative( uint code, uint mod, uint sym )
63 {
64  m_code = code;
65  m_mod = mod;
66  m_sym = sym;
67 }
68 
69 KKeyNative::~KKeyNative()
70  { }
71 
72 void KKeyNative::clear()
73 {
74  m_code = 0;
75  m_mod = 0;
76  m_sym = 0;
77 }
78 
79 #ifdef Q_WS_X11
80 bool KKeyNative::init( const XEvent* pEvent )
81 {
82  KeySym keySym;
83  m_code = pEvent->xkey.keycode;
84  m_mod = pEvent->xkey.state;
85  XLookupString( (XKeyEvent*) pEvent, 0, 0, &keySym, 0 );
86  m_sym = (uint) keySym;
87  return true;
88 }
89 #endif
90 
91 bool KKeyNative::init( const KKey& key )
92 {
93 #ifdef Q_WS_WIN
94  m_sym = key.sym();
95  m_code = m_sym; //key.keyCodeQt();
96  m_mod = key.m_mod;
97 #elif !defined(Q_WS_WIN) && !defined(Q_WS_MACX)
98  // Get any extra mods required by the sym.
99  // E.g., XK_Plus requires SHIFT on the en layout.
100  m_sym = key.sym();
101  uint modExtra = KKeyServer::Sym(m_sym).getModsRequired();
102  // Get the X modifier equivalent.
103  if( !m_sym || !KKeyServer::modToModX( key.modFlags() | modExtra, m_mod ) ) {
104  m_sym = m_mod = 0;
105  m_code = 0;
106  return false;
107  }
108 
109  // XKeysymToKeycode returns the wrong keycode for XK_Print and XK_Break.
110  // Specifically, it returns the code for SysReq instead of Print
111  // Only do this for the default Xorg layout, other keycode mappings
112  // (e.g. evdev) don't need or want it.
113  if( m_sym == XK_Print && !(m_mod & Mod1Mask) &&
114  XKeycodeToKeysym( qt_xdisplay(), 111, 0 ) == XK_Print )
115  m_code = 111; // code for Print
116  else if( m_sym == XK_Break || (m_sym == XK_Pause && (m_mod & ControlMask)) &&
117  XKeycodeToKeysym( qt_xdisplay(), 114, 0 ) == XK_Pause )
118  m_code = 114;
119  else
120  m_code = XKeysymToKeycode( qt_xdisplay(), m_sym );
121 
122  if( !m_code && m_sym )
123  kdDebug(125) << "Couldn't get code for sym" << endl;
124  // Now get the true sym formed by the modifiers
125  // E.g., Shift+Equal => Plus on the en layout.
126  if( key.modFlags() && ( ( m_sym < XK_Home || m_sym > XK_Begin ) &&
127  m_sym != XK_Insert && m_sym != XK_Delete ))
128  KKeyServer::codeXToSym( m_code, m_mod, m_sym );
129 #endif
130  return true;
131 }
132 
133 bool KKeyNative::init( const KKeyNative& key )
134 {
135  m_code = key.m_code;
136  m_mod = key.m_mod;
137  m_sym = key.m_sym;
138  return true;
139 }
140 
141 uint KKeyNative::code() const { return m_code; }
142 uint KKeyNative::mod() const { return m_mod; }
143 uint KKeyNative::sym() const { return m_sym; }
144 
145 bool KKeyNative::isNull() const
146 {
147  return m_sym == 0;
148 }
149 
150 int KKeyNative::compare( const KKeyNative& key ) const
151 {
152  if( m_sym != key.m_sym ) return m_sym - key.m_sym;
153  if( m_mod != key.m_mod ) return m_mod - key.m_mod;
154  if( m_code != key.m_code ) return m_code - key.m_code;
155  return 0;
156 }
157 
158 KKeyNative& KKeyNative::null()
159 {
160  if( !gx_pkey )
161  gx_pkey = new KKeyNative;
162  if( !gx_pkey->isNull() )
163  gx_pkey->clear();
164  return *gx_pkey;
165 }
166 
167 KKey KKeyNative::key() const
168 {
169 #ifdef Q_WS_WIN
170  return KKey( m_sym, m_mod );
171 #else
172  uint modSpec;
173  if( KKeyServer::modXToMod( m_mod, modSpec ) )
174  return KKey( m_sym, modSpec );
175  else
176  return KKey();
177 #endif
178 }
179 
180 int KKeyNative::keyCodeQt() const
181 {
182  int keyQt = KKeyServer::Sym(m_sym).qt();
183  int modQt;
184 
185  if( (keyQt != TQt::Key_unknown) && (KKeyServer::modXToModQt( m_mod, modQt )) ) {
186  return keyQt | modQt;
187  }
188 
189  return 0;
190 }
191 
192 bool KKeyNative::keyboardHasWinKey() { return KKeyServer::keyboardHasWinKey(); }
193 
194 #ifdef Q_WS_X11
195 uint KKeyNative::modX( KKey::ModFlag modFlag ) { return KKeyServer::modX( modFlag ); }
196 uint KKeyNative::accelModMaskX() { return KKeyServer::accelModMaskX(); }
197 uint KKeyNative::modXNumLock() { return KKeyServer::modXNumLock(); }
198 uint KKeyNative::modXLock() { return KKeyServer::modXLock(); }
199 uint KKeyNative::modXScrollLock() { return KKeyServer::modXScrollLock(); }
200 uint KKeyNative::modXModeSwitch() { return KKeyServer::modXModeSwitch(); }
201 #endif
202 
203 #endif // Q_WS_X11
KKey::ModFlag
ModFlag
Flags to represent the modifiers.
Definition: kshortcut.h:53
KKeyServer::Sym
Represents a key symbol.
Definition: kkeyserver_x11.h:47
KKeyServer::codeXToSym
bool codeXToSym(uchar codeX, uint modX, uint &symX)
Converts a X11 key code and a mask of ORed X11 modifiers into a X11 symbol.
KKeyNative::compare
int compare(const KKeyNative &key) const
Compares this key with the given KKeyNative object.
KKeyNative::key
KKey key() const
Returns the KKey representation of this key.
KKeyServer::Sym::getModsRequired
uint getModsRequired() const
Returns the mods that are required for this symbol as ORed KKey::ModFlag&#39;s.
KKeyServer::modXNumLock
uint modXNumLock()
Returns the X11 NumLock modifier mask/flag.
KKeyServer::modXScrollLock
uint modXScrollLock()
Returns the X11 ScrollLock modifier mask/flag.
KKeyServer::modXModeSwitch
uint modXModeSwitch()
Returns the X11 Mode_switch modifier mask/flag.
KKeyNative::init
bool init(const KKey &key)
Creates a new native key for the given KKey code.
klocale.h
KKeyNative::clear
void clear()
Clears the key.
KKeyServer::keyboardHasWinKey
bool keyboardHasWinKey()
Returns true if the current keyboard layout supports the Win key.
KKeyNative::keyCodeQt
int keyCodeQt() const
Returns the qt key code.
KKeyNative::mod
uint mod() const
The native modifier flags of the key.
KKeyNative::code
uint code() const
The native keycode of the key.
KKeyServer::modX
uint modX(KKey::ModFlag modFlag)
Returns the equivalent X modifier mask of the given modifier flag.
KKeyServer::modXToMod
bool modXToMod(uint modX, uint &mod)
Converts the mask of ORed X11 modifiers to a mask of ORed KKey::ModFlag modifiers.
KKeyServer::Sym::qt
int qt() const
Returns the qt key code of the symbol.
KKeyServer::modXLock
uint modXLock()
Returns the X11 Lock modifier mask/flag.
KKeyServer::modToModX
bool modToModX(uint mod, uint &modX)
Converts the mask of ORed KKey::ModFlag modifiers to a mask of ORed X11 modifiers.
KKeyNative
Representation of a key in the format native of the windowing system (eg.
Definition: kkeynative.h:37
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: kshortcut.h:40
KKeyServer::modXToModQt
bool modXToModQt(uint modX, int &modQt)
Converts the mask of ORed X11 modifiers to a mask of ORed Qt key code modifiers.
KKeyNative::keyboardHasWinKey
static bool keyboardHasWinKey()
Checks whether the keyboard has a Win key.
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KKeyNative::sym
uint sym() const
The native symbol (KeySym) of the key.
KKeyNative::null
static KKeyNative & null()
Returns a null key.
KKeyNative::isNull
bool isNull() const
Returns true if the key is null (after clear() or empty constructor).
KKeyNative::KKeyNative
KKeyNative()
Creates a new null KKey.
KKeyServer::accelModMaskX
uint accelModMaskX()
Returns bitwise OR&#39;ed mask containing Shift, Ctrl, Alt, and Win (if available).

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |