nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / app / i18n_xkb.cxx
blob0fc4d7933fc392048657b73094f4b560da8dae07
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 <stdlib.h>
21 #include <stdio.h>
22 #include <iostream>
24 #include <sal/log.hxx>
26 #include <X11/Xlib.h>
27 #include <X11/XKBlib.h>
29 #include <unx/i18n_xkb.hxx>
31 SalI18N_KeyboardExtension::SalI18N_KeyboardExtension( Display* pDisplay )
32 : mbUseExtension(true)
33 , mnEventBase(0)
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 != nullptr )
43 mbUseExtension = pUseKeyboardExtension[0] != '\0' ;
46 // query XServer support for XKB Extension,
47 // do not call XQueryExtension() / XInitExtension() due to possible version
48 // clashes !
49 if ( mbUseExtension )
51 int nMajorExtOpcode;
52 int nExtMajorVersion = XkbMajorVersion;
53 int nExtMinorVersion = XkbMinorVersion;
54 int nErrorBase = 0;
56 mbUseExtension = XkbQueryExtension( pDisplay,
57 &nMajorExtOpcode, &mnEventBase, &nErrorBase,
58 &nExtMajorVersion, &nExtMinorVersion ) != 0;
61 // query notification for changes of the keyboard group
62 if ( mbUseExtension )
64 constexpr auto XkbGroupMask = XkbGroupStateMask | XkbGroupBaseMask
65 | XkbGroupLatchMask | XkbGroupLockMask;
67 mbUseExtension = XkbSelectEventDetails( pDisplay,
68 XkbUseCoreKbd, XkbStateNotify, XkbGroupMask, XkbGroupMask );
71 // query initial keyboard group
72 if ( mbUseExtension )
74 XkbStateRec aStateRecord;
75 XkbGetState( pDisplay, XkbUseCoreKbd, &aStateRecord );
79 void
80 SalI18N_KeyboardExtension::Dispatch( XEvent* pEvent )
82 // must the event be handled?
83 if ( !mbUseExtension
84 || (pEvent->type != mnEventBase) )
85 return;
87 // only handle state notify events for now, and only interested
88 // in group details
89 sal_uInt32 nXKBType = reinterpret_cast<XkbAnyEvent*>(pEvent)->xkb_type;
90 switch ( nXKBType )
92 case XkbStateNotify:
93 break;
95 default:
96 #if OSL_DEBUG_LEVEL > 1
97 SAL_WARN("vcl.app", "Got unrequested XkbAnyEvent "
98 << std::hex << std::showbase
99 << static_cast<unsigned int>(nXKBType)
100 << "/" << std::dec
101 << static_cast<int>(nXKBType));
102 #endif
103 break;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */