-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will let us write a script that ensures the necessary wayland interfaces exist and otherwise fall back to x11.
- Loading branch information
Alex Saveau
committed
Nov 20, 2024
1 parent
b931b23
commit cabaae4
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ members = [ | |
"egui", | ||
"server", | ||
"tui", | ||
"wayland-interface-check", | ||
"x11", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "wayland-interface-check" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
description = "Binary to answer the question, \"Is this Wayland interface available?\"" | ||
repository.workspace = true | ||
keywords = ["tools", "wayland", "cli"] | ||
categories = ["command-line-utilities", "development-tools"] | ||
license.workspace = true | ||
|
||
[dependencies] | ||
rustc-hash = "2.0.0" | ||
wayland-client = "0.31.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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> | ||
|
||
This simple binary answers the question, "Is this Wayland interface available?" For example, | ||
|
||
```sh | ||
$ wayland-interface-check zwlr_data_control_manager_v1 | ||
$ echo $? | ||
0 | ||
``` | ||
|
||
means the interface is available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#![feature(exitcode_exit_method)] | ||
|
||
use std::{ | ||
collections::HashSet, env, ffi::OsString, hash::BuildHasherDefault, os::unix::ffi::OsStringExt, | ||
process::ExitCode, | ||
}; | ||
|
||
use rustc_hash::FxHasher; | ||
use wayland_client::{ | ||
Connection, Dispatch, QueueHandle, | ||
protocol::{wl_registry, wl_registry::WlRegistry}, | ||
}; | ||
|
||
fn main() -> ExitCode { | ||
let interfaces = env::args_os() | ||
.skip(1) | ||
.map(OsString::into_vec) | ||
.collect::<HashSet<_, _>>(); | ||
if interfaces.is_empty() { | ||
return ExitCode::SUCCESS; | ||
} | ||
|
||
let Ok(conn) = Connection::connect_to_env() else { | ||
return ExitCode::FAILURE; | ||
}; | ||
let display = conn.display(); | ||
|
||
let mut event_queue = conn.new_event_queue(); | ||
let qh = event_queue.handle(); | ||
|
||
let mut state = State(interfaces); | ||
|
||
display.get_registry(&qh, ()); | ||
let Ok(_) = event_queue.roundtrip(&mut state) else { | ||
return ExitCode::FAILURE; | ||
}; | ||
|
||
if state.0.is_empty() { | ||
ExitCode::SUCCESS | ||
} else { | ||
ExitCode::FAILURE | ||
} | ||
} | ||
|
||
struct State(HashSet<Vec<u8>, BuildHasherDefault<FxHasher>>); | ||
|
||
impl Dispatch<WlRegistry, ()> for State { | ||
fn event( | ||
this: &mut Self, | ||
_: &WlRegistry, | ||
event: wl_registry::Event, | ||
(): &(), | ||
_: &Connection, | ||
_: &QueueHandle<Self>, | ||
) { | ||
if let wl_registry::Event::Global { | ||
name: _, | ||
interface, | ||
version: _, | ||
} = event | ||
{ | ||
this.0.remove(interface.as_bytes()); | ||
if this.0.is_empty() { | ||
ExitCode::SUCCESS.exit_process() | ||
} | ||
} | ||
} | ||
} |