Skip to content

Commit 99343ea

Browse files
donny-dontaperezdc
authored andcommitted
Explicitly enable xkb
The `xkbcommon` library is geared towards platforms using the XKB specification so it should be toggleable. Add a `WPE_ENABLE_XKB` option to compile xkb code. By default this option is on. The contents of `wpe/input.h` that require `xkbcommon` are split into `wpe/input-xkb.h` The `src/input.c` was renamed to `src/input-xkb.c` to indicate the file is specific to xkb being enabled. The pkg-config definition was expanded to support additional compilation flags and dependencies.
1 parent d256ece commit 99343ea

File tree

9 files changed

+154
-66
lines changed

9 files changed

+154
-66
lines changed

CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ set(WPE_BACKEND
2323
""
2424
CACHE STRING "Name of the backend library to load, instead of libWPEBackend-default.so"
2525
)
26+
set(WPE_ENABLE_XKB
27+
ON
28+
CACHE STRING "Enable use of libxkbcommon for keyboard input"
29+
)
2630

2731
include(CheckCCompilerFlag)
2832
include(CheckCXXCompilerFlag)
@@ -48,14 +52,14 @@ include(DistTargets)
4852
include(GNUInstallDirs)
4953

5054
find_package(EGL REQUIRED)
51-
find_package(Libxkbcommon REQUIRED)
5255

5356
set(WPE_PUBLIC_HEADERS
5457
include/wpe/libwpe-version.h
5558
include/wpe/version.h
5659
include/wpe/version-deprecated.h
5760
include/wpe/export.h
5861
include/wpe/input.h
62+
include/wpe/input-xkb.h
5963
include/wpe/keysyms.h
6064
include/wpe/loader.h
6165
include/wpe/pasteboard.h
@@ -68,7 +72,7 @@ set(WPE_PUBLIC_HEADERS
6872

6973
add_library(
7074
wpe SHARED
71-
src/input.c
75+
src/input-xkb.c
7276
src/key-unicode.c
7377
src/loader.c
7478
src/pasteboard.c
@@ -88,8 +92,18 @@ target_compile_definitions(
8892
if (WPE_BACKEND)
8993
target_compile_definitions(wpe PRIVATE WPE_BACKEND=\"${WPE_BACKEND}\")
9094
endif ()
95+
if (WPE_ENABLE_XKB)
96+
target_compile_definitions(wpe PUBLIC WPE_ENABLE_XKB=1)
97+
set(WPE_PC_CFLAGS -DWPE_ENABLE_XKB=1)
98+
endif ()
9199
target_compile_options(wpe PRIVATE $<TARGET_PROPERTY:GL::egl,INTERFACE_COMPILE_OPTIONS>)
92-
target_link_libraries(wpe PRIVATE XkbCommon::libxkbcommon ${CMAKE_DL_LIBS})
100+
101+
target_link_libraries(wpe PRIVATE ${CMAKE_DL_LIBS})
102+
if (WPE_ENABLE_XKB)
103+
find_package(Libxkbcommon REQUIRED)
104+
target_link_libraries(wpe PRIVATE XkbCommon::libxkbcommon)
105+
set(WPE_PC_REQUIRES xkbcommon)
106+
endif ()
93107

94108
set_target_properties(
95109
wpe

include/wpe/input-xkb.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (C) 2015, 2016 Igalia S.L.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#if !defined(__WPE_H_INSIDE__) && !defined(WPE_COMPILATION)
28+
#error "Only <wpe/wpe.h> can be included directly."
29+
#endif
30+
31+
#ifndef wpe_input_xkb_h
32+
#define wpe_input_xkb_h
33+
34+
/**
35+
* SECTION:input
36+
* @short_description: Input Handling
37+
* @title: Input
38+
*/
39+
40+
#if defined(WPE_ENABLE_XKB) && WPE_ENABLE_XKB
41+
42+
#if defined(WPE_COMPILATION)
43+
#include "export.h"
44+
#endif
45+
46+
#include <stdbool.h>
47+
#include <stdint.h>
48+
#include <xkbcommon/xkbcommon.h>
49+
#include <xkbcommon/xkbcommon-compose.h>
50+
51+
#ifdef __cplusplus
52+
extern "C" {
53+
#endif
54+
55+
struct wpe_input_xkb_context;
56+
57+
struct wpe_input_xkb_keymap_entry {
58+
uint32_t hardware_key_code;
59+
int32_t layout;
60+
int32_t level;
61+
};
62+
63+
WPE_EXPORT
64+
struct wpe_input_xkb_context*
65+
wpe_input_xkb_context_get_default();
66+
67+
WPE_EXPORT
68+
struct xkb_context*
69+
wpe_input_xkb_context_get_context(struct wpe_input_xkb_context*);
70+
71+
WPE_EXPORT
72+
struct xkb_keymap*
73+
wpe_input_xkb_context_get_keymap(struct wpe_input_xkb_context*);
74+
75+
WPE_EXPORT
76+
void
77+
wpe_input_xkb_context_set_keymap(struct wpe_input_xkb_context*, struct xkb_keymap*);
78+
79+
WPE_EXPORT
80+
struct xkb_state*
81+
wpe_input_xkb_context_get_state(struct wpe_input_xkb_context*);
82+
83+
WPE_EXPORT
84+
struct xkb_compose_table*
85+
wpe_input_xkb_context_get_compose_table(struct wpe_input_xkb_context*);
86+
87+
WPE_EXPORT
88+
void
89+
wpe_input_xkb_context_set_compose_table(struct wpe_input_xkb_context*, struct xkb_compose_table*);
90+
91+
WPE_EXPORT
92+
struct xkb_compose_state*
93+
wpe_input_xkb_context_get_compose_state(struct wpe_input_xkb_context*);
94+
95+
WPE_EXPORT
96+
uint32_t
97+
wpe_input_xkb_context_get_modifiers(struct wpe_input_xkb_context*, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group);
98+
99+
WPE_EXPORT
100+
uint32_t
101+
wpe_input_xkb_context_get_key_code(struct wpe_input_xkb_context*, uint32_t hardware_key_code, bool pressed);
102+
103+
WPE_EXPORT
104+
void
105+
wpe_input_xkb_context_get_entries_for_key_code(struct wpe_input_xkb_context*, uint32_t key_code, struct wpe_input_xkb_keymap_entry**, uint32_t* n_entries);
106+
107+
#ifdef __cplusplus
108+
}
109+
#endif
110+
111+
#endif /* defined(WPE_ENABLE_XKB) && WPE_ENABLE_XKB */
112+
113+
#endif /* wpe_input_xkb_h */

include/wpe/input.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343

4444
#include <stdbool.h>
4545
#include <stdint.h>
46-
#include <xkbcommon/xkbcommon.h>
47-
#include <xkbcommon/xkbcommon-compose.h>
4846

4947
#ifdef __cplusplus
5048
extern "C" {
@@ -140,58 +138,6 @@ struct wpe_input_touch_event {
140138
};
141139

142140

143-
struct wpe_input_xkb_context;
144-
145-
struct wpe_input_xkb_keymap_entry {
146-
uint32_t hardware_key_code;
147-
int32_t layout;
148-
int32_t level;
149-
};
150-
151-
WPE_EXPORT
152-
struct wpe_input_xkb_context*
153-
wpe_input_xkb_context_get_default();
154-
155-
WPE_EXPORT
156-
struct xkb_context*
157-
wpe_input_xkb_context_get_context(struct wpe_input_xkb_context*);
158-
159-
WPE_EXPORT
160-
struct xkb_keymap*
161-
wpe_input_xkb_context_get_keymap(struct wpe_input_xkb_context*);
162-
163-
WPE_EXPORT
164-
void
165-
wpe_input_xkb_context_set_keymap(struct wpe_input_xkb_context*, struct xkb_keymap*);
166-
167-
WPE_EXPORT
168-
struct xkb_state*
169-
wpe_input_xkb_context_get_state(struct wpe_input_xkb_context*);
170-
171-
WPE_EXPORT
172-
struct xkb_compose_table*
173-
wpe_input_xkb_context_get_compose_table(struct wpe_input_xkb_context*);
174-
175-
WPE_EXPORT
176-
void
177-
wpe_input_xkb_context_set_compose_table(struct wpe_input_xkb_context*, struct xkb_compose_table*);
178-
179-
WPE_EXPORT
180-
struct xkb_compose_state*
181-
wpe_input_xkb_context_get_compose_state(struct wpe_input_xkb_context*);
182-
183-
WPE_EXPORT
184-
uint32_t
185-
wpe_input_xkb_context_get_modifiers(struct wpe_input_xkb_context*, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group);
186-
187-
WPE_EXPORT
188-
uint32_t
189-
wpe_input_xkb_context_get_key_code(struct wpe_input_xkb_context*, uint32_t hardware_key_code, bool pressed);
190-
191-
WPE_EXPORT
192-
void
193-
wpe_input_xkb_context_get_entries_for_key_code(struct wpe_input_xkb_context*, uint32_t key_code, struct wpe_input_xkb_keymap_entry**, uint32_t* n_entries);
194-
195141
WPE_EXPORT
196142
uint32_t
197143
wpe_key_code_to_unicode (uint32_t);

include/wpe/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
api_headers = [
22
'export.h',
33
'input.h',
4+
'input-xkb.h',
45
'keysyms.h',
56
'libwpe-version.h',
67
'loader.h',

include/wpe/wpe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "export.h"
3838
#include "input.h"
39+
#include "input-xkb.h"
3940
#include "keysyms.h"
4041
#include "loader.h"
4142
#include "pasteboard.h"

meson.build

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ dependencies = []
5151
#
5252
can_allow_fallback = meson.version().version_compare('>=0.55.0')
5353

54-
if can_allow_fallback
55-
dependencies += dependency('xkbcommon',
56-
fallback: ['libxkbcommon', 'libxkbcommon_dep'],
57-
)
58-
else
59-
dependencies += dependency('xkbcommon')
54+
if get_option('enable-xkb')
55+
add_project_arguments('-DWPE_ENABLE_XKB=1', language: ['c', 'cpp'])
56+
if can_allow_fallback
57+
dependencies += dependency('xkbcommon',
58+
fallback: ['libxkbcommon', 'libxkbcommon_dep'],
59+
)
60+
else
61+
dependencies += dependency('xkbcommon')
62+
endif
6063
endif
6164

6265
cc = meson.get_compiler('c')
@@ -83,7 +86,7 @@ if not cc.has_function('dlopen')
8386
endif
8487

8588
libwpe = library('wpe-' + api_version,
86-
'src/input.c',
89+
'src/input-xkb.c',
8790
'src/key-unicode.c',
8891
'src/loader.c',
8992
'src/pasteboard.c',

meson_options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ option('default-backend',
33
value: '',
44
description: 'Name of the backend library to load, instead of libWPEBackend-default.so'
55
)
6+
option('enable-xkb',
7+
type: 'boolean',
8+
value: true,
9+
description: 'Enable use of libxkbcommon for keyboard input'
10+
)
611
option('build-docs',
712
type: 'boolean',
813
value: false,

src/input.c renamed to src/input-xkb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27+
#if defined(WPE_ENABLE_XKB) && WPE_ENABLE_XKB
28+
29+
#include "../include/wpe/input-xkb.h"
2730
#include "../include/wpe/input.h"
2831

2932
#include <locale.h>
@@ -244,3 +247,5 @@ wpe_input_xkb_context_get_entries_for_key_code(struct wpe_input_xkb_context* xkb
244247
*entries = array;
245248
*n_entries = array_size;
246249
}
250+
251+
#endif /* defined(WPE_ENABLE_XKB) && WPE_ENABLE_XKB */

wpe.pc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ libdir=${exec_prefix}/lib
66
Name: wpe-@WPE_API_VERSION@
77
Description: The wpe library
88
Version: @PROJECT_VERSION@
9-
Requires: xkbcommon
10-
Cflags: -I${includedir}/wpe-@WPE_API_VERSION@
9+
Requires: @WPE_PC_REQUIRES@
10+
Cflags: -I${includedir}/wpe-@WPE_API_VERSION@ @WPE_PC_CFLAGS@
1111
Libs: -L${libdir} -lwpe-@WPE_API_VERSION@

0 commit comments

Comments
 (0)