--- rxvt-unicode/src/perl/tabbed 2008/02/08 13:18:02 1.22 +++ rxvt-unicode/src/perl/tabbed 2014/05/17 13:38:23 1.37 @@ -1,5 +1,41 @@ #! perl +#:META:RESOURCE:tabbar-fg:colour:tab bar foreground colour +#:META:RESOURCE:tabbar-bg:colour:tab bar background colour +#:META:RESOURCE:tab-fg:colour:tab foreground colour +#:META:RESOURCE:tab-bg:colour:tab background colour + +=head1 NAME + +tabbed - tabbed interface to urxvt + +=head1 DESCRIPTION + +This transforms the terminal into a tabbar with additional terminals, that +is, it implements what is commonly referred to as "tabbed terminal". The topmost line +displays a "[NEW]" button, which, when clicked, will add a new tab, followed by one +button per tab. + +Clicking a button will activate that tab. Pressing B and +B will switch to the tab left or right of the current one, +while B creates a new tab. Pressing B and +B will renumber the current tab by moving it to the left or +to the right. + +The tabbar itself can be configured similarly to a normal terminal, but +with a resource class of C. In addition, it supports the +following four resources (shown with defaults): + + URxvt.tabbed.tabbar-fg: + URxvt.tabbed.tabbar-bg: + URxvt.tabbed.tab-fg: + URxvt.tabbed.tab-bg: + +See I in the @@RXVT_NAME@@(1) manpage for valid +indices. + +=cut + sub refresh { my ($self) = @_; @@ -46,18 +82,19 @@ 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; - $term->resource ($_->[0] => $_->[1]) - for @{ $self->{resource} || [] }; + 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::; @@ -99,33 +136,32 @@ my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); - my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); - - delete $our_props{$self->XInternAtom ($_)} - for qw(WM_STATE WM_ICON_SIZE - _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS); + 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); - - delete $our_props{$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 ($dtype, $dformat, $ditems) = $self->XGetWindowProperty ($self->parent, $atom); + my $cur = delete $current->{$atom}; - if ($dtype != $type or $dformat != $format or $ditems ne $items) { - $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); - } + # 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]; } - $self->XDeleteProperty ($self->parent, $_) for keys %our_props; + # pass 2, delete all extraneous properties + $self->XDeleteProperty ($self->parent, $_) for keys %$current; } sub make_current { @@ -136,15 +172,15 @@ $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; @@ -168,6 +204,14 @@ () } +sub on_tt_write { + my ($self, $octets) = @_; + + $self->{cur}->tt_write ($octets); + + 1 +} + sub on_key_press { my ($self, $event) = @_; @@ -209,12 +253,7 @@ sub on_init { my ($self) = @_; - for (qw(name perl_ext_1 perl_ext_2)) { - my $val = $self->resource ($_); - - push @{ $self->{resource} }, [$_ => $val] - if defined $val; - } + $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1]; $self->resource (int_bwidth => 0); $self->resource (name => "URxvt.tabbed"); @@ -317,7 +356,7 @@ ++$idx if $keysym == 0xff53; $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); - + return 1; } elsif ($keysym == 0xff54) { $self->new_tab; @@ -363,7 +402,7 @@ # simply proxies all interesting calls back to the tabbed class. { - for my $hook qw(start destroy key_press property_notify) { + for my $hook (qw(start destroy key_press property_notify)) { eval qq{ sub on_$hook { my \$parent = \$_[0]{term}{parent}