bump product version to 5.0.4.1
[LibreOffice.git] / vcl / unx / generic / app / i18n_xkb.cxx
blobf9618f4d98264299e7bdafd867d0f91309bc1b34
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
22 #include "unx/saldisp.hxx"
23 #include "unx/saldata.hxx"
24 #include "unx/i18n_xkb.hxx"
26 SalI18N_KeyboardExtension::SalI18N_KeyboardExtension( Display* pDisplay )
27 : mbUseExtension(true)
28 , mnDefaultGroup(0)
29 , mnGroup(0)
30 , mnEventBase(0)
31 , mnErrorBase(0)
32 , mpDisplay(pDisplay)
35 // allow user to set the default keyboard group idx or to disable the usage
36 // of x keyboard extension at all:
37 // setenv SAL_XKEYBOARDGROUP disables keyboard extension
38 // setenv SAL_XKEYBOARDGROUP 2 sets the keyboard group index to 2
39 // keyboard group index must be in [1,4], may be specified in hex or decimal
40 static char *pUseKeyboardExtension = getenv( "SAL_XKEYBOARDGROUP" );
41 if ( pUseKeyboardExtension != NULL )
43 mbUseExtension = pUseKeyboardExtension[0] != '\0' ;
44 if ( mbUseExtension )
45 mnDefaultGroup = strtol( pUseKeyboardExtension, NULL, 0 );
46 if ( mnDefaultGroup > XkbMaxKbdGroup )
47 mnDefaultGroup = 0;
50 // query XServer support for XKB Extension,
51 // do not call XQueryExtension() / XInitExtension() due to possible version
52 // clashes !
53 if ( mbUseExtension )
55 int nMajorExtOpcode;
56 int nExtMajorVersion = XkbMajorVersion;
57 int nExtMinorVersion = XkbMinorVersion;
59 mbUseExtension = XkbQueryExtension( mpDisplay,
60 &nMajorExtOpcode, &mnEventBase, &mnErrorBase,
61 &nExtMajorVersion, &nExtMinorVersion ) != 0;
64 // query notification for changes of the keyboard group
65 if ( mbUseExtension )
67 #define XkbGroupMask ( XkbGroupStateMask | XkbGroupBaseMask \
68 | XkbGroupLatchMask | XkbGroupLockMask )
70 mbUseExtension = XkbSelectEventDetails( mpDisplay,
71 XkbUseCoreKbd, XkbStateNotify, XkbGroupMask, XkbGroupMask );
74 // query initial keyboard group
75 if ( mbUseExtension )
77 XkbStateRec aStateRecord;
78 XkbGetState( mpDisplay, XkbUseCoreKbd, &aStateRecord );
79 mnGroup = aStateRecord.group;
83 void
84 SalI18N_KeyboardExtension::Dispatch( XEvent* pEvent )
86 // must the event be handled?
87 if ( !mbUseExtension
88 || (pEvent->type != mnEventBase) )
89 return;
91 // only handle state notify events for now, and only interested
92 // in group details
93 sal_uInt32 nXKBType = reinterpret_cast<XkbAnyEvent*>(pEvent)->xkb_type;
94 switch ( nXKBType )
96 case XkbStateNotify:
98 mnGroup = reinterpret_cast<XkbStateNotifyEvent*>(pEvent)->group;
99 break;
101 default:
103 #if OSL_DEBUG_LEVEL > 1
104 fprintf(stderr, "Got unrequested XkbAnyEvent %#x/%i\n",
105 static_cast<unsigned int>(nXKBType), static_cast<int>(nXKBType) );
106 #endif
107 break;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */