Skip to content

Xkb

Module to parse XKB files.

It uses the system library libxkbcommon.

parse(filename)

Parse a .xkb file.

Parameters:

Name Type Description Default
filename Path

path to local file to parse.

required

Returns:

Type Description

(xkbcommon.xkb.Keymap) A xkbcommon keymap object.

Source code in kcg/parsers/xkb.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def parse(filename: Path):
    """Parse a .xkb file.

    Args:
        filename (pathlib.Path): path to local file to parse.

    Returns:
        (xkbcommon.xkb.Keymap) A xkbcommon keymap object.
    """
    context = xkb.Context()
    with open(filename, "r+") as fpt:
        # open with r+ because keymap_new_from_file uses mmap, which tries
        # to map read/write methods on the file. But do not worry, file is not
        # modified whatsoever.
        keymap = context.keymap_new_from_file(fpt)
    return keymap