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.19 by root, Sat Feb 11 02:28:19 2006 UTC vs.
Revision 1.36 by root, Sat May 25 23:14:08 2013 UTC

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
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 @@RXVT_NAME@@(1) manpage for valid
35indices.
36
37=cut
2 38
3sub refresh { 39sub refresh {
4 my ($self) = @_; 40 my ($self) = @_;
5 41
6 my $ncol = $self->ncol; 42 my $ncol = $self->ncol;
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) = @_;
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
130sub make_current { 167sub 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 $tab->focus_in; 180
181 $tab->focus_out; # just in case, should be a nop
182 $tab->focus_in if $self->focus;
183
144 $tab->XMapWindow ($tab->parent); 184 $tab->XMapWindow ($tab->parent);
145 delete $tab->{activity}; 185 delete $tab->{activity};
146 $self->refresh; 186 $self->refresh;
147 187
148 () 188 ()
160 my ($self, $event) = @_; 200 my ($self, $event) = @_;
161 201
162 $self->{cur}->focus_out; 202 $self->{cur}->focus_out;
163 203
164 () 204 ()
205}
206
207sub on_tt_write {
208 my ($self, $octets) = @_;
209
210 $self->{cur}->tt_write ($octets);
211
212 1
165} 213}
166 214
167sub on_key_press { 215sub on_key_press {
168 my ($self, $event) = @_; 216 my ($self, $event) = @_;
169 217
203} 251}
204 252
205sub on_init { 253sub on_init {
206 my ($self) = @_; 254 my ($self) = @_;
207 255
208 for (qw(name perl_ext_1 perl_ext_2)) { 256 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
209 my $val = $self->resource ($_);
210
211 push @{ $self->{resource} }, [$_ => $val]
212 if defined $val;
213 }
214 257
215 $self->resource (int_bwidth => 0); 258 $self->resource (int_bwidth => 0);
216 $self->resource (name => "URxvt.tabbed"); 259 $self->resource (name => "URxvt.tabbed");
217 $self->resource (pty_fd => -1); 260 $self->resource (pty_fd => -1);
218 261
239 282
240 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 283 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
241 284
242 $self->cmd_parse ("\033[?25l"); 285 $self->cmd_parse ("\033[?25l");
243 286
287 my @argv = $self->argv;
288
289 do {
290 shift @argv;
291 } while @argv && $argv[0] ne "-e";
292
244 $self->new_tab; 293 $self->new_tab (@argv);
245 294
246 () 295 ()
247} 296}
248 297
249sub on_configure_notify { 298sub on_configure_notify {
305 354
306 --$idx if $keysym == 0xff51; 355 --$idx if $keysym == 0xff51;
307 ++$idx if $keysym == 0xff53; 356 ++$idx if $keysym == 0xff53;
308 357
309 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 358 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
310 359
311 return 1; 360 return 1;
312 } elsif ($keysym == 0xff54) { 361 } elsif ($keysym == 0xff54) {
313 $self->new_tab; 362 $self->new_tab;
314 363
315 return 1; 364 return 1;
316 } 365 }
317 } 366 }
367 elsif ($event->{state} & urxvt::ControlMask) {
368 if ($keysym == 0xff51 || $keysym == 0xff53) {
369 my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
370 my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };
371
372 ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
373 ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
374
375 $self->make_current ($self->{tabs}[$idx2]);
376
377 return 1;
378 }
379 }
318 380
319 () 381 ()
320} 382}
321 383
322sub tab_property_notify { 384sub tab_property_notify {
338 400
339# helper extension implementing the subwindows of a tabbed terminal. 401# helper extension implementing the subwindows of a tabbed terminal.
340# simply proxies all interesting calls back to the tabbed class. 402# simply proxies all interesting calls back to the tabbed class.
341 403
342{ 404{
343 for my $hook qw(start destroy key_press property_notify) { 405 for my $hook (qw(start destroy key_press property_notify)) {
344 eval qq{ 406 eval qq{
345 sub on_$hook { 407 sub on_$hook {
346 my \$parent = \$_[0]{term}{parent} 408 my \$parent = \$_[0]{term}{parent}
347 or return; 409 or return;
348 \$parent->tab_$hook (\@_) 410 \$parent->tab_$hook (\@_)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines