diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MTools/Adapters/WacomAdapter.pm | 89 | ||||
-rw-r--r-- | src/MTools/MTimer.pm | 98 |
2 files changed, 119 insertions, 68 deletions
diff --git a/src/MTools/Adapters/WacomAdapter.pm b/src/MTools/Adapters/WacomAdapter.pm index 5f71d3a..1adc909 100644 --- a/src/MTools/Adapters/WacomAdapter.pm +++ b/src/MTools/Adapters/WacomAdapter.pm @@ -20,6 +20,7 @@ use strict; use MTools qw(!binding); use MTools::MObjet; use MTools::MIvy; +use MTools::MTimer; use vars qw /@ISA/; BEGIN @@ -37,8 +38,23 @@ sub new { $wacom_adresse = 'default'; } bless $self, $class; + $self -> recordProperty ('compress_move', 1); + $self -> plisten ('compress_move', + sub { + my ($src, $key, $val) = @_; + if ($val == 0) + { + if ($self->{__timer}->is_running()) { + $self->callback(); + $self->{__timer}->stop(); + } + } + }); + $self -> {__pointer_status} = 0; $self -> {__ivy} = new MTools::MIvy ($adresse, $ivy_name); + $self -> {__datas} = undef; + $self -> {__timer} = new MTools::MTimer(1,0,[\&callback,$self]); #$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']); @@ -95,18 +111,25 @@ sub binding { ################################################################################ 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"; + + if ($self->{__timer}->is_running()) { + $self->compute_callbacks('pointers', $self->{__datas}); + $self->{__datas} = undef; + $self->{__timer}->stop(); + } + $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}); + $zinc->idletasks(); } ################################################################################ @@ -125,20 +148,26 @@ sub wacom_event_pointers { # $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"; + $self -> {__datas} = {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}; + if ($self->mget('compress_move')) { + if (!$self->{__timer}->is_running()) { + $self->{__timer}->start(); + } + } else { + $self->callback(); + } } ############################################################################### @@ -208,6 +237,14 @@ sub wacom_event { } ################################################################################### +sub callback { + my ($self) = @_; + $self->compute_callbacks('pointers', $self->{__datas}); + $self->{__datas} = undef; + $zinc->idletasks(); +} + +################################################################################### sub compute_callbacks { my ($self, $type, $fields) = @_; my @callbacks = (); diff --git a/src/MTools/MTimer.pm b/src/MTools/MTimer.pm index 9377706..ff74c72 100644 --- a/src/MTools/MTimer.pm +++ b/src/MTools/MTimer.pm @@ -51,53 +51,67 @@ use Tk; sub new { - my ($class, $timeout, $repeat, $callback, %options) = @_; - my $self = new MTools::MObjet (); - bless $self, $class; - - $repeat = 0 if !defined $repeat; - $repeat = 0 if !defined $callback; - - $self -> recordEvent ('TIME_OUT'); - $self -> recordEvent ('TIMER_STOPPED'); - $self -> recordProperty ('timeout', $timeout); - $self -> recordProperty ('repeat', $repeat); - $self -> recordProperty ('callback', $callback); - $self -> recordProperty ('-visible', 0); - $self -> plisten ('-visible', sub { - my ($src, $key, $val) = @_; - if ($val == 0) - { - $self -> stop (); - } - else - { - $self -> start (); - } - }); - $self -> mconfigure (%options); - - return $self; + my ($class, $timeout, $repeat, $callback, %options) = @_; + my $self = new MTools::MObjet (); + bless $self, $class; + + $repeat = 0 if !defined $repeat; + $repeat = 0 if !defined $callback; + + $self -> recordEvent ('TIME_OUT'); + $self -> recordEvent ('TIMER_STOPPED'); + $self -> recordProperty ('timeout', $timeout); + $self -> recordProperty ('repeat', $repeat); + $self -> recordProperty ('callback', $callback); + $self -> recordProperty ('-visible', 0); + $self-> {__timer} = undef; + $self -> plisten ('-visible', + sub { + my ($src, $key, $val) = @_; + if ($val == 0) + { + $self -> stop (); + } + else + { + $self -> start (); + } + }); + $self -> mconfigure (%options); + return $self; } sub start { - my ($self) = @_; - my $repeat = $self -> mget ('repeat'); - my $timeout = $self -> mget ('timeout'); - my $callback = $self -> mget ('callback'); - my $function = $repeat ? 'repeat' : 'after'; - $self -> {__timer} = $zinc -> $function ($timeout, sub { - $self -> notify ('TIME_OUT'); - if ($callback) - { - executer ($callback); - } - }); + my ($self) = @_; + my $repeat = $self -> mget ('repeat'); + my $timeout = $self -> mget ('timeout'); + my $callback = $self -> mget ('callback'); + my $function = $repeat ? 'repeat' : 'after'; + $self -> {__timer} = $zinc -> $function ($timeout, + sub { + $self -> notify ('TIME_OUT'); + if ($callback) + { + executer ($callback); + } + $self -> {__timer} = undef unless $repeat; + }); } sub stop { - my ($self) = @_; - $zinc -> afterCancel ($self -> {__timer}); - $self -> notify ('TIMER_STOPPED'); + my ($self) = @_; + return unless defined $self -> {__timer}; + $zinc -> afterCancel ($self -> {__timer}); + $self -> {__timer} = undef; + $self -> notify ('TIMER_STOPPED'); +} + +sub is_running { + my ($self) = @_; + return (defined $self -> {__timer} ? 1 : 0); } + 1; + + + |