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