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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines