1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #include <sal/log.hxx>
27 #include <X11/XKBlib.h>
29 #include <unx/i18n_xkb.hxx>
31 SalI18N_KeyboardExtension::SalI18N_KeyboardExtension( Display
* pDisplay
)
32 : mbUseExtension(true)
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
52 int nExtMajorVersion
= XkbMajorVersion
;
53 int nExtMinorVersion
= XkbMinorVersion
;
56 mbUseExtension
= XkbQueryExtension( pDisplay
,
57 &nMajorExtOpcode
, &mnEventBase
, &nErrorBase
,
58 &nExtMajorVersion
, &nExtMinorVersion
) != 0;
61 // query notification for changes of the keyboard group
64 constexpr auto XkbGroupMask
= XkbGroupStateMask
| XkbGroupBaseMask
65 | XkbGroupLatchMask
| XkbGroupLockMask
;
67 mbUseExtension
= XkbSelectEventDetails( pDisplay
,
68 XkbUseCoreKbd
, XkbStateNotify
, XkbGroupMask
, XkbGroupMask
);
71 // query initial keyboard group
74 XkbStateRec aStateRecord
;
75 XkbGetState( pDisplay
, XkbUseCoreKbd
, &aStateRecord
);
80 SalI18N_KeyboardExtension::Dispatch( XEvent
* pEvent
)
82 // must the event be handled?
84 || (pEvent
->type
!= mnEventBase
) )
87 // only handle state notify events for now, and only interested
89 sal_uInt32 nXKBType
= reinterpret_cast<XkbAnyEvent
*>(pEvent
)->xkb_type
;
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
)
101 << static_cast<int>(nXKBType
));
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */