ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/tabbed
Revision: 1.5
Committed: Fri Jan 20 14:02:41 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.4: +18 -16 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.5 my $tab = $self->{cur};
55    
56     $tab->XMoveResizeWindow (
57     $tab->parent,
58 root 1.4 0, $self->{tabheight},
59     $self->width, $self->height - $self->{tabheight}
60 root 1.1 );
61 root 1.5
62     my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
63    
64     for my $atom ($tab->XListProperties ($tab->parent)) {
65     my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
66    
67     if ($atom == $wm_normal_hints) {
68     my (@hints) = unpack "l!*", $items;
69    
70     $hints[ 4] += $self->{tabheight};
71     $hints[16] += $self->{tabheight};
72     }
73     $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
74     }
75 root 1.1 }
76    
77     sub make_current {
78     my ($self, $tab) = @_;
79    
80     if (my $cur = $self->{cur}) {
81     $cur->XUnmapWindow ($cur->parent)
82     if $cur->mapped;
83     }
84    
85     $self->{cur} = $tab;
86    
87     $self->configure;
88    
89     $tab->XMapWindow ($tab->parent);
90    
91     $self->refresh;
92    
93     ()
94     }
95    
96     sub on_button_press {
97     1
98     }
99    
100     sub on_button_release {
101     my ($self, $event) = @_;
102    
103     my $ofs = $self->{tabofs};
104    
105     if ($event->{row} == 0) {
106     for my $i (0 .. @$ofs - 2) {
107     if ($event->{col} >= $ofs->[$i]
108     && $event->{col} < $ofs->[$i+1]) {
109     $self->make_current ($self->{tabs}[$i]);
110     }
111     }
112     }
113    
114     1
115     }
116    
117     sub on_motion_notify {
118     1
119     }
120    
121     sub on_init {
122     my ($self) = @_;
123    
124     for (qw(name perl_ext_1 perl_ext_2)) {
125     my $val = $self->resource ($_);
126    
127     push @{ $self->{resource} }, [$_ => $val]
128     if defined $val;
129     }
130    
131     $self->resource (int_bwidth => 0);
132     $self->resource (name => "URxvt.tab");
133     $self->resource (pty_fd => -1);
134    
135     $self->option ($urxvt::OPTION{scrollBar}, 0);
136    
137     ()
138     }
139    
140     sub on_start {
141     my ($self) = @_;
142    
143 root 1.4 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
144    
145 root 1.1 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
146     $self->new_tab;
147     $self->new_tab;
148     $self->new_tab;
149    
150     ()
151     }
152    
153     sub on_configure_notify {
154     my ($self, $event) = @_;
155    
156     $self->configure;
157    
158     ()
159     }
160    
161     sub on_wm_delete_window {
162     my ($self) = @_;
163    
164     $_->destroy for @{ $self->{tabs} };
165    
166     1
167     }
168    
169     sub tab_start {
170     my ($self, $tab) = @_;
171    
172     push @{ $self->{tabs} }, $tab;
173    
174     $tab->{name} ||= scalar @{ $self->{tabs} };
175     $self->make_current ($tab);
176    
177     ()
178     }
179    
180     sub tab_destroy {
181     my ($self, $tab) = @_;
182    
183     $self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ];
184    
185     if (@{ $self->{tabs} }) {
186     if ($self->{cur} == $tab) {
187     delete $self->{cur};
188     $self->make_current ($self->{tabs}[-1]);
189     }
190     } else {
191     # delay destruction a tiny bit
192     $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy });
193     }
194    
195     ()
196     }
197    
198     package urxvt::ext::tabbed::tab;
199    
200     # helper extension implementing the subwindows of a tabbed terminal.
201     # simply proxies all interesting calls back to the tabbed class.
202    
203     {
204     for my $hook qw(start destroy) {
205     eval qq{
206     sub on_$hook {
207     my \$parent = \$_[0]{term}{parent}
208     or return;
209     \$parent->tab_$hook (\@_)
210     }
211     };
212     die if $@;
213     }
214     }
215    
216    
217