xkbcommon_rs_codegen/
config.rs

1// Based on meson.build and meson_options
2
3use std::fs::File;
4use std::io::{BufWriter, Write};
5use std::path::Path;
6
7fn xkb_config_root() -> &'static str {
8    // `xkeyboard-config install path`
9    // This is taken from README.md
10    // Set according to
11    "/usr/share/X11/xkb"
12}
13fn xkb_config_extra_path() -> &'static str {
14    // `/etc` is assumed to be
15    // the value of `$sysconfdir` in meson.
16    "/etc/xkb"
17}
18
19fn xkb_default_rules() -> &'static str {
20    // From `meson_options.txt`
21    "evdev"
22}
23fn xkb_default_model() -> &'static str {
24    // From `meson_options.txt`
25    "pc105"
26}
27fn xkb_default_layout() -> &'static str {
28    // From `meson_options.txt`
29    "us"
30}
31fn xkb_default_variant() -> &'static str {
32    // From `meson_options.txt`
33    ""
34}
35fn xkb_default_options() -> &'static str {
36    // From `meson_options.txt`
37    ""
38}
39
40pub fn make_config(out_path: &Path) {
41    let mut out_file = BufWriter::new(File::create(out_path).unwrap());
42
43    let vars = vec![
44        ("DFLT_XKB_CONFIG_ROOT", xkb_config_root()),
45        ("DFLT_XKB_CONFIG_EXTRA_PATH", xkb_config_extra_path()),
46        ("DEFAULT_XKB_RULES", xkb_default_rules()),
47        ("DEFAULT_XKB_MODEL", xkb_default_model()),
48        ("DEFAULT_XKB_LAYOUT", xkb_default_layout()),
49        ("DEFAULT_XKB_VARIANT", xkb_default_variant()),
50        ("DEFAULT_XKB_OPTIONS", xkb_default_options()),
51        // TODO: others as needed
52    ];
53
54    writeln!(
55        &mut out_file,
56        "// This file was autogenerated by `build_tools/src/config.rs"
57    )
58    .unwrap();
59
60    for (varname, value) in vars {
61        writeln!(
62            &mut out_file,
63            "pub(crate) const {}: &str = \"{}\";",
64            varname, value
65        )
66        .unwrap();
67    }
68}