1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:tabbar-fg:colour:tab bar foreground colour |
|
|
4 | #:META:X_RESOURCE:tabbar-bg:colour:tab bar background colour |
|
|
5 | #:META:X_RESOURCE:tab-fg:colour:tab foreground colour |
|
|
6 | #:META:X_RESOURCE:tab-bg:colour:tab background colour |
|
|
7 | |
|
|
8 | =head1 NAME |
|
|
9 | |
|
|
10 | tabbed - tabbed interface to urxvt |
|
|
11 | |
|
|
12 | =head1 DESCRIPTION |
|
|
13 | |
|
|
14 | This transforms the terminal into a tabbar with additional terminals, that |
|
|
15 | is, it implements what is commonly referred to as "tabbed terminal". The topmost line |
|
|
16 | displays a "[NEW]" button, which, when clicked, will add a new tab, followed by one |
|
|
17 | button per tab. |
|
|
18 | |
|
|
19 | Clicking a button will activate that tab. Pressing B<Shift-Left> and |
|
|
20 | B<Shift-Right> will switch to the tab left or right of the current one, |
|
|
21 | while B<Shift-Down> creates a new tab. |
|
|
22 | |
|
|
23 | The tabbar itself can be configured similarly to a normal terminal, but |
|
|
24 | with a resource class of C<URxvt.tabbed>. In addition, it supports the |
|
|
25 | following four resources (shown with defaults): |
|
|
26 | |
|
|
27 | URxvt.tabbed.tabbar-fg: <colour-index, default 3> |
|
|
28 | URxvt.tabbed.tabbar-bg: <colour-index, default 0> |
|
|
29 | URxvt.tabbed.tab-fg: <colour-index, default 0> |
|
|
30 | URxvt.tabbed.tab-bg: <colour-index, default 1> |
|
|
31 | |
|
|
32 | See I<COLOR AND GRAPHICS> in the @@RXVT_NAME@@(1) manpage for valid |
|
|
33 | indices. |
|
|
34 | |
|
|
35 | =cut |
2 | |
36 | |
3 | sub refresh { |
37 | sub refresh { |
4 | my ($self) = @_; |
38 | my ($self) = @_; |
5 | |
39 | |
6 | my $ncol = $self->ncol; |
40 | my $ncol = $self->ncol; |
… | |
… | |
42 | |
76 | |
43 | $self->want_refresh; |
77 | $self->want_refresh; |
44 | } |
78 | } |
45 | |
79 | |
46 | sub new_tab { |
80 | sub new_tab { |
47 | my ($self) = @_; |
81 | my ($self, @argv) = @_; |
48 | |
|
|
49 | my $offset = $self->fheight; |
|
|
50 | |
82 | |
51 | # save a backlink to us, make sure tabbed is inactive |
83 | # save a backlink to us, make sure tabbed is inactive |
52 | push @urxvt::TERM_INIT, sub { |
84 | push @urxvt::TERM_INIT, sub { |
53 | my ($term) = @_; |
85 | my ($term) = @_; |
54 | $term->{parent} = $self; |
86 | $term->{parent} = $self; |
55 | |
87 | |
56 | $term->resource ($_->[0] => $_->[1]) |
88 | for (0 .. urxvt::NUM_RESOURCES - 1) { |
57 | for @{ $self->{resource} || [] }; |
89 | my $value = $self->{resource}[$_]; |
|
|
90 | |
|
|
91 | $term->resource ("+$_" => $value) |
|
|
92 | if defined $value; |
|
|
93 | } |
58 | |
94 | |
59 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
95 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
60 | |
|
|
61 | }; |
96 | }; |
62 | |
97 | |
63 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
98 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
64 | |
99 | |
65 | my $term = new urxvt::term |
100 | my $term = new urxvt::term |
66 | $self->env, $urxvt::RXVTNAME, |
101 | $self->env, $urxvt::RXVTNAME, |
67 | -embed => $self->parent, |
102 | -embed => $self->parent, |
|
|
103 | @argv, |
68 | ; |
104 | ; |
69 | } |
105 | } |
70 | |
106 | |
71 | sub configure { |
107 | sub configure { |
72 | my ($self) = @_; |
108 | my ($self) = @_; |
… | |
… | |
84 | 0, $self->{tabheight}, |
120 | 0, $self->{tabheight}, |
85 | $self->width, $self->height - $self->{tabheight} |
121 | $self->width, $self->height - $self->{tabheight} |
86 | ); |
122 | ); |
87 | } |
123 | } |
88 | |
124 | |
|
|
125 | sub on_resize_all_windows { |
|
|
126 | my ($self, $width, $height) = @_; |
|
|
127 | |
|
|
128 | 1 |
|
|
129 | } |
|
|
130 | |
89 | sub copy_properties { |
131 | sub copy_properties { |
90 | my ($self) = @_; |
132 | my ($self) = @_; |
91 | my $tab = $self->{cur}; |
133 | my $tab = $self->{cur}; |
92 | |
134 | |
93 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
135 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
94 | |
136 | |
95 | my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); |
137 | my $current = delete $self->{current_properties}; |
96 | |
138 | |
97 | delete $our_props{$self->XInternAtom ($_)} |
139 | # pass 1: copy over properties different or nonexisting |
98 | for qw(WM_STATE WM_ICON_SIZE |
|
|
99 | _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS); |
|
|
100 | |
|
|
101 | for my $atom ($tab->XListProperties ($tab->parent)) { |
140 | for my $atom ($tab->XListProperties ($tab->parent)) { |
102 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
141 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
103 | |
|
|
104 | delete $our_props{$atom}; |
|
|
105 | |
142 | |
|
|
143 | # fix up size hints |
106 | if ($atom == $wm_normal_hints) { |
144 | if ($atom == $wm_normal_hints) { |
107 | my (@hints) = unpack "l!*", $items; |
145 | my (@hints) = unpack "l!*", $items; |
108 | |
146 | |
109 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
147 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
110 | |
148 | |
111 | $items = pack "l!*", @hints; |
149 | $items = pack "l!*", @hints; |
112 | } |
150 | } |
|
|
151 | |
|
|
152 | my $cur = delete $current->{$atom}; |
|
|
153 | |
|
|
154 | # update if changed, we assume empty items and zero type and format will not happen |
113 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
155 | $self->XChangeProperty ($self->parent, $atom, $type, $format, $items) |
114 | } |
156 | if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items; |
115 | |
157 | |
|
|
158 | $self->{current_properties}{$atom} = [$type, $format, $items]; |
|
|
159 | } |
|
|
160 | |
|
|
161 | # pass 2, delete all extraneous properties |
116 | $self->XDeleteProperty ($self->parent, $_) for keys %our_props; |
162 | $self->XDeleteProperty ($self->parent, $_) for keys %$current; |
117 | } |
163 | } |
118 | |
164 | |
119 | sub make_current { |
165 | sub make_current { |
120 | my ($self, $tab) = @_; |
166 | my ($self, $tab) = @_; |
121 | |
167 | |
122 | if (my $cur = $self->{cur}) { |
168 | if (my $cur = $self->{cur}) { |
123 | delete $cur->{activity}; |
169 | delete $cur->{activity}; |
124 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
170 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
125 | $cur->focus_out; |
171 | $cur->focus_out; |
126 | } |
172 | } |
127 | |
173 | |
128 | $self->{cur} = $tab; |
174 | $self->{cur} = $tab; |
129 | |
175 | |
130 | $self->configure; |
176 | $self->configure; |
131 | $self->copy_properties; |
177 | $self->copy_properties; |
132 | $tab->focus_in; |
178 | |
|
|
179 | $tab->focus_out; # just in case, should be a nop |
|
|
180 | $tab->focus_in if $self->focus; |
|
|
181 | |
133 | $tab->XMapWindow ($tab->parent); |
182 | $tab->XMapWindow ($tab->parent); |
134 | delete $tab->{activity}; |
183 | delete $tab->{activity}; |
135 | $self->refresh; |
184 | $self->refresh; |
136 | |
185 | |
137 | () |
186 | () |
… | |
… | |
149 | my ($self, $event) = @_; |
198 | my ($self, $event) = @_; |
150 | |
199 | |
151 | $self->{cur}->focus_out; |
200 | $self->{cur}->focus_out; |
152 | |
201 | |
153 | () |
202 | () |
|
|
203 | } |
|
|
204 | |
|
|
205 | sub on_tt_write { |
|
|
206 | my ($self, $octets) = @_; |
|
|
207 | |
|
|
208 | $self->{cur}->tt_write ($octets); |
|
|
209 | |
|
|
210 | 1 |
154 | } |
211 | } |
155 | |
212 | |
156 | sub on_key_press { |
213 | sub on_key_press { |
157 | my ($self, $event) = @_; |
214 | my ($self, $event) = @_; |
158 | |
215 | |
… | |
… | |
192 | } |
249 | } |
193 | |
250 | |
194 | sub on_init { |
251 | sub on_init { |
195 | my ($self) = @_; |
252 | my ($self) = @_; |
196 | |
253 | |
197 | for (qw(name perl_ext_1 perl_ext_2)) { |
254 | $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1]; |
198 | my $val = $self->resource ($_); |
|
|
199 | |
|
|
200 | push @{ $self->{resource} }, [$_ => $val] |
|
|
201 | if defined $val; |
|
|
202 | } |
|
|
203 | |
255 | |
204 | $self->resource (int_bwidth => 0); |
256 | $self->resource (int_bwidth => 0); |
205 | $self->resource (name => "URxvt.tabbed"); |
257 | $self->resource (name => "URxvt.tabbed"); |
206 | $self->resource (pty_fd => -1); |
258 | $self->resource (pty_fd => -1); |
207 | |
259 | |
… | |
… | |
228 | |
280 | |
229 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
281 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
230 | |
282 | |
231 | $self->cmd_parse ("\033[?25l"); |
283 | $self->cmd_parse ("\033[?25l"); |
232 | |
284 | |
|
|
285 | my @argv = $self->argv; |
|
|
286 | |
|
|
287 | do { |
|
|
288 | shift @argv; |
|
|
289 | } while @argv && $argv[0] ne "-e"; |
|
|
290 | |
233 | $self->new_tab; |
291 | $self->new_tab (@argv); |
234 | |
292 | |
235 | () |
293 | () |
236 | } |
294 | } |
237 | |
295 | |
238 | sub on_configure_notify { |
296 | sub on_configure_notify { |
… | |
… | |
294 | |
352 | |
295 | --$idx if $keysym == 0xff51; |
353 | --$idx if $keysym == 0xff51; |
296 | ++$idx if $keysym == 0xff53; |
354 | ++$idx if $keysym == 0xff53; |
297 | |
355 | |
298 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
356 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
299 | |
357 | |
300 | return 1; |
358 | return 1; |
301 | } elsif ($keysym == 0xff54) { |
359 | } elsif ($keysym == 0xff54) { |
302 | $self->new_tab; |
360 | $self->new_tab; |
|
|
361 | |
|
|
362 | return 1; |
|
|
363 | } |
|
|
364 | } |
|
|
365 | elsif ($event->{state} & urxvt::ControlMask) { |
|
|
366 | if ($keysym == 0xff51 || $keysym == 0xff53) { |
|
|
367 | my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; |
|
|
368 | my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} }; |
|
|
369 | |
|
|
370 | ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) = |
|
|
371 | ($self->{tabs}[$idx2], $self->{tabs}[$idx1]); |
|
|
372 | |
|
|
373 | $self->make_current ($self->{tabs}[$idx2]); |
303 | |
374 | |
304 | return 1; |
375 | return 1; |
305 | } |
376 | } |
306 | } |
377 | } |
307 | |
378 | |