1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: i18n_xkb.cxx,v $
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"
37 #include "saldisp.hxx"
38 #include "saldata.hxx"
39 #include "i18n_xkb.hxx"
41 SalI18N_KeyboardExtension::SalI18N_KeyboardExtension( Display
*
42 #if __XKeyboardExtension__
46 : mbUseExtension( (sal_Bool
)__XKeyboardExtension__
),
49 #if __XKeyboardExtension__
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' ;
63 mnDefaultGroup
= strtol( pUseKeyboardExtension
, NULL
, 0 );
64 if ( mnDefaultGroup
> XkbMaxKbdGroup
)
68 // query XServer support for XKB Extension,
69 // do not call XQueryExtension() / XInitExtension() due to possible version
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
85 #define XkbGroupMask ( XkbGroupStateMask | XkbGroupBaseMask \
86 | XkbGroupLatchMask | XkbGroupLockMask )
88 mbUseExtension
= XkbSelectEventDetails( mpDisplay
,
89 XkbUseCoreKbd
, XkbStateNotify
, XkbGroupMask
, XkbGroupMask
);
92 // query initial keyboard group
95 XkbStateRec aStateRecord
;
96 XkbGetState( mpDisplay
, XkbUseCoreKbd
, &aStateRecord
);
97 mnGroup
= aStateRecord
.group
;
100 #endif // __XKeyboardExtension__
104 SalI18N_KeyboardExtension::Dispatch( XEvent
*
105 #if __XKeyboardExtension__
110 #if __XKeyboardExtension__
112 // must the event be handled?
114 || (pEvent
->type
!= mnEventBase
) )
117 // only handle state notify events for now, and only interested
119 sal_uInt32 nXKBType
= ((XkbAnyEvent
*)pEvent
)->xkb_type
;
124 mnGroup
= ((XkbStateNotifyEvent
*)pEvent
)->group
;
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
) );
135 #endif // __XKeyboardExtension__
138 #if __XKeyboardExtension__
140 SalI18N_KeyboardExtension::LookupKeysymInGroup( sal_uInt32 nKeyCode
,
141 sal_uInt32 nShiftState
,
142 sal_uInt32 nGroup
) const
145 SalI18N_KeyboardExtension::LookupKeysymInGroup( sal_uInt32
,sal_uInt32
,sal_uInt32
) const
148 #if __XKeyboardExtension__
150 if ( !mbUseExtension
)
153 nShiftState
&= ShiftMask
;
156 nKeySymbol
= XkbKeycodeToKeysym( mpDisplay
, nKeyCode
, nGroup
, nShiftState
);
163 #endif // __XKeyboardExtension__