Skip to content

X

Generators for Linux X system.

generate(context, output, target=None)

Generate configuration files for X system.

Parameters:

Name Type Description Default
context dict

the context as a dict (read doc/context.md).

required
output Path

directory to write output files.

required
target str) (optional

select a single output file to generate. If not provided (default) all output files are generated. Can be: - xkb-root - xkb-user - xmodmap - xcompose

None
Source code in kcg/generators/x.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def generate(context: dict, output: pathlib.Path, target: str = None) -> None:
    """Generate configuration files for X system.

    Args:
        context (dict): the context as a dict (read doc/context.md).
        output (pathlib.Path): directory to write output files.
        target (str) (optional): select a single output file to generate. If not
            provided (default) all output files are generated. Can be:
                - xkb-root
                - xkb-user
                - xmodmap
                - xcompose
    """
    name = context["basic_info"]["name"]
    targets = {
        "xkb-root": ("x_xkb_root", f"{name}-system.xkb"),
        "xkb-user": ("x_xkb_user", f"{name}.xkb"),
        "xmodmap": ("x_xmodmap", f"{name}.xmodmap"),
        "xcompose": ("x_compose", "XCompose"),
    }

    for target_name, (perl_function, output_filename) in targets.items():
        if target is not None and target_name != target:
            continue
        run_perl_script(context, perl_function, output.joinpath(output_filename))

    # create a legacy file with a small substitution
    with open(output.joinpath(f"{name}.xkb"), encoding="utf-8") as fin:
        with open(
            output.joinpath(f"{name}-xorglegacy.xkb"), "w", encoding="utf-8"
        ) as fout:
            for line in fin:
                fout.write(
                    line.replace('\tinclude "pc(pc105)"', '\tinclude "pc/pc(pc105)"')
                )