1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:RESOURCE:tabbar-fg:colour:tab bar foreground colour |
|
|
4 | #:META:RESOURCE:tabbar-bg:colour:tab bar background colour |
|
|
5 | #:META:RESOURCE:tab-fg:colour:tab foreground colour |
|
|
6 | #:META: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. Pressing B<Ctrl-Left> and |
|
|
22 | B<Ctrl-Right> will renumber the current tab by moving it to the left or |
|
|
23 | to the right. |
|
|
24 | |
|
|
25 | The tabbar itself can be configured similarly to a normal terminal, but |
|
|
26 | with a resource class of C<URxvt.tabbed>. In addition, it supports the |
|
|
27 | following four resources (shown with defaults): |
|
|
28 | |
|
|
29 | URxvt.tabbed.tabbar-fg: <colour-index, default 3> |
|
|
30 | URxvt.tabbed.tabbar-bg: <colour-index, default 0> |
|
|
31 | URxvt.tabbed.tab-fg: <colour-index, default 0> |
|
|
32 | URxvt.tabbed.tab-bg: <colour-index, default 1> |
|
|
33 | |
|
|
34 | See I<COLOR AND GRAPHICS> in the urxvt(1) manpage for valid |
|
|
35 | indices. |
|
|
36 | |
|
|
37 | =cut |
2 | |
38 | |
3 | sub refresh { |
39 | sub refresh { |
4 | my ($self) = @_; |
40 | my ($self) = @_; |
5 | |
41 | |
6 | my $ncol = $self->ncol; |
42 | my $ncol = $self->ncol; |
… | |
… | |
43 | $self->want_refresh; |
79 | $self->want_refresh; |
44 | } |
80 | } |
45 | |
81 | |
46 | sub new_tab { |
82 | sub new_tab { |
47 | my ($self, @argv) = @_; |
83 | my ($self, @argv) = @_; |
48 | |
|
|
49 | my $offset = $self->fheight; |
|
|
50 | |
84 | |
51 | # save a backlink to us, make sure tabbed is inactive |
85 | # save a backlink to us, make sure tabbed is inactive |
52 | push @urxvt::TERM_INIT, sub { |
86 | push @urxvt::TERM_INIT, sub { |
53 | my ($term) = @_; |
87 | my ($term) = @_; |
54 | $term->{parent} = $self; |
88 | $term->{parent} = $self; |
55 | |
89 | |
56 | $term->resource ($_->[0] => $_->[1]) |
90 | for (0 .. urxvt::NUM_RESOURCES - 1) { |
57 | for @{ $self->{resource} || [] }; |
91 | my $value = $self->{resource}[$_]; |
|
|
92 | |
|
|
93 | $term->resource ("+$_" => $value) |
|
|
94 | if defined $value; |
|
|
95 | } |
58 | |
96 | |
59 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
97 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
60 | }; |
98 | }; |
61 | |
99 | |
62 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
100 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
… | |
… | |
96 | my ($self) = @_; |
134 | my ($self) = @_; |
97 | my $tab = $self->{cur}; |
135 | my $tab = $self->{cur}; |
98 | |
136 | |
99 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
137 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
100 | |
138 | |
101 | my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); |
139 | my $current = delete $self->{current_properties}; |
102 | |
140 | |
103 | delete $our_props{$self->XInternAtom ($_)} |
141 | # pass 1: copy over properties different or nonexisting |
104 | for qw(WM_STATE WM_ICON_SIZE |
|
|
105 | _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS); |
|
|
106 | |
|
|
107 | for my $atom ($tab->XListProperties ($tab->parent)) { |
142 | for my $atom ($tab->XListProperties ($tab->parent)) { |
108 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
143 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
109 | |
|
|
110 | delete $our_props{$atom}; |
|
|
111 | |
144 | |
|
|
145 | # fix up size hints |
112 | if ($atom == $wm_normal_hints) { |
146 | if ($atom == $wm_normal_hints) { |
113 | my (@hints) = unpack "l!*", $items; |
147 | my (@hints) = unpack "l!*", $items; |
114 | |
148 | |
115 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
149 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
116 | |
150 | |
117 | $items = pack "l!*", @hints; |
151 | $items = pack "l!*", @hints; |
118 | } |
152 | } |
119 | |
153 | |
120 | my ($dtype, $dformat, $ditems) = $self->XGetWindowProperty ($self->parent, $atom); |
154 | my $cur = delete $current->{$atom}; |
121 | |
155 | |
122 | if ($dtype != $type or $dformat != $format or $ditems ne $items) { |
156 | # update if changed, we assume empty items and zero type and format will not happen |
123 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
157 | $self->XChangeProperty ($self->parent, $atom, $type, $format, $items) |
124 | } |
158 | if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items; |
125 | } |
|
|
126 | |
159 | |
|
|
160 | $self->{current_properties}{$atom} = [$type, $format, $items]; |
|
|
161 | } |
|
|
162 | |
|
|
163 | # pass 2, delete all extraneous properties |
127 | $self->XDeleteProperty ($self->parent, $_) for keys %our_props; |
164 | $self->XDeleteProperty ($self->parent, $_) for keys %$current; |
128 | } |
165 | } |
129 | |
166 | |
130 | sub make_current { |
167 | sub make_current { |
131 | my ($self, $tab) = @_; |
168 | my ($self, $tab) = @_; |
132 | |
169 | |
133 | if (my $cur = $self->{cur}) { |
170 | if (my $cur = $self->{cur}) { |
134 | delete $cur->{activity}; |
171 | delete $cur->{activity}; |
135 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
172 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
136 | $cur->focus_out; |
173 | $cur->focus_out; |
137 | } |
174 | } |
138 | |
175 | |
139 | $self->{cur} = $tab; |
176 | $self->{cur} = $tab; |
140 | |
177 | |
141 | $self->configure; |
178 | $self->configure; |
142 | $self->copy_properties; |
179 | $self->copy_properties; |
143 | |
180 | |
144 | $tab->focus_out; # just in case, should be a nop |
181 | $tab->focus_out; # just in case, should be a nop |
145 | $tab->focus_in if $self->focus; |
182 | $tab->focus_in if $self->focus; |
146 | |
183 | |
147 | $tab->XMapWindow ($tab->parent); |
184 | $tab->XMapWindow ($tab->parent); |
148 | delete $tab->{activity}; |
185 | delete $tab->{activity}; |
149 | $self->refresh; |
186 | $self->refresh; |
150 | |
187 | |
151 | () |
188 | () |
… | |
… | |
165 | $self->{cur}->focus_out; |
202 | $self->{cur}->focus_out; |
166 | |
203 | |
167 | () |
204 | () |
168 | } |
205 | } |
169 | |
206 | |
|
|
207 | sub on_tt_write { |
|
|
208 | my ($self, $octets) = @_; |
|
|
209 | |
|
|
210 | $self->{cur}->tt_write ($octets); |
|
|
211 | |
|
|
212 | 1 |
|
|
213 | } |
|
|
214 | |
170 | sub on_key_press { |
215 | sub on_key_press { |
171 | my ($self, $event) = @_; |
216 | my ($self, $event) = @_; |
172 | |
217 | |
173 | $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time}); |
218 | $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time}); |
|
|
219 | $self->{cur}->refresh_check; |
174 | |
220 | |
175 | 1 |
221 | 1 |
176 | } |
222 | } |
177 | |
223 | |
178 | sub on_key_release { |
224 | sub on_key_release { |
179 | my ($self, $event) = @_; |
225 | my ($self, $event) = @_; |
180 | |
226 | |
181 | $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time}); |
227 | $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time}); |
|
|
228 | $self->{cur}->refresh_check; |
182 | |
229 | |
183 | 1 |
230 | 1 |
184 | } |
231 | } |
185 | |
232 | |
186 | sub on_button_press { |
233 | sub on_button_press { |
… | |
… | |
206 | } |
253 | } |
207 | |
254 | |
208 | sub on_init { |
255 | sub on_init { |
209 | my ($self) = @_; |
256 | my ($self) = @_; |
210 | |
257 | |
211 | for (qw(name chdir perl_ext_1 perl_ext_2)) { |
258 | $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1]; |
212 | my $val = $self->resource ($_); |
|
|
213 | |
|
|
214 | push @{ $self->{resource} }, [$_ => $val] |
|
|
215 | if defined $val; |
|
|
216 | } |
|
|
217 | |
259 | |
218 | $self->resource (int_bwidth => 0); |
260 | $self->resource (int_bwidth => 0); |
219 | $self->resource (name => "URxvt.tabbed"); |
261 | $self->resource (name => "URxvt.tabbed"); |
220 | $self->resource (pty_fd => -1); |
262 | $self->resource (pty_fd => -1); |
221 | |
263 | |
… | |
… | |
314 | |
356 | |
315 | --$idx if $keysym == 0xff51; |
357 | --$idx if $keysym == 0xff51; |
316 | ++$idx if $keysym == 0xff53; |
358 | ++$idx if $keysym == 0xff53; |
317 | |
359 | |
318 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
360 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
319 | |
361 | |
320 | return 1; |
362 | return 1; |
321 | } elsif ($keysym == 0xff54) { |
363 | } elsif ($keysym == 0xff54) { |
322 | $self->new_tab; |
364 | $self->new_tab; |
323 | |
365 | |
324 | return 1; |
366 | return 1; |
… | |
… | |
360 | |
402 | |
361 | # helper extension implementing the subwindows of a tabbed terminal. |
403 | # helper extension implementing the subwindows of a tabbed terminal. |
362 | # simply proxies all interesting calls back to the tabbed class. |
404 | # simply proxies all interesting calls back to the tabbed class. |
363 | |
405 | |
364 | { |
406 | { |
365 | for my $hook qw(start destroy key_press property_notify) { |
407 | for my $hook (qw(start destroy key_press property_notify)) { |
366 | eval qq{ |
408 | eval qq{ |
367 | sub on_$hook { |
409 | sub on_$hook { |
368 | my \$parent = \$_[0]{term}{parent} |
410 | my \$parent = \$_[0]{term}{parent} |
369 | or return; |
411 | or return; |
370 | \$parent->tab_$hook (\@_) |
412 | \$parent->tab_$hook (\@_) |