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