1+ use crate :: commands:: OK_COLOUR ;
12use crate :: { Context , Error } ;
23
34use std:: fmt:: Write ;
45
5- use poise:: serenity_prelude:: CreateAttachment ;
6+ use poise:: serenity_prelude:: { CreateAttachment , CreateEmbed } ;
67use 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- ```\n sudo 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
4045fn 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\" \n SUBSYSTEM==\" 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- "\n SUBSYSTEM==\" input\" , ATTRS{{idVendor}}==\" {id_vendor:X}\" , ATTRS{{idProduct}}==\" {id_product:X}\" "
50- ) . unwrap ( ) ;
56+ "\n SUBSYSTEM==\" 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