ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/tabbed
(Generate patch)

Comparing rxvt-unicode/src/perl/tabbed (file contents):
Revision 1.10 by root, Fri Jan 20 16:18:07 2006 UTC vs.
Revision 1.39 by sf-exg, Sun Feb 26 06:36:46 2017 UTC

1#! perl 1#! perl
2 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
10tabbed - tabbed interface to urxvt
11
12=head1 DESCRIPTION
13
14This transforms the terminal into a tabbar with additional terminals, that
15is, it implements what is commonly referred to as "tabbed terminal". The topmost line
16displays a "[NEW]" button, which, when clicked, will add a new tab, followed by one
17button per tab.
18
19Clicking a button will activate that tab. Pressing B<Shift-Left> and
20B<Shift-Right> will switch to the tab left or right of the current one,
21while B<Shift-Down> creates a new tab. Pressing B<Ctrl-Left> and
22B<Ctrl-Right> will renumber the current tab by moving it to the left or
23to the right.
24
25The tabbar itself can be configured similarly to a normal terminal, but
26with a resource class of C<URxvt.tabbed>. In addition, it supports the
27following 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
34See I<COLOR AND GRAPHICS> in the urxvt(1) manpage for valid
35indices.
36
37=cut
38
3sub refresh { 39sub refresh {
4 my ($self) = @_; 40 my ($self) = @_;
5 41
6 my $ncol = $self->ncol; 42 my $ncol = $self->ncol;
7 43
8 my $text = " " x $ncol; 44 my $text = " " x $ncol;
9 my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; 45 my $rend = [($self->{rs_tabbar}) x $ncol];
10 46
11 my @ofs; 47 my @ofs;
12 48
13 substr $text, 0, 7, "[NEW] |"; 49 substr $text, 0, 7, "[NEW] |";
14 @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; 50 @$rend[0 .. 5] = ($self->{rs_tab}) x 6;
15 push @ofs, [0, 6, sub { $_[0]->new_tab }]; 51 push @ofs, [0, 6, sub { $_[0]->new_tab }];
16 52
17 my $ofs = 7; 53 my $ofs = 7;
18 my $idx = 0; 54 my $idx = 0;
19 55
25 61
26 my $txt = "$act$idx$act"; 62 my $txt = "$act$idx$act";
27 my $len = length $txt; 63 my $len = length $txt;
28 64
29 substr $text, $ofs, $len + 1, "$txt|"; 65 substr $text, $ofs, $len + 1, "$txt|";
30 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len 66 @$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len
31 if $tab == $self->{cur}; 67 if $tab == $self->{cur};
32 68
33 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; 69 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
34 70
35 $ofs += $len + 1; 71 $ofs += $len + 1;
42 78
43 $self->want_refresh; 79 $self->want_refresh;
44} 80}
45 81
46sub new_tab { 82sub new_tab {
47 my ($self) = @_; 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
61 }; 98 };
62 99
63 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; 100 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
64 101
65 my $term = new urxvt::term 102 my $term = new urxvt::term
66 $self->env, $urxvt::RXVTNAME, 103 $self->env, $urxvt::RXVTNAME,
67 -embed => $self->parent, 104 -embed => $self->parent,
105 @argv,
68 ; 106 ;
69} 107}
70 108
71sub configure { 109sub configure {
72 my ($self) = @_; 110 my ($self) = @_;
73 111
74 my $tab = $self->{cur}; 112 my $tab = $self->{cur};
75 113
114 # this is an extremely dirty way to force a configurenotify, but who cares
115 $tab->XMoveResizeWindow (
116 $tab->parent,
117 0, $self->{tabheight} + 1,
118 $self->width, $self->height - $self->{tabheight}
119 );
76 $tab->XMoveResizeWindow ( 120 $tab->XMoveResizeWindow (
77 $tab->parent, 121 $tab->parent,
78 0, $self->{tabheight}, 122 0, $self->{tabheight},
79 $self->width, $self->height - $self->{tabheight} 123 $self->width, $self->height - $self->{tabheight}
80 ); 124 );
125}
126
127sub on_resize_all_windows {
128 my ($self, $width, $height) = @_;
129
130 1
131}
132
133sub copy_properties {
134 my ($self) = @_;
135 my $tab = $self->{cur};
81 136
82 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 137 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
83 138
139 my $current = delete $self->{current_properties};
140
141 # pass 1: copy over properties different or nonexisting
84 for my $atom ($tab->XListProperties ($tab->parent)) { 142 for my $atom ($tab->XListProperties ($tab->parent)) {
85 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 143 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
86 144
145 # fix up size hints
87 if ($atom == $wm_normal_hints) { 146 if ($atom == $wm_normal_hints) {
88 my (@hints) = unpack "l!*", $items; 147 my (@hints) = unpack "l!*", $items;
89 148
90 $hints[$_] += $self->{tabheight} for (4, 6, 16); 149 $hints[$_] += $self->{tabheight} for (4, 6, 16);
91 150
92 $items = pack "l!*", @hints; 151 $items = pack "l!*", @hints;
93 } 152 }
153
154 my $cur = delete $current->{$atom};
155
156 # update if changed, we assume empty items and zero type and format will not happen
94 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 157 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
95 } 158 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
96 159
97 $self->refresh; 160 $self->{current_properties}{$atom} = [$type, $format, $items];
161 }
162
163 # pass 2, delete all extraneous properties
164 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
98} 165}
99 166
100sub make_current { 167sub make_current {
101 my ($self, $tab) = @_; 168 my ($self, $tab) = @_;
102 169
103 if (my $cur = $self->{cur}) { 170 if (my $cur = $self->{cur}) {
104 delete $cur->{activity}; 171 delete $cur->{activity};
105 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 172 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
106 $cur->focus_out; 173 $cur->focus_out;
107 } 174 }
108 175
109 $self->{cur} = $tab; 176 $self->{cur} = $tab;
110 177
111 $self->configure; 178 $self->configure;
112 $tab->focus_in; 179 $self->copy_properties;
180
181 $tab->focus_out; # just in case, should be a nop
182 $tab->focus_in if $self->focus;
183
113 $tab->XMapWindow ($tab->parent); 184 $tab->XMapWindow ($tab->parent);
114 delete $tab->{activity}; 185 delete $tab->{activity};
115 $self->refresh; 186 $self->refresh;
116 187
117 () 188 ()
189}
190
191sub on_focus_in {
192 my ($self, $event) = @_;
193
194 $self->{cur}->focus_in;
195
196 ()
197}
198
199sub on_focus_out {
200 my ($self, $event) = @_;
201
202 $self->{cur}->focus_out;
203
204 ()
205}
206
207sub on_tt_write {
208 my ($self, $octets) = @_;
209
210 $self->{cur}->tt_write ($octets);
211
212 1
213}
214
215sub on_key_press {
216 my ($self, $event) = @_;
217
218 $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time});
219 $self->{cur}->refresh_check;
220
221 1
222}
223
224sub on_key_release {
225 my ($self, $event) = @_;
226
227 $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time});
228 $self->{cur}->refresh_check;
229
230 1
118} 231}
119 232
120sub on_button_press { 233sub on_button_press {
121 1 234 1
122} 235}
140} 253}
141 254
142sub on_init { 255sub on_init {
143 my ($self) = @_; 256 my ($self) = @_;
144 257
145 for (qw(name perl_ext_1 perl_ext_2)) { 258 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
146 my $val = $self->resource ($_);
147
148 push @{ $self->{resource} }, [$_ => $val]
149 if defined $val;
150 }
151 259
152 $self->resource (int_bwidth => 0); 260 $self->resource (int_bwidth => 0);
153 $self->resource (name => "URxvt.tab"); 261 $self->resource (name => "URxvt.tabbed");
154 $self->resource (pty_fd => -1); 262 $self->resource (pty_fd => -1);
155 263
156 $self->option ($urxvt::OPTION{scrollBar}, 0); 264 $self->option ($urxvt::OPTION{scrollBar}, 0);
157 265
266 my $fg = $self->x_resource ("tabbar-fg");
267 my $bg = $self->x_resource ("tabbar-bg");
268 my $tabfg = $self->x_resource ("tab-fg");
269 my $tabbg = $self->x_resource ("tab-bg");
270
271 defined $fg or $fg = 3;
272 defined $bg or $bg = 0;
273 defined $tabfg or $tabfg = 0;
274 defined $tabbg or $tabbg = 1;
275
276 $self->{rs_tabbar} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $fg + 2, $bg + 2);
277 $self->{rs_tab} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $tabfg + 2, $tabbg + 2);
278
158 () 279 ()
159} 280}
160 281
161sub on_start { 282sub on_start {
162 my ($self) = @_; 283 my ($self) = @_;
163 284
164 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 285 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
165 286
287 $self->cmd_parse ("\033[?25l");
288
289 my @argv = $self->argv;
290
291 do {
292 shift @argv;
293 } while @argv && $argv[0] ne "-e";
294
166 $self->new_tab; 295 $self->new_tab (@argv);
167 296
168 () 297 ()
169} 298}
170 299
171sub on_configure_notify { 300sub on_configure_notify {
172 my ($self, $event) = @_; 301 my ($self, $event) = @_;
173 302
174 $self->configure; 303 $self->configure;
304 $self->refresh;
175 305
176 () 306 ()
177} 307}
178 308
179sub on_wm_delete_window { 309sub on_wm_delete_window {
184 1 314 1
185} 315}
186 316
187sub tab_start { 317sub tab_start {
188 my ($self, $tab) = @_; 318 my ($self, $tab) = @_;
319
320 $tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask);
189 321
190 push @{ $self->{tabs} }, $tab; 322 push @{ $self->{tabs} }, $tab;
191 323
192# $tab->{name} ||= scalar @{ $self->{tabs} }; 324# $tab->{name} ||= scalar @{ $self->{tabs} };
193 $self->make_current ($tab); 325 $self->make_current ($tab);
224 356
225 --$idx if $keysym == 0xff51; 357 --$idx if $keysym == 0xff51;
226 ++$idx if $keysym == 0xff53; 358 ++$idx if $keysym == 0xff53;
227 359
228 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 360 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
229 361
230 return 1; 362 return 1;
231 } elsif ($keysym == 0xff54) { 363 } elsif ($keysym == 0xff54) {
232 $self->new_tab; 364 $self->new_tab;
233 365
234 return 1; 366 return 1;
235 } 367 }
236 } 368 }
369 elsif ($event->{state} & urxvt::ControlMask) {
370 if ($keysym == 0xff51 || $keysym == 0xff53) {
371 my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
372 my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };
373
374 ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
375 ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
376
377 $self->make_current ($self->{tabs}[$idx2]);
378
379 return 1;
380 }
381 }
382
383 ()
384}
385
386sub tab_property_notify {
387 my ($self, $tab, $event) = @_;
388
389 $self->copy_properties
390 if $event->{window} == $tab->parent;
237 391
238 () 392 ()
239} 393}
240 394
241sub tab_activity { 395sub tab_activity {
248 402
249# helper extension implementing the subwindows of a tabbed terminal. 403# helper extension implementing the subwindows of a tabbed terminal.
250# simply proxies all interesting calls back to the tabbed class. 404# simply proxies all interesting calls back to the tabbed class.
251 405
252{ 406{
253 for my $hook qw(start destroy key_press) { 407 for my $hook (qw(start destroy key_press property_notify)) {
254 eval qq{ 408 eval qq{
255 sub on_$hook { 409 sub on_$hook {
256 my \$parent = \$_[0]{term}{parent} 410 my \$parent = \$_[0]{term}{parent}
257 or return; 411 or return;
258 \$parent->tab_$hook (\@_) 412 \$parent->tab_$hook (\@_)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines