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.13 by root, Fri Feb 3 05:47:05 2006 UTC vs.
Revision 1.33 by root, Sun Jun 10 17:31:53 2012 UTC

1#! perl 1#! perl
2 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
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.
22
23The tabbar itself can be configured similarly to a normal terminal, but
24with a resource class of C<URxvt.tabbed>. In addition, it supports the
25following 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
32See I<COLOR AND GRAPHICS> in the @@RXVT_NAME@@(1) manpage for valid
33indices.
34
35=cut
36
3sub refresh { 37sub refresh {
4 my ($self) = @_; 38 my ($self) = @_;
5 39
6 my $ncol = $self->ncol; 40 my $ncol = $self->ncol;
7 41
8 my $text = " " x $ncol; 42 my $text = " " x $ncol;
9 my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; 43 my $rend = [($self->{rs_tabbar}) x $ncol];
10 44
11 my @ofs; 45 my @ofs;
12 46
13 substr $text, 0, 7, "[NEW] |"; 47 substr $text, 0, 7, "[NEW] |";
14 @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; 48 @$rend[0 .. 5] = ($self->{rs_tab}) x 6;
15 push @ofs, [0, 6, sub { $_[0]->new_tab }]; 49 push @ofs, [0, 6, sub { $_[0]->new_tab }];
16 50
17 my $ofs = 7; 51 my $ofs = 7;
18 my $idx = 0; 52 my $idx = 0;
19 53
25 59
26 my $txt = "$act$idx$act"; 60 my $txt = "$act$idx$act";
27 my $len = length $txt; 61 my $len = length $txt;
28 62
29 substr $text, $ofs, $len + 1, "$txt|"; 63 substr $text, $ofs, $len + 1, "$txt|";
30 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len 64 @$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len
31 if $tab == $self->{cur}; 65 if $tab == $self->{cur};
32 66
33 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; 67 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
34 68
35 $ofs += $len + 1; 69 $ofs += $len + 1;
42 76
43 $self->want_refresh; 77 $self->want_refresh;
44} 78}
45 79
46sub new_tab { 80sub 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
71sub configure { 107sub configure {
72 my ($self) = @_; 108 my ($self) = @_;
73 109
74 my $tab = $self->{cur}; 110 my $tab = $self->{cur};
75 111
112 # this is an extremely dirty way to force a configurenotify, but who cares
76 $tab->XMoveResizeWindow ( 113 $tab->XMoveResizeWindow (
77 $tab->parent, 114 $tab->parent,
78 0, $self->{tabheight} - 1, 115 0, $self->{tabheight} + 1,
79 $self->width, $self->height - $self->{tabheight} 116 $self->width, $self->height - $self->{tabheight}
80 ); 117 );
81 $tab->XMoveResizeWindow ( 118 $tab->XMoveResizeWindow (
82 $tab->parent, 119 $tab->parent,
83 0, $self->{tabheight}, 120 0, $self->{tabheight},
84 $self->width, $self->height - $self->{tabheight} 121 $self->width, $self->height - $self->{tabheight}
85 ); 122 );
86} 123}
87 124
125sub on_resize_all_windows {
126 my ($self, $width, $height) = @_;
127
128 1
129}
130
88sub copy_properties { 131sub copy_properties {
89 my ($self) = @_; 132 my ($self) = @_;
90 my $tab = $self->{cur}; 133 my $tab = $self->{cur};
91 134
92 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 135 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
93 136
94 my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); 137 my $current = delete $self->{current_properties};
95 138
139 # pass 1: copy over properties different or nonexisting
96 for my $atom ($tab->XListProperties ($tab->parent)) { 140 for my $atom ($tab->XListProperties ($tab->parent)) {
97 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 141 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
98
99 delete $our_props{$atom};
100 142
143 # fix up size hints
101 if ($atom == $wm_normal_hints) { 144 if ($atom == $wm_normal_hints) {
102 my (@hints) = unpack "l!*", $items; 145 my (@hints) = unpack "l!*", $items;
103 146
104 $hints[$_] += $self->{tabheight} for (4, 6, 16); 147 $hints[$_] += $self->{tabheight} for (4, 6, 16);
105 148
106 $items = pack "l!*", @hints; 149 $items = pack "l!*", @hints;
107 } 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
108 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 155 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
109 } 156 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
110 157
158 $self->{current_properties}{$atom} = [$type, $format, $items];
159 }
160
161 # pass 2, delete all extraneous properties
111 $self->XDeleteProperty ($self->parent, $_) for keys %our_props; 162 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
112} 163}
113 164
114sub make_current { 165sub make_current {
115 my ($self, $tab) = @_; 166 my ($self, $tab) = @_;
116 167
117 if (my $cur = $self->{cur}) { 168 if (my $cur = $self->{cur}) {
118 delete $cur->{activity}; 169 delete $cur->{activity};
119 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 170 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
120 $cur->focus_out; 171 $cur->focus_out;
121 } 172 }
122 173
123 $self->{cur} = $tab; 174 $self->{cur} = $tab;
124 175
125 $self->configure; 176 $self->configure;
126 $self->copy_properties; 177 $self->copy_properties;
127 $tab->focus_in; 178
179 $tab->focus_out; # just in case, should be a nop
180 $tab->focus_in if $self->focus;
181
128 $tab->XMapWindow ($tab->parent); 182 $tab->XMapWindow ($tab->parent);
129 delete $tab->{activity}; 183 delete $tab->{activity};
130 $self->refresh; 184 $self->refresh;
131 185
132 () 186 ()
187}
188
189sub on_focus_in {
190 my ($self, $event) = @_;
191
192 $self->{cur}->focus_in;
193
194 ()
195}
196
197sub on_focus_out {
198 my ($self, $event) = @_;
199
200 $self->{cur}->focus_out;
201
202 ()
203}
204
205sub on_tt_write {
206 my ($self, $octets) = @_;
207
208 $self->{cur}->tt_write ($octets);
209
210 1
211}
212
213sub on_key_press {
214 my ($self, $event) = @_;
215
216 $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time});
217
218 1
219}
220
221sub on_key_release {
222 my ($self, $event) = @_;
223
224 $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time});
225
226 1
133} 227}
134 228
135sub on_button_press { 229sub on_button_press {
136 1 230 1
137} 231}
155} 249}
156 250
157sub on_init { 251sub on_init {
158 my ($self) = @_; 252 my ($self) = @_;
159 253
160 for (qw(name perl_ext_1 perl_ext_2)) { 254 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
161 my $val = $self->resource ($_);
162
163 push @{ $self->{resource} }, [$_ => $val]
164 if defined $val;
165 }
166 255
167 $self->resource (int_bwidth => 0); 256 $self->resource (int_bwidth => 0);
168 $self->resource (name => "URxvt.tab"); 257 $self->resource (name => "URxvt.tabbed");
169 $self->resource (pty_fd => -1); 258 $self->resource (pty_fd => -1);
170 259
171 $self->option ($urxvt::OPTION{scrollBar}, 0); 260 $self->option ($urxvt::OPTION{scrollBar}, 0);
172 261
262 my $fg = $self->x_resource ("tabbar-fg");
263 my $bg = $self->x_resource ("tabbar-bg");
264 my $tabfg = $self->x_resource ("tab-fg");
265 my $tabbg = $self->x_resource ("tab-bg");
266
267 defined $fg or $fg = 3;
268 defined $bg or $bg = 0;
269 defined $tabfg or $tabfg = 0;
270 defined $tabbg or $tabbg = 1;
271
272 $self->{rs_tabbar} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $fg + 2, $bg + 2);
273 $self->{rs_tab} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $tabfg + 2, $tabbg + 2);
274
173 () 275 ()
174} 276}
175 277
176sub on_start { 278sub on_start {
177 my ($self) = @_; 279 my ($self) = @_;
178 280
179 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 281 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
180 282
283 $self->cmd_parse ("\033[?25l");
284
285 my @argv = $self->argv;
286
287 do {
288 shift @argv;
289 } while @argv && $argv[0] ne "-e";
290
181 $self->new_tab; 291 $self->new_tab (@argv);
182 292
183 () 293 ()
184} 294}
185 295
186sub on_configure_notify { 296sub on_configure_notify {
242 352
243 --$idx if $keysym == 0xff51; 353 --$idx if $keysym == 0xff51;
244 ++$idx if $keysym == 0xff53; 354 ++$idx if $keysym == 0xff53;
245 355
246 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 356 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
247 357
248 return 1; 358 return 1;
249 } elsif ($keysym == 0xff54) { 359 } elsif ($keysym == 0xff54) {
250 $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]);
251 374
252 return 1; 375 return 1;
253 } 376 }
254 } 377 }
255 378

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines