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.8 by root, Fri Jan 20 15:47:55 2006 UTC vs.
Revision 1.31 by root, Wed Jun 6 15:06:41 2012 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:tabbar-fg:tab bar foreground colour
4#:META:X_RESOURCE:tabbar-bg:tab bar background colour
5#:META:X_RESOURCE:tab-fg:tab foreground colour
6#:META:X_RESOURCE:tab-bg:tab background colour
7
3sub refresh { 8sub refresh {
4 my ($self) = @_; 9 my ($self) = @_;
5 10
6 my $ncol = $self->ncol; 11 my $ncol = $self->ncol;
7 12
8 my $text = " " x $ncol; 13 my $text = " " x $ncol;
9 my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; 14 my $rend = [($self->{rs_tabbar}) x $ncol];
10 15
11 my @ofs; 16 my @ofs;
12 17
13 substr $text, 0, 7, "[NEW] |"; 18 substr $text, 0, 7, "[NEW] |";
14 @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; 19 @$rend[0 .. 5] = ($self->{rs_tab}) x 6;
15 push @ofs, [0, 6, sub { $_[0]->new_tab }]; 20 push @ofs, [0, 6, sub { $_[0]->new_tab }];
16 21
17 my $ofs = 7; 22 my $ofs = 7;
18 my $idx = 0; 23 my $idx = 0;
19 24
20 for my $tab (@{ $self->{tabs} }) { 25 for my $tab (@{ $self->{tabs} }) {
21 $idx++; 26 $idx++;
22 27
28 my $act = $tab->{activity} && $tab != $self->{cur}
29 ? "*" : " ";
30
23 my $txt = " $idx "; 31 my $txt = "$act$idx$act";
24 my $len = length $txt; 32 my $len = length $txt;
25 33
26 substr $text, $ofs, $len + 1, "$txt|"; 34 substr $text, $ofs, $len + 1, "$txt|";
27 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len 35 @$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len
28 if $tab == $self->{cur}; 36 if $tab == $self->{cur};
29 37
30 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; 38 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
31 39
32 $ofs += $len + 1; 40 $ofs += $len + 1;
39 47
40 $self->want_refresh; 48 $self->want_refresh;
41} 49}
42 50
43sub new_tab { 51sub new_tab {
44 my ($self) = @_; 52 my ($self, @argv) = @_;
45
46 my $offset = $self->fheight;
47 53
48 # save a backlink to us, make sure tabbed is inactive 54 # save a backlink to us, make sure tabbed is inactive
49 push @urxvt::TERM_INIT, sub { 55 push @urxvt::TERM_INIT, sub {
50 my ($term) = @_; 56 my ($term) = @_;
51 $term->{parent} = $self; 57 $term->{parent} = $self;
52 58
53 $term->resource ($_->[0] => $_->[1]) 59 for (0 .. urxvt::NUM_RESOURCES - 1) {
54 for @{ $self->{resource} || [] }; 60 my $value = $self->{resource}[$_];
61
62 $term->resource ("+$_" => $value)
63 if defined $value;
64 }
55 65
56 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); 66 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
57
58 }; 67 };
59 68
60 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; 69 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
61 70
62 my $term = new urxvt::term 71 my $term = new urxvt::term
63 $self->env, $urxvt::RXVTNAME, 72 $self->env, $urxvt::RXVTNAME,
64 -embed => $self->parent, 73 -embed => $self->parent,
74 @argv,
65 ; 75 ;
66} 76}
67 77
68sub configure { 78sub configure {
69 my ($self) = @_; 79 my ($self) = @_;
70 80
71 my $tab = $self->{cur}; 81 my $tab = $self->{cur};
72 82
83 # this is an extremely dirty way to force a configurenotify, but who cares
84 $tab->XMoveResizeWindow (
85 $tab->parent,
86 0, $self->{tabheight} + 1,
87 $self->width, $self->height - $self->{tabheight}
88 );
73 $tab->XMoveResizeWindow ( 89 $tab->XMoveResizeWindow (
74 $tab->parent, 90 $tab->parent,
75 0, $self->{tabheight}, 91 0, $self->{tabheight},
76 $self->width, $self->height - $self->{tabheight} 92 $self->width, $self->height - $self->{tabheight}
77 ); 93 );
94}
95
96sub on_resize_all_windows {
97 my ($self, $width, $height) = @_;
98
99 1
100}
101
102sub copy_properties {
103 my ($self) = @_;
104 my $tab = $self->{cur};
78 105
79 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 106 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
80 107
108 my $current = delete $self->{current_properties};
109
110 # pass 1: copy over properties different or nonexisting
81 for my $atom ($tab->XListProperties ($tab->parent)) { 111 for my $atom ($tab->XListProperties ($tab->parent)) {
82 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 112 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
83 113
114 # fix up size hints
84 if ($atom == $wm_normal_hints) { 115 if ($atom == $wm_normal_hints) {
85 my (@hints) = unpack "l!*", $items; 116 my (@hints) = unpack "l!*", $items;
86 117
87 $hints[$_] += $self->{tabheight} for (4, 6, 16); 118 $hints[$_] += $self->{tabheight} for (4, 6, 16);
88 119
89 $items = pack "l!*", @hints; 120 $items = pack "l!*", @hints;
90 } 121 }
122
123 my $cur = delete $current->{$atom};
124
125 # update if changed, we assume empty items and zero type and format will not happen
91 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 126 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
92 } 127 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
93 128
94 $self->refresh; 129 $self->{current_properties}{$atom} = [$type, $format, $items];
130 }
131
132 # pass 2, delete all extraneous properties
133 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
95} 134}
96 135
97sub make_current { 136sub make_current {
98 my ($self, $tab) = @_; 137 my ($self, $tab) = @_;
99 138
100 if (my $cur = $self->{cur}) { 139 if (my $cur = $self->{cur}) {
140 delete $cur->{activity};
101 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 141 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
102 $cur->focus_out; 142 $cur->focus_out;
103 } 143 }
104 144
105 $self->{cur} = $tab; 145 $self->{cur} = $tab;
106 146
107 $self->configure; 147 $self->configure;
108 $tab->focus_in; 148 $self->copy_properties;
149
150 $tab->focus_out; # just in case, should be a nop
151 $tab->focus_in if $self->focus;
152
109 $tab->XMapWindow ($tab->parent); 153 $tab->XMapWindow ($tab->parent);
154 delete $tab->{activity};
110 $self->refresh; 155 $self->refresh;
111 156
112 () 157 ()
158}
159
160sub on_focus_in {
161 my ($self, $event) = @_;
162
163 $self->{cur}->focus_in;
164
165 ()
166}
167
168sub on_focus_out {
169 my ($self, $event) = @_;
170
171 $self->{cur}->focus_out;
172
173 ()
174}
175
176sub on_tt_write {
177 my ($self, $octets) = @_;
178
179 $self->{cur}->tt_write ($octets);
180
181 1
182}
183
184sub on_key_press {
185 my ($self, $event) = @_;
186
187 $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time});
188
189 1
190}
191
192sub on_key_release {
193 my ($self, $event) = @_;
194
195 $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time});
196
197 1
113} 198}
114 199
115sub on_button_press { 200sub on_button_press {
116 1 201 1
117} 202}
135} 220}
136 221
137sub on_init { 222sub on_init {
138 my ($self) = @_; 223 my ($self) = @_;
139 224
140 for (qw(name perl_ext_1 perl_ext_2)) { 225 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
141 my $val = $self->resource ($_);
142
143 push @{ $self->{resource} }, [$_ => $val]
144 if defined $val;
145 }
146 226
147 $self->resource (int_bwidth => 0); 227 $self->resource (int_bwidth => 0);
148 $self->resource (name => "URxvt.tab"); 228 $self->resource (name => "URxvt.tabbed");
149 $self->resource (pty_fd => -1); 229 $self->resource (pty_fd => -1);
150 230
151 $self->option ($urxvt::OPTION{scrollBar}, 0); 231 $self->option ($urxvt::OPTION{scrollBar}, 0);
152 232
233 my $fg = $self->x_resource ("tabbar-fg");
234 my $bg = $self->x_resource ("tabbar-bg");
235 my $tabfg = $self->x_resource ("tab-fg");
236 my $tabbg = $self->x_resource ("tab-bg");
237
238 defined $fg or $fg = 3;
239 defined $bg or $bg = 0;
240 defined $tabfg or $tabfg = 0;
241 defined $tabbg or $tabbg = 1;
242
243 $self->{rs_tabbar} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $fg + 2, $bg + 2);
244 $self->{rs_tab} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $tabfg + 2, $tabbg + 2);
245
153 () 246 ()
154} 247}
155 248
156sub on_start { 249sub on_start {
157 my ($self) = @_; 250 my ($self) = @_;
158 251
159 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 252 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
160 253
254 $self->cmd_parse ("\033[?25l");
255
256 my @argv = $self->argv;
257
258 do {
259 shift @argv;
260 } while @argv && $argv[0] ne "-e";
261
161 $self->new_tab; 262 $self->new_tab (@argv);
162 263
163 () 264 ()
164} 265}
165 266
166sub on_configure_notify { 267sub on_configure_notify {
167 my ($self, $event) = @_; 268 my ($self, $event) = @_;
168 269
169 $self->configure; 270 $self->configure;
271 $self->refresh;
170 272
171 () 273 ()
172} 274}
173 275
174sub on_wm_delete_window { 276sub on_wm_delete_window {
179 1 281 1
180} 282}
181 283
182sub tab_start { 284sub tab_start {
183 my ($self, $tab) = @_; 285 my ($self, $tab) = @_;
286
287 $tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask);
184 288
185 push @{ $self->{tabs} }, $tab; 289 push @{ $self->{tabs} }, $tab;
186 290
187# $tab->{name} ||= scalar @{ $self->{tabs} }; 291# $tab->{name} ||= scalar @{ $self->{tabs} };
188 $self->make_current ($tab); 292 $self->make_current ($tab);
211} 315}
212 316
213sub tab_key_press { 317sub tab_key_press {
214 my ($self, $tab, $event, $keysym, $str) = @_; 318 my ($self, $tab, $event, $keysym, $str) = @_;
215 319
216 if ($event->{state} & urxvt::ShiftMask 320 if ($event->{state} & urxvt::ShiftMask) {
217 && ($keysym == 0xff51 || $keysym == 0xff53)) { 321 if ($keysym == 0xff51 || $keysym == 0xff53) {
218 my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; 322 my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
219 323
220 --$idx if $keysym == 0xff51; 324 --$idx if $keysym == 0xff51;
221 ++$idx if $keysym == 0xff53; 325 ++$idx if $keysym == 0xff53;
222 326
223 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 327 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
224 $self->refresh; 328
329 return 1;
330 } elsif ($keysym == 0xff54) {
331 $self->new_tab;
332
333 return 1;
225 334 }
335 }
336 elsif ($event->{state} & urxvt::ControlMask) {
337 if ($keysym == 0xff51 || $keysym == 0xff53) {
338 my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
339 my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };
340
341 ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
342 ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
343
344 $self->make_current ($self->{tabs}[$idx2]);
345
226 return 1; 346 return 1;
347 }
227 } 348 }
228 349
229 () 350 ()
351}
352
353sub tab_property_notify {
354 my ($self, $tab, $event) = @_;
355
356 $self->copy_properties
357 if $event->{window} == $tab->parent;
358
359 ()
360}
361
362sub tab_activity {
363 my ($self, $tab) = @_;
364
365 $self->refresh;
230} 366}
231 367
232package urxvt::ext::tabbed::tab; 368package urxvt::ext::tabbed::tab;
233 369
234# helper extension implementing the subwindows of a tabbed terminal. 370# helper extension implementing the subwindows of a tabbed terminal.
235# simply proxies all interesting calls back to the tabbed class. 371# simply proxies all interesting calls back to the tabbed class.
236 372
237{ 373{
238 for my $hook qw(start destroy key_press) { 374 for my $hook qw(start destroy key_press property_notify) {
239 eval qq{ 375 eval qq{
240 sub on_$hook { 376 sub on_$hook {
241 my \$parent = \$_[0]{term}{parent} 377 my \$parent = \$_[0]{term}{parent}
242 or return; 378 or return;
243 \$parent->tab_$hook (\@_) 379 \$parent->tab_$hook (\@_)
245 }; 381 };
246 die if $@; 382 die if $@;
247 } 383 }
248} 384}
249 385
386sub on_add_lines {
387 $_[0]->{activity}++
388 or $_[0]{term}{parent}->tab_activity ($_[0]);
389 ()
390}
250 391
251 392

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines