line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Karabiner::Manipulator::Actions::From ; |
2
|
|
|
|
|
|
|
$JSON::Karabiner::Manipulator::Actions::From::VERSION = '0.018'; |
3
|
5
|
|
|
5
|
|
37
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
163
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
118
|
|
5
|
5
|
|
|
5
|
|
1277
|
use JSON; |
|
5
|
|
|
|
|
17000
|
|
|
5
|
|
|
|
|
26
|
|
6
|
5
|
|
|
5
|
|
636
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
350
|
|
7
|
5
|
|
|
5
|
|
1399
|
use parent 'JSON::Karabiner::Manipulator::Actions'; |
|
5
|
|
|
|
|
918
|
|
|
5
|
|
|
|
|
31
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
8
|
|
|
8
|
1
|
19
|
my $class = shift; |
12
|
8
|
|
|
|
|
24
|
my ($type, $value) = @_; |
13
|
8
|
|
|
|
|
53
|
my $obj = $class->SUPER::new($type, $value); |
14
|
|
|
|
|
|
|
$obj->{data} = $value || {}, |
15
|
8
|
|
50
|
|
|
81
|
$obj->{has_mandatory_modifiers} = 0; |
16
|
8
|
|
|
|
|
18
|
$obj->{has_optional_modifiers} = 0; |
17
|
8
|
|
|
|
|
20
|
$obj->{has_code_set} = 0; |
18
|
8
|
|
|
|
|
25
|
return $obj; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_key_code { |
22
|
9
|
|
|
9
|
1
|
1603
|
my $s = shift; |
23
|
9
|
|
|
|
|
23
|
my @key_codes = @_; |
24
|
9
|
|
|
|
|
16
|
my $last_arg = $key_codes[-1]; |
25
|
9
|
|
|
|
|
19
|
my $input_type = 'key_code'; |
26
|
9
|
100
|
66
|
|
|
66
|
if ($last_arg && $last_arg =~ /^any|consumer_key_code|pointing_button$/) { |
27
|
4
|
|
|
|
|
9
|
$input_type = $last_arg; |
28
|
4
|
|
|
|
|
7
|
pop @key_codes; |
29
|
|
|
|
|
|
|
} |
30
|
9
|
50
|
|
|
|
28
|
croak 'No key code passed' if !@key_codes; |
31
|
9
|
100
|
|
|
|
94
|
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
|
|
|
|
15
|
if (scalar @key_codes > 1) { |
35
|
0
|
|
|
|
|
0
|
croak 'Only one input type can be entered for "from" defintions'; |
36
|
|
|
|
|
|
|
} |
37
|
5
|
|
|
|
|
12
|
my ($letter_code, $ms); |
38
|
5
|
50
|
|
|
|
27
|
if ($key_codes[0] =~ /-([A-Z])|(\d+)$/) { |
39
|
0
|
|
|
|
|
0
|
$letter_code = $1; |
40
|
0
|
|
|
|
|
0
|
$ms = $2; |
41
|
|
|
|
|
|
|
} |
42
|
5
|
50
|
33
|
|
|
26
|
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
|
|
|
|
|
13
|
$s->{data}{$input_type} = $key_codes[0]; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
21
|
$s->{code_set} = 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add_any { |
53
|
1
|
|
|
1
|
1
|
343
|
my $s = shift; |
54
|
1
|
50
|
|
|
|
5
|
croak 'You must pass a value' if !$_[0]; |
55
|
1
|
|
|
|
|
3
|
$s->add_key_code(@_, 'any'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_optional_modifiers { |
59
|
1
|
|
|
1
|
1
|
778
|
my $s = shift; |
60
|
1
|
|
|
|
|
4
|
$s->_add_modifiers('optional', @_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_mandatory_modifiers { |
64
|
2
|
|
|
2
|
1
|
649
|
my $s = shift; |
65
|
2
|
|
|
|
|
6
|
$s->_add_modifiers('mandatory', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _add_modifiers { |
69
|
3
|
|
|
3
|
|
5
|
my $s = shift; |
70
|
3
|
|
|
|
|
6
|
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
|
|
|
|
|
8
|
$s->{data}{modifiers}{$mod_type} = \@_; |
75
|
2
|
|
|
|
|
9
|
$s->{"has_${mod_type}_modifiers"} = 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add_simultaneous { |
79
|
2
|
|
|
2
|
0
|
1097
|
my $s = shift; |
80
|
2
|
|
|
|
|
7
|
my @keys = @_; |
81
|
2
|
50
|
|
|
|
20
|
my $key_type = shift @keys if $keys[0] =~ /key_code|pointing|any/i; |
82
|
2
|
|
|
|
|
5
|
my @hashes; |
83
|
2
|
100
|
|
|
|
7
|
if (defined $s->{data}{simultaneous}) { |
84
|
1
|
|
|
|
|
2
|
@hashes = @{$s->{data}{simultaneous}}; |
|
1
|
|
|
|
|
4
|
|
85
|
|
|
|
|
|
|
} |
86
|
2
|
|
|
|
|
6
|
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 object definition |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |