ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/tabbed
Revision: 1.1
Committed: Fri Jan 20 12:16:28 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

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