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.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
25 30
26 my $txt = "$act$idx$act"; 31 my $txt = "$act$idx$act";
27 my $len = length $txt; 32 my $len = length $txt;
28 33
29 substr $text, $ofs, $len + 1, "$txt|"; 34 substr $text, $ofs, $len + 1, "$txt|";
30 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len 35 @$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len
31 if $tab == $self->{cur}; 36 if $tab == $self->{cur};
32 37
33 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; 38 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
34 39
35 $ofs += $len + 1; 40 $ofs += $len + 1;
42 47
43 $self->want_refresh; 48 $self->want_refresh;
44} 49}
45 50
46sub new_tab { 51sub new_tab {
47 my ($self) = @_; 52 my ($self, @argv) = @_;
48
49 my $offset = $self->fheight;
50 53
51 # save a backlink to us, make sure tabbed is inactive 54 # save a backlink to us, make sure tabbed is inactive
52 push @urxvt::TERM_INIT, sub { 55 push @urxvt::TERM_INIT, sub {
53 my ($term) = @_; 56 my ($term) = @_;
54 $term->{parent} = $self; 57 $term->{parent} = $self;
55 58
56 $term->resource ($_->[0] => $_->[1]) 59 for (0 .. urxvt::NUM_RESOURCES - 1) {
57 for @{ $self->{resource} || [] }; 60 my $value = $self->{resource}[$_];
61
62 $term->resource ("+$_" => $value)
63 if defined $value;
64 }
58 65
59 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); 66 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
60
61 }; 67 };
62 68
63 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; 69 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
64 70
65 my $term = new urxvt::term 71 my $term = new urxvt::term
66 $self->env, $urxvt::RXVTNAME, 72 $self->env, $urxvt::RXVTNAME,
67 -embed => $self->parent, 73 -embed => $self->parent,
74 @argv,
68 ; 75 ;
69} 76}
70 77
71sub configure { 78sub configure {
72 my ($self) = @_; 79 my ($self) = @_;
73 80
74 my $tab = $self->{cur}; 81 my $tab = $self->{cur};
75 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 );
76 $tab->XMoveResizeWindow ( 89 $tab->XMoveResizeWindow (
77 $tab->parent, 90 $tab->parent,
78 0, $self->{tabheight}, 91 0, $self->{tabheight},
79 $self->width, $self->height - $self->{tabheight} 92 $self->width, $self->height - $self->{tabheight}
80 ); 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};
81 105
82 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 106 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
83 107
108 my $current = delete $self->{current_properties};
109
110 # pass 1: copy over properties different or nonexisting
84 for my $atom ($tab->XListProperties ($tab->parent)) { 111 for my $atom ($tab->XListProperties ($tab->parent)) {
85 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 112 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
86 113
114 # fix up size hints
87 if ($atom == $wm_normal_hints) { 115 if ($atom == $wm_normal_hints) {
88 my (@hints) = unpack "l!*", $items; 116 my (@hints) = unpack "l!*", $items;
89 117
90 $hints[$_] += $self->{tabheight} for (4, 6, 16); 118 $hints[$_] += $self->{tabheight} for (4, 6, 16);
91 119
92 $items = pack "l!*", @hints; 120 $items = pack "l!*", @hints;
93 } 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
94 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 126 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
95 } 127 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
96 128
97 $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;
98} 134}
99 135
100sub make_current { 136sub make_current {
101 my ($self, $tab) = @_; 137 my ($self, $tab) = @_;
102 138
103 if (my $cur = $self->{cur}) { 139 if (my $cur = $self->{cur}) {
104 delete $cur->{activity}; 140 delete $cur->{activity};
105 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 141 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
106 $cur->focus_out; 142 $cur->focus_out;
107 } 143 }
108 144
109 $self->{cur} = $tab; 145 $self->{cur} = $tab;
110 146
111 $self->configure; 147 $self->configure;
112 $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
113 $tab->XMapWindow ($tab->parent); 153 $tab->XMapWindow ($tab->parent);
114 delete $tab->{activity}; 154 delete $tab->{activity};
115 $self->refresh; 155 $self->refresh;
116 156
117 () 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
118} 198}
119 199
120sub on_button_press { 200sub on_button_press {
121 1 201 1
122} 202}
140} 220}
141 221
142sub on_init { 222sub on_init {
143 my ($self) = @_; 223 my ($self) = @_;
144 224
145 for (qw(name perl_ext_1 perl_ext_2)) { 225 $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 226
152 $self->resource (int_bwidth => 0); 227 $self->resource (int_bwidth => 0);
153 $self->resource (name => "URxvt.tab"); 228 $self->resource (name => "URxvt.tabbed");
154 $self->resource (pty_fd => -1); 229 $self->resource (pty_fd => -1);
155 230
156 $self->option ($urxvt::OPTION{scrollBar}, 0); 231 $self->option ($urxvt::OPTION{scrollBar}, 0);
157 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
158 () 246 ()
159} 247}
160 248
161sub on_start { 249sub on_start {
162 my ($self) = @_; 250 my ($self) = @_;
163 251
164 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 252 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
165 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
166 $self->new_tab; 262 $self->new_tab (@argv);
167 263
168 () 264 ()
169} 265}
170 266
171sub on_configure_notify { 267sub on_configure_notify {
172 my ($self, $event) = @_; 268 my ($self, $event) = @_;
173 269
174 $self->configure; 270 $self->configure;
271 $self->refresh;
175 272
176 () 273 ()
177} 274}
178 275
179sub on_wm_delete_window { 276sub on_wm_delete_window {
184 1 281 1
185} 282}
186 283
187sub tab_start { 284sub tab_start {
188 my ($self, $tab) = @_; 285 my ($self, $tab) = @_;
286
287 $tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask);
189 288
190 push @{ $self->{tabs} }, $tab; 289 push @{ $self->{tabs} }, $tab;
191 290
192# $tab->{name} ||= scalar @{ $self->{tabs} }; 291# $tab->{name} ||= scalar @{ $self->{tabs} };
193 $self->make_current ($tab); 292 $self->make_current ($tab);
224 323
225 --$idx if $keysym == 0xff51; 324 --$idx if $keysym == 0xff51;
226 ++$idx if $keysym == 0xff53; 325 ++$idx if $keysym == 0xff53;
227 326
228 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 327 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
229 328
230 return 1; 329 return 1;
231 } elsif ($keysym == 0xff54) { 330 } elsif ($keysym == 0xff54) {
232 $self->new_tab; 331 $self->new_tab;
233 332
234 return 1; 333 return 1;
235 } 334 }
236 } 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
346 return 1;
347 }
348 }
349
350 ()
351}
352
353sub tab_property_notify {
354 my ($self, $tab, $event) = @_;
355
356 $self->copy_properties
357 if $event->{window} == $tab->parent;
237 358
238 () 359 ()
239} 360}
240 361
241sub tab_activity { 362sub tab_activity {
248 369
249# helper extension implementing the subwindows of a tabbed terminal. 370# helper extension implementing the subwindows of a tabbed terminal.
250# simply proxies all interesting calls back to the tabbed class. 371# simply proxies all interesting calls back to the tabbed class.
251 372
252{ 373{
253 for my $hook qw(start destroy key_press) { 374 for my $hook qw(start destroy key_press property_notify) {
254 eval qq{ 375 eval qq{
255 sub on_$hook { 376 sub on_$hook {
256 my \$parent = \$_[0]{term}{parent} 377 my \$parent = \$_[0]{term}{parent}
257 or return; 378 or return;
258 \$parent->tab_$hook (\@_) 379 \$parent->tab_$hook (\@_)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines