Skip to content

Commit a484f17

Browse files
Added vendor support (#7)
Co-authored-by: Azarattum <azarattum@pm.me>
1 parent e2ddee6 commit a484f17

6 files changed

Lines changed: 41 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.7.1
2+
3+
- Added support for the vendor flag on OpenRGB clients.
4+
5+
The vendor name is read from the manufacturer string from what the OS got off the keyboard's USB firmware when it was plugged in, using the manufacturer field added to async-hid's DeviceInfo in version 0.5.1. The manufacturer name has been compiled into the QMK firmware and is then basically reported to OpenRGB clients.
6+
17
## 0.7.0
28

39
- (potentially breaking) Direct mode is now always reported to clients at index 0 (this does not affect your JSON configs)

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "ColorHoster"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2024"
55

66
[dependencies]
77
anyhow = "1.0.97"
8-
async-hid = "0.4.2"
8+
async-hid = "0.5.1"
99
ceviche = "0.7.0"
1010
chrono = "0.4.40"
1111
clap = { version = "4.5.32", features = ["derive"] }

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Effect = (String, i32, u32);
1818
#[derive(Debug, Clone)]
1919
pub struct Config {
2020
pub name: String,
21+
pub vendor: String,
2122
pub vendor_id: u16,
2223
pub product_id: u16,
2324
pub leds: Vec<(u8, Position)>,
@@ -42,6 +43,7 @@ impl Config {
4243

4344
Ok(Self {
4445
name,
46+
vendor: "Unknown".to_string(),
4547
vendor_id: parse_hex(&vendor_id),
4648
product_id: parse_hex(&product_id),
4749
matrix: (matrix.cols, matrix.rows),

src/handlers.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ pub async fn handle(
8888
buffer.extend_from_slice(&DEVICE_TYPE_KEYBOARD.to_le_bytes());
8989
buffer.extend_from_str(&config.name);
9090
if ctx.protocol_version >= 1 {
91-
buffer.extend_from_str("Unknown");
91+
buffer.extend_from_str(&config.vendor);
9292
}
93-
buffer.extend_from_str(&format!("{} via ColorHoster", &config.name));
93+
buffer.extend_from_str(&format!(
94+
"{} {} via ColorHoster",
95+
&config.vendor, &config.name
96+
));
9497
buffer.extend_from_str(env!("CARGO_PKG_VERSION"));
9598
buffer.extend_from_str(&id);
9699
buffer.extend_from_str(&format!("HID: {}", id));

src/keyboards.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ impl Keyboards {
3535

3636
while let Some(device) = stream.next().await {
3737
if is_compatible(&device)
38-
&& let Some(config) = configs.remove(&(device.vendor_id, device.product_id))
38+
&& let Some(mut config) = configs.remove(&(device.vendor_id, device.product_id))
3939
{
40-
debug!("Keyboard {} connected!", config.name.bold());
40+
if let Some(manufacturer) = device.manufacturer.clone() {
41+
config.vendor = manufacturer;
42+
}
43+
debug!(
44+
"Keyboard {} {} connected!",
45+
config.name.bold().blue(),
46+
format!("({})", config.vendor).bold().cyan()
47+
);
4148
match Keyboard::from_config(config, device).await {
4249
Err(error) => warn!("Failed to initialize keyboard: {error}"),
4350
Ok(keyboard) => {
@@ -74,8 +81,15 @@ impl Keyboards {
7481
configs.lock().unwrap().remove(key)
7582
});
7683

77-
if let (Some(config), Some(device)) = (config, device) {
78-
debug!("Keyboard {} connected!", config.name.bold());
84+
if let (Some(mut config), Some(device)) = (config, device) {
85+
if let Some(manufacturer) = device.manufacturer.clone() {
86+
config.vendor = manufacturer;
87+
}
88+
debug!(
89+
"Keyboard {} {} connected!",
90+
config.name.bold().blue(),
91+
format!("({})", config.vendor).bold().cyan()
92+
);
7993
match Keyboard::from_config(config, device).await {
8094
Err(error) => warn!("Failed to initialize keyboard: {error}"),
8195
Ok(keyboard) => {
@@ -89,7 +103,11 @@ impl Keyboards {
89103
DeviceEvent::Disconnected(id) => {
90104
if let Some(device) = keyboards.lock().await.shift_remove(&id) {
91105
let config = device.into_config().await;
92-
debug!("Keyboard {} disconnected!", config.name.bold());
106+
debug!(
107+
"Keyboard {} {} disconnected!",
108+
config.name.bold().blue(),
109+
format!("({})", config.vendor).bold().cyan()
110+
);
93111

94112
configs
95113
.lock()

0 commit comments

Comments
 (0)