Skip to content

Commit

Permalink
Merge pull request #43 from jamesbt365/udev
Browse files Browse the repository at this point in the history
Fix udev and dumb time crate issue
  • Loading branch information
InfinityGhost authored Aug 15, 2024
2 parents 6669e0f + d271c10 commit 1926b14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

33 changes: 21 additions & 12 deletions src/commands/udev.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::commands::OK_COLOUR;
use crate::{Context, Error};

use std::fmt::Write;

use poise::serenity_prelude::CreateAttachment;
use poise::serenity_prelude::{CreateAttachment, CreateEmbed};
use poise::CreateReply;

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

let attachment = CreateAttachment::bytes(udev, "70-opentabletdriver.rules");
ctx.send(
CreateReply::default()
.content("place this file in `/etc/udev/rules.d/70-opentabletdriver.rules` then run the following:\n \
```\nsudo udevadm control --reload-rules && sudo udevadm trigger\n```")
.attachment(attachment),
)
.await?;
let embed = CreateEmbed::new()
.title("Generated udev rules")
.description(
"Move this file to `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \
following commands: \n```sudo udevadm control --reload-rules && sudo udevadm \
trigger\n```",
)
.color(OK_COLOUR);

ctx.send(CreateReply::default().embed(embed).attachment(attachment))
.await?;

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

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

if libinput_override {
write!(
udev_rules,
"\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\""
).unwrap();
"\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \
ATTRS{{idProduct}}==\"{id_product:04x}\", ENV{{LIBINPUT_IGNORE_DEVICE}}=\"1\""
)
.unwrap();
}

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

0 comments on commit 1926b14

Please sign in to comment.