package MTools::Adapters::WacomAdapter; # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU LGPL Libray General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, # or refer to http://www.gnu.org/copyleft/lgpl.html # ################################################################## use strict; use MTools qw(!binding); use MTools::MObjet; use MTools::MIvy; use vars qw /@ISA/; BEGIN { @ISA = qw /MTools::MObjet/; } use Tk; sub new { my ($class, $adresse, $ivy_name, $wacom_adresse) = @_; my $self = new MTools::MObjet (); if (!defined $wacom_adresse) { $wacom_adresse = 'default'; } bless $self, $class; $self -> {__pointer_status} = 0; $self -> {__ivy} = new MTools::MIvy ($adresse, $ivy_name); #$self -> {__ivy} -> binding ('pad_event device_id='.$wacom_adresse.' button=(.*) status=(.*) time=(.*)', [\&wacom_event, $self, 'buttons']); $self -> {__ivy} -> binding ('^InputButtonEvent '.$wacom_adresse.' num=(.*) state=(.*) Abs_X=(.*) Abs_Y=(\S+) .*Abs_Wheel=(.*) Abs_Pressure=(\S+) .*Abs_Tilt_X=(.*) Abs_Tilt_Y=(.*) Abs_Tool_Type=(.*) unknown=(.*) time=(.*)',[\&wacom_event_buttons, $self]); #$self -> {__ivy} -> binding ('slider_event device_id='.$wacom_adresse.' value=(.*) side=(.*) time=(.*)', [\&wacom_event, $self, 'sliders']); #$self -> {__ivy} -> binding ('pointer_event device_id='.$wacom_adresse.' x=(.*) y=(.*) presure=(.*) tilt_x=(.*) tilt_y=(.*) wheel=(.*) predicted_x=(.*) predicted_y=(.*) type=(.*) serial_number=(.*) time=(.*)', [\&wacom_event, $self, 'pointers']); $self -> {__ivy} -> binding ('^InputMoveEvent '.$wacom_adresse.' Abs_X=(.*) Abs_Y=(\S+) .*Abs_Rotary_X=(.*) Abs_Rotary_Y=(\S+) .*Abs_Wheel=(.*) Abs_Pressure=(\S+) .*Abs_Tilt_X=(.*) Abs_Tilt_Y=(.*) Abs_Tool_Type=(.*) unknown=(.*) time=(.*)', [\&wacom_event_pointers, $self]); return $self; } sub binding { my ($self, $reg, $cb) = @_; if ($reg eq '') { push (@{$self -> {sliders} -> {all}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {sliders} -> {$1} -> {$2}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {sliders} -> {$1} -> {all}}, $cb); } elsif ($reg eq '') { push (@{$self -> {buttons} -> {all}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {buttons} -> {$1} -> {$2}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {buttons} -> {$1} -> {all}}, $cb); } elsif ($reg eq '') { push (@{$self -> {pointers} -> {all}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {pointers} -> {$1} -> {$2}}, $cb); } elsif ($reg =~ /\/) { push (@{$self -> {pointers} -> {$1} -> {all}}, $cb); } else { die "Can't recognize a wacom event in $reg\n"; } } ################################################################################ sub wacom_event_buttons { my ($agent, $self, $num, $state, $x, $y, $wheel, $presure, $tilt_x, $tilt_y, $type, $serial_number, $time) = @_; $self->compute_callbacks('buttons',{num => $num, state => $state, X => $x, Y => $y, wheel => $wheel, presure => $presure, tilt_x => $tilt_x, tilt_y => $tilt_y, type => $type, serial_number => $serial_number, time => $time}); print STDERR "\nwacom_event_buttons $num,$state\n\n"; } ################################################################################ sub wacom_event_pointers { my ($agent, $self, $x, $y, $rotary_x, $rotary_y, $wheel, $presure, $tilt_x, $tilt_y, $type, $serial_number, $time) = @_; #if ($time == 0) { # $value = 'Release'; # $self -> {__pointer_status} = 0; # } #else { # if ($self -> {__pointer_status}) { # $value = 'Motion'; # } # else { # $value = 'Press'; # $self -> {__pointer_status} = 1; # } # } $self->compute_callbacks('pointers',{num => '', state => int $type, X => $x, Y => $y, rotary_X => $rotary_x, rotary_Y => $rotary_y, wheel => $wheel, presure => $presure, tilt_x => $tilt_x, tilt_y => $tilt_y, type => $type, serial_number => $serial_number, time => $time}); print STDERR "\nwacom_event_pointers $type\n\n"; } ############################################################################### sub wacom_event { my ($agent, $self, $type, $value, $status, $time, @others) = @_; my @callbacks = (); my @args = (); if ($type eq 'sliders') { my $nb = 0; if ($value != 0) { while ($value != 1) { $value = $value / 2; $nb ++; } $nb++; } $value = $nb; } if ($type eq 'pointers') { $status = $others [5]; if ($status =~ /(.*)_(.*)_(.*)_(.*)/) { $status = $3; } elsif ($status =~ /(.*)_(.*)_(.*)/) { $status = $2; } if ($time == 0) { $value = 'Release'; $self -> {__pointer_status} = 0; } else { if ($self -> {__pointer_status}) { $value = 'Motion'; } else { $value = 'Press'; $self -> {__pointer_status} = 1; } } } if (defined $self -> {$type} -> {all}) { push (@callbacks, @{$self -> {$type} -> {all}}); } if (defined $self -> {$type} -> {$status} -> {all}) { push (@callbacks, @{$self -> {$type} -> {$status} -> {all}}); } if (defined $self -> {$type} -> {$status} -> {$value}) { push (@callbacks, @{$self -> {$type} -> {$status} -> {$value}}); } for (my $i = 0; $i < @callbacks; $i ++) { executer ($callbacks[$i], $value, $status, $type); } } ################################################################################### sub compute_callbacks { my ($self, $type, $fields) = @_; my @callbacks = (); if (defined $self -> {$type} -> {all}) { push (@callbacks, @{$self -> {$type} -> {all}}); } if (defined $self -> {$type} -> {$fields->{state}} -> {all}) { push (@callbacks, @{$self -> {$type} -> {$fields->{state}} -> {all}}); } if (defined $self -> {$type} -> {$fields->{state}} -> {$fields->{num}}) { push (@callbacks, @{$self -> {$type} -> {$fields->{state}} -> {$fields->{num}}}); } for (my $i = 0; $i < @callbacks; $i ++) { executer ($callbacks[$i],$fields); } } 1;