// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025  Medusa Slockbower
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================

/*
 * Copyright © 2009-2012 Daniel Stone
 * Copyright © 2012 Intel Corporation
 * Copyright © 2012 Ran Benita
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Author: Daniel Stone <daniel@fooishbar.org>
 */

#include <stdio.h>
#include <fennec/platform/linux/xkb/lib/fwd.h>

#ifndef FENNEC_LIB
#define FENNEC_LIB(...)
#endif

#ifndef FENNEC_SYMBOL
#define FENNEC_SYMBOL(...)
#endif

#ifndef FENNEC_GLOBAL
#define FENNEC_GLOBAL(...)
#endif

FENNEC_LIB(XKB);

FENNEC_SYMBOL(int, xkb_keysym_get_name, xkb_keysym_t keysym, char *buffer, size_t size);
FENNEC_SYMBOL(xkb_keysym_t, xkb_keysym_from_name, const char *name, enum xkb_keysym_flags flags);
FENNEC_SYMBOL(int, xkb_keysym_to_utf8, xkb_keysym_t keysym, char *buffer, size_t size);
FENNEC_SYMBOL(uint32_t, xkb_keysym_to_utf32, xkb_keysym_t keysym);
FENNEC_SYMBOL(xkb_keysym_t, xkb_utf32_to_keysym, uint32_t ucs);
FENNEC_SYMBOL(xkb_keysym_t, xkb_keysym_to_upper, xkb_keysym_t ks);
FENNEC_SYMBOL(xkb_keysym_t, xkb_keysym_to_lower, xkb_keysym_t ks);
FENNEC_SYMBOL(struct xkb_context*, xkb_context_new, enum xkb_context_flags flags);
FENNEC_SYMBOL(struct xkb_context*, xkb_context_ref, struct xkb_context *context);
FENNEC_SYMBOL(void, xkb_context_unref, struct xkb_context *context);
FENNEC_SYMBOL(void, xkb_context_set_user_data, struct xkb_context *context, void *user_data);
FENNEC_SYMBOL(void*, xkb_context_get_user_data, struct xkb_context *context);
FENNEC_SYMBOL(int, xkb_context_include_path_append, struct xkb_context *context, const char *path);
FENNEC_SYMBOL(int, xkb_context_include_path_append_default, struct xkb_context *context);
FENNEC_SYMBOL(int, xkb_context_include_path_reset_defaults, struct xkb_context *context);
FENNEC_SYMBOL(void, xkb_context_include_path_clear, struct xkb_context *context);
FENNEC_SYMBOL(unsigned int, xkb_context_num_include_paths, struct xkb_context *context);
FENNEC_SYMBOL(const char*, xkb_context_include_path_get, struct xkb_context *context, unsigned int index);
FENNEC_SYMBOL(void, xkb_context_set_log_level, struct xkb_context *context, enum xkb_log_level level);
FENNEC_SYMBOL(enum xkb_log_level, xkb_context_get_log_level, struct xkb_context *context);
FENNEC_SYMBOL(void, xkb_context_set_log_verbosity, struct xkb_context *context, int verbosity);
FENNEC_SYMBOL(int, xkb_context_get_log_verbosity, struct xkb_context *context);
FENNEC_SYMBOL(void, xkb_context_set_log_fn, struct xkb_context *context, void (*log_fn)(struct xkb_context *context, enum xkb_log_level level, const char *format, va_list args));
FENNEC_SYMBOL(struct xkb_keymap*, xkb_keymap_new_from_names, struct xkb_context *context, const struct xkb_rule_names *names, enum xkb_keymap_compile_flags flags);
FENNEC_SYMBOL(struct xkb_keymap*, xkb_keymap_new_from_file, struct xkb_context *context, FILE *file, enum xkb_keymap_format format, enum xkb_keymap_compile_flags flags);
FENNEC_SYMBOL(struct xkb_keymap*, xkb_keymap_new_from_string, struct xkb_context *context, const char *string, enum xkb_keymap_format format, enum xkb_keymap_compile_flags flags);
FENNEC_SYMBOL(struct xkb_keymap*, xkb_keymap_new_from_buffer, struct xkb_context *context, const char *buffer, size_t length, enum xkb_keymap_format format, enum xkb_keymap_compile_flags flags);
FENNEC_SYMBOL(struct xkb_keymap*, xkb_keymap_ref, struct xkb_keymap *keymap);
FENNEC_SYMBOL(void, xkb_keymap_unref, struct xkb_keymap *keymap);
FENNEC_SYMBOL(char*, xkb_keymap_get_as_string, struct xkb_keymap *keymap, enum xkb_keymap_format format);
FENNEC_SYMBOL(xkb_keycode_t, xkb_keymap_min_keycode, struct xkb_keymap *keymap);
FENNEC_SYMBOL(xkb_keycode_t, xkb_keymap_max_keycode, struct xkb_keymap *keymap);
FENNEC_SYMBOL(void, xkb_keymap_key_for_each, struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter, void *data);
FENNEC_SYMBOL(const char*, xkb_keymap_key_get_name, struct xkb_keymap *keymap, xkb_keycode_t key);
FENNEC_SYMBOL(xkb_keycode_t, xkb_keymap_key_by_name, struct xkb_keymap *keymap, const char *name);
FENNEC_SYMBOL(xkb_mod_index_t, xkb_keymap_num_mods, struct xkb_keymap *keymap);
FENNEC_SYMBOL(const char*, xkb_keymap_mod_get_name, struct xkb_keymap *keymap, xkb_mod_index_t idx);
FENNEC_SYMBOL(xkb_mod_index_t, xkb_keymap_mod_get_index, struct xkb_keymap *keymap, const char *name);
FENNEC_SYMBOL(xkb_layout_index_t, xkb_keymap_num_layouts, struct xkb_keymap *keymap);
FENNEC_SYMBOL(const char*, xkb_keymap_layout_get_name, struct xkb_keymap *keymap, xkb_layout_index_t idx);
FENNEC_SYMBOL(xkb_layout_index_t, xkb_keymap_layout_get_index, struct xkb_keymap *keymap, const char *name);
FENNEC_SYMBOL(xkb_led_index_t, xkb_keymap_num_leds, struct xkb_keymap *keymap);
FENNEC_SYMBOL(const char*, xkb_keymap_led_get_name, struct xkb_keymap *keymap, xkb_led_index_t idx);
FENNEC_SYMBOL(xkb_led_index_t, xkb_keymap_led_get_index, struct xkb_keymap *keymap, const char *name);
FENNEC_SYMBOL(xkb_layout_index_t, xkb_keymap_num_layouts_for_key, struct xkb_keymap *keymap, xkb_keycode_t key);
FENNEC_SYMBOL(xkb_level_index_t, xkb_keymap_num_levels_for_key, struct xkb_keymap *keymap, xkb_keycode_t key, xkb_layout_index_t layout);
FENNEC_SYMBOL(size_t, xkb_keymap_key_get_mods_for_level, struct xkb_keymap *keymap, xkb_keycode_t key, xkb_layout_index_t layout, xkb_level_index_t level, xkb_mod_mask_t *masks_out, size_t masks_size);
FENNEC_SYMBOL(int, xkb_keymap_key_get_syms_by_level, struct xkb_keymap *keymap, xkb_keycode_t key, xkb_layout_index_t layout, xkb_level_index_t level, const xkb_keysym_t **syms_out);
FENNEC_SYMBOL(int, xkb_keymap_key_repeats, struct xkb_keymap *keymap, xkb_keycode_t key);
FENNEC_SYMBOL(struct xkb_state*, xkb_state_new, struct xkb_keymap *keymap);
FENNEC_SYMBOL(struct xkb_state*, xkb_state_ref, struct xkb_state *state);
FENNEC_SYMBOL(void, xkb_state_unref, struct xkb_state *state);
FENNEC_SYMBOL(struct xkb_keymap*, xkb_state_get_keymap, struct xkb_state *state);
FENNEC_SYMBOL(enum xkb_state_component, xkb_state_update_key, struct xkb_state *state, xkb_keycode_t key, enum xkb_key_direction direction);
FENNEC_SYMBOL(enum xkb_state_component, xkb_state_update_mask, struct xkb_state *state, xkb_mod_mask_t depressed_mods, xkb_mod_mask_t latched_mods, xkb_mod_mask_t locked_mods, xkb_layout_index_t depressed_layout, xkb_layout_index_t latched_layout, xkb_layout_index_t locked_layout);
FENNEC_SYMBOL(int, xkb_state_key_get_syms, struct xkb_state *state, xkb_keycode_t key, const xkb_keysym_t **syms_out);
FENNEC_SYMBOL(int, xkb_state_key_get_utf8, struct xkb_state *state, xkb_keycode_t key, char *buffer, size_t size);
FENNEC_SYMBOL(uint32_t, xkb_state_key_get_utf32, struct xkb_state *state, xkb_keycode_t key);
FENNEC_SYMBOL(xkb_keysym_t, xkb_state_key_get_one_sym, struct xkb_state *state, xkb_keycode_t key);
FENNEC_SYMBOL(xkb_layout_index_t, xkb_state_key_get_layout, struct xkb_state *state, xkb_keycode_t key);
FENNEC_SYMBOL(xkb_level_index_t, xkb_state_key_get_level, struct xkb_state *state, xkb_keycode_t key, xkb_layout_index_t layout);
FENNEC_SYMBOL(xkb_mod_mask_t, xkb_state_serialize_mods, struct xkb_state *state, enum xkb_state_component components);
FENNEC_SYMBOL(xkb_layout_index_t, xkb_state_serialize_layout, struct xkb_state *state, enum xkb_state_component components);
FENNEC_SYMBOL(int, xkb_state_mod_name_is_active, struct xkb_state *state, const char *name, enum xkb_state_component type);
FENNEC_SYMBOL(int, xkb_state_mod_names_are_active, struct xkb_state *state, enum xkb_state_component type, enum xkb_state_match match, ...);
FENNEC_SYMBOL(int, xkb_state_mod_index_is_active, struct xkb_state *state, xkb_mod_index_t idx, enum xkb_state_component type);
FENNEC_SYMBOL(int, xkb_state_mod_indices_are_active, struct xkb_state *state, enum xkb_state_component type, enum xkb_state_match match, ...);
FENNEC_SYMBOL(xkb_mod_mask_t, xkb_state_key_get_consumed_mods2, struct xkb_state *state, xkb_keycode_t key, enum xkb_consumed_mode mode);
FENNEC_SYMBOL(xkb_mod_mask_t, xkb_state_key_get_consumed_mods, struct xkb_state *state, xkb_keycode_t key);
FENNEC_SYMBOL(int, xkb_state_mod_index_is_consumed2, struct xkb_state *state, xkb_keycode_t key, xkb_mod_index_t idx, enum xkb_consumed_mode mode);
FENNEC_SYMBOL(int, xkb_state_mod_index_is_consumed, struct xkb_state *state, xkb_keycode_t key, xkb_mod_index_t idx);
FENNEC_SYMBOL(xkb_mod_mask_t, xkb_state_mod_mask_remove_consumed, struct xkb_state *state, xkb_keycode_t key, xkb_mod_mask_t mask);
FENNEC_SYMBOL(int, xkb_state_layout_name_is_active, struct xkb_state *state, const char *name, enum xkb_state_component type);
FENNEC_SYMBOL(int, xkb_state_layout_index_is_active, struct xkb_state *state, xkb_layout_index_t idx, enum xkb_state_component type);
FENNEC_SYMBOL(int, xkb_state_led_name_is_active, struct xkb_state *state, const char *name);
FENNEC_SYMBOL(int, xkb_state_led_index_is_active, struct xkb_state *state, xkb_led_index_t idx);

#undef FENNEC_LIB
#undef FENNEC_SYMBOL
#undef FENNEC_GLOBAL
