… | |
… | |
51 | } |
51 | } |
52 | |
52 | |
53 | sub start { |
53 | sub start { |
54 | my ($self, @extra_args) = @_; |
54 | my ($self, @extra_args) = @_; |
55 | |
55 | |
56 | return if $self->{fh}; |
56 | return 0 if $self->{fh}; |
57 | |
57 | |
58 | # cache optionlist for same "path" |
58 | # cache optionlist for same "path" |
59 | ($mpv_path, $mpv_optionlist) = ($self->{mpv}, scalar qx{\Q$self->{mpv}\E --list-options}) |
59 | ($mpv_path, $mpv_optionlist) = ($self->{mpv}, scalar qx{\Q$self->{mpv}\E --list-options}) |
60 | if $self->{mpv} ne $mpv_path; |
60 | if $self->{mpv} ne $mpv_path; |
61 | |
61 | |
… | |
… | |
107 | if ( |
107 | if ( |
108 | $reply->{event} eq "client-message" |
108 | $reply->{event} eq "client-message" |
109 | and $reply->{args}[0] eq "AnyEvent::MPV" |
109 | and $reply->{args}[0] eq "AnyEvent::MPV" |
110 | ) { |
110 | ) { |
111 | if ($reply->{args}[1] eq "key") { |
111 | if ($reply->{args}[1] eq "key") { |
|
|
112 | (my $key = $reply->{args}[2]) =~ s/\\x(..)/chr hex $1/ge; |
112 | $self->on_key ($reply->{args}[2]); |
113 | $self->on_key ($key); |
113 | } |
114 | } |
114 | } else { |
115 | } else { |
115 | $self->on_event ($reply); |
116 | $self->on_event ($reply); |
116 | } |
117 | } |
117 | } elsif (exists $reply->{request_id}) { |
118 | } elsif (exists $reply->{request_id}) { |
… | |
… | |
154 | my $len = syswrite $fh, $wbuf; |
155 | my $len = syswrite $fh, $wbuf; |
155 | substr $wbuf, 0, $len, ""; |
156 | substr $wbuf, 0, $len, ""; |
156 | undef $self->{ww} unless length $wbuf; |
157 | undef $self->{ww} unless length $wbuf; |
157 | }; |
158 | }; |
158 | }; |
159 | }; |
|
|
160 | |
|
|
161 | 1 |
159 | } |
162 | } |
160 | |
163 | |
161 | sub on_eof { |
164 | sub on_eof { |
162 | my ($self) = @_; |
165 | my ($self) = @_; |
163 | |
166 | |
… | |
… | |
190 | $cmd =~ s/\xf4\x8e\x97\x9f(..)/sprintf sprintf "\\x%02x", hex $1/ges; # f48e979f == 10e5df in utf-8 |
193 | $cmd =~ s/\xf4\x8e\x97\x9f(..)/sprintf sprintf "\\x%02x", hex $1/ges; # f48e979f == 10e5df in utf-8 |
191 | |
194 | |
192 | $self->{_send}($cmd); |
195 | $self->{_send}($cmd); |
193 | |
196 | |
194 | $cv |
197 | $cv |
|
|
198 | } |
|
|
199 | |
|
|
200 | sub cmd_recv { |
|
|
201 | &cmd->recv |
|
|
202 | } |
|
|
203 | |
|
|
204 | sub bind_key { |
|
|
205 | my ($self, $key, $event) = @_; |
|
|
206 | |
|
|
207 | $event =~ s/([^A-Za-z0-9\-_])/sprintf "\\x%02x", ord $1/ge; |
|
|
208 | $self->cmd (keybind => $key => "no-osd script-message AnyEvent::MPV key $event"); |
195 | } |
209 | } |
196 | |
210 | |
197 | sub stop { |
211 | sub stop { |
198 | my ($self) = @_; |
212 | my ($self) = @_; |
199 | |
213 | |