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.21 by root, Mon Feb 20 20:44:22 2006 UTC vs.
Revision 1.39 by sf-exg, Sun Feb 26 06:36:46 2017 UTC

1#! perl 1#! perl
2
3#:META:RESOURCE:tabbar-fg:colour:tab bar foreground colour
4#:META:RESOURCE:tabbar-bg:colour:tab bar background colour
5#:META:RESOURCE:tab-fg:colour:tab foreground colour
6#:META:RESOURCE:tab-bg:colour:tab background colour
7
8=head1 NAME
9
10tabbed - 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. Pressing B<Ctrl-Left> and
22B<Ctrl-Right> will renumber the current tab by moving it to the left or
23to the right.
24
25The tabbar itself can be configured similarly to a normal terminal, but
26with a resource class of C<URxvt.tabbed>. In addition, it supports the
27following four resources (shown with defaults):
28
29 URxvt.tabbed.tabbar-fg: <colour-index, default 3>
30 URxvt.tabbed.tabbar-bg: <colour-index, default 0>
31 URxvt.tabbed.tab-fg: <colour-index, default 0>
32 URxvt.tabbed.tab-bg: <colour-index, default 1>
33
34See I<COLOR AND GRAPHICS> in the urxvt(1) manpage for valid
35indices.
36
37=cut
2 38
3sub refresh { 39sub refresh {
4 my ($self) = @_; 40 my ($self) = @_;
5 41
6 my $ncol = $self->ncol; 42 my $ncol = $self->ncol;
43 $self->want_refresh; 79 $self->want_refresh;
44} 80}
45 81
46sub new_tab { 82sub new_tab {
47 my ($self, @argv) = @_; 83 my ($self, @argv) = @_;
48
49 my $offset = $self->fheight;
50 84
51 # save a backlink to us, make sure tabbed is inactive 85 # save a backlink to us, make sure tabbed is inactive
52 push @urxvt::TERM_INIT, sub { 86 push @urxvt::TERM_INIT, sub {
53 my ($term) = @_; 87 my ($term) = @_;
54 $term->{parent} = $self; 88 $term->{parent} = $self;
55 89
56 $term->resource ($_->[0] => $_->[1]) 90 for (0 .. urxvt::NUM_RESOURCES - 1) {
57 for @{ $self->{resource} || [] }; 91 my $value = $self->{resource}[$_];
92
93 $term->resource ("+$_" => $value)
94 if defined $value;
95 }
58 96
59 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); 97 $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed");
60
61 }; 98 };
62 99
63 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; 100 push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
64 101
65 my $term = new urxvt::term 102 my $term = new urxvt::term
97 my ($self) = @_; 134 my ($self) = @_;
98 my $tab = $self->{cur}; 135 my $tab = $self->{cur};
99 136
100 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); 137 my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
101 138
102 my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); 139 my $current = delete $self->{current_properties};
103 140
104 delete $our_props{$self->XInternAtom ($_)} 141 # pass 1: copy over properties different or nonexisting
105 for qw(WM_STATE WM_ICON_SIZE
106 _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS);
107
108 for my $atom ($tab->XListProperties ($tab->parent)) { 142 for my $atom ($tab->XListProperties ($tab->parent)) {
109 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); 143 my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
110
111 delete $our_props{$atom};
112 144
145 # fix up size hints
113 if ($atom == $wm_normal_hints) { 146 if ($atom == $wm_normal_hints) {
114 my (@hints) = unpack "l!*", $items; 147 my (@hints) = unpack "l!*", $items;
115 148
116 $hints[$_] += $self->{tabheight} for (4, 6, 16); 149 $hints[$_] += $self->{tabheight} for (4, 6, 16);
117 150
118 $items = pack "l!*", @hints; 151 $items = pack "l!*", @hints;
119 } 152 }
120 153
121 my ($dtype, $dformat, $ditems) = $self->XGetWindowProperty ($self->parent, $atom); 154 my $cur = delete $current->{$atom};
122 155
123 if ($dtype != $type or $dformat != $format or $ditems ne $items) { 156 # update if changed, we assume empty items and zero type and format will not happen
124 $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); 157 $self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
125 } 158 if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
126 }
127 159
160 $self->{current_properties}{$atom} = [$type, $format, $items];
161 }
162
163 # pass 2, delete all extraneous properties
128 $self->XDeleteProperty ($self->parent, $_) for keys %our_props; 164 $self->XDeleteProperty ($self->parent, $_) for keys %$current;
129} 165}
130 166
131sub make_current { 167sub make_current {
132 my ($self, $tab) = @_; 168 my ($self, $tab) = @_;
133 169
134 if (my $cur = $self->{cur}) { 170 if (my $cur = $self->{cur}) {
135 delete $cur->{activity}; 171 delete $cur->{activity};
136 $cur->XUnmapWindow ($cur->parent) if $cur->mapped; 172 $cur->XUnmapWindow ($cur->parent) if $cur->mapped;
137 $cur->focus_out; 173 $cur->focus_out;
138 } 174 }
139 175
140 $self->{cur} = $tab; 176 $self->{cur} = $tab;
141 177
142 $self->configure; 178 $self->configure;
143 $self->copy_properties; 179 $self->copy_properties;
144 180
145 $tab->focus_out; # just in case, should be a nop 181 $tab->focus_out; # just in case, should be a nop
146 $tab->focus_in if $self->focus; 182 $tab->focus_in if $self->focus;
147 183
148 $tab->XMapWindow ($tab->parent); 184 $tab->XMapWindow ($tab->parent);
149 delete $tab->{activity}; 185 delete $tab->{activity};
150 $self->refresh; 186 $self->refresh;
151 187
152 () 188 ()
166 $self->{cur}->focus_out; 202 $self->{cur}->focus_out;
167 203
168 () 204 ()
169} 205}
170 206
207sub on_tt_write {
208 my ($self, $octets) = @_;
209
210 $self->{cur}->tt_write ($octets);
211
212 1
213}
214
171sub on_key_press { 215sub on_key_press {
172 my ($self, $event) = @_; 216 my ($self, $event) = @_;
173 217
174 $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time}); 218 $self->{cur}->key_press ($event->{state}, $event->{keycode}, $event->{time});
219 $self->{cur}->refresh_check;
175 220
176 1 221 1
177} 222}
178 223
179sub on_key_release { 224sub on_key_release {
180 my ($self, $event) = @_; 225 my ($self, $event) = @_;
181 226
182 $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time}); 227 $self->{cur}->key_release ($event->{state}, $event->{keycode}, $event->{time});
228 $self->{cur}->refresh_check;
183 229
184 1 230 1
185} 231}
186 232
187sub on_button_press { 233sub on_button_press {
207} 253}
208 254
209sub on_init { 255sub on_init {
210 my ($self) = @_; 256 my ($self) = @_;
211 257
212 for (qw(name perl_ext_1 perl_ext_2)) { 258 $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];
213 my $val = $self->resource ($_);
214
215 push @{ $self->{resource} }, [$_ => $val]
216 if defined $val;
217 }
218 259
219 $self->resource (int_bwidth => 0); 260 $self->resource (int_bwidth => 0);
220 $self->resource (name => "URxvt.tabbed"); 261 $self->resource (name => "URxvt.tabbed");
221 $self->resource (pty_fd => -1); 262 $self->resource (pty_fd => -1);
222 263
315 356
316 --$idx if $keysym == 0xff51; 357 --$idx if $keysym == 0xff51;
317 ++$idx if $keysym == 0xff53; 358 ++$idx if $keysym == 0xff53;
318 359
319 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); 360 $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);
320 361
321 return 1; 362 return 1;
322 } elsif ($keysym == 0xff54) { 363 } elsif ($keysym == 0xff54) {
323 $self->new_tab; 364 $self->new_tab;
324 365
325 return 1; 366 return 1;
326 } 367 }
327 } 368 }
369 elsif ($event->{state} & urxvt::ControlMask) {
370 if ($keysym == 0xff51 || $keysym == 0xff53) {
371 my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
372 my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };
373
374 ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
375 ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
376
377 $self->make_current ($self->{tabs}[$idx2]);
378
379 return 1;
380 }
381 }
328 382
329 () 383 ()
330} 384}
331 385
332sub tab_property_notify { 386sub tab_property_notify {
348 402
349# helper extension implementing the subwindows of a tabbed terminal. 403# helper extension implementing the subwindows of a tabbed terminal.
350# simply proxies all interesting calls back to the tabbed class. 404# simply proxies all interesting calls back to the tabbed class.
351 405
352{ 406{
353 for my $hook qw(start destroy key_press property_notify) { 407 for my $hook (qw(start destroy key_press property_notify)) {
354 eval qq{ 408 eval qq{
355 sub on_$hook { 409 sub on_$hook {
356 my \$parent = \$_[0]{term}{parent} 410 my \$parent = \$_[0]{term}{parent}
357 or return; 411 or return;
358 \$parent->tab_$hook (\@_) 412 \$parent->tab_$hook (\@_)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines