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.3 by root, Fri Jan 20 12:18:05 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 for my $atom ($tab->XListProperties ($tab->parent)) {
76 warn "$atom\n";
77 }
78
79 $tab->XMapWindow ($tab->parent); 109 $tab->XMapWindow ($tab->parent);
80
81 $self->refresh; 110 $self->refresh;
82 111
83 () 112 ()
84} 113}
85 114
88} 117}
89 118
90sub on_button_release { 119sub on_button_release {
91 my ($self, $event) = @_; 120 my ($self, $event) = @_;
92 121
93 my $ofs = $self->{tabofs};
94
95 if ($event->{row} == 0) { 122 if ($event->{row} == 0) {
96 for my $i (0 .. @$ofs - 2) { 123 for my $button (@{ $self->{tabofs} }) {
124 $button->[2]->($self, $event)
97 if ($event->{col} >= $ofs->[$i] 125 if $event->{col} >= $button->[0]
98 && $event->{col} < $ofs->[$i+1]) { 126 && $event->{col} < $button->[1];
99 $self->make_current ($self->{tabs}[$i]);
100 }
101 } 127 }
102 } 128 }
103 129
104 1 130 1
105} 131}
128} 154}
129 155
130sub on_start { 156sub on_start {
131 my ($self) = @_; 157 my ($self) = @_;
132 158
133 $self->cmd_parse ("\x1b[?25l\x1b[?7l"); 159 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
134 $self->new_tab; 160
135 $self->new_tab;
136 $self->new_tab; 161 $self->new_tab;
137 162
138 () 163 ()
139} 164}
140 165
157sub tab_start { 182sub tab_start {
158 my ($self, $tab) = @_; 183 my ($self, $tab) = @_;
159 184
160 push @{ $self->{tabs} }, $tab; 185 push @{ $self->{tabs} }, $tab;
161 186
162 $tab->{name} ||= scalar @{ $self->{tabs} }; 187# $tab->{name} ||= scalar @{ $self->{tabs} };
163 $self->make_current ($tab); 188 $self->make_current ($tab);
164 189
165 () 190 ()
166} 191}
167 192
172 197
173 if (@{ $self->{tabs} }) { 198 if (@{ $self->{tabs} }) {
174 if ($self->{cur} == $tab) { 199 if ($self->{cur} == $tab) {
175 delete $self->{cur}; 200 delete $self->{cur};
176 $self->make_current ($self->{tabs}[-1]); 201 $self->make_current ($self->{tabs}[-1]);
202 } else {
203 $self->refresh;
177 } 204 }
178 } else { 205 } else {
179 # delay destruction a tiny bit 206 # delay destruction a tiny bit
180 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); 207 $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy });
181 } 208 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines