Update ooo320-m1
[ooovba.git] / vcl / unx / source / app / i18n_xkb.cxx
blob999e7353fc39e358eafca86d20e591b9d010fe91
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: i18n_xkb.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
35 #include <stdio.h>
37 #include "saldisp.hxx"
38 #include "saldata.hxx"
39 #include "i18n_xkb.hxx"
41 SalI18N_KeyboardExtension::SalI18N_KeyboardExtension( Display*
42 #if __XKeyboardExtension__
43 pDisplay
44 #endif
46 : mbUseExtension( (sal_Bool)__XKeyboardExtension__ ),
47 mnDefaultGroup( 0 )
49 #if __XKeyboardExtension__
51 mpDisplay = pDisplay;
53 // allow user to set the default keyboard group idx or to disable the usage
54 // of x keyboard extension at all:
55 // setenv SAL_XKEYBOARDGROUP disables keyboard extension
56 // setenv SAL_XKEYBOARDGROUP 2 sets the keyboard group index to 2
57 // keyboard group index must be in [1,4], may be specified in hex or decimal
58 static char *pUseKeyboardExtension = getenv( "SAL_XKEYBOARDGROUP" );
59 if ( pUseKeyboardExtension != NULL )
61 mbUseExtension = pUseKeyboardExtension[0] != '\0' ;
62 if ( mbUseExtension )
63 mnDefaultGroup = strtol( pUseKeyboardExtension, NULL, 0 );
64 if ( mnDefaultGroup > XkbMaxKbdGroup )
65 mnDefaultGroup = 0;
68 // query XServer support for XKB Extension,
69 // do not call XQueryExtension() / XInitExtension() due to possible version
70 // clashes !
71 if ( mbUseExtension )
73 int nMajorExtOpcode;
74 int nExtMajorVersion = XkbMajorVersion;
75 int nExtMinorVersion = XkbMinorVersion;
77 mbUseExtension = (sal_Bool)XkbQueryExtension( mpDisplay,
78 &nMajorExtOpcode, (int*)&mnEventBase, (int*)&mnErrorBase,
79 &nExtMajorVersion, &nExtMinorVersion );
82 // query notification for changes of the keyboard group
83 if ( mbUseExtension )
85 #define XkbGroupMask ( XkbGroupStateMask | XkbGroupBaseMask \
86 | XkbGroupLatchMask | XkbGroupLockMask )
88 mbUseExtension = XkbSelectEventDetails( mpDisplay,
89 XkbUseCoreKbd, XkbStateNotify, XkbGroupMask, XkbGroupMask );
92 // query initial keyboard group
93 if ( mbUseExtension )
95 XkbStateRec aStateRecord;
96 XkbGetState( mpDisplay, XkbUseCoreKbd, &aStateRecord );
97 mnGroup = aStateRecord.group;
100 #endif // __XKeyboardExtension__
103 void
104 SalI18N_KeyboardExtension::Dispatch( XEvent*
105 #if __XKeyboardExtension__
106 pEvent
107 #endif
110 #if __XKeyboardExtension__
112 // must the event be handled?
113 if ( !mbUseExtension
114 || (pEvent->type != mnEventBase) )
115 return;
117 // only handle state notify events for now, and only interested
118 // in group details
119 sal_uInt32 nXKBType = ((XkbAnyEvent*)pEvent)->xkb_type;
120 switch ( nXKBType )
122 case XkbStateNotify:
124 mnGroup = ((XkbStateNotifyEvent*)pEvent)->group;
125 break;
127 default:
129 #if OSL_DEBUG_LEVEL > 1
130 fprintf(stderr, "Got unrequested XkbAnyEvent %#x/%i\n",
131 static_cast<unsigned int>(nXKBType), static_cast<int>(nXKBType) );
132 #endif
133 break;
135 #endif // __XKeyboardExtension__
138 #if __XKeyboardExtension__
139 sal_uInt32
140 SalI18N_KeyboardExtension::LookupKeysymInGroup( sal_uInt32 nKeyCode,
141 sal_uInt32 nShiftState,
142 sal_uInt32 nGroup ) const
143 #else
144 sal_uInt32
145 SalI18N_KeyboardExtension::LookupKeysymInGroup( sal_uInt32,sal_uInt32,sal_uInt32 ) const
146 #endif
148 #if __XKeyboardExtension__
150 if ( !mbUseExtension )
151 return NoSymbol;
153 nShiftState &= ShiftMask;
155 KeySym nKeySymbol;
156 nKeySymbol = XkbKeycodeToKeysym( mpDisplay, nKeyCode, nGroup, nShiftState );
157 return nKeySymbol;
159 #else
161 return NoSymbol;
163 #endif // __XKeyboardExtension__