ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/tabbed
Revision: 1.7
Committed: Fri Jan 20 15:40:39 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.6: +23 -22 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 sub refresh {
4 my ($self) = @_;
5
6 my $ncol = $self->ncol;
7
8 my $text = " " x $ncol;
9 my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol];
10
11 my @ofs;
12
13 substr $text, 0, 7, "[NEW] |";
14 @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6;
15 push @ofs, [0, 6, sub { $_[0]->new_tab }];
16
17 my $ofs = 7;
18 my $idx = 0;
19
20 for my $tab (@{ $self->{tabs} }) {
21 $idx++;
22
23 my $txt = " $idx ";
24 my $len = length $txt;
25
26 substr $text, $ofs, $len + 1, "$txt|";
27 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len
28 if $tab == $self->{cur};
29
30 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
31
32 $ofs += $len + 1;
33 }
34
35 $self->{tabofs} = \@ofs;
36
37 $self->ROW_t (0, $text, 0, 0, $ncol);
38 $self->ROW_r (0, $rend, 0, 0, $ncol);
39
40 $self->want_refresh;
41 }
42
43 sub new_tab {
44 my ($self) = @_;
45
46 my $offset = $self->fheight;
47
48 # save a backlink to us, make sure tabbed is inactive
49 push @urxvt::TERM_INIT, sub {
50 my ($term) = @_;
51 $term->{parent} = $self;
52
53 $term->resource ($_->[0] => $_->[1])
54 for @{ $self->{resource} || [] };
55
56 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
57
58 };
59
60 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
61
62 my $term = new urxvt::term
63 $self->env, $urxvt::RXVTNAME,
64 -embed => $self->parent,
65 ;
66 }
67
68 sub configure {
69 my ($self) = @_;
70
71 my $tab = $self->{cur};
72
73 $tab->XMoveResizeWindow (
74 $tab->parent,
75 0, $self->{tabheight},
76 $self->width, $self->height - $self->{tabheight}
77 );
78
79 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
80
81 for my $atom ($tab->XListProperties ($tab->parent)) {
82 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
83
84 if ($atom == $wm_normal_hints) {
85 my (@hints) = unpack "l!*", $items;
86
87 $hints[$_] += $self->{tabheight} for (4, 6, 16);
88
89 $items = pack "l!*", @hints;
90 }
91 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
92 }
93
94 $self->refresh;
95 }
96
97 sub make_current {
98 my ($self, $tab) = @_;
99
100 if (my $cur = $self->{cur}) {
101 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
102 $cur->focus_out;
103 }
104
105 $self->{cur} = $tab;
106
107 $self->configure;
108 $tab->focus_in;
109 $tab->XMapWindow ($tab->parent);
110 $self->refresh;
111
112 ()
113 }
114
115 sub on_button_press {
116 1
117 }
118
119 sub on_button_release {
120 my ($self, $event) = @_;
121
122 if ($event->{row} == 0) {
123 for my $button (@{ $self->{tabofs} }) {
124 $button->[2]->($self, $event)
125 if $event->{col} >= $button->[0]
126 && $event->{col} < $button->[1];
127 }
128 }
129
130 1
131 }
132
133 sub on_motion_notify {
134 1
135 }
136
137 sub on_init {
138 my ($self) = @_;
139
140 for (qw(name perl_ext_1 perl_ext_2)) {
141 my $val = $self->resource ($_);
142
143 push @{ $self->{resource} }, [$_ => $val]
144 if defined $val;
145 }
146
147 $self->resource (int_bwidth => 0);
148 $self->resource (name => "URxvt.tab");
149 $self->resource (pty_fd => -1);
150
151 $self->option ($urxvt::OPTION{scrollBar}, 0);
152
153 ()
154 }
155
156 sub on_start {
157 my ($self) = @_;
158
159 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
160
161 $self->new_tab;
162
163 ()
164 }
165
166 sub on_configure_notify {
167 my ($self, $event) = @_;
168
169 $self->configure;
170
171 ()
172 }
173
174 sub on_wm_delete_window {
175 my ($self) = @_;
176
177 $_->destroy for @{ $self->{tabs} };
178
179 1
180 }
181
182 sub tab_start {
183 my ($self, $tab) = @_;
184
185 push @{ $self->{tabs} }, $tab;
186
187 # $tab->{name} ||= scalar @{ $self->{tabs} };
188 $self->make_current ($tab);
189
190 ()
191 }
192
193 sub tab_destroy {
194 my ($self, $tab) = @_;
195
196 $self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ];
197
198 if (@{ $self->{tabs} }) {
199 if ($self->{cur} == $tab) {
200 delete $self->{cur};
201 $self->make_current ($self->{tabs}[-1]);
202 } else {
203 $self->refresh;
204 }
205 } else {
206 # delay destruction a tiny bit
207 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy });
208 }
209
210 ()
211 }
212
213 package urxvt::ext::tabbed::tab;
214
215 # helper extension implementing the subwindows of a tabbed terminal.
216 # simply proxies all interesting calls back to the tabbed class.
217
218 {
219 for my $hook qw(start destroy) {
220 eval qq{
221 sub on_$hook {
222 my \$parent = \$_[0]{term}{parent}
223 or return;
224 \$parent->tab_$hook (\@_)
225 }
226 };
227 die if $@;
228 }
229 }
230
231
232