ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MPV/MPV.pm
(Generate patch)

Comparing AnyEvent-MPV/MPV.pm (file contents):
Revision 1.2 by root, Sun Mar 19 20:30:48 2023 UTC vs.
Revision 1.4 by root, Sun Mar 19 20:56:59 2023 UTC

51} 51}
52 52
53sub start { 53sub 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
105 105
106 if (exists $reply->{event}) { 106 if (exists $reply->{event}) {
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 and $reply->{args}[1] eq "keyhack"
111 ) { 110 ) {
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);
114 }
113 } else { 115 } else {
114 $self->on_event ($reply->{event}); 116 $self->on_event ($reply);
115 } 117 }
116 } elsif (exists $reply->{request_id}) { 118 } elsif (exists $reply->{request_id}) {
117 my $cv = delete $self->{cmd_cv}{$reply->{request_id}}; 119 my $cv = delete $self->{cmd_cv}{$reply->{request_id}};
118 120
119 unless ($cv) { 121 unless ($cv) {
153 my $len = syswrite $fh, $wbuf; 155 my $len = syswrite $fh, $wbuf;
154 substr $wbuf, 0, $len, ""; 156 substr $wbuf, 0, $len, "";
155 undef $self->{ww} unless length $wbuf; 157 undef $self->{ww} unless length $wbuf;
156 }; 158 };
157 }; 159 };
160
161 1
158} 162}
159 163
160sub on_eof { 164sub on_eof {
161 my ($self) = @_; 165 my ($self) = @_;
162 166
189 $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
190 194
191 $self->{_send}($cmd); 195 $self->{_send}($cmd);
192 196
193 $cv 197 $cv
198}
199
200sub cmd_recv {
201 &cmd->recv
202}
203
204sub 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");
194} 209}
195 210
196sub stop { 211sub stop {
197 my ($self) = @_; 212 my ($self) = @_;
198 213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines