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.23 by root, Sun Jun 15 13:54:16 2008 UTC vs.
Revision 1.33 by root, Sun Jun 10 17:31:53 2012 UTC

1#! perl 1#! perl
2
3#:META:X_RESOURCE:tabbar-fg:colour:tab bar foreground colour
4#:META:X_RESOURCE:tabbar-bg:colour:tab bar background colour
5#:META:X_RESOURCE:tab-fg:colour:tab foreground colour
6#:META:X_RESOURCE:tab-bg:colour:tab background colour
7
8=head1 NAME
9
10 tabbed - tabbed interface to urxvt
11
12=head1 DESCRIPTION
13
14This transforms the terminal into a tabbar with additional terminals, that
15is, it implements what is commonly referred to as "tabbed terminal". The topmost line
16displays a "[NEW]" button, which, when clicked, will add a new tab, followed by one
17button per tab.
18
19Clicking a button will activate that tab. Pressing B<Shift-Left> and
20B<Shift-Right> will switch to the tab left or right of the current one,
21while B<Shift-Down> creates a new tab.
22
23The tabbar itself can be configured similarly to a normal terminal, but
24with a resource class of C<URxvt.tabbed>. In addition, it supports the
25following four resources (shown with defaults):
26
27 URxvt.tabbed.tabbar-fg: <colour-index, default 3>
28 URxvt.tabbed.tabbar-bg: <colour-index, default 0>
29 URxvt.tabbed.tab-fg: <colour-index, default 0>
30 URxvt.tabbed.tab-bg: <colour-index, default 1>
31
32See I<COLOR AND GRAPHICS> in the @@RXVT_NAME@@(1) manpage for valid
33indices.
34
35=cut
2 36
3sub refresh { 37sub refresh {
4 my ($self) = @_; 38 my ($self) = @_;
5 39
6 my $ncol = $self->ncol; 40 my $ncol = $self->ncol;
43 $self->want_refresh; 77 $self->want_refresh;
44} 78}
45 79
46sub new_tab { 80sub new_tab {
47 my ($self, @argv) = @_; 81 my ($self, @argv) = @_;
48
49 my $offset = $self->fheight;
50 82
51 # save a backlink to us, make sure tabbed is inactive 83 # save a backlink to us, make sure tabbed is inactive
52 push @urxvt::TERM_INIT, sub { 84 push @urxvt::TERM_INIT, sub {
53 my ($term) = @_; 85 my ($term) = @_;
54 $term->{parent} = $self; 86 $term->{parent} = $self;
55 87
56 $term->resource ($_->[0] => $_->[1]) 88 for (0 .. urxvt::NUM_RESOURCES - 1) {
57 for @{ $self->{resource} || [] }; 89 my $value = $self->{resource}[$_];
90
91 $term->resource ("+$_" => $value)
92 if defined $value;
93 }
58 94
59 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); 95 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
60 }; 96 };
61 97
62 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; 98 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
96 my ($self) = @_; 132 my ($self) = @_;
97 my $tab = $self->{cur}; 133 my $tab = $self->{cur};
98 134
99 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 135 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
100 136
101 my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); 137 my $current = delete $self->{current_properties};
102 138
103 delete $our_props{$self->XInternAtom ($_)} 139 # pass 1: copy over properties different or nonexisting
104 for qw(WM_STATE WM_ICON_SIZE
105 _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS);
106
107 for my $atom ($tab->XListProperties ($tab->parent)) { 140 for my $atom ($tab->XListProperties ($tab->parent)) {
108 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 141 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
109
110 delete $our_props{$atom};
111 142
143 # fix up size hints
112 if ($atom == $wm_normal_hints) { 144 if ($atom == $wm_normal_hints) {
113 my (@hints) = unpack "l!*", $items; 145 my (@hints) = unpack "l!*", $items;
114 146
115 $hints[$_] += $self->{tabheight} for (4, 6, 16); 147 $hints[$_] += $self->{tabheight} for (4, 6, 16);
116 148
117 $items = pack "l!*", @hints; 149 $items = pack "l!*", @hints;
118 } 150 }
119 151
120 my ($dtype, $dformat, $ditems) = $self->XGetWindowProperty ($self->parent, $atom); 152 my $cur = delete $current->{$atom};
121 153
122 if ($dtype != $type or $dformat != $format or $ditems ne $items) { 154 # update if changed, we assume empty items and zero type and format will not happen
123 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 155 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
124 } 156 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
125 }
126 157
158 $self->{current_properties}{$atom} = [$type, $format, $items];
159 }
160
161 # pass 2, delete all extraneous properties
127 $self->XDeleteProperty ($self->parent, $_) for keys %our_props; 162 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
128} 163}
129 164
130sub make_current { 165sub make_current {
131 my ($self, $tab) = @_; 166 my ($self, $tab) = @_;
132 167
133 if (my $cur = $self->{cur}) { 168 if (my $cur = $self->{cur}) {
134 delete $cur->{activity}; 169 delete $cur->{activity};
135 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 170 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
136 $cur->focus_out; 171 $cur->focus_out;
137 } 172 }
138 173
139 $self->{cur} = $tab; 174 $self->{cur} = $tab;
140 175
141 $self->configure; 176 $self->configure;
142 $self->copy_properties; 177 $self->copy_properties;
143 178
144 $tab->focus_out; # just in case, should be a nop 179 $tab->focus_out; # just in case, should be a nop
145 $tab->focus_in if $self->focus; 180 $tab->focus_in if $self->focus;
146 181
147 $tab->XMapWindow ($tab->parent); 182 $tab->XMapWindow ($tab->parent);
148 delete $tab->{activity}; 183 delete $tab->{activity};
149 $self->refresh; 184 $self->refresh;
150 185
151 () 186 ()
163 my ($self, $event) = @_; 198 my ($self, $event) = @_;
164 199
165 $self->{cur}->focus_out; 200 $self->{cur}->focus_out;
166 201
167 () 202 ()
203}
204
205sub on_tt_write {
206 my ($self, $octets) = @_;
207
208 $self->{cur}->tt_write ($octets);
209
210 1
168} 211}
169 212
170sub on_key_press { 213sub on_key_press {
171 my ($self, $event) = @_; 214 my ($self, $event) = @_;
172 215
206} 249}
207 250
208sub on_init { 251sub on_init {
209 my ($self) = @_; 252 my ($self) = @_;
210 253
211 for (qw(name chdir perl_ext_1 perl_ext_2)) { 254 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
212 my $val = $self->resource ($_);
213
214 push @{ $self->{resource} }, [$_ => $val]
215 if defined $val;
216 }
217 255
218 $self->resource (int_bwidth => 0); 256 $self->resource (int_bwidth => 0);
219 $self->resource (name => "URxvt.tabbed"); 257 $self->resource (name => "URxvt.tabbed");
220 $self->resource (pty_fd => -1); 258 $self->resource (pty_fd => -1);
221 259
314 352
315 --$idx if $keysym == 0xff51; 353 --$idx if $keysym == 0xff51;
316 ++$idx if $keysym == 0xff53; 354 ++$idx if $keysym == 0xff53;
317 355
318 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 356 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
319 357
320 return 1; 358 return 1;
321 } elsif ($keysym == 0xff54) { 359 } elsif ($keysym == 0xff54) {
322 $self->new_tab; 360 $self->new_tab;
323 361
324 return 1; 362 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines