1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:tabbar-fg:tab bar foreground colour |
|
|
4 | #:META:X_RESOURCE:tabbar-bg:tab bar background colour |
|
|
5 | #:META:X_RESOURCE:tab-fg:tab foreground colour |
|
|
6 | #:META:X_RESOURCE:tab-bg:tab background colour |
2 | |
7 | |
3 | sub refresh { |
8 | sub refresh { |
4 | my ($self) = @_; |
9 | my ($self) = @_; |
5 | |
10 | |
6 | my $ncol = $self->ncol; |
11 | my $ncol = $self->ncol; |
… | |
… | |
43 | $self->want_refresh; |
48 | $self->want_refresh; |
44 | } |
49 | } |
45 | |
50 | |
46 | sub new_tab { |
51 | sub new_tab { |
47 | my ($self, @argv) = @_; |
52 | my ($self, @argv) = @_; |
48 | |
|
|
49 | my $offset = $self->fheight; |
|
|
50 | |
53 | |
51 | # save a backlink to us, make sure tabbed is inactive |
54 | # save a backlink to us, make sure tabbed is inactive |
52 | push @urxvt::TERM_INIT, sub { |
55 | push @urxvt::TERM_INIT, sub { |
53 | my ($term) = @_; |
56 | my ($term) = @_; |
54 | $term->{parent} = $self; |
57 | $term->{parent} = $self; |
55 | |
58 | |
56 | $term->resource ($_->[0] => $_->[1]) |
59 | for (0 .. urxvt::NUM_RESOURCES - 1) { |
57 | for @{ $self->{resource} || [] }; |
60 | my $value = $self->{resource}[$_]; |
|
|
61 | |
|
|
62 | $term->resource ("+$_" => $value) |
|
|
63 | if defined $value; |
|
|
64 | } |
58 | |
65 | |
59 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
66 | $term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbed"); |
60 | }; |
67 | }; |
61 | |
68 | |
62 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
69 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
… | |
… | |
101 | my $current = delete $self->{current_properties}; |
108 | my $current = delete $self->{current_properties}; |
102 | |
109 | |
103 | # pass 1: copy over properties different or nonexisting |
110 | # pass 1: copy over properties different or nonexisting |
104 | for my $atom ($tab->XListProperties ($tab->parent)) { |
111 | for my $atom ($tab->XListProperties ($tab->parent)) { |
105 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
112 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
106 | |
113 | |
107 | # fix up size hints |
114 | # fix up size hints |
108 | if ($atom == $wm_normal_hints) { |
115 | if ($atom == $wm_normal_hints) { |
109 | my (@hints) = unpack "l!*", $items; |
116 | my (@hints) = unpack "l!*", $items; |
110 | |
117 | |
111 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
118 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
112 | |
119 | |
113 | $items = pack "l!*", @hints; |
120 | $items = pack "l!*", @hints; |
114 | } |
121 | } |
115 | |
122 | |
116 | my $cur = delete $current->{$atom}; |
123 | my $cur = delete $current->{$atom}; |
117 | |
124 | |
… | |
… | |
132 | if (my $cur = $self->{cur}) { |
139 | if (my $cur = $self->{cur}) { |
133 | delete $cur->{activity}; |
140 | delete $cur->{activity}; |
134 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
141 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
135 | $cur->focus_out; |
142 | $cur->focus_out; |
136 | } |
143 | } |
137 | |
144 | |
138 | $self->{cur} = $tab; |
145 | $self->{cur} = $tab; |
139 | |
146 | |
140 | $self->configure; |
147 | $self->configure; |
141 | $self->copy_properties; |
148 | $self->copy_properties; |
142 | |
149 | |
143 | $tab->focus_out; # just in case, should be a nop |
150 | $tab->focus_out; # just in case, should be a nop |
144 | $tab->focus_in if $self->focus; |
151 | $tab->focus_in if $self->focus; |
145 | |
152 | |
146 | $tab->XMapWindow ($tab->parent); |
153 | $tab->XMapWindow ($tab->parent); |
147 | delete $tab->{activity}; |
154 | delete $tab->{activity}; |
148 | $self->refresh; |
155 | $self->refresh; |
149 | |
156 | |
150 | () |
157 | () |
… | |
… | |
162 | my ($self, $event) = @_; |
169 | my ($self, $event) = @_; |
163 | |
170 | |
164 | $self->{cur}->focus_out; |
171 | $self->{cur}->focus_out; |
165 | |
172 | |
166 | () |
173 | () |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub on_tt_write { |
|
|
177 | my ($self, $octets) = @_; |
|
|
178 | |
|
|
179 | $self->{cur}->tt_write ($octets); |
|
|
180 | |
|
|
181 | 1 |
167 | } |
182 | } |
168 | |
183 | |
169 | sub on_key_press { |
184 | sub on_key_press { |
170 | my ($self, $event) = @_; |
185 | my ($self, $event) = @_; |
171 | |
186 | |
… | |
… | |
205 | } |
220 | } |
206 | |
221 | |
207 | sub on_init { |
222 | sub on_init { |
208 | my ($self) = @_; |
223 | my ($self) = @_; |
209 | |
224 | |
210 | for (qw(name chdir perl_ext_1 perl_ext_2)) { |
225 | $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1]; |
211 | my $val = $self->resource ($_); |
|
|
212 | |
|
|
213 | push @{ $self->{resource} }, [$_ => $val] |
|
|
214 | if defined $val; |
|
|
215 | } |
|
|
216 | |
226 | |
217 | $self->resource (int_bwidth => 0); |
227 | $self->resource (int_bwidth => 0); |
218 | $self->resource (name => "URxvt.tabbed"); |
228 | $self->resource (name => "URxvt.tabbed"); |
219 | $self->resource (pty_fd => -1); |
229 | $self->resource (pty_fd => -1); |
220 | |
230 | |
… | |
… | |
313 | |
323 | |
314 | --$idx if $keysym == 0xff51; |
324 | --$idx if $keysym == 0xff51; |
315 | ++$idx if $keysym == 0xff53; |
325 | ++$idx if $keysym == 0xff53; |
316 | |
326 | |
317 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
327 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
318 | |
328 | |
319 | return 1; |
329 | return 1; |
320 | } elsif ($keysym == 0xff54) { |
330 | } elsif ($keysym == 0xff54) { |
321 | $self->new_tab; |
331 | $self->new_tab; |
322 | |
332 | |
323 | return 1; |
333 | return 1; |