line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Karabiner::Manipulator::Actions::From ; |
2
|
|
|
|
|
|
|
$JSON::Karabiner::Manipulator::Actions::From::VERSION = '0.016'; |
3
|
5
|
|
|
5
|
|
34
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
161
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
123
|
|
5
|
5
|
|
|
5
|
|
1317
|
use JSON; |
|
5
|
|
|
|
|
16737
|
|
|
5
|
|
|
|
|
28
|
|
6
|
5
|
|
|
5
|
|
688
|
use Carp; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
334
|
|
7
|
5
|
|
|
5
|
|
1458
|
use parent 'JSON::Karabiner::Manipulator::Actions'; |
|
5
|
|
|
|
|
912
|
|
|
5
|
|
|
|
|
27
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
8
|
|
|
8
|
1
|
18
|
my $class = shift; |
12
|
8
|
|
|
|
|
23
|
my ($type, $value) = @_; |
13
|
8
|
|
|
|
|
56
|
my $obj = $class->SUPER::new($type, $value); |
14
|
|
|
|
|
|
|
$obj->{data} = $value || {}, |
15
|
8
|
|
50
|
|
|
80
|
$obj->{has_mandatory_modifiers} = 0; |
16
|
8
|
|
|
|
|
20
|
$obj->{has_optional_modifiers} = 0; |
17
|
8
|
|
|
|
|
14
|
$obj->{has_code_set} = 0; |
18
|
8
|
|
|
|
|
23
|
return $obj; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_key_code { |
22
|
9
|
|
|
9
|
1
|
1520
|
my $s = shift; |
23
|
9
|
|
|
|
|
22
|
my @key_codes = @_; |
24
|
9
|
|
|
|
|
16
|
my $last_arg = $key_codes[-1]; |
25
|
9
|
|
|
|
|
32
|
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
|
|
|
|
|
8
|
pop @key_codes; |
29
|
|
|
|
|
|
|
} |
30
|
9
|
50
|
|
|
|
24
|
croak 'No key code passed' if !@key_codes; |
31
|
9
|
100
|
|
|
|
76
|
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
|
|
|
|
21
|
if (scalar @key_codes > 1) { |
35
|
0
|
|
|
|
|
0
|
croak 'Only one input type can be entered for "from" defintions'; |
36
|
|
|
|
|
|
|
} |
37
|
5
|
|
|
|
|
11
|
my ($letter_code, $ms); |
38
|
5
|
50
|
|
|
|
26
|
if ($key_codes[0] =~ /-([A-Z])|(\d+)$/) { |
39
|
0
|
|
|
|
|
0
|
$letter_code = $1; |
40
|
0
|
|
|
|
|
0
|
$ms = $2; |
41
|
|
|
|
|
|
|
} |
42
|
5
|
50
|
33
|
|
|
23
|
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
|
|
|
|
16
|
if (exists $s->{data}{$input_type}) { |
45
|
0
|
|
|
|
|
0
|
croak 'From action already has that property'; |
46
|
|
|
|
|
|
|
} |
47
|
5
|
|
|
|
|
12
|
$s->{data}{$input_type} = $key_codes[0]; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
29
|
$s->{code_set} = 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add_any { |
53
|
1
|
|
|
1
|
1
|
315
|
my $s = shift; |
54
|
1
|
50
|
|
|
|
4
|
croak 'You must pass a value' if !$_[0]; |
55
|
1
|
|
|
|
|
7
|
$s->add_key_code(@_, 'any'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_optional_modifiers { |
59
|
1
|
|
|
1
|
1
|
777
|
my $s = shift; |
60
|
1
|
|
|
|
|
4
|
$s->_add_modifiers('optional', @_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_mandatory_modifiers { |
64
|
2
|
|
|
2
|
1
|
643
|
my $s = shift; |
65
|
2
|
|
|
|
|
5
|
$s->_add_modifiers('mandatory', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _add_modifiers { |
69
|
3
|
|
|
3
|
|
6
|
my $s = shift; |
70
|
3
|
|
|
|
|
5
|
my $mod_type = shift; |
71
|
3
|
|
|
|
|
6
|
my $values = \@_; |
72
|
3
|
100
|
|
|
|
21
|
croak "This action already has $mod_type modifiers" if $s->{"has_${mod_type}_modifiers"}; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
6
|
$s->{data}{modifiers}{$mod_type} = \@_; |
75
|
2
|
|
|
|
|
9
|
$s->{"has_${mod_type}_modifiers"} = 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add_simultaneous { |
79
|
2
|
|
|
2
|
0
|
1041
|
my $s = shift; |
80
|
2
|
|
|
|
|
6
|
my @keys = @_; |
81
|
2
|
50
|
|
|
|
24
|
my $key_type = shift @keys if $keys[0] =~ /key_code|pointing|any/i; |
82
|
2
|
|
|
|
|
5
|
my @hashes; |
83
|
2
|
100
|
|
|
|
6
|
if (defined $s->{data}{simultaneous}) { |
84
|
1
|
|
|
|
|
3
|
@hashes = @{$s->{data}{simultaneous}}; |
|
1
|
|
|
|
|
2
|
|
85
|
|
|
|
|
|
|
} |
86
|
2
|
|
|
|
|
4
|
foreach my $key ( @keys ) { |
87
|
6
|
|
50
|
|
|
19
|
push @hashes, { $key_type || 'key_code' => $key }; |
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
9
|
$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__ |