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.17 by root, Sat Feb 11 02:01:16 2006 UTC vs.
Revision 1.32 by root, Wed Jun 6 15:09:49 2012 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
2 7
3sub refresh { 8sub refresh {
4 my ($self) = @_; 9 my ($self) = @_;
5 10
6 my $ncol = $self->ncol; 11 my $ncol = $self->ncol;
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) = @_;
84 0, $self->{tabheight}, 91 0, $self->{tabheight},
85 $self->width, $self->height - $self->{tabheight} 92 $self->width, $self->height - $self->{tabheight}
86 ); 93 );
87} 94}
88 95
96sub on_resize_all_windows {
97 my ($self, $width, $height) = @_;
98
99 1
100}
101
89sub copy_properties { 102sub copy_properties {
90 my ($self) = @_; 103 my ($self) = @_;
91 my $tab = $self->{cur}; 104 my $tab = $self->{cur};
92 105
93 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 106 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
94 107
95 my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); 108 my $current = delete $self->{current_properties};
96 109
97 delete $our_props{$self->XInternAtom ($_)} for qw(WM_STATE WM_ICON_SIZE); 110 # pass 1: copy over properties different or nonexisting
98
99 for my $atom ($tab->XListProperties ($tab->parent)) { 111 for my $atom ($tab->XListProperties ($tab->parent)) {
100 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 112 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
101
102 delete $our_props{$atom};
103 113
114 # fix up size hints
104 if ($atom == $wm_normal_hints) { 115 if ($atom == $wm_normal_hints) {
105 my (@hints) = unpack "l!*", $items; 116 my (@hints) = unpack "l!*", $items;
106 117
107 $hints[$_] += $self->{tabheight} for (4, 6, 16); 118 $hints[$_] += $self->{tabheight} for (4, 6, 16);
108 119
109 $items = pack "l!*", @hints; 120 $items = pack "l!*", @hints;
110 } 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
111 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 126 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
112 } 127 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
113 128
129 $self->{current_properties}{$atom} = [$type, $format, $items];
130 }
131
132 # pass 2, delete all extraneous properties
114 $self->XDeleteProperty ($self->parent, $_) for keys %our_props; 133 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
115} 134}
116 135
117sub make_current { 136sub make_current {
118 my ($self, $tab) = @_; 137 my ($self, $tab) = @_;
119 138
120 if (my $cur = $self->{cur}) { 139 if (my $cur = $self->{cur}) {
121 delete $cur->{activity}; 140 delete $cur->{activity};
122 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 141 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
123 $cur->focus_out; 142 $cur->focus_out;
124 } 143 }
125 144
126 $self->{cur} = $tab; 145 $self->{cur} = $tab;
127 146
128 $self->configure; 147 $self->configure;
129 $self->copy_properties; 148 $self->copy_properties;
130 $tab->focus_in; 149
150 $tab->focus_out; # just in case, should be a nop
151 $tab->focus_in if $self->focus;
152
131 $tab->XMapWindow ($tab->parent); 153 $tab->XMapWindow ($tab->parent);
132 delete $tab->{activity}; 154 delete $tab->{activity};
133 $self->refresh; 155 $self->refresh;
134 156
135 () 157 ()
147 my ($self, $event) = @_; 169 my ($self, $event) = @_;
148 170
149 $self->{cur}->focus_out; 171 $self->{cur}->focus_out;
150 172
151 () 173 ()
174}
175
176sub on_tt_write {
177 my ($self, $octets) = @_;
178
179 $self->{cur}->tt_write ($octets);
180
181 1
152} 182}
153 183
154sub on_key_press { 184sub on_key_press {
155 my ($self, $event) = @_; 185 my ($self, $event) = @_;
156 186
190} 220}
191 221
192sub on_init { 222sub on_init {
193 my ($self) = @_; 223 my ($self) = @_;
194 224
195 for (qw(name perl_ext_1 perl_ext_2)) { 225 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
196 my $val = $self->resource ($_);
197
198 push @{ $self->{resource} }, [$_ => $val]
199 if defined $val;
200 }
201 226
202 $self->resource (int_bwidth => 0); 227 $self->resource (int_bwidth => 0);
203 $self->resource (name => "URxvt.tabbed"); 228 $self->resource (name => "URxvt.tabbed");
204 $self->resource (pty_fd => -1); 229 $self->resource (pty_fd => -1);
205 230
226 251
227 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 252 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
228 253
229 $self->cmd_parse ("\033[?25l"); 254 $self->cmd_parse ("\033[?25l");
230 255
256 my @argv = $self->argv;
257
258 do {
259 shift @argv;
260 } while @argv && $argv[0] ne "-e";
261
231 $self->new_tab; 262 $self->new_tab (@argv);
232 263
233 () 264 ()
234} 265}
235 266
236sub on_configure_notify { 267sub on_configure_notify {
292 323
293 --$idx if $keysym == 0xff51; 324 --$idx if $keysym == 0xff51;
294 ++$idx if $keysym == 0xff53; 325 ++$idx if $keysym == 0xff53;
295 326
296 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 327 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
297 328
298 return 1; 329 return 1;
299 } elsif ($keysym == 0xff54) { 330 } elsif ($keysym == 0xff54) {
300 $self->new_tab; 331 $self->new_tab;
332
333 return 1;
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]);
301 345
302 return 1; 346 return 1;
303 } 347 }
304 } 348 }
305 349

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines