… | |
… | |
445 | sub verbose { |
445 | sub verbose { |
446 | my ($level, $msg) = @_; |
446 | my ($level, $msg) = @_; |
447 | warn "$msg\n" if $level <= $verbosity; |
447 | warn "$msg\n" if $level <= $verbosity; |
448 | } |
448 | } |
449 | |
449 | |
450 | # find on_xxx subs in the package and register them |
|
|
451 | # as hooks |
|
|
452 | sub register_package($) { |
|
|
453 | my ($pkg) = @_; |
|
|
454 | |
|
|
455 | for my $htype (0.. $#HOOKNAME) { |
|
|
456 | my $name = $HOOKNAME[$htype]; |
|
|
457 | |
|
|
458 | my $ref = $pkg->can ("on_" . lc $name) |
|
|
459 | or next; |
|
|
460 | |
|
|
461 | $TERM->{_hook}[$htype]{$pkg} = $ref; |
|
|
462 | $hook_count[$htype]++ |
|
|
463 | or set_should_invoke $htype, 1; |
|
|
464 | } |
|
|
465 | } |
|
|
466 | |
|
|
467 | my $extension_pkg = "extension0000"; |
450 | my $extension_pkg = "extension0000"; |
468 | my %extension_pkg; |
451 | my %extension_pkg; |
469 | |
452 | |
470 | # load a single script into its own package, once only |
453 | # load a single script into its own package, once only |
471 | sub extension_package($) { |
454 | sub extension_package($) { |
… | |
… | |
499 | my $htype = shift; |
482 | my $htype = shift; |
500 | |
483 | |
501 | if ($htype == 0) { # INIT |
484 | if ($htype == 0) { # INIT |
502 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
485 | my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); |
503 | |
486 | |
504 | my %want_ext; |
487 | my %ext_arg; |
505 | |
488 | |
506 | for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { |
489 | for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { |
507 | if ($_ eq "default") { |
490 | if ($_ eq "default") { |
508 | $want_ext{$_}++ for qw(selection option-popup selection-popup); |
491 | $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup); |
509 | } elsif (/^-(.*)$/) { |
492 | } elsif (/^-(.*)$/) { |
510 | delete $want_ext{$1}; |
493 | delete $ext_arg{$1}; |
|
|
494 | } elsif (/^([^<]+)<(.*)>$/) { |
|
|
495 | push @{ $ext_arg{$1} }, $2; |
511 | } else { |
496 | } else { |
512 | $want_ext{$_}++; |
497 | $ext_arg{$_} ||= []; |
513 | } |
498 | } |
514 | } |
499 | } |
515 | |
500 | |
516 | for my $ext (keys %want_ext) { |
501 | while (my ($ext, $argv) = each %ext_arg) { |
517 | my @files = grep -f $_, map "$_/$ext", @dirs; |
502 | my @files = grep -f $_, map "$_/$ext", @dirs; |
518 | |
503 | |
519 | if (@files) { |
504 | if (@files) { |
520 | register_package extension_package $files[0]; |
505 | $TERM->register_package (extension_package $files[0], $argv); |
521 | } else { |
506 | } else { |
522 | warn "perl extension '$ext' not found in perl library search path\n"; |
507 | warn "perl extension '$ext' not found in perl library search path\n"; |
523 | } |
508 | } |
524 | } |
509 | } |
525 | |
510 | |
… | |
… | |
534 | if $verbosity >= 10; |
519 | if $verbosity >= 10; |
535 | |
520 | |
536 | keys %$cb; |
521 | keys %$cb; |
537 | |
522 | |
538 | while (my ($pkg, $cb) = each %$cb) { |
523 | while (my ($pkg, $cb) = each %$cb) { |
539 | eval { |
524 | $retval = eval { $cb->($TERM->{_pkg}{$pkg}, @_) } |
540 | $retval = $cb->( |
|
|
541 | $TERM->{_pkg}{$pkg} ||= do { |
|
|
542 | my $proxy = bless { }, $pkg; |
|
|
543 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
544 | $proxy |
|
|
545 | }, |
|
|
546 | @_, |
|
|
547 | ) and last; |
525 | and last; |
548 | }; |
526 | |
549 | if ($@) { |
527 | if ($@) { |
550 | $TERM->ungrab; # better to lose the grab than the session |
528 | $TERM->ungrab; # better to lose the grab than the session |
551 | warn $@; |
529 | warn $@; |
552 | } |
530 | } |
553 | } |
531 | } |
… | |
… | |
674 | package urxvt::term; |
652 | package urxvt::term; |
675 | |
653 | |
676 | =head2 The C<urxvt::term> Class |
654 | =head2 The C<urxvt::term> Class |
677 | |
655 | |
678 | =over 4 |
656 | =over 4 |
|
|
657 | |
|
|
658 | =cut |
|
|
659 | |
|
|
660 | # find on_xxx subs in the package and register them |
|
|
661 | # as hooks |
|
|
662 | sub register_package { |
|
|
663 | my ($self, $pkg, $argv) = @_; |
|
|
664 | |
|
|
665 | my $proxy = bless { argv => $argv }, $pkg; |
|
|
666 | Scalar::Util::weaken ($proxy->{term} = $TERM); |
|
|
667 | |
|
|
668 | $self->{_pkg}{$pkg} = $proxy; |
|
|
669 | |
|
|
670 | for my $htype (0.. $#HOOKNAME) { |
|
|
671 | my $name = $HOOKNAME[$htype]; |
|
|
672 | |
|
|
673 | my $ref = $pkg->can ("on_" . lc $name) |
|
|
674 | or next; |
|
|
675 | |
|
|
676 | $self->{_hook}[$htype]{$pkg} = $ref; |
|
|
677 | $hook_count[$htype]++ |
|
|
678 | or urxvt::set_should_invoke $htype, 1; |
|
|
679 | } |
|
|
680 | } |
679 | |
681 | |
680 | =item $term->destroy |
682 | =item $term->destroy |
681 | |
683 | |
682 | Destroy the terminal object (close the window, free resources etc.). |
684 | Destroy the terminal object (close the window, free resources etc.). |
683 | |
685 | |
… | |
… | |
917 | |
919 | |
918 | =item $lines_in_scrollback = $term->nsaved |
920 | =item $lines_in_scrollback = $term->nsaved |
919 | |
921 | |
920 | Return various integers describing terminal characteristics. |
922 | Return various integers describing terminal characteristics. |
921 | |
923 | |
|
|
924 | =item $lc_ctype = $term->locale |
|
|
925 | |
|
|
926 | Returns the LC_CTYPE category string used by this rxvt-unicode. |
|
|
927 | |
|
|
928 | =item $x_display = $term->display_id |
|
|
929 | |
|
|
930 | Return the DISPLAY used by rxvt-unicode. |
|
|
931 | |
922 | =item $modifiermask = $term->ModLevel3Mask |
932 | =item $modifiermask = $term->ModLevel3Mask |
923 | |
933 | |
924 | =item $modifiermask = $term->ModMetaMask |
934 | =item $modifiermask = $term->ModMetaMask |
925 | |
935 | |
926 | =item $modifiermask = $term->ModNumLockMask |
936 | =item $modifiermask = $term->ModNumLockMask |
… | |
… | |
1115 | Converts rxvt-unicodes text reprsentation into a perl string. See |
1125 | Converts rxvt-unicodes text reprsentation into a perl string. See |
1116 | C<< $term->ROW_t >> for details. |
1126 | C<< $term->ROW_t >> for details. |
1117 | |
1127 | |
1118 | =item $success = $term->grab_button ($button, $modifiermask) |
1128 | =item $success = $term->grab_button ($button, $modifiermask) |
1119 | |
1129 | |
1120 | Registers a synchronous button grab. See XGrabButton. |
1130 | Registers a synchronous button grab. See the XGrabButton manpage. |
1121 | |
1131 | |
1122 | =item $success = $term->grab ($eventtime[, $sync]) |
1132 | =item $success = $term->grab ($eventtime[, $sync]) |
1123 | |
1133 | |
1124 | Calls XGrabPointer and XGrabKeyboard in asynchronous (default) or |
1134 | Calls XGrabPointer and XGrabKeyboard in asynchronous (default) or |
1125 | synchronous (C<$sync> is true). Also remembers the grab timestampe. |
1135 | synchronous (C<$sync> is true). Also remembers the grab timestampe. |
… | |
… | |
1168 | } |
1178 | } |
1169 | |
1179 | |
1170 | sub add_separator { |
1180 | sub add_separator { |
1171 | my ($self, $sep) = @_; |
1181 | my ($self, $sep) = @_; |
1172 | |
1182 | |
1173 | $sep ||= "═"; |
1183 | $sep ||= "="; |
1174 | |
1184 | |
1175 | $self->add_item ({ |
1185 | $self->add_item ({ |
1176 | rend => { normal => "\x1b[0;30;47m", hover => "\x1b[0;30;47m", active => "\x1b[0;30;47m" }, |
1186 | rend => { normal => "\x1b[0;30;47m", hover => "\x1b[0;30;47m", active => "\x1b[0;30;47m" }, |
1177 | text => "", |
1187 | text => "", |
1178 | render => sub { $sep x $urxvt::TERM->ncol }, |
1188 | render => sub { $sep x $self->{term}->ncol }, |
1179 | activate => sub { }, |
1189 | activate => sub { }, |
1180 | }); |
1190 | }); |
1181 | } |
1191 | } |
1182 | |
1192 | |
1183 | sub add_title { |
1193 | sub add_title { |
… | |
… | |
1191 | } |
1201 | } |
1192 | |
1202 | |
1193 | sub add_button { |
1203 | sub add_button { |
1194 | my ($self, $text, $cb) = @_; |
1204 | my ($self, $text, $cb) = @_; |
1195 | |
1205 | |
1196 | $self->add_item ({ type => "button", text => "[ $text ]", activate => $cb}); |
1206 | $self->add_item ({ type => "button", text => $text, activate => $cb}); |
1197 | } |
1207 | } |
1198 | |
1208 | |
1199 | sub add_toggle { |
1209 | sub add_toggle { |
1200 | my ($self, $text, $cb, $value) = @_; |
1210 | my ($self, $text, $cb, $value) = @_; |
1201 | |
1211 | |
… | |
… | |
1212 | |
1222 | |
1213 | sub show { |
1223 | sub show { |
1214 | my ($self) = @_; |
1224 | my ($self) = @_; |
1215 | |
1225 | |
1216 | local $urxvt::popup::self = $self; |
1226 | local $urxvt::popup::self = $self; |
|
|
1227 | |
|
|
1228 | local $ENV{LC_ALL} = $self->{term}->locale; |
1217 | |
1229 | |
1218 | urxvt->new ("--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, |
1230 | urxvt->new ("--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, |
1219 | "--transient-for" => $self->{term}->parent, |
1231 | "--transient-for" => $self->{term}->parent, |
1220 | "-display" => $self->{term}->display_id, |
1232 | "-display" => $self->{term}->display_id, |
1221 | "-pe" => "urxvt-popup") |
1233 | "-pe" => "urxvt-popup") |