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