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.6 by root, Fri Jan 20 15:24:24 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
8 my $text = " " x $ncol;
9 my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol];
10
7 my $txt; 11 my $txt;
8 my @ofs = (0); 12 my $ofs = 0;
13 my @ofs;
9 14
10 for my $tab (@{ $self->{tabs} }) { 15 for my $tab (@{ $self->{tabs} }) {
11 if ($tab == $self->{cur}) {
12 $txt = " [$tab->{name}] "; 16 my $txt = " $tab->{name} ";
13 } else { 17 my $len = length $txt;
14 $txt = " $tab->{name} "; 18
19 substr $text, $ofs, $len + 1, "$txt|";
20 @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len;
21
22 push @ofs, [
23 $ofs,
24 $ofs + $len,
25 sub {
26 my ($self, $event) = @_;
27 $self->make_current ($tab);
28 },
15 } 29 ];
16 30
17 $cmd .= $txt; 31 $ofs += $len + 1;
18 push @ofs, $ofs[-1] + length $txt;
19 } 32 }
20 33
21 $self->{tabofs} = \@ofs; 34 $self->{tabofs} = \@ofs;
22 35
23 $self->cmd_parse ($self->locale_encode ($cmd)); 36 $self->ROW_t (0, $text);
37 $self->ROW_r (0, $rend);
24} 38}
25 39
26sub new_tab { 40sub new_tab {
27 my ($self) = @_; 41 my ($self) = @_;
28 42
49} 63}
50 64
51sub configure { 65sub configure {
52 my ($self) = @_; 66 my ($self) = @_;
53 67
54 my $tabheight = $self->int_bwidth + $self->fheight + $self->lineSpace; 68 my $tab = $self->{cur};
55 69
56 $self->{cur}->XMoveResizeWindow ( 70 $tab->XMoveResizeWindow (
57 $self->{cur}->parent, 71 $tab->parent,
58 0, $tabheight, 72 0, $self->{tabheight},
59 $self->width, $self->height - $tabheight 73 $self->width, $self->height - $self->{tabheight}
60 ); 74 );
75
76 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
77
78 for my $atom ($tab->XListProperties ($tab->parent)) {
79 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
80
81 if ($atom == $wm_normal_hints) {
82 my (@hints) = unpack "l!*", $items;
83
84 $hints[$_] += $self->{tabheight} for (4, 6, 16);
85
86 $items = pack "l!*", @hints;
87 }
88 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
89 }
90
91 $self->refresh;
61} 92}
62 93
63sub make_current { 94sub make_current {
64 my ($self, $tab) = @_; 95 my ($self, $tab) = @_;
65 96
70 101
71 $self->{cur} = $tab; 102 $self->{cur} = $tab;
72 103
73 $self->configure; 104 $self->configure;
74 105
75 for my $atom ($tab->XListProperties ($tab->parent)) {
76 warn "$atom\n";
77 }
78
79 $tab->XMapWindow ($tab->parent); 106 $tab->XMapWindow ($tab->parent);
80 107
81 $self->refresh; 108 $self->refresh;
82 109
83 () 110 ()
88} 115}
89 116
90sub on_button_release { 117sub on_button_release {
91 my ($self, $event) = @_; 118 my ($self, $event) = @_;
92 119
93 my $ofs = $self->{tabofs};
94
95 if ($event->{row} == 0) { 120 if ($event->{row} == 0) {
96 for my $i (0 .. @$ofs - 2) { 121 for my $button (@{ $self->{tabofs} }) {
122 $button->[2]->($self, $event)
97 if ($event->{col} >= $ofs->[$i] 123 if $event->{col} >= $button->[0]
98 && $event->{col} < $ofs->[$i+1]) { 124 && $event->{col} < $button->[1];
99 $self->make_current ($self->{tabs}[$i]);
100 }
101 } 125 }
102 } 126 }
103 127
104 1 128 1
105} 129}
127 () 151 ()
128} 152}
129 153
130sub on_start { 154sub on_start {
131 my ($self) = @_; 155 my ($self) = @_;
156
157 $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace;
132 158
133 $self->cmd_parse ("\x1b[?25l\x1b[?7l"); 159 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
134 $self->new_tab; 160 $self->new_tab;
135 $self->new_tab; 161 $self->new_tab;
136 $self->new_tab; 162 $self->new_tab;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines