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