Recently Written · git

xinput-persistence

xinput for mouse or keyboard configurations that work when disconnected or on boot.

git clone https://github.com/equwal/xinput-persistence

Log | Files | Refs


monitor.pl (908 bytes)

1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 my $xname;
5 my $devname;
6 my $comm1;
7 my $comm2;
8 my $act;
9 while($#ARGV > 0) {
10     $_ = shift @ARGV;
11     if($_ eq '-n') {
12         $xname = shift @ARGV;
13     }
14     elsif($_ eq '-d') {
15         $devname = shift @ARGV;
16     }
17     elsif($_ eq '-c1') {
18         $comm1 = shift @ARGV;
19     }
20     elsif($_ eq '-c2') {
21         $comm2 = shift @ARGV;
22     }
23     elsif($_ eq '-a') {
24         $act = shift @ARGV;
25     } else {
26         print "unexpected argument\n";
27     }
28 }
29 open my $udev, '-|', qw(udevadm monitor);
30 while (<$udev>) {
31     my ($source, $ts, $action, $dev, $sys) = split;
32     if (defined($action) and ($action eq $act and ($dev =~ /usb/))) {
33         my $comm = $comm1;
34         if(defined $comm2){
35             my $xlist = `xinput`;
36             $xlist =~ /$xname\W+id=(.*?)\W+/;
37             $comm = $comm1 . $1 . $comm2;
38         }
39         print $comm;
40          `$comm`;
41     }
42 }