1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
sub refresh { |
4 |
|
|
my ($self) = @_; |
5 |
|
|
|
6 |
root |
1.6 |
my $ncol = $self->ncol; |
7 |
|
|
|
8 |
|
|
my $text = " " x $ncol; |
9 |
|
|
my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; |
10 |
|
|
|
11 |
|
|
my @ofs; |
12 |
root |
1.1 |
|
13 |
root |
1.7 |
substr $text, 0, 7, "[NEW] |"; |
14 |
|
|
@$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; |
15 |
|
|
push @ofs, [0, 6, sub { $_[0]->new_tab }]; |
16 |
|
|
|
17 |
|
|
my $ofs = 7; |
18 |
|
|
my $idx = 0; |
19 |
|
|
|
20 |
root |
1.1 |
for my $tab (@{ $self->{tabs} }) { |
21 |
root |
1.7 |
$idx++; |
22 |
|
|
|
23 |
root |
1.9 |
my $act = $tab->{activity} && $tab != $self->{cur} |
24 |
|
|
? "*" : " "; |
25 |
|
|
|
26 |
|
|
my $txt = "$act$idx$act"; |
27 |
root |
1.6 |
my $len = length $txt; |
28 |
|
|
|
29 |
|
|
substr $text, $ofs, $len + 1, "$txt|"; |
30 |
root |
1.7 |
@$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len |
31 |
|
|
if $tab == $self->{cur}; |
32 |
root |
1.6 |
|
33 |
root |
1.7 |
push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; |
34 |
root |
1.1 |
|
35 |
root |
1.6 |
$ofs += $len + 1; |
36 |
root |
1.1 |
} |
37 |
|
|
|
38 |
|
|
$self->{tabofs} = \@ofs; |
39 |
|
|
|
40 |
root |
1.7 |
$self->ROW_t (0, $text, 0, 0, $ncol); |
41 |
|
|
$self->ROW_r (0, $rend, 0, 0, $ncol); |
42 |
|
|
|
43 |
|
|
$self->want_refresh; |
44 |
root |
1.1 |
} |
45 |
|
|
|
46 |
|
|
sub new_tab { |
47 |
|
|
my ($self) = @_; |
48 |
|
|
|
49 |
|
|
my $offset = $self->fheight; |
50 |
|
|
|
51 |
|
|
# save a backlink to us, make sure tabbed is inactive |
52 |
|
|
push @urxvt::TERM_INIT, sub { |
53 |
|
|
my ($term) = @_; |
54 |
|
|
$term->{parent} = $self; |
55 |
|
|
|
56 |
|
|
$term->resource ($_->[0] => $_->[1]) |
57 |
|
|
for @{ $self->{resource} || [] }; |
58 |
|
|
|
59 |
|
|
$term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
60 |
|
|
|
61 |
|
|
}; |
62 |
|
|
|
63 |
|
|
push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
64 |
|
|
|
65 |
|
|
my $term = new urxvt::term |
66 |
|
|
$self->env, $urxvt::RXVTNAME, |
67 |
|
|
-embed => $self->parent, |
68 |
|
|
; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
sub configure { |
72 |
|
|
my ($self) = @_; |
73 |
|
|
|
74 |
root |
1.5 |
my $tab = $self->{cur}; |
75 |
|
|
|
76 |
|
|
$tab->XMoveResizeWindow ( |
77 |
|
|
$tab->parent, |
78 |
root |
1.4 |
0, $self->{tabheight}, |
79 |
|
|
$self->width, $self->height - $self->{tabheight} |
80 |
root |
1.1 |
); |
81 |
root |
1.11 |
} |
82 |
|
|
|
83 |
|
|
sub copy_properties { |
84 |
|
|
my ($self) = @_; |
85 |
|
|
my $tab = $self->{cur}; |
86 |
root |
1.5 |
|
87 |
|
|
my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
88 |
|
|
|
89 |
root |
1.11 |
my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); |
90 |
|
|
|
91 |
root |
1.5 |
for my $atom ($tab->XListProperties ($tab->parent)) { |
92 |
|
|
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
93 |
root |
1.11 |
|
94 |
|
|
delete $our_props{$atom}; |
95 |
root |
1.5 |
|
96 |
|
|
if ($atom == $wm_normal_hints) { |
97 |
|
|
my (@hints) = unpack "l!*", $items; |
98 |
|
|
|
99 |
root |
1.6 |
$hints[$_] += $self->{tabheight} for (4, 6, 16); |
100 |
|
|
|
101 |
|
|
$items = pack "l!*", @hints; |
102 |
root |
1.5 |
} |
103 |
|
|
$self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
104 |
|
|
} |
105 |
root |
1.6 |
|
106 |
root |
1.11 |
$self->XDeleteProperty ($self->parent, $_) for keys %our_props; |
107 |
root |
1.1 |
} |
108 |
|
|
|
109 |
|
|
sub make_current { |
110 |
|
|
my ($self, $tab) = @_; |
111 |
|
|
|
112 |
|
|
if (my $cur = $self->{cur}) { |
113 |
root |
1.9 |
delete $cur->{activity}; |
114 |
root |
1.7 |
$cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
115 |
|
|
$cur->focus_out; |
116 |
root |
1.1 |
} |
117 |
|
|
|
118 |
|
|
$self->{cur} = $tab; |
119 |
|
|
|
120 |
|
|
$self->configure; |
121 |
root |
1.11 |
$self->copy_properties; |
122 |
root |
1.7 |
$tab->focus_in; |
123 |
root |
1.1 |
$tab->XMapWindow ($tab->parent); |
124 |
root |
1.10 |
delete $tab->{activity}; |
125 |
root |
1.1 |
$self->refresh; |
126 |
|
|
|
127 |
|
|
() |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
sub on_button_press { |
131 |
|
|
1 |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
sub on_button_release { |
135 |
|
|
my ($self, $event) = @_; |
136 |
|
|
|
137 |
|
|
if ($event->{row} == 0) { |
138 |
root |
1.6 |
for my $button (@{ $self->{tabofs} }) { |
139 |
|
|
$button->[2]->($self, $event) |
140 |
|
|
if $event->{col} >= $button->[0] |
141 |
|
|
&& $event->{col} < $button->[1]; |
142 |
root |
1.1 |
} |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
1 |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
sub on_motion_notify { |
149 |
|
|
1 |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
sub on_init { |
153 |
|
|
my ($self) = @_; |
154 |
|
|
|
155 |
|
|
for (qw(name perl_ext_1 perl_ext_2)) { |
156 |
|
|
my $val = $self->resource ($_); |
157 |
|
|
|
158 |
|
|
push @{ $self->{resource} }, [$_ => $val] |
159 |
|
|
if defined $val; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
$self->resource (int_bwidth => 0); |
163 |
|
|
$self->resource (name => "URxvt.tab"); |
164 |
|
|
$self->resource (pty_fd => -1); |
165 |
|
|
|
166 |
|
|
$self->option ($urxvt::OPTION{scrollBar}, 0); |
167 |
|
|
|
168 |
|
|
() |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
sub on_start { |
172 |
|
|
my ($self) = @_; |
173 |
|
|
|
174 |
root |
1.4 |
$self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
175 |
|
|
|
176 |
root |
1.1 |
$self->new_tab; |
177 |
|
|
|
178 |
|
|
() |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
sub on_configure_notify { |
182 |
|
|
my ($self, $event) = @_; |
183 |
|
|
|
184 |
|
|
$self->configure; |
185 |
root |
1.12 |
$self->refresh; |
186 |
root |
1.1 |
|
187 |
|
|
() |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
sub on_wm_delete_window { |
191 |
|
|
my ($self) = @_; |
192 |
|
|
|
193 |
|
|
$_->destroy for @{ $self->{tabs} }; |
194 |
|
|
|
195 |
|
|
1 |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
sub tab_start { |
199 |
|
|
my ($self, $tab) = @_; |
200 |
|
|
|
201 |
root |
1.11 |
$tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask); |
202 |
|
|
|
203 |
root |
1.1 |
push @{ $self->{tabs} }, $tab; |
204 |
|
|
|
205 |
root |
1.7 |
# $tab->{name} ||= scalar @{ $self->{tabs} }; |
206 |
root |
1.1 |
$self->make_current ($tab); |
207 |
|
|
|
208 |
|
|
() |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
sub tab_destroy { |
212 |
|
|
my ($self, $tab) = @_; |
213 |
|
|
|
214 |
|
|
$self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ]; |
215 |
|
|
|
216 |
|
|
if (@{ $self->{tabs} }) { |
217 |
|
|
if ($self->{cur} == $tab) { |
218 |
|
|
delete $self->{cur}; |
219 |
|
|
$self->make_current ($self->{tabs}[-1]); |
220 |
root |
1.7 |
} else { |
221 |
|
|
$self->refresh; |
222 |
root |
1.1 |
} |
223 |
|
|
} else { |
224 |
|
|
# delay destruction a tiny bit |
225 |
|
|
$self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
() |
229 |
|
|
} |
230 |
|
|
|
231 |
root |
1.8 |
sub tab_key_press { |
232 |
|
|
my ($self, $tab, $event, $keysym, $str) = @_; |
233 |
|
|
|
234 |
root |
1.10 |
if ($event->{state} & urxvt::ShiftMask) { |
235 |
|
|
if ($keysym == 0xff51 || $keysym == 0xff53) { |
236 |
|
|
my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; |
237 |
|
|
|
238 |
|
|
--$idx if $keysym == 0xff51; |
239 |
|
|
++$idx if $keysym == 0xff53; |
240 |
|
|
|
241 |
|
|
$self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
242 |
|
|
|
243 |
|
|
return 1; |
244 |
|
|
} elsif ($keysym == 0xff54) { |
245 |
|
|
$self->new_tab; |
246 |
|
|
|
247 |
|
|
return 1; |
248 |
|
|
} |
249 |
root |
1.8 |
} |
250 |
|
|
|
251 |
|
|
() |
252 |
|
|
} |
253 |
|
|
|
254 |
root |
1.11 |
sub tab_property_notify { |
255 |
|
|
my ($self, $tab, $event) = @_; |
256 |
|
|
|
257 |
|
|
$self->copy_properties |
258 |
|
|
if $event->{window} == $tab->parent; |
259 |
|
|
|
260 |
|
|
() |
261 |
|
|
} |
262 |
|
|
|
263 |
root |
1.9 |
sub tab_activity { |
264 |
|
|
my ($self, $tab) = @_; |
265 |
|
|
|
266 |
|
|
$self->refresh; |
267 |
|
|
} |
268 |
|
|
|
269 |
root |
1.1 |
package urxvt::ext::tabbed::tab; |
270 |
|
|
|
271 |
|
|
# helper extension implementing the subwindows of a tabbed terminal. |
272 |
|
|
# simply proxies all interesting calls back to the tabbed class. |
273 |
|
|
|
274 |
|
|
{ |
275 |
root |
1.11 |
for my $hook qw(start destroy key_press property_notify) { |
276 |
root |
1.1 |
eval qq{ |
277 |
|
|
sub on_$hook { |
278 |
|
|
my \$parent = \$_[0]{term}{parent} |
279 |
|
|
or return; |
280 |
|
|
\$parent->tab_$hook (\@_) |
281 |
|
|
} |
282 |
|
|
}; |
283 |
|
|
die if $@; |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
|
287 |
root |
1.9 |
sub on_add_lines { |
288 |
|
|
$_[0]->{activity}++ |
289 |
|
|
or $_[0]{term}{parent}->tab_activity ($_[0]); |
290 |
|
|
() |
291 |
|
|
} |
292 |
root |
1.1 |
|
293 |
|
|
|