Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcuts tweak #523

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changes/api/+keymap-compile-options.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Added a new keymap compile options API:
- `xkb_keymap_compile_options_new`
- `xkb_keymap_compile_options_free`
- `xkb_keymap_new_from_names2`
- `xkb_keymap_new_from_file2`
- `xkb_keymap_new_from_buffer2`

This interface allows to configure keymap options that cannot be passed as flags.
114 changes: 107 additions & 7 deletions include/xkbcommon/xkbcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#ifndef _XKBCOMMON_H_
#define _XKBCOMMON_H_

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
Expand Down Expand Up @@ -878,6 +879,53 @@ enum xkb_keymap_compile_flags {
XKB_KEYMAP_COMPILE_NO_FLAGS = 0
};

/** The possible keymap formats. */
enum xkb_keymap_format {
/** The current/classic XKB text format, as generated by xkbcomp -xkb. */
XKB_KEYMAP_FORMAT_TEXT_V1 = 1
};

/**
* @struct xkb_keymap_compile_options
* Opaque keymap compilation options.
*
* TODO: more doc
*
* @since 1.8.0
*/
struct xkb_keymap_compile_options;

/**
* Create a keymap options object.
*
* TODO: more doc
*
* @since 1.8.0
*/
struct xkb_keymap_compile_options*
xkb_keymap_compile_options_new(enum xkb_keymap_format format,
enum xkb_keymap_compile_flags flags);

/**
* Destroy a keymap compilation options object.
*
* TODO: more doc
*
* @since 1.8.0
*/
void
xkb_keymap_compile_options_free(struct xkb_keymap_compile_options *options);

/**
* TODO: doc
*
* @since 1.8.0
*/
bool
xkb_keymap_compile_options_set_shortcuts_reference_layout(
struct xkb_keymap_compile_options *options,
xkb_layout_index_t source, xkb_layout_index_t target);

/**
* Create a keymap from RMLVO names.
*
Expand All @@ -886,7 +934,7 @@ enum xkb_keymap_compile_flags {
*
* @param context The context in which to create the keymap.
* @param names The RMLVO names to use. See xkb_rule_names.
* @param flags Optional flags for the keymap, or 0.
* @param flags Optional flags for the keymap, or ::XKB_KEYMAP_COMPILE_NO_FLAGS.
*
* @returns A keymap compiled according to the RMLVO names, or NULL if
* the compilation failed.
Expand All @@ -899,19 +947,36 @@ xkb_keymap_new_from_names(struct xkb_context *context,
const struct xkb_rule_names *names,
enum xkb_keymap_compile_flags flags);

/** The possible keymap formats. */
enum xkb_keymap_format {
/** The current/classic XKB text format, as generated by xkbcomp -xkb. */
XKB_KEYMAP_FORMAT_TEXT_V1 = 1
};
/**
* Create a keymap from RMLVO names.
*
* The primary keymap entry point: creates a new XKB keymap from a set of
* RMLVO (Rules + Model + Layouts + Variants + Options) names.
*
* @param context The context in which to create the keymap.
* @param names The RMLVO names to use. See xkb_rule_names.
* @param options The eymap compilation options.
*
* @returns A keymap compiled according to the RMLVO names, or NULL if
* the compilation failed.
*
* @sa xkb_rule_names, xkb_keymap_new_from_names()
* @memberof xkb_keymap
*
* @since 1.8.0
*/
struct xkb_keymap *
xkb_keymap_new_from_names2(struct xkb_context *context,
const struct xkb_rule_names *names,
const struct xkb_keymap_compile_options *options);

/**
* Create a keymap from a keymap file.
*
* @param context The context in which to create the keymap.
* @param file The keymap file to compile.
* @param format The text format of the keymap file to compile.
* @param flags Optional flags for the keymap, or 0.
* @param flags Optional flags for the keymap, or ::XKB_KEYMAP_COMPILE_NO_FLAGS.
*
* @returns A keymap compiled from the given XKB keymap file, or NULL if
* the compilation failed.
Expand All @@ -928,6 +993,29 @@ xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
enum xkb_keymap_format format,
enum xkb_keymap_compile_flags flags);

/**
* Create a keymap from a keymap file.
*
* @param context The context in which to create the keymap.
* @param file The keymap file to compile.
* @param options The Keymap compilation options.
*
* @returns A keymap compiled from the given XKB keymap file, or NULL if
* the compilation failed.
*
* The file must contain a complete keymap. For example, in the
* XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
* top level '%xkb_keymap' section, which in turn contains other required
* sections.
*
* @since 1.8.0
*
* @memberof xkb_keymap, xkb_keymap_new_from_file2()
*/
struct xkb_keymap *
xkb_keymap_new_from_file2(struct xkb_context *context, FILE *file,
const struct xkb_keymap_compile_options *options);

/**
* Create a keymap from a keymap string.
*
Expand Down Expand Up @@ -957,6 +1045,18 @@ 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);

/**
* Create a keymap from a memory buffer.
*
* @see xkb_keymap_new_from_buffer()
* @memberof xkb_keymap
* @since 1.8.0
*/
struct xkb_keymap *
xkb_keymap_new_from_buffer2(struct xkb_context *context,
const char *buffer, size_t length,
const struct xkb_keymap_compile_options *options);

/**
* Take a new reference on a keymap.
*
Expand Down
7 changes: 3 additions & 4 deletions src/keymap-priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ update_builtin_keymap_fields(struct xkb_keymap *keymap)

struct xkb_keymap *
xkb_keymap_new(struct xkb_context *ctx,
enum xkb_keymap_format format,
enum xkb_keymap_compile_flags flags)
const struct xkb_keymap_compile_options *options)
{
struct xkb_keymap *keymap;

Expand All @@ -66,8 +65,8 @@ xkb_keymap_new(struct xkb_context *ctx,
keymap->refcnt = 1;
keymap->ctx = xkb_context_ref(ctx);

keymap->format = format;
keymap->flags = flags;
keymap->format = options->format;
keymap->flags = options->flags;

update_builtin_keymap_fields(keymap);

Expand Down
Loading
Loading