Skip to content

Commit

Permalink
Add --verbose flag to wayland-interface-check so you can print out al…
Browse files Browse the repository at this point in the history
…l the available interfaces
  • Loading branch information
Alex Saveau committed Nov 29, 2024
1 parent 89fc0b6 commit e8bd4c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion wayland-interface-check/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wayland interface check
# Wayland Interface Check

<a href="https://crates.io/crates/wayland-interface-check">![Crates.io Version](https://img.shields.io/crates/v/wayland-interface-check)</a>

Expand Down
36 changes: 29 additions & 7 deletions wayland-interface-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#![feature(exitcode_exit_method)]

use std::{
collections::HashSet, env, ffi::OsString, hash::BuildHasherDefault, os::unix::ffi::OsStringExt,
collections::HashSet,
env,
ffi::{OsStr, OsString},
hash::BuildHasherDefault,
os::unix::ffi::OsStringExt,
process::ExitCode,
};

Expand All @@ -12,8 +16,17 @@ use wayland_client::{
};

fn main() -> ExitCode {
let mut verbose = false;
let interfaces = env::args_os()
.skip(1)
.filter(|arg| {
if arg == OsStr::new("--verbose") {
verbose = true;
false
} else {
true
}
})
.map(OsString::into_vec)
.collect::<HashSet<_, _>>();
if interfaces.is_empty() {
Expand All @@ -28,21 +41,27 @@ fn main() -> ExitCode {
let mut event_queue = conn.new_event_queue();
let qh = event_queue.handle();

let mut state = State(interfaces);
let mut state = State {
verbose,
interfaces,
};

display.get_registry(&qh, ());
let Ok(_) = event_queue.roundtrip(&mut state) else {
return ExitCode::FAILURE;
};

if state.0.is_empty() {
if state.interfaces.is_empty() {
ExitCode::SUCCESS
} else {
ExitCode::FAILURE
}
}

struct State(HashSet<Vec<u8>, BuildHasherDefault<FxHasher>>);
struct State {
verbose: bool,
interfaces: HashSet<Vec<u8>, BuildHasherDefault<FxHasher>>,
}

impl Dispatch<WlRegistry, ()> for State {
fn event(
Expand All @@ -56,11 +75,14 @@ impl Dispatch<WlRegistry, ()> for State {
if let wl_registry::Event::Global {
name: _,
interface,
version: _,
version,
} = event
{
this.0.remove(interface.as_bytes());
if this.0.is_empty() {
if this.verbose {
println!("{interface}:v{version}");
}
this.interfaces.remove(interface.as_bytes());
if this.interfaces.is_empty() {
ExitCode::SUCCESS.exit_process()
}
}
Expand Down

0 comments on commit e8bd4c6

Please sign in to comment.