1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | sub refresh { |
3 | sub 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 | |
26 | sub new_tab { |
40 | sub new_tab { |
27 | my ($self) = @_; |
41 | my ($self) = @_; |
28 | |
42 | |
… | |
… | |
65 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
79 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
66 | |
80 | |
67 | if ($atom == $wm_normal_hints) { |
81 | if ($atom == $wm_normal_hints) { |
68 | my (@hints) = unpack "l!*", $items; |
82 | my (@hints) = unpack "l!*", $items; |
69 | |
83 | |
70 | $hints[ 4] += $self->{tabheight}; |
84 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
71 | $hints[16] += $self->{tabheight}; |
85 | |
|
|
86 | $items = pack "l!*", @hints; |
72 | } |
87 | } |
73 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
88 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
74 | } |
89 | } |
|
|
90 | |
|
|
91 | $self->refresh; |
75 | } |
92 | } |
76 | |
93 | |
77 | sub make_current { |
94 | sub make_current { |
78 | my ($self, $tab) = @_; |
95 | my ($self, $tab) = @_; |
79 | |
96 | |
… | |
… | |
98 | } |
115 | } |
99 | |
116 | |
100 | sub on_button_release { |
117 | sub on_button_release { |
101 | my ($self, $event) = @_; |
118 | my ($self, $event) = @_; |
102 | |
119 | |
103 | my $ofs = $self->{tabofs}; |
|
|
104 | |
|
|
105 | if ($event->{row} == 0) { |
120 | if ($event->{row} == 0) { |
106 | for my $i (0 .. @$ofs - 2) { |
121 | for my $button (@{ $self->{tabofs} }) { |
|
|
122 | $button->[2]->($self, $event) |
107 | if ($event->{col} >= $ofs->[$i] |
123 | if $event->{col} >= $button->[0] |
108 | && $event->{col} < $ofs->[$i+1]) { |
124 | && $event->{col} < $button->[1]; |
109 | $self->make_current ($self->{tabs}[$i]); |
|
|
110 | } |
|
|
111 | } |
125 | } |
112 | } |
126 | } |
113 | |
127 | |
114 | 1 |
128 | 1 |
115 | } |
129 | } |