From 136c04e5af20a1ee3522177d2a29568ca94c6aa8 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Thu, 20 Nov 2025 12:47:32 +0100 Subject: [PATCH] Add xkb_get_version() Enable to apps to query the version of the libxkbcommon library actually in use and adapt their behavior. --- include/xkbcommon/xkbcommon.h | 10 ++++++++++ meson.build | 10 ++++++++++ src/version.c.in | 18 ++++++++++++++++++ xkbcommon.map | 1 + 4 files changed, 39 insertions(+) create mode 100644 src/version.c.in diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h index 7d539b229..124f70a43 100644 --- a/include/xkbcommon/xkbcommon.h +++ b/include/xkbcommon/xkbcommon.h @@ -313,6 +313,16 @@ typedef uint32_t xkb_led_mask_t; */ #define xkb_keycode_is_legal_x11(key) ((key) >= 8 && (key) <= 255) +/** + * Get the version of libxkbcommon in use. + * + * @returns a triplet representing MAJOR.MINOR.PATCH library version. + * + * @since 1.14.0 + */ +XKB_EXPORT const uint8_t * +xkb_get_version(void); + /** * @defgroup rules-api Rules * Utility functions related to *rules*, whose purpose is introduced in: diff --git a/meson.build b/meson.build index ed0f918c5..56f1aefce 100644 --- a/meson.build +++ b/meson.build @@ -324,6 +324,15 @@ yacc_gen = generator( output: ['@BASENAME@.c', '@BASENAME@.h'], arguments: ['--defines=@OUTPUT1@', '-o', '@OUTPUT0@', '-p', '_xkbcommon_', '@INPUT@'], ) +version_file = configure_file( + input: 'src/version.c.in', + output: 'version.c', + configuration: { + 'MAJOR': xkbcommon_project_version[0], + 'MINOR': xkbcommon_project_version[1], + 'PATCH': xkbcommon_project_version[2], + }, +) libxkbcommon_sources = [ 'src/compose/constants.h', 'src/compose/parser.c', @@ -394,6 +403,7 @@ libxkbcommon_sources = [ 'src/utils-numbers.h', 'src/utils-paths.c', 'src/utils-paths.h', + version_file, ] libxkbcommon_link_args = [] libxkbcommon_link_deps = [] diff --git a/src/version.c.in b/src/version.c.in new file mode 100644 index 000000000..36a29d9e3 --- /dev/null +++ b/src/version.c.in @@ -0,0 +1,18 @@ +/* + * Copyright © 2025 Pierre Le Marre + * SPDX-License-Identifier: MIT + */ + +#include "config.h" + +#include + +#include "xkbcommon/xkbcommon.h" + +static const uint8_t version[] = { @MAJOR@, @MINOR@, @PATCH@ }; + +const uint8_t * +xkb_get_version(void) +{ + return version; +} diff --git a/xkbcommon.map b/xkbcommon.map index 81194630d..50d9fda22 100644 --- a/xkbcommon.map +++ b/xkbcommon.map @@ -150,6 +150,7 @@ global: V_1.14.0 { global: + xkb_get_version; xkb_keymap_key_iterator_new; xkb_keymap_key_iterator_destroy; xkb_keymap_key_iterator_next;