Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Perl by mydoom ( 16 years ago )
#! perl
sub refresh {
my ($self) = @_;
my $ncol = $self->ncol;
my $text = " " x $ncol;
my $rend = [($self->{rs_tabbar}) x $ncol];
my @ofs;
substr $text, 0, 4, "[+] ";
@$rend[0 .. 2] = ($self->{rs_tab}) x 3;
push @ofs, [0, 3, sub { $_[0]->new_tab }];
my $ofs = 4;
my $idx = 0;
for my $tab (@{ $self->{tabs} }) {
$idx++;
my $act = $tab->{activity} && $tab != $self->{cur}
? "*" : " ";
my $txt = "$act$idx";
my $len = length $txt;
substr $text, $ofs, $len + 1, "$txt";
@$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len
if $tab == $self->{cur};
push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
$ofs += $len + 1;
}
$self->{tabofs} = @ofs;
$self->ROW_t (0, $text, 0, 0, $ncol);
$self->ROW_r (0, $rend, 0, 0, $ncol);
$self->want_refresh;
}
sub new_tab {
my ($self, @argv) = @_;
my $offset = $self->fheight;
# save a backlink to us, make sure tabbed is inactive
push @urxvt::TERM_INIT, sub {
my ($term) = @_;
$term->{parent} = $self;
for (0 .. urxvt::NUM_RESOURCES - 1) {
my $value = $self->{resource}[$_];
$term->resource ("+$_" => $value)
if defined $value;
}
$term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
};
push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
my $term = new urxvt::term
$self->env, $urxvt::RXVTNAME,
-embed => $self->parent,
@argv,
;
}
sub configure {
my ($self) = @_;
my $tab = $self->{cur};
# this is an extremely dirty way to force a configurenotify, but who cares
$tab->XMoveResizeWindow (
$tab->parent,
0, $self->{tabheight} + 1,
$self->width, $self->height - $self->{tabheight}
);
$tab->XMoveResizeWindow (
$tab->parent,
0, $self->{tabheight},
$self->width, $self->height - $self->{tabheight}
);
}
sub on_resize_all_windows {
my ($self, $width, $height) = @_;
1
}
sub copy_properties {
my ($self) = @_;
my $tab = $self->{cur};
my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
my $current = delete $self->{current_properties};
# pass 1: copy over properties different or nonexisting
for my $atom ($tab->XListProperties ($tab->parent)) {
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
# fix up size hints
if ($atom == $wm_normal_hints) {
my (@hints) = unpack "l!*", $items;
$hints[$_] += $self->{tabheight} for (4, 6, 16);
$items = pack "l!*", @hints;
}
my $cur = delete $current->{$atom};
# update if changed, we assume empty items and zero type and format will not happen
$self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
$self->{current_properties}{$atom} = [$type, $format, $items];
}
# pass 2, delete all extraneous properties
$self->XDeleteProperty ($self->parent, $_) for keys %$current;
}
sub make_current {
my ($self, $tab) = @_;
if (my $cur = $self->{cur}) {
delete $cur->{activity};
$cur->XUnmapWindow ($cur->parent) if $cur->mapped;
$cur->focus_out;
}
$self->{cur} = $tab;
$self->configure;
$self->copy_properties;
$tab->focus_out; # just in case, should be a nop
$tab->focus_in if $self->focus;
$tab->XMapWindow ($tab->parent);
delete $tab->{activity};
$self->refresh;
()
}
sub on_focus_in {
my ($self, $event) = @_;
$self->{cur}->focus_in;
()
}
sub on_focus_out {
my ($self, $event) = @_;
$self->{cur}->focus_out;
()
}
sub on_key_press {
my ($self, $event) = @_;
$self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time});
1
}
sub on_key_release {
my ($self, $event) = @_;
$self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time});
1
}
sub on_button_press {
1
}
sub on_button_release {
my ($self, $event) = @_;
if ($event->{row} == 0) {
for my $button (@{ $self->{tabofs} }) {
$button->[2]->($self, $event)
if $event->{col} >= $button->[0]
&& $event->{col} < $button->[1];
}
}
1
}
sub on_motion_notify {
1
}
sub on_init {
my ($self) = @_;
$self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
$self->resource (int_bwidth => 0);
$self->resource (name => "URxvt.tabbed");
$self->resource (pty_fd => -1);
$self->option ($urxvt::OPTION{scrollBar}, 0);
my $fg = $self->x_resource ("tabbar-fg");
my $bg = $self->x_resource ("tabbar-bg");
my $tabfg = $self->x_resource ("tab-fg");
my $tabbg = $self->x_resource ("tab-bg");
defined $fg or $fg = 6;
defined $bg or $bg = 0;
defined $tabfg or $tabfg = 7;
defined $tabbg or $tabbg = 0;
$self->{rs_tabbar} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $fg + 2, $bg + 2);
$self->{rs_tab} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $tabfg + 2, $tabbg + 2);
()
}
sub on_start {
my ($self) = @_;
$self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
$self->cmd_parse ("