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.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
68 my $tab = $self->{cur};
69
54 $self->{cur}->XMoveResizeWindow ( 70 $tab->XMoveResizeWindow (
55 $self->{cur}->parent, 71 $tab->parent,
56 0, $self->{tabheight}, 72 0, $self->{tabheight},
57 $self->width, $self->height - $self->{tabheight} 73 $self->width, $self->height - $self->{tabheight}
58 ); 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;
59} 92}
60 93
61sub make_current { 94sub make_current {
62 my ($self, $tab) = @_; 95 my ($self, $tab) = @_;
63 96
68 101
69 $self->{cur} = $tab; 102 $self->{cur} = $tab;
70 103
71 $self->configure; 104 $self->configure;
72 105
73 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
74
75 for my $atom ($tab->XListProperties ($tab->parent)) {
76 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
77
78 if ($atom == $wm_normal_hints) {
79 my (@hints) = unpack "l!*", $items;
80 $hints[ 4] += $self->{tabheight};
81 $hints[16] += $self->{tabheight};
82 $items = pack "l!*", @hints;
83 }
84 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items);
85 }
86
87 $tab->XMapWindow ($tab->parent); 106 $tab->XMapWindow ($tab->parent);
88 107
89 $self->refresh; 108 $self->refresh;
90 109
91 () 110 ()
96} 115}
97 116
98sub on_button_release { 117sub on_button_release {
99 my ($self, $event) = @_; 118 my ($self, $event) = @_;
100 119
101 my $ofs = $self->{tabofs};
102
103 if ($event->{row} == 0) { 120 if ($event->{row} == 0) {
104 for my $i (0 .. @$ofs - 2) { 121 for my $button (@{ $self->{tabofs} }) {
122 $button->[2]->($self, $event)
105 if ($event->{col} >= $ofs->[$i] 123 if $event->{col} >= $button->[0]
106 && $event->{col} < $ofs->[$i+1]) { 124 && $event->{col} < $button->[1];
107 $self->make_current ($self->{tabs}[$i]);
108 }
109 } 125 }
110 } 126 }
111 127
112 1 128 1
113} 129}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines