| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
sub refresh { |
| 4 |
|
|
my ($self) = @_; |
| 5 |
|
|
|
| 6 |
|
|
my $cmd = "\x1b[H\x1b[7m\x1b[K"; |
| 7 |
|
|
my $txt; |
| 8 |
|
|
my @ofs = (0); |
| 9 |
|
|
|
| 10 |
|
|
for my $tab (@{ $self->{tabs} }) { |
| 11 |
|
|
if ($tab == $self->{cur}) { |
| 12 |
|
|
$txt = " [$tab->{name}] "; |
| 13 |
|
|
} else { |
| 14 |
|
|
$txt = " $tab->{name} "; |
| 15 |
|
|
} |
| 16 |
|
|
|
| 17 |
|
|
$cmd .= $txt; |
| 18 |
|
|
push @ofs, $ofs[-1] + length $txt; |
| 19 |
|
|
} |
| 20 |
|
|
|
| 21 |
|
|
$self->{tabofs} = \@ofs; |
| 22 |
|
|
|
| 23 |
|
|
$self->cmd_parse ($self->locale_encode ($cmd)); |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
|
|
sub new_tab { |
| 27 |
|
|
my ($self) = @_; |
| 28 |
|
|
|
| 29 |
|
|
my $offset = $self->fheight; |
| 30 |
|
|
|
| 31 |
|
|
# save a backlink to us, make sure tabbed is inactive |
| 32 |
|
|
push @urxvt::TERM_INIT, sub { |
| 33 |
|
|
my ($term) = @_; |
| 34 |
|
|
$term->{parent} = $self; |
| 35 |
|
|
|
| 36 |
|
|
$term->resource ($_->[0] => $_->[1]) |
| 37 |
|
|
for @{ $self->{resource} || [] }; |
| 38 |
|
|
|
| 39 |
|
|
$term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
| 40 |
|
|
|
| 41 |
|
|
}; |
| 42 |
|
|
|
| 43 |
|
|
push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
| 44 |
|
|
|
| 45 |
|
|
my $term = new urxvt::term |
| 46 |
|
|
$self->env, $urxvt::RXVTNAME, |
| 47 |
|
|
-embed => $self->parent, |
| 48 |
|
|
; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
sub configure { |
| 52 |
|
|
my ($self) = @_; |
| 53 |
|
|
|
| 54 |
|
|
$self->{cur}->XMoveResizeWindow ( |
| 55 |
|
|
$self->{cur}->parent, |
| 56 |
root |
1.4 |
0, $self->{tabheight}, |
| 57 |
|
|
$self->width, $self->height - $self->{tabheight} |
| 58 |
root |
1.1 |
); |
| 59 |
|
|
} |
| 60 |
|
|
|
| 61 |
|
|
sub make_current { |
| 62 |
|
|
my ($self, $tab) = @_; |
| 63 |
|
|
|
| 64 |
|
|
if (my $cur = $self->{cur}) { |
| 65 |
|
|
$cur->XUnmapWindow ($cur->parent) |
| 66 |
|
|
if $cur->mapped; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
$self->{cur} = $tab; |
| 70 |
|
|
|
| 71 |
|
|
$self->configure; |
| 72 |
|
|
|
| 73 |
root |
1.4 |
my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
| 74 |
|
|
|
| 75 |
root |
1.3 |
for my $atom ($tab->XListProperties ($tab->parent)) { |
| 76 |
root |
1.4 |
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
| 77 |
|
|
|
| 78 |
|
|
if ($atom == $wm_normal_hints) { |
| 79 |
|
|
my (@hints) = unpack "l!*", $items; |
| 80 |
|
|
$hints[ 4] += $self->{tabheight}; |
| 81 |
|
|
$hints[16] += $self->{tabheight}; |
| 82 |
|
|
$items = pack "l!*", @hints; |
| 83 |
|
|
} |
| 84 |
|
|
$self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
| 85 |
root |
1.2 |
} |
| 86 |
|
|
|
| 87 |
root |
1.1 |
$tab->XMapWindow ($tab->parent); |
| 88 |
|
|
|
| 89 |
|
|
$self->refresh; |
| 90 |
|
|
|
| 91 |
|
|
() |
| 92 |
|
|
} |
| 93 |
|
|
|
| 94 |
|
|
sub on_button_press { |
| 95 |
|
|
1 |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
sub on_button_release { |
| 99 |
|
|
my ($self, $event) = @_; |
| 100 |
|
|
|
| 101 |
|
|
my $ofs = $self->{tabofs}; |
| 102 |
|
|
|
| 103 |
|
|
if ($event->{row} == 0) { |
| 104 |
|
|
for my $i (0 .. @$ofs - 2) { |
| 105 |
|
|
if ($event->{col} >= $ofs->[$i] |
| 106 |
|
|
&& $event->{col} < $ofs->[$i+1]) { |
| 107 |
|
|
$self->make_current ($self->{tabs}[$i]); |
| 108 |
|
|
} |
| 109 |
|
|
} |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
1 |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
sub on_motion_notify { |
| 116 |
|
|
1 |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
sub on_init { |
| 120 |
|
|
my ($self) = @_; |
| 121 |
|
|
|
| 122 |
|
|
for (qw(name perl_ext_1 perl_ext_2)) { |
| 123 |
|
|
my $val = $self->resource ($_); |
| 124 |
|
|
|
| 125 |
|
|
push @{ $self->{resource} }, [$_ => $val] |
| 126 |
|
|
if defined $val; |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
$self->resource (int_bwidth => 0); |
| 130 |
|
|
$self->resource (name => "URxvt.tab"); |
| 131 |
|
|
$self->resource (pty_fd => -1); |
| 132 |
|
|
|
| 133 |
|
|
$self->option ($urxvt::OPTION{scrollBar}, 0); |
| 134 |
|
|
|
| 135 |
|
|
() |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
sub on_start { |
| 139 |
|
|
my ($self) = @_; |
| 140 |
|
|
|
| 141 |
root |
1.4 |
$self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
| 142 |
|
|
|
| 143 |
root |
1.1 |
$self->cmd_parse ("\x1b[?25l\x1b[?7l"); |
| 144 |
|
|
$self->new_tab; |
| 145 |
|
|
$self->new_tab; |
| 146 |
|
|
$self->new_tab; |
| 147 |
|
|
|
| 148 |
|
|
() |
| 149 |
|
|
} |
| 150 |
|
|
|
| 151 |
|
|
sub on_configure_notify { |
| 152 |
|
|
my ($self, $event) = @_; |
| 153 |
|
|
|
| 154 |
|
|
$self->configure; |
| 155 |
|
|
|
| 156 |
|
|
() |
| 157 |
|
|
} |
| 158 |
|
|
|
| 159 |
|
|
sub on_wm_delete_window { |
| 160 |
|
|
my ($self) = @_; |
| 161 |
|
|
|
| 162 |
|
|
$_->destroy for @{ $self->{tabs} }; |
| 163 |
|
|
|
| 164 |
|
|
1 |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
|
|
sub tab_start { |
| 168 |
|
|
my ($self, $tab) = @_; |
| 169 |
|
|
|
| 170 |
|
|
push @{ $self->{tabs} }, $tab; |
| 171 |
|
|
|
| 172 |
|
|
$tab->{name} ||= scalar @{ $self->{tabs} }; |
| 173 |
|
|
$self->make_current ($tab); |
| 174 |
|
|
|
| 175 |
|
|
() |
| 176 |
|
|
} |
| 177 |
|
|
|
| 178 |
|
|
sub tab_destroy { |
| 179 |
|
|
my ($self, $tab) = @_; |
| 180 |
|
|
|
| 181 |
|
|
$self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ]; |
| 182 |
|
|
|
| 183 |
|
|
if (@{ $self->{tabs} }) { |
| 184 |
|
|
if ($self->{cur} == $tab) { |
| 185 |
|
|
delete $self->{cur}; |
| 186 |
|
|
$self->make_current ($self->{tabs}[-1]); |
| 187 |
|
|
} |
| 188 |
|
|
} else { |
| 189 |
|
|
# delay destruction a tiny bit |
| 190 |
|
|
$self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
() |
| 194 |
|
|
} |
| 195 |
|
|
|
| 196 |
|
|
package urxvt::ext::tabbed::tab; |
| 197 |
|
|
|
| 198 |
|
|
# helper extension implementing the subwindows of a tabbed terminal. |
| 199 |
|
|
# simply proxies all interesting calls back to the tabbed class. |
| 200 |
|
|
|
| 201 |
|
|
{ |
| 202 |
|
|
for my $hook qw(start destroy) { |
| 203 |
|
|
eval qq{ |
| 204 |
|
|
sub on_$hook { |
| 205 |
|
|
my \$parent = \$_[0]{term}{parent} |
| 206 |
|
|
or return; |
| 207 |
|
|
\$parent->tab_$hook (\@_) |
| 208 |
|
|
} |
| 209 |
|
|
}; |
| 210 |
|
|
die if $@; |
| 211 |
|
|
} |
| 212 |
|
|
} |
| 213 |
|
|
|
| 214 |
|
|
|
| 215 |
|
|
|