ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/tabbed
(Generate patch)

Comparing rxvt-unicode/src/perl/tabbed (file contents):
Revision 1.5 by root, Fri Jan 20 14:02:41 2006 UTC vs.
Revision 1.7 by root, Fri Jan 20 15:40:39 2006 UTC

1#! perl 1#! perl
2 2
3sub refresh { 3sub refresh {
4 my ($self) = @_; 4 my ($self) = @_;
5 5
6 my $cmd = "\x1b[H\x1b[7m\x1b[K"; 6 my $ncol = $self->ncol;
7 my $txt; 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
8 my @ofs = (0); 17 my $ofs = 7;
18 my $idx = 0;
9 19
10 for my $tab (@{ $self->{tabs} }) { 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
11 if ($tab == $self->{cur}) { 28 if $tab == $self->{cur};
12 $txt = " [$tab->{name}] ";
13 } else {
14 $txt = " $tab->{name} ";
15 }
16 29
17 $cmd .= $txt; 30 push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
18 push @ofs, $ofs[-1] + length $txt; 31
32 $ofs += $len + 1;
19 } 33 }
20 34
21 $self->{tabofs} = \@ofs; 35 $self->{tabofs} = \@ofs;
22 36
23 $self->cmd_parse ($self->locale_encode ($cmd)); 37 $self->ROW_t (0, $text, 0, 0, $ncol);
38 $self->ROW_r (0, $rend, 0, 0, $ncol);
39
40 $self->want_refresh;
24} 41}
25 42
26sub new_tab { 43sub new_tab {
27 my ($self) = @_; 44 my ($self) = @_;
28 45
65 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 82 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
66 83
67 if ($atom == $wm_normal_hints) { 84 if ($atom == $wm_normal_hints) {
68 my (@hints) = unpack "l!*", $items; 85 my (@hints) = unpack "l!*", $items;
69 86
70 $hints[ 4] += $self->{tabheight}; 87 $hints[$_] += $self->{tabheight} for (4, 6, 16);
71 $hints[16] += $self->{tabheight}; 88
89 $items = pack "l!*", @hints;
72 } 90 }
73 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 91 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
74 } 92 }
93
94 $self->refresh;
75} 95}
76 96
77sub make_current { 97sub make_current {
78 my ($self, $tab) = @_; 98 my ($self, $tab) = @_;
79 99
80 if (my $cur = $self->{cur}) { 100 if (my $cur = $self->{cur}) {
81 $cur->XUnmapWindow ($cur->parent) 101 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
82 if $cur->mapped; 102 $cur->focus_out;
83 } 103 }
84 104
85 $self->{cur} = $tab; 105 $self->{cur} = $tab;
86 106
87 $self->configure; 107 $self->configure;
88 108 $tab->focus_in;
89 $tab->XMapWindow ($tab->parent); 109 $tab->XMapWindow ($tab->parent);
90
91 $self->refresh; 110 $self->refresh;
92 111
93 () 112 ()
94} 113}
95 114
98} 117}
99 118
100sub on_button_release { 119sub on_button_release {
101 my ($self, $event) = @_; 120 my ($self, $event) = @_;
102 121
103 my $ofs = $self->{tabofs};
104
105 if ($event->{row} == 0) { 122 if ($event->{row} == 0) {
106 for my $i (0 .. @$ofs - 2) { 123 for my $button (@{ $self->{tabofs} }) {
124 $button->[2]->($self, $event)
107 if ($event->{col} >= $ofs->[$i] 125 if $event->{col} >= $button->[0]
108 && $event->{col} < $ofs->[$i+1]) { 126 && $event->{col} < $button->[1];
109 $self->make_current ($self->{tabs}[$i]);
110 }
111 } 127 }
112 } 128 }
113 129
114 1 130 1
115} 131}
140sub on_start { 156sub on_start {
141 my ($self) = @_; 157 my ($self) = @_;
142 158
143 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 159 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
144 160
145 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
146 $self->new_tab;
147 $self->new_tab;
148 $self->new_tab; 161 $self->new_tab;
149 162
150 () 163 ()
151} 164}
152 165
169sub tab_start { 182sub tab_start {
170 my ($self, $tab) = @_; 183 my ($self, $tab) = @_;
171 184
172 push @{ $self->{tabs} }, $tab; 185 push @{ $self->{tabs} }, $tab;
173 186
174 $tab->{name} ||= scalar @{ $self->{tabs} }; 187# $tab->{name} ||= scalar @{ $self->{tabs} };
175 $self->make_current ($tab); 188 $self->make_current ($tab);
176 189
177 () 190 ()
178} 191}
179 192
184 197
185 if (@{ $self->{tabs} }) { 198 if (@{ $self->{tabs} }) {
186 if ($self->{cur} == $tab) { 199 if ($self->{cur} == $tab) {
187 delete $self->{cur}; 200 delete $self->{cur};
188 $self->make_current ($self->{tabs}[-1]); 201 $self->make_current ($self->{tabs}[-1]);
202 } else {
203 $self->refresh;
189 } 204 }
190 } else { 205 } else {
191 # delay destruction a tiny bit 206 # delay destruction a tiny bit
192 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); 207 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy });
193 } 208 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines