line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Karabiner::Manipulator::Actions::To ; |
2
|
|
|
|
|
|
|
$JSON::Karabiner::Manipulator::Actions::To::VERSION = '0.016'; |
3
|
11
|
|
|
11
|
|
3188
|
use strict; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
329
|
|
4
|
11
|
|
|
11
|
|
55
|
use warnings; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
253
|
|
5
|
11
|
|
|
11
|
|
56
|
use JSON; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
63
|
|
6
|
11
|
|
|
11
|
|
1180
|
use Carp; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
636
|
|
7
|
11
|
|
|
11
|
|
1543
|
use parent 'JSON::Karabiner::Manipulator::Actions'; |
|
11
|
|
|
|
|
985
|
|
|
11
|
|
|
|
|
101
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
20
|
|
|
20
|
1
|
43
|
my $class = shift; |
11
|
20
|
|
|
|
|
49
|
my ($type, $value) = @_; |
12
|
20
|
|
|
|
|
103
|
my $obj = $class->SUPER::new($type, $value); |
13
|
|
|
|
|
|
|
$obj->{data} = $value || [], |
14
|
|
|
|
|
|
|
$obj->{shell_command} => 0, |
15
|
|
|
|
|
|
|
$obj->{select_input_source} => 0, |
16
|
|
|
|
|
|
|
$obj->{select_input_source_data} => '', |
17
|
|
|
|
|
|
|
$obj->{set_variable} => 0, |
18
|
20
|
|
50
|
|
|
192
|
$obj->{mouse_key} => 0, |
19
|
|
|
|
|
|
|
return $obj; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add_key_code { |
23
|
78
|
|
|
78
|
1
|
20855
|
my $s = shift; |
24
|
78
|
|
|
|
|
134
|
my @key_codes; |
25
|
78
|
50
|
|
|
|
243
|
if (ref $s) { |
26
|
78
|
|
|
|
|
180
|
@key_codes = @_; |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
0
|
@key_codes = ($s, @_); |
29
|
0
|
|
|
|
|
0
|
$s = $main::current_action; |
30
|
|
|
|
|
|
|
} |
31
|
78
|
|
|
|
|
127
|
my $last_arg = $key_codes[-1]; |
32
|
78
|
|
|
|
|
126
|
my $input_type = 'key_code'; |
33
|
78
|
100
|
100
|
|
|
437
|
if ($last_arg && $last_arg =~ /^any|consumer_key_code|pointing_button$/) { |
34
|
12
|
|
|
|
|
28
|
$input_type = $last_arg; |
35
|
12
|
|
|
|
|
20
|
pop @key_codes; |
36
|
|
|
|
|
|
|
} |
37
|
78
|
100
|
|
|
|
327
|
croak 'No key code passed' if !@key_codes; |
38
|
72
|
50
|
|
|
|
179
|
croak 'You can only set one key_code, consumer_key_code, pointing_button or any' if ($s->{code_set}); |
39
|
|
|
|
|
|
|
#TODO: validate $key_code |
40
|
|
|
|
|
|
|
|
41
|
72
|
|
|
|
|
278
|
$s->_is_exclusive($input_type); |
42
|
|
|
|
|
|
|
|
43
|
72
|
|
|
|
|
139
|
foreach my $key_code (@key_codes) { |
44
|
90
|
|
|
|
|
204
|
my %hash; |
45
|
|
|
|
|
|
|
my $letter_code; |
46
|
90
|
|
|
|
|
0
|
my $ms; |
47
|
90
|
100
|
|
|
|
431
|
if ($key_code =~ /-([A-Z])|(\d+)$/) { |
48
|
24
|
|
|
|
|
66
|
$letter_code = $1; |
49
|
24
|
|
|
|
|
56
|
$ms = $2; |
50
|
24
|
|
|
|
|
127
|
$key_code =~ s/-(.*?)$//; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
90
|
|
|
|
|
215
|
$hash{$input_type} = $key_code; |
54
|
90
|
100
|
100
|
|
|
257
|
$hash{lazy} = JSON::true if $letter_code && $letter_code eq 'L'; |
55
|
90
|
100
|
100
|
|
|
261
|
$hash{halt} = JSON::true if $letter_code && $letter_code eq 'H'; |
56
|
90
|
100
|
100
|
|
|
292
|
$hash{repeat} = JSON::true if $letter_code && $letter_code eq 'R'; |
57
|
90
|
100
|
|
|
|
206
|
$hash{hold_down_milliseconds} = $ms if $ms; |
58
|
90
|
|
|
|
|
259
|
$s->_push_data(\%hash); |
59
|
90
|
|
|
|
|
399
|
$s->{last_key_code} = \%hash; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _push_data { |
64
|
120
|
|
|
120
|
|
198
|
my $s = shift; |
65
|
120
|
|
|
|
|
177
|
my $data = shift; |
66
|
120
|
100
|
|
|
|
300
|
if ($s->{def_name} eq 'to_delayed_action') { |
67
|
38
|
100
|
|
|
|
74
|
if ($s->{delayed_type} eq 'invoked') { |
68
|
19
|
|
|
|
|
27
|
push @{$s->{data}{to_if_invoked}}, $data; |
|
19
|
|
|
|
|
69
|
|
69
|
|
|
|
|
|
|
} else { |
70
|
19
|
|
|
|
|
25
|
push @{$s->{data}{to_if_canceled}}, $data; |
|
19
|
|
|
|
|
67
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} else { |
73
|
82
|
|
|
|
|
122
|
push @{$s->{data}}, $data; |
|
82
|
|
|
|
|
260
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub add_shell_command { |
78
|
6
|
|
|
6
|
1
|
207
|
my $s = shift; |
79
|
|
|
|
|
|
|
|
80
|
6
|
|
|
|
|
21
|
$s->_is_exclusive('shell_command'); |
81
|
6
|
|
|
|
|
12
|
my $value = shift; |
82
|
6
|
|
|
|
|
19
|
my %hash; |
83
|
6
|
|
|
|
|
13
|
$hash{shell_command} = $value; |
84
|
6
|
|
|
|
|
18
|
$s->_push_data(\%hash); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub add_select_input_source { |
88
|
12
|
|
|
12
|
1
|
377
|
my $s = shift; |
89
|
12
|
|
|
|
|
47
|
$s->_is_exclusive('select_input_source'); |
90
|
12
|
|
|
|
|
20
|
my $option = shift; |
91
|
12
|
|
|
|
|
20
|
my $value = shift; |
92
|
12
|
50
|
|
|
|
73
|
if ($option !~ /^language|input_source_id|input_mode_id$/) { |
93
|
0
|
|
|
|
|
0
|
croak "Invalid option: $option"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#TODO: determing if key alredy exists |
97
|
|
|
|
|
|
|
# find existing hash ref |
98
|
12
|
|
|
|
|
26
|
my $existing = $s->{select_input_source_data}; |
99
|
12
|
|
50
|
|
|
54
|
my $select_input_source = $existing || { }; |
100
|
|
|
|
|
|
|
|
101
|
12
|
|
|
|
|
38
|
$select_input_source->{$option} = $value; |
102
|
12
|
50
|
|
|
|
49
|
$s->_push_data( { select_input_source => $select_input_source } ) if !$existing; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub add_set_variable { |
106
|
6
|
|
|
6
|
1
|
209
|
my $s = shift; |
107
|
6
|
|
|
|
|
26
|
$s->_is_exclusive('set_variable'); |
108
|
6
|
|
|
|
|
13
|
my $name = shift; |
109
|
6
|
50
|
|
|
|
24
|
croak 'No name passed' unless defined $name; |
110
|
6
|
|
|
|
|
14
|
my $value = shift; |
111
|
6
|
50
|
|
|
|
16
|
croak 'No value passed' unless defined $value; |
112
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
22
|
my %hash; |
114
|
6
|
|
|
|
|
28
|
$hash{set_variable}{name} = $name; |
115
|
6
|
|
|
|
|
16
|
$hash{set_variable}{value} = $value; |
116
|
6
|
|
|
|
|
44
|
$s->_push_data(\%hash); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add_mouse_key { |
120
|
6
|
|
|
6
|
1
|
196
|
my $s = shift; |
121
|
6
|
|
|
|
|
24
|
$s->_is_exclusive('mouse_key'); |
122
|
6
|
|
|
|
|
13
|
my $name = shift; |
123
|
6
|
50
|
|
|
|
18
|
croak 'No name passed' unless $name; |
124
|
6
|
|
|
|
|
22
|
my $value = shift; |
125
|
6
|
50
|
|
|
|
30
|
croak 'No value passed' unless defined $value; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#TODO: make sure $names have not been set already |
128
|
|
|
|
|
|
|
#TODO: make sure names are valid |
129
|
6
|
|
|
|
|
10
|
my %hash; |
130
|
6
|
|
|
|
|
18
|
$hash{mouse_key}{$name} = $value; |
131
|
6
|
|
|
|
|
17
|
$s->_push_data(\%hash); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub add_modifiers { |
135
|
12
|
|
|
12
|
1
|
376
|
my $s = shift; |
136
|
12
|
|
|
|
|
29
|
my $lkc = $s->{last_key_code}; |
137
|
12
|
100
|
|
|
|
111
|
croak 'Nothing to attach the modifiers to' if !$lkc; |
138
|
6
|
|
|
|
|
14
|
my $existing = []; |
139
|
6
|
50
|
|
|
|
27
|
if (exists $lkc->{modifiers} ) { |
140
|
0
|
|
|
|
|
0
|
$existing = $lkc->{modifiers}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#TODO: check that modifiers are valid |
144
|
6
|
|
|
|
|
19
|
my @modifiers = @_; |
145
|
6
|
|
|
|
|
29
|
push @$existing, @modifiers; |
146
|
6
|
|
|
|
|
35
|
$lkc->{modifiers} = $existing; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# ABSTRACT: To action |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |