line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Karabiner::Manipulator::Actions::From ; |
2
|
|
|
|
|
|
|
$JSON::Karabiner::Manipulator::Actions::From::VERSION = '0.017'; |
3
|
5
|
|
|
5
|
|
35
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
158
|
|
4
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
120
|
|
5
|
5
|
|
|
5
|
|
1375
|
use JSON; |
|
5
|
|
|
|
|
17654
|
|
|
5
|
|
|
|
|
28
|
|
6
|
5
|
|
|
5
|
|
665
|
use Carp; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
307
|
|
7
|
5
|
|
|
5
|
|
1358
|
use parent 'JSON::Karabiner::Manipulator::Actions'; |
|
5
|
|
|
|
|
918
|
|
|
5
|
|
|
|
|
30
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
8
|
|
|
8
|
1
|
18
|
my $class = shift; |
12
|
8
|
|
|
|
|
26
|
my ($type, $value) = @_; |
13
|
8
|
|
|
|
|
50
|
my $obj = $class->SUPER::new($type, $value); |
14
|
|
|
|
|
|
|
$obj->{data} = $value || {}, |
15
|
8
|
|
50
|
|
|
80
|
$obj->{has_mandatory_modifiers} = 0; |
16
|
8
|
|
|
|
|
19
|
$obj->{has_optional_modifiers} = 0; |
17
|
8
|
|
|
|
|
21
|
$obj->{has_code_set} = 0; |
18
|
8
|
|
|
|
|
24
|
return $obj; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_key_code { |
22
|
9
|
|
|
9
|
1
|
1547
|
my $s = shift; |
23
|
9
|
|
|
|
|
23
|
my @key_codes = @_; |
24
|
9
|
|
|
|
|
19
|
my $last_arg = $key_codes[-1]; |
25
|
9
|
|
|
|
|
16
|
my $input_type = 'key_code'; |
26
|
9
|
100
|
66
|
|
|
66
|
if ($last_arg && $last_arg =~ /^any|consumer_key_code|pointing_button$/) { |
27
|
4
|
|
|
|
|
8
|
$input_type = $last_arg; |
28
|
4
|
|
|
|
|
7
|
pop @key_codes; |
29
|
|
|
|
|
|
|
} |
30
|
9
|
50
|
|
|
|
26
|
croak 'No key code passed' if !@key_codes; |
31
|
9
|
100
|
|
|
|
69
|
croak 'You can only set one key_code, consumer_key_code, pointing_button or any' if ($s->{code_set}); |
32
|
|
|
|
|
|
|
#TODO: validate $key_code |
33
|
|
|
|
|
|
|
|
34
|
5
|
50
|
|
|
|
14
|
if (scalar @key_codes > 1) { |
35
|
0
|
|
|
|
|
0
|
croak 'Only one input type can be entered for "from" defintions'; |
36
|
|
|
|
|
|
|
} |
37
|
5
|
|
|
|
|
10
|
my ($letter_code, $ms); |
38
|
5
|
50
|
|
|
|
28
|
if ($key_codes[0] =~ /-([A-Z])|(\d+)$/) { |
39
|
0
|
|
|
|
|
0
|
$letter_code = $1; |
40
|
0
|
|
|
|
|
0
|
$ms = $2; |
41
|
|
|
|
|
|
|
} |
42
|
5
|
50
|
33
|
|
|
28
|
croak 'Specifiers such as lazy, repeat, halt, and hold_down_in_milliseconds do not apply in "from" actions' |
43
|
|
|
|
|
|
|
if $letter_code || $ms; |
44
|
5
|
50
|
|
|
|
15
|
if (exists $s->{data}{$input_type}) { |
45
|
0
|
|
|
|
|
0
|
croak 'From action already has that property'; |
46
|
|
|
|
|
|
|
} |
47
|
5
|
|
|
|
|
13
|
$s->{data}{$input_type} = $key_codes[0]; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
24
|
$s->{code_set} = 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add_any { |
53
|
1
|
|
|
1
|
1
|
360
|
my $s = shift; |
54
|
1
|
50
|
|
|
|
5
|
croak 'You must pass a value' if !$_[0]; |
55
|
1
|
|
|
|
|
2
|
$s->add_key_code(@_, 'any'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_optional_modifiers { |
59
|
1
|
|
|
1
|
1
|
760
|
my $s = shift; |
60
|
1
|
|
|
|
|
3
|
$s->_add_modifiers('optional', @_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_mandatory_modifiers { |
64
|
2
|
|
|
2
|
1
|
685
|
my $s = shift; |
65
|
2
|
|
|
|
|
6
|
$s->_add_modifiers('mandatory', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _add_modifiers { |
69
|
3
|
|
|
3
|
|
6
|
my $s = shift; |
70
|
3
|
|
|
|
|
6
|
my $mod_type = shift; |
71
|
3
|
|
|
|
|
6
|
my $values = \@_; |
72
|
3
|
100
|
|
|
|
19
|
croak "This action already has $mod_type modifiers" if $s->{"has_${mod_type}_modifiers"}; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
7
|
$s->{data}{modifiers}{$mod_type} = \@_; |
75
|
2
|
|
|
|
|
9
|
$s->{"has_${mod_type}_modifiers"} = 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add_simultaneous { |
79
|
2
|
|
|
2
|
0
|
1100
|
my $s = shift; |
80
|
2
|
|
|
|
|
7
|
my @keys = @_; |
81
|
2
|
50
|
|
|
|
18
|
my $key_type = shift @keys if $keys[0] =~ /key_code|pointing|any/i; |
82
|
2
|
|
|
|
|
4
|
my @hashes; |
83
|
2
|
100
|
|
|
|
7
|
if (defined $s->{data}{simultaneous}) { |
84
|
1
|
|
|
|
|
3
|
@hashes = @{$s->{data}{simultaneous}}; |
|
1
|
|
|
|
|
3
|
|
85
|
|
|
|
|
|
|
} |
86
|
2
|
|
|
|
|
4
|
foreach my $key ( @keys ) { |
87
|
6
|
|
50
|
|
|
19
|
push @hashes, { $key_type || 'key_code' => $key }; |
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
10
|
$s->{data}{simultaneous} = \@hashes ; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub add_simultaneous_options { |
93
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
94
|
0
|
|
|
|
|
|
my $option = shift; |
95
|
0
|
|
|
|
|
|
my @values = @_; |
96
|
0
|
|
|
|
|
|
my @allowed_options = qw ( detect_key_down_uninterruptedly |
97
|
|
|
|
|
|
|
key_down_order key_up_when to_after_key_up ); |
98
|
0
|
|
|
|
|
|
my $exists = grep { $_ = $option } @allowed_options; |
|
0
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
croak "Simultaneous option is not a valid option" if $exists; |
100
|
0
|
|
|
|
|
|
my $value = $values[0]; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#TODO: detect if option already exists and die if it does |
103
|
|
|
|
|
|
|
#TODO: offer suggestions if error thrown |
104
|
0
|
0
|
|
|
|
|
croak "Simultaneous option $option has already been set" if ($s->{"so_${option}_is_set"} == 1); |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
if ($option eq 'detect_key_down_uninterruptedly') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ($value !~ /true|false/) { |
108
|
0
|
|
|
|
|
|
croak "$value is not a valid option for $option"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} elsif ($option eq 'key_down_order' || $option eq 'key_up_order') { |
111
|
0
|
0
|
|
|
|
|
if ($value !~ /insenstive|strict|strict_inverse/) { |
112
|
0
|
|
|
|
|
|
croak "$value is not a valid option for $option"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} elsif ($option eq 'key_up_when') { |
115
|
0
|
0
|
|
|
|
|
if ($value !~ /any|when/) { |
116
|
0
|
|
|
|
|
|
croak "$value is not a valid option for $option"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} elsif ($option eq 'to_after_key_up') { |
119
|
|
|
|
|
|
|
#TODO: Figure out how this is supposed to work |
120
|
0
|
|
|
|
|
|
croak 'This option is currently unspported by JSON::Karabiner'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$s->{"so_${option}_is_set"} = 1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ABSTRACT: From defintion |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |