--- rxvt-unicode/src/perl/tabbed 2006/02/11 02:01:16 1.17 +++ rxvt-unicode/src/perl/tabbed 2012/06/06 15:09:49 1.32 @@ -1,5 +1,10 @@ #! perl +#:META:X_RESOURCE:tabbar-fg:colour:tab bar foreground colour +#:META:X_RESOURCE:tabbar-bg:colour:tab bar background colour +#:META:X_RESOURCE:tab-fg:colour:tab foreground colour +#:META:X_RESOURCE:tab-bg:colour:tab background colour + sub refresh { my ($self) = @_; @@ -44,20 +49,21 @@ } sub new_tab { - my ($self) = @_; - - my $offset = $self->fheight; + my ($self, @argv) = @_; # 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::; @@ -65,6 +71,7 @@ my $term = new urxvt::term $self->env, $urxvt::RXVTNAME, -embed => $self->parent, + @argv, ; } @@ -86,21 +93,25 @@ ); } +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 %our_props = map +($_ => undef), $self->XListProperties ($self->parent); - - delete $our_props{$self->XInternAtom ($_)} for qw(WM_STATE WM_ICON_SIZE); + 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; @@ -108,10 +119,18 @@ $items = pack "l!*", @hints; } - $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); + + 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]; } - $self->XDeleteProperty ($self->parent, $_) for keys %our_props; + # pass 2, delete all extraneous properties + $self->XDeleteProperty ($self->parent, $_) for keys %$current; } sub make_current { @@ -122,12 +141,15 @@ $cur->XUnmapWindow ($cur->parent) if $cur->mapped; $cur->focus_out; } - + $self->{cur} = $tab; $self->configure; $self->copy_properties; - $tab->focus_in; + + $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; @@ -151,6 +173,14 @@ () } +sub on_tt_write { + my ($self, $octets) = @_; + + $self->{cur}->tt_write ($octets); + + 1 +} + sub on_key_press { my ($self, $event) = @_; @@ -192,12 +222,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"); @@ -228,7 +253,13 @@ $self->cmd_parse ("\033[?25l"); - $self->new_tab; + my @argv = $self->argv; + + do { + shift @argv; + } while @argv && $argv[0] ne "-e"; + + $self->new_tab (@argv); () } @@ -294,13 +325,26 @@ ++$idx if $keysym == 0xff53; $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); - + return 1; } elsif ($keysym == 0xff54) { $self->new_tab; return 1; } + } + elsif ($event->{state} & urxvt::ControlMask) { + if ($keysym == 0xff51 || $keysym == 0xff53) { + my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; + my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} }; + + ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) = + ($self->{tabs}[$idx2], $self->{tabs}[$idx1]); + + $self->make_current ($self->{tabs}[$idx2]); + + return 1; + } } ()