Skip to content
Merged
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
110 changes: 30 additions & 80 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions kbvm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ utf8-console = "0.1.0"

[target.'cfg(unix)'.dependencies]
wl-client = "0.2.0"
x11rb = { version = "0.13.2", default-features = false }
kbvm = { version = "0.1.5", path = "../kbvm", features = ["x11"] }

[target.'cfg(target_os = "linux")'.dependencies]
uapi = "0.2.13"
Expand Down
15 changes: 14 additions & 1 deletion kbvm-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(unix)]
use crate::dump_x11::{self, DumpX11Args};
#[cfg(unix)]
use crate::test_wayland::{self, TestWaylandArgs};
use {
crate::{
Expand Down Expand Up @@ -31,6 +33,9 @@ enum Cmd {
CompileXkb(CompileXkbArgs),
/// Generate shell completion scripts for kbvm.
GenerateCompletion(GenerateArgs),
/// Loads the keymap from the X server and writes it to stdout.
#[cfg(unix)]
DumpX11(DumpX11Args),
}

#[derive(Args, Debug, Default)]
Expand All @@ -44,6 +49,10 @@ pub struct CompileArgs {
/// Append an include path.
#[clap(long, value_hint = ValueHint::DirPath)]
pub append_include: Vec<String>,
}

#[derive(Args, Debug, Default)]
pub struct FormatArgs {
/// Don't include key actions or behaviors.
#[clap(long)]
pub lookup_only: bool,
Expand All @@ -64,8 +73,10 @@ impl CompileArgs {
builder.append_path(dir);
}
}
}

pub fn apply2<'a>(&self, mut formatter: Formatter<'a>) -> Formatter<'a> {
impl FormatArgs {
pub fn apply<'a>(&self, mut formatter: Formatter<'a>) -> Formatter<'a> {
if self.lookup_only {
formatter = formatter.lookup_only(true);
}
Expand All @@ -85,5 +96,7 @@ pub fn main() {
Cmd::CompileRmlvo(args) => compile_rmlvo::main(args),
Cmd::CompileXkb(args) => compile_xkb::main(args),
Cmd::GenerateCompletion(args) => generate::main(args),
#[cfg(unix)]
Cmd::DumpX11(args) => dump_x11::main(args),
}
}
10 changes: 8 additions & 2 deletions kbvm-cli/src/compile_rmlvo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use {
crate::{cli::CompileArgs, compile_xkb::format_keymap, expand_rmlvo::RmlvoArgs},
crate::{
cli::{CompileArgs, FormatArgs},
compile_xkb::format_keymap,
expand_rmlvo::RmlvoArgs,
},
clap::Args,
kbvm::xkb::{Context, diagnostic::WriteToLog},
};
Expand All @@ -9,6 +13,8 @@ pub struct CompileRmlvoArgs {
#[clap(flatten)]
compile_args: CompileArgs,
#[clap(flatten)]
format_args: FormatArgs,
#[clap(flatten)]
rmlvo: RmlvoArgs,
}

Expand All @@ -24,5 +30,5 @@ pub fn main(args: CompileRmlvoArgs) {
groups.as_deref(),
options.as_deref(),
);
format_keymap(args.compile_args.apply2(expanded.format()));
format_keymap(args.format_args.apply(expanded.format()));
}
9 changes: 7 additions & 2 deletions kbvm-cli/src/compile_xkb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use {
crate::{cli::CompileArgs, utils::read_path},
crate::{
cli::{CompileArgs, FormatArgs},
utils::read_path,
},
clap::{Args, ValueHint},
error_reporter::Report,
kbvm::xkb::{Context, diagnostic::WriteToLog},
Expand All @@ -14,6 +17,8 @@ use {
pub struct CompileXkbArgs {
#[clap(flatten)]
compile_args: CompileArgs,
#[clap(flatten)]
format_args: FormatArgs,
/// The path to the keymap.
///
/// If the path is not specified or if the path is `-`, the keymap is read from stdin.
Expand All @@ -30,7 +35,7 @@ pub fn main(args: CompileXkbArgs) {
let expanded = context.keymap_from_bytes(WriteToLog, Some(path.as_ref()), &source);
match expanded {
Ok(map) => {
format_keymap(args.compile_args.apply2(map.format()));
format_keymap(args.format_args.apply(map.format()));
}
Err(_) => {
log::error!("could not compile keymap");
Expand Down
43 changes: 43 additions & 0 deletions kbvm-cli/src/dump_x11.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use {
crate::{cli::FormatArgs, compile_xkb::format_keymap},
clap::Args,
error_reporter::Report,
kbvm::xkb::x11::KbvmX11Ext,
};

#[derive(Args, Debug, Default)]
pub struct DumpX11Args {
#[clap(flatten)]
format_args: FormatArgs,
}

pub fn main(args: DumpX11Args) {
let (con, _) = match x11rb::connect(None) {
Ok(c) => c,
Err(e) => {
log::error!("could not connect to X11: {}", Report::new(e));
std::process::exit(1);
}
};
if let Err(e) = con.setup_xkb_extension() {
log::error!("could not enable the XKB extension: {}", Report::new(e));
std::process::exit(1);
}
let dev_id = match con.get_xkb_core_device_id() {
Ok(i) => i,
Err(e) => {
log::error!("could not retrieve the core device ID: {}", Report::new(e));
std::process::exit(1);
}
};
let expanded = con.get_xkb_keymap(dev_id);
match expanded {
Ok(map) => {
format_keymap(args.format_args.apply(map.format()));
}
Err(e) => {
log::error!("could not retrieve the keymap from X11: {}", Report::new(e));
std::process::exit(1);
}
}
}
Loading