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.4 by root, Fri Jan 20 13:32:29 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
49} 66}
50 67
51sub configure { 68sub configure {
52 my ($self) = @_; 69 my ($self) = @_;
53 70
71 my $tab = $self->{cur};
72
54 $self->{cur}->XMoveResizeWindow ( 73 $tab->XMoveResizeWindow (
55 $self->{cur}->parent, 74 $tab->parent,
56 0, $self->{tabheight}, 75 0, $self->{tabheight},
57 $self->width, $self->height - $self->{tabheight} 76 $self->width, $self->height - $self->{tabheight}
58 ); 77 );
59}
60
61sub make_current {
62 my ($self, $tab) = @_;
63
64 if (my $cur = $self->{cur}) {
65 $cur->XUnmapWindow ($cur->parent)
66 if $cur->mapped;
67 }
68
69 $self->{cur} = $tab;
70
71 $self->configure;
72 78
73 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 79 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
74 80
75 for my $atom ($tab->XListProperties ($tab->parent)) { 81 for my $atom ($tab->XListProperties ($tab->parent)) {
76 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 82 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
77 83
78 if ($atom == $wm_normal_hints) { 84 if ($atom == $wm_normal_hints) {
79 my (@hints) = unpack "l!*", $items; 85 my (@hints) = unpack "l!*", $items;
86
80 $hints[ 4] += $self->{tabheight}; 87 $hints[$_] += $self->{tabheight} for (4, 6, 16);
81 $hints[16] += $self->{tabheight}; 88
82 $items = pack "l!*", @hints; 89 $items = pack "l!*", @hints;
83 } 90 }
84 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 91 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
85 } 92 }
86 93
94 $self->refresh;
95}
96
97sub make_current {
98 my ($self, $tab) = @_;
99
100 if (my $cur = $self->{cur}) {
101 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
102 $cur->focus_out;
103 }
104
105 $self->{cur} = $tab;
106
107 $self->configure;
108 $tab->focus_in;
87 $tab->XMapWindow ($tab->parent); 109 $tab->XMapWindow ($tab->parent);
88
89 $self->refresh; 110 $self->refresh;
90 111
91 () 112 ()
92} 113}
93 114
96} 117}
97 118
98sub on_button_release { 119sub on_button_release {
99 my ($self, $event) = @_; 120 my ($self, $event) = @_;
100 121
101 my $ofs = $self->{tabofs};
102
103 if ($event->{row} == 0) { 122 if ($event->{row} == 0) {
104 for my $i (0 .. @$ofs - 2) { 123 for my $button (@{ $self->{tabofs} }) {
124 $button->[2]->($self, $event)
105 if ($event->{col} >= $ofs->[$i] 125 if $event->{col} >= $button->[0]
106 && $event->{col} < $ofs->[$i+1]) { 126 && $event->{col} < $button->[1];
107 $self->make_current ($self->{tabs}[$i]);
108 }
109 } 127 }
110 } 128 }
111 129
112 1 130 1
113} 131}
138sub on_start { 156sub on_start {
139 my ($self) = @_; 157 my ($self) = @_;
140 158
141 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; 159 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
142 160
143 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
144 $self->new_tab;
145 $self->new_tab;
146 $self->new_tab; 161 $self->new_tab;
147 162
148 () 163 ()
149} 164}
150 165
167sub tab_start { 182sub tab_start {
168 my ($self, $tab) = @_; 183 my ($self, $tab) = @_;
169 184
170 push @{ $self->{tabs} }, $tab; 185 push @{ $self->{tabs} }, $tab;
171 186
172 $tab->{name} ||= scalar @{ $self->{tabs} }; 187# $tab->{name} ||= scalar @{ $self->{tabs} };
173 $self->make_current ($tab); 188 $self->make_current ($tab);
174 189
175 () 190 ()
176} 191}
177 192
182 197
183 if (@{ $self->{tabs} }) { 198 if (@{ $self->{tabs} }) {
184 if ($self->{cur} == $tab) { 199 if ($self->{cur} == $tab) {
185 delete $self->{cur}; 200 delete $self->{cur};
186 $self->make_current ($self->{tabs}[-1]); 201 $self->make_current ($self->{tabs}[-1]);
202 } else {
203 $self->refresh;
187 } 204 }
188 } else { 205 } else {
189 # delay destruction a tiny bit 206 # delay destruction a tiny bit
190 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); 207 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy });
191 } 208 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines