commit ae6c106ff1ea44672b905862c69a25d90d5f0415 Spenser Truex <spensertruexonline@gmail.com> 2019-04-22 15:10:41 -0700 Insert xinput id.
README.org | 25 ++++++++++++++++--------- commands.conf | 4 ++-- forking.pl | 5 ++++- monitor.pl | 37 ++++++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/README.org b/README.org index d5400f4..a870845 100644 --- a/README.org +++ b/README.org @@ -6,14 +6,15 @@ monitor udev. Here I chose to monitor udev for all devices. * Installation -First, you need to know a portion of each device's name and device path. Find -these out like this: +First, you need to know the last portion of each device's name, a portion of the +device path, and the name of the property you want to watch for. Find these out +like this: ```shell # Plugin the device $ xinput ... -...DeathAdder... +...DeathAdder Elite... # Unplug the device $ udevadm monitor ... @@ -27,17 +28,23 @@ UDEV [2607.521415] add /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.2/0 Now that you have those, modify commands.conf from my personal choices: ```shell -monitor.pl -n 'device name #1' -d 'usb or other part of the path' -monitor.pl -n 'device name #2' -d 'usb or other part of the path' +monitor.pl -n 'device name #1' -d 'usb or other part of the path' -c1 'xinput ' <id inserted here> -c2 ' rest of command' +monitor.pl -n 'device name #2' -d 'usb or other part of the path' -c1 'no-id-required command' ``` +Perl will insert the ID of the xinput device if -c2 is specified, and it will be +placed between the c1 and c2 commands. Commands that do not need the xinput id +can omit -c2. + You can have as many devices as required. For example, you might add a PS/2 keyboard also: ```shell -monitor.pl -n 'device name #1' -d 'usb or other part of the path' -monitor.pl -n 'device name #2' -d 'usb or other part of the path' -monitor.pl -n 'N-rollover' -d 'ps/2' +monitor.pl -n 'device name #1' -d 'usb or other part of the path' -c 'command' +monitor.pl -n 'device name #2' -d 'usb or other part of the path' -c 'command' +monitor.pl -n 'N-rollover' -d 'ps/2' -c 'command' ``` -The program will fork each one. +The program will fork each one, with the controller process looping forever. + +Make sure to add forking.pl to your startup scripts. diff --git a/commands.conf b/commands.conf index 1465899..fac9d91 100644 --- a/commands.conf +++ b/commands.conf @@ -1,2 +1,2 @@ -monitor.pl -n 'DeathAdder Elite' -d 'usb' -monitor.pl -n 'Rosewell' -d 'usb' +monitor.pl -a 'add' -n 'DeathAdder Elite' -d 'usb' -c1 'xinput set-prop ' -c2 ' 153 0.114285, 0.000000, 0.000000, 0.000000, 0.114285, 0.000000, 0.000000, 0.000000, 1.000000' +monitor.pl -a 'add' -n 'Rosewell' -d 'usb' -c1 '/usr/bin/desired-keymap' diff --git a/forking.pl b/forking.pl index e5582b2..1cbd257 100755 --- a/forking.pl +++ b/forking.pl @@ -1,4 +1,4 @@ -#/usr/bin/perl +#!/usr/bin/perl use strict; use warnings; open my $com, '<', 'commands.conf'; @@ -6,6 +6,9 @@ for(<$com>) { my $f = fork(); if (defined $f) { print; + chomp; `$_`; } } + +while(1){;} diff --git a/monitor.pl b/monitor.pl index 0c329aa..2304410 100755 --- a/monitor.pl +++ b/monitor.pl @@ -1,27 +1,42 @@ #!/usr/bin/perl use warnings; use strict; -open my $udev, '-|', qw(udevadm monitor); my $xname; my $devname; -for(@ARGV) { +my $comm1; +my $comm2; +my $act; +while($#ARGV > 0) { $_ = shift @ARGV; if($_ eq '-n') { $xname = shift @ARGV; } - if($_ eq '-d') { + elsif($_ eq '-d') { $devname = shift @ARGV; } + elsif($_ eq '-c1') { + $comm1 = shift @ARGV; + } + elsif($_ eq '-c2') { + $comm2 = shift @ARGV; + } + elsif($_ eq '-a') { + $act = shift @ARGV; + } else { + print "unexpected argument\n"; + } } +open my $udev, '-|', qw(udevadm monitor); while (<$udev>) { my ($source, $ts, $action, $dev, $sys) = split; - print; - if ($action eq 'add' and $dev =~ /usb/) { - my $xlist = `xinput`; - $xlist =~ /DeathAdder Elite\W+id=(.*?)\W+/; - `xinput set-prop $1 153 0.114285, 0.000000, 0.000000, 0.000000, 0.114285, 0.000000, 0.000000, 0.000000, 1.000000` + if (defined($action) and ($action eq $act and ($dev =~ /usb/))) { + my $comm = $comm1; + if(defined $comm2){ + my $xlist = `xinput`; + $xlist =~ /$xname\W+id=(.*?)\W+/; + $comm = $comm1 . $1 . $comm2; + } + print $comm; + `$comm`; } } -# Add this udev rule to automatically run this script when mouse is connected. -# ACTION=="add", RUN+="/usr/bin/mouseset" -# to file /etc/udev/rules.d/100-usb.rules