Skip to content

Commit 1926b14

Browse files
Merge pull request #43 from jamesbt365/udev
Fix udev and dumb time crate issue
2 parents 6669e0f + d271c10 commit 1926b14

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

Cargo.lock

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

src/commands/udev.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use crate::commands::OK_COLOUR;
12
use crate::{Context, Error};
23

34
use std::fmt::Write;
45

5-
use poise::serenity_prelude::CreateAttachment;
6+
use poise::serenity_prelude::{CreateAttachment, CreateEmbed};
67
use poise::CreateReply;
78

89
/// Generates udev rules for the given vendor and product Ids.
@@ -21,13 +22,17 @@ pub async fn generate_udev(
2122
let udev = gen_udev(vendor_id, product_id, libinput_override.unwrap_or(true));
2223

2324
let attachment = CreateAttachment::bytes(udev, "70-opentabletdriver.rules");
24-
ctx.send(
25-
CreateReply::default()
26-
.content("place this file in `/etc/udev/rules.d/70-opentabletdriver.rules` then run the following:\n \
27-
```\nsudo udevadm control --reload-rules && sudo udevadm trigger\n```")
28-
.attachment(attachment),
29-
)
30-
.await?;
25+
let embed = CreateEmbed::new()
26+
.title("Generated udev rules")
27+
.description(
28+
"Move this file to `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \
29+
following commands: \n```sudo udevadm control --reload-rules && sudo udevadm \
30+
trigger\n```",
31+
)
32+
.color(OK_COLOUR);
33+
34+
ctx.send(CreateReply::default().embed(embed).attachment(attachment))
35+
.await?;
3136

3237
Ok(())
3338
}
@@ -39,15 +44,19 @@ KERNEL=="js[0-9]*", SUBSYSTEM=="input", ATTRS{name}=="OpenTabletDriver Virtual T
3944

4045
fn gen_udev(id_vendor: u64, id_product: u64, libinput_override: bool) -> String {
4146
let mut udev_rules = format!(
42-
"KERNEL==\"hidraw*\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\", TAG+=\"uaccess\", TAG+=\"udev-acl\"\n\
43-
SUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\", TAG+=\"uaccess\", TAG+=\"udev-acl\""
47+
"KERNEL==\"hidraw*\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \
48+
ATTRS{{idProduct}}==\"{id_product:04x}\", TAG+=\"uaccess\", \
49+
TAG+=\"udev-acl\"\nSUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \
50+
ATTRS{{idProduct}}==\"{id_product:04x}\", TAG+=\"uaccess\", TAG+=\"udev-acl\""
4451
);
4552

4653
if libinput_override {
4754
write!(
4855
udev_rules,
49-
"\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\""
50-
).unwrap();
56+
"\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \
57+
ATTRS{{idProduct}}==\"{id_product:04x}\", ENV{{LIBINPUT_IGNORE_DEVICE}}=\"1\""
58+
)
59+
.unwrap();
5160
}
5261

5362
format!("{REQUIRED_UDEV_STR}\n# Generated by TabletBot\n{udev_rules}")

0 commit comments

Comments
 (0)