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

tdecore

  • tdecore
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(TQ_WS_X11) || defined(TQ_WS_WIN) || defined(TQ_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 <tdelocale.h>
36
37#ifdef TQ_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/XKBlib.h>
44#include <X11/keysymdef.h>
45#include <ctype.h>
46#endif
47
48//---------------------------------------------------------------------
49
50static KKeyNative* gx_pkey = 0;
51
52//---------------------------------------------------------------------
53// KKeyNative
54//---------------------------------------------------------------------
55
56KKeyNative::KKeyNative() { clear(); }
57KKeyNative::KKeyNative( const KKey& key ) { init( key ); }
58KKeyNative::KKeyNative( const KKeyNative& key ) { init( key ); }
59#ifdef TQ_WS_X11
60KKeyNative::KKeyNative( const XEvent* pEvent ) { init( pEvent ); }
61#endif
62
63KKeyNative::KKeyNative( uint code, uint mod, uint sym )
64{
65 m_code = code;
66 m_mod = mod;
67 m_sym = sym;
68}
69
70KKeyNative::~KKeyNative()
71 { }
72
73void KKeyNative::clear()
74{
75 m_code = 0;
76 m_mod = 0;
77 m_sym = 0;
78}
79
80#ifdef TQ_WS_X11
81bool KKeyNative::init( const XEvent* pEvent )
82{
83 KeySym keySym;
84 m_code = pEvent->xkey.keycode;
85 m_mod = pEvent->xkey.state;
86 XLookupString( (XKeyEvent*) pEvent, 0, 0, &keySym, 0 );
87 m_sym = (uint) keySym;
88 return true;
89}
90#endif
91
92bool KKeyNative::init( const KKey& key )
93{
94#ifdef TQ_WS_WIN
95 m_sym = key.sym();
96 m_code = m_sym; //key.keyCodeQt();
97 m_mod = key.m_mod;
98#elif !defined(TQ_WS_WIN) && !defined(TQ_WS_MACX)
99 // Get any extra mods required by the sym.
100 // E.g., XK_Plus requires SHIFT on the en layout.
101 m_sym = key.sym();
102 uint modExtra = KKeyServer::Sym(m_sym).getModsRequired();
103 // Get the X modifier equivalent.
104 if( !m_sym || !KKeyServer::modToModX( key.modFlags() | modExtra, m_mod ) ) {
105 m_sym = m_mod = 0;
106 m_code = 0;
107 return false;
108 }
109
110 // XKeysymToKeycode returns the wrong keycode for XK_Print and XK_Break.
111 // Specifically, it returns the code for SysReq instead of Print
112 // Only do this for the default Xorg layout, other keycode mappings
113 // (e.g. evdev) don't need or want it.
114 if( m_sym == XK_Print && !(m_mod & Mod1Mask) &&
115 XkbKeycodeToKeysym( tqt_xdisplay(), 111, 0, 0 ) == XK_Print )
116 m_code = 111; // code for Print
117 else if( m_sym == XK_Break || (m_sym == XK_Pause && (m_mod & ControlMask)) &&
118 XkbKeycodeToKeysym( tqt_xdisplay(), 114, 0, 0 ) == XK_Pause )
119 m_code = 114;
120 else
121 m_code = XKeysymToKeycode( tqt_xdisplay(), m_sym );
122
123 if( !m_code && m_sym )
124 kdDebug(125) << "Couldn't get code for sym" << endl;
125 // Now get the true sym formed by the modifiers
126 // E.g., Shift+Equal => Plus on the en layout.
127 if( key.modFlags() && ( ( m_sym < XK_Home || m_sym > XK_Begin ) &&
128 m_sym != XK_Insert && m_sym != XK_Delete ))
129 KKeyServer::codeXToSym( m_code, m_mod, m_sym );
130#endif
131 return true;
132}
133
134bool KKeyNative::init( const KKeyNative& key )
135{
136 m_code = key.m_code;
137 m_mod = key.m_mod;
138 m_sym = key.m_sym;
139 return true;
140}
141
142uint KKeyNative::code() const { return m_code; }
143uint KKeyNative::mod() const { return m_mod; }
144uint KKeyNative::sym() const { return m_sym; }
145
146bool KKeyNative::isNull() const
147{
148 return m_sym == 0;
149}
150
151int KKeyNative::compare( const KKeyNative& key ) const
152{
153 if( m_sym != key.m_sym ) return m_sym - key.m_sym;
154 if( m_mod != key.m_mod ) return m_mod - key.m_mod;
155 if( m_code != key.m_code ) return m_code - key.m_code;
156 return 0;
157}
158
159KKeyNative& KKeyNative::null()
160{
161 if( !gx_pkey )
162 gx_pkey = new KKeyNative;
163 if( !gx_pkey->isNull() )
164 gx_pkey->clear();
165 return *gx_pkey;
166}
167
168KKey KKeyNative::key() const
169{
170#ifdef TQ_WS_WIN
171 return KKey( m_sym, m_mod );
172#else
173 uint modSpec;
174 if( KKeyServer::modXToMod( m_mod, modSpec ) )
175 return KKey( m_sym, modSpec );
176 else
177 return KKey();
178#endif
179}
180
181int KKeyNative::keyCodeQt() const
182{
183 int keyQt = KKeyServer::Sym(m_sym).qt();
184 int modQt;
185
186 if( (keyQt != TQt::Key_unknown) && (KKeyServer::modXToModQt( m_mod, modQt )) ) {
187 return keyQt | modQt;
188 }
189
190 return 0;
191}
192
193bool KKeyNative::keyboardHasWinKey() { return KKeyServer::keyboardHasWinKey(); }
194
195#ifdef TQ_WS_X11
196uint KKeyNative::modX( KKey::ModFlag modFlag ) { return KKeyServer::modX( modFlag ); }
197uint KKeyNative::accelModMaskX() { return KKeyServer::accelModMaskX(); }
198uint KKeyNative::modXNumLock() { return KKeyServer::modXNumLock(); }
199uint KKeyNative::modXLock() { return KKeyServer::modXLock(); }
200uint KKeyNative::modXScrollLock() { return KKeyServer::modXScrollLock(); }
201uint KKeyNative::modXModeSwitch() { return KKeyServer::modXModeSwitch(); }
202#endif
203
204#endif // TQ_WS_X11
KKeyNative
Representation of a key in the format native of the windowing system (eg.
Definition: kkeynative.h:38
KKeyNative::clear
void clear()
Clears the key.
KKeyNative::compare
int compare(const KKeyNative &key) const
Compares this key with the given KKeyNative object.
KKeyNative::keyCodeQt
int keyCodeQt() const
Returns the qt key code.
KKeyNative::isNull
bool isNull() const
Returns true if the key is null (after clear() or empty constructor).
KKeyNative::key
KKey key() const
Returns the KKey representation of this key.
KKeyNative::mod
uint mod() const
The native modifier flags of the key.
KKeyNative::code
uint code() const
The native keycode of the key.
KKeyNative::sym
uint sym() const
The native symbol (KeySym) of the key.
KKeyNative::null
static KKeyNative & null()
Returns a null key.
KKeyNative::init
bool init(const KKey &key)
Creates a new native key for the given KKey code.
KKeyNative::KKeyNative
KKeyNative()
Creates a new null KKey.
KKeyNative::keyboardHasWinKey
static bool keyboardHasWinKey()
Checks whether the keyboard has a Win key.
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: tdeshortcut.h:41
KKey::ModFlag
ModFlag
Flags to represent the modifiers.
Definition: tdeshortcut.h:53
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KKeyServer::modXModeSwitch
uint modXModeSwitch()
Returns the X11 Mode_switch modifier mask/flag.
KKeyServer::modX
uint modX(KKey::ModFlag modFlag)
Returns the equivalent X modifier mask of the given modifier flag.
KKeyServer::modXNumLock
uint modXNumLock()
Returns the X11 NumLock modifier mask/flag.
KKeyServer::modXToModQt
bool modXToModQt(uint modX, int &modQt)
Converts the mask of ORed X11 modifiers to a mask of ORed Qt key code modifiers.
KKeyServer::modXLock
uint modXLock()
Returns the X11 Lock modifier mask/flag.
KKeyServer::keyboardHasWinKey
bool keyboardHasWinKey()
Returns true if the current keyboard layout supports the Win key.
KKeyServer::modToModX
bool modToModX(uint mod, uint &modX)
Converts the mask of ORed KKey::ModFlag modifiers to a mask of ORed X11 modifiers.
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.
KKeyServer::modXToMod
bool modXToMod(uint modX, uint &mod)
Converts the mask of ORed X11 modifiers to a mask of ORed KKey::ModFlag modifiers.
KKeyServer::accelModMaskX
uint accelModMaskX()
Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and Win (if available).
KKeyServer::modXScrollLock
uint modXScrollLock()
Returns the X11 ScrollLock modifier mask/flag.
KKeyServer::Sym
Represents a key symbol.
Definition: kkeyserver_x11.h:48
KKeyServer::Sym::qt
int qt() const
Returns the qt key code of the symbol.
KKeyServer::Sym::getModsRequired
uint getModsRequired() const
Returns the mods that are required for this symbol as ORed KKey::ModFlag's.
tdelocale.h

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.9.4
This website is maintained by Timothy Pearson.