App-DTWMIC
view release on metacpan or search on metacpan
use warnings;
use utf8;
use Getopt::Long;
use App::DTWMIC;
use Udev::FFI;
use YAML::Syck;
use constant {
DEVICE_INPUT_OTHER => 0,
DEVICE_INPUT_MOUSE => 1,
DEVICE_INPUT_TOUCHPAD => 2,
DEVICE_INPUT_TABLET => 3,
DEVICE_INPUT_TOUCHSCREEN => 4,
SYNCLIENT_LOCATIONS => [
'/usr/bin/synclient'
]
};
my $config;
my $udev;
sub _get_device_type {
my $device = shift;
my $id_input_mouse = $device->get_property_value('ID_INPUT_MOUSE');
my $id_input_touchpad = $device->get_property_value('ID_INPUT_TOUCHPAD');
my $id_input_tablet = $device->get_property_value('ID_INPUT_TABLET');
my $id_input_touchscreen = $device->get_property_value('ID_INPUT_TOUCHSCREEN');
if (defined($id_input_mouse) && $id_input_mouse eq '1') {
# ID_INPUT_MOUSE: Touchscreens and tablets have this flag as well, since by the type of events they can produce
# they act as a mouse.
# https://askubuntu.com/questions/520359/how-to-detect-touchscreen-devices-from-a-script
if (defined($id_input_touchpad) && $id_input_touchpad eq '1') {
return DEVICE_INPUT_TOUCHPAD;
}
elsif (defined($id_input_tablet) && $id_input_tablet eq '1') {
return DEVICE_INPUT_TABLET;
}
elsif (defined($id_input_touchscreen) && $id_input_touchscreen eq '1') {
return DEVICE_INPUT_TOUCHSCREEN;
}
return DEVICE_INPUT_MOUSE;
}
elsif (defined($id_input_touchpad) && $id_input_touchpad eq '1') {
return DEVICE_INPUT_TOUCHPAD;
}
elsif (defined($id_input_tablet) && $id_input_tablet eq '1') {
return DEVICE_INPUT_TABLET;
}
elsif (defined($id_input_touchscreen) && $id_input_touchscreen eq '1') {
return DEVICE_INPUT_TOUCHSCREEN;
}
return DEVICE_INPUT_OTHER;
}
sub _get_device_data {
my $device = shift;
my $parent = $device->get_parent_with_subsystem_devtype('input');
return {}
unless defined $parent;
my $devices = $enumerate->get_list_entries() or
die("Can't get devices: $!");
for (keys(%$devices)) {
if (defined(my $device = $udev->new_device_from_syspath($_))) {
my $device_data = _get_device_data($device);
next
unless %$device_data;
if (DEVICE_INPUT_TOUCHPAD == $device_data->{'type'}) {
$touchpads->{ $device_data->{'sysname'} } = $device_data->{'data'};
}
elsif (DEVICE_INPUT_MOUSE == $device_data->{'type'}) {
++$has_mouse_devices;
}
}
}
_enable_touchpads($touchpads, 0 == $has_mouse_devices ? 1 : 0);
}
my $config_path;
$str_length = length($device_data->{'data'}{'name'});
if ($str_length > $max_str_length) {
$max_str_length = $str_length;
}
}
}
$max_str_length += 8 - ($max_str_length % 4);
for my $dev_type (@{ [[DEVICE_INPUT_MOUSE, 'MOUSE DEVICES'], [DEVICE_INPUT_TOUCHPAD, 'TOUCHPAD DEVICES']] }) {
print("$dev_type->[1]:\n");
while (my ($sysname, $device_data) = each(%{ $input_devices->{ $dev_type->[0] } })) {
print(' '.$device_data->{'name'}.(' ' x ($max_str_length - length($device_data->{'name'}))).
"sysname: $sysname\n");
}
print("\n");
}
( run in 0.380 second using v1.01-cache-2.11-cpan-4e96b696675 )