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; |
… | |
… | |
42 | |
47 | |
43 | $self->want_refresh; |
48 | $self->want_refresh; |
44 | } |
49 | } |
45 | |
50 | |
46 | sub new_tab { |
51 | sub new_tab { |
47 | my ($self) = @_; |
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 | |
|
|
61 | }; |
67 | }; |
62 | |
68 | |
63 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
69 | push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::; |
64 | |
70 | |
65 | my $term = new urxvt::term |
71 | my $term = new urxvt::term |
66 | $self->env, $urxvt::RXVTNAME, |
72 | $self->env, $urxvt::RXVTNAME, |
67 | -embed => $self->parent, |
73 | -embed => $self->parent, |
|
|
74 | @argv, |
68 | ; |
75 | ; |
69 | } |
76 | } |
70 | |
77 | |
71 | sub configure { |
78 | sub configure { |
72 | my ($self) = @_; |
79 | my ($self) = @_; |
… | |
… | |
84 | 0, $self->{tabheight}, |
91 | 0, $self->{tabheight}, |
85 | $self->width, $self->height - $self->{tabheight} |
92 | $self->width, $self->height - $self->{tabheight} |
86 | ); |
93 | ); |
87 | } |
94 | } |
88 | |
95 | |
|
|
96 | sub on_resize_all_windows { |
|
|
97 | my ($self, $width, $height) = @_; |
|
|
98 | |
|
|
99 | 1 |
|
|
100 | } |
|
|
101 | |
89 | sub copy_properties { |
102 | sub copy_properties { |
90 | my ($self) = @_; |
103 | my ($self) = @_; |
91 | my $tab = $self->{cur}; |
104 | my $tab = $self->{cur}; |
92 | |
105 | |
93 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
106 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
94 | |
107 | |
95 | my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); |
108 | my $current = delete $self->{current_properties}; |
96 | |
109 | |
97 | delete $our_props{$self->XInternAtom ($_)} |
110 | # pass 1: copy over properties different or nonexisting |
98 | for qw(WM_STATE WM_ICON_SIZE |
|
|
99 | _NET_WM_VISIBLE_NAME _NET_WM_VISIBLE_ICON_NAME _NET_WM_ICON_GEOMETRY _NET_FRAME_EXTENTS); |
|
|
100 | |
|
|
101 | for my $atom ($tab->XListProperties ($tab->parent)) { |
111 | for my $atom ($tab->XListProperties ($tab->parent)) { |
102 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
112 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
103 | |
|
|
104 | delete $our_props{$atom}; |
|
|
105 | |
113 | |
|
|
114 | # fix up size hints |
106 | if ($atom == $wm_normal_hints) { |
115 | if ($atom == $wm_normal_hints) { |
107 | my (@hints) = unpack "l!*", $items; |
116 | my (@hints) = unpack "l!*", $items; |
108 | |
117 | |
109 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
118 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
110 | |
119 | |
111 | $items = pack "l!*", @hints; |
120 | $items = pack "l!*", @hints; |
112 | } |
121 | } |
|
|
122 | |
|
|
123 | my $cur = delete $current->{$atom}; |
|
|
124 | |
|
|
125 | # update if changed, we assume empty items and zero type and format will not happen |
113 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
126 | $self->XChangeProperty ($self->parent, $atom, $type, $format, $items) |
114 | } |
127 | if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items; |
115 | |
128 | |
|
|
129 | $self->{current_properties}{$atom} = [$type, $format, $items]; |
|
|
130 | } |
|
|
131 | |
|
|
132 | # pass 2, delete all extraneous properties |
116 | $self->XDeleteProperty ($self->parent, $_) for keys %our_props; |
133 | $self->XDeleteProperty ($self->parent, $_) for keys %$current; |
117 | } |
134 | } |
118 | |
135 | |
119 | sub make_current { |
136 | sub make_current { |
120 | my ($self, $tab) = @_; |
137 | my ($self, $tab) = @_; |
121 | |
138 | |
122 | if (my $cur = $self->{cur}) { |
139 | if (my $cur = $self->{cur}) { |
123 | delete $cur->{activity}; |
140 | delete $cur->{activity}; |
124 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
141 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
125 | $cur->focus_out; |
142 | $cur->focus_out; |
126 | } |
143 | } |
127 | |
144 | |
128 | $self->{cur} = $tab; |
145 | $self->{cur} = $tab; |
129 | |
146 | |
130 | $self->configure; |
147 | $self->configure; |
131 | $self->copy_properties; |
148 | $self->copy_properties; |
132 | $tab->focus_in; |
149 | |
|
|
150 | $tab->focus_out; # just in case, should be a nop |
|
|
151 | $tab->focus_in if $self->focus; |
|
|
152 | |
133 | $tab->XMapWindow ($tab->parent); |
153 | $tab->XMapWindow ($tab->parent); |
134 | delete $tab->{activity}; |
154 | delete $tab->{activity}; |
135 | $self->refresh; |
155 | $self->refresh; |
136 | |
156 | |
137 | () |
157 | () |
… | |
… | |
149 | my ($self, $event) = @_; |
169 | my ($self, $event) = @_; |
150 | |
170 | |
151 | $self->{cur}->focus_out; |
171 | $self->{cur}->focus_out; |
152 | |
172 | |
153 | () |
173 | () |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub on_tt_write { |
|
|
177 | my ($self, $octets) = @_; |
|
|
178 | |
|
|
179 | $self->{cur}->tt_write ($octets); |
|
|
180 | |
|
|
181 | 1 |
154 | } |
182 | } |
155 | |
183 | |
156 | sub on_key_press { |
184 | sub on_key_press { |
157 | my ($self, $event) = @_; |
185 | my ($self, $event) = @_; |
158 | |
186 | |
… | |
… | |
192 | } |
220 | } |
193 | |
221 | |
194 | sub on_init { |
222 | sub on_init { |
195 | my ($self) = @_; |
223 | my ($self) = @_; |
196 | |
224 | |
197 | for (qw(name perl_ext_1 perl_ext_2)) { |
225 | $self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1]; |
198 | my $val = $self->resource ($_); |
|
|
199 | |
|
|
200 | push @{ $self->{resource} }, [$_ => $val] |
|
|
201 | if defined $val; |
|
|
202 | } |
|
|
203 | |
226 | |
204 | $self->resource (int_bwidth => 0); |
227 | $self->resource (int_bwidth => 0); |
205 | $self->resource (name => "URxvt.tabbed"); |
228 | $self->resource (name => "URxvt.tabbed"); |
206 | $self->resource (pty_fd => -1); |
229 | $self->resource (pty_fd => -1); |
207 | |
230 | |
… | |
… | |
228 | |
251 | |
229 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
252 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
230 | |
253 | |
231 | $self->cmd_parse ("\033[?25l"); |
254 | $self->cmd_parse ("\033[?25l"); |
232 | |
255 | |
|
|
256 | my @argv = $self->argv; |
|
|
257 | |
|
|
258 | do { |
|
|
259 | shift @argv; |
|
|
260 | } while @argv && $argv[0] ne "-e"; |
|
|
261 | |
233 | $self->new_tab; |
262 | $self->new_tab (@argv); |
234 | |
263 | |
235 | () |
264 | () |
236 | } |
265 | } |
237 | |
266 | |
238 | sub on_configure_notify { |
267 | sub on_configure_notify { |
… | |
… | |
294 | |
323 | |
295 | --$idx if $keysym == 0xff51; |
324 | --$idx if $keysym == 0xff51; |
296 | ++$idx if $keysym == 0xff53; |
325 | ++$idx if $keysym == 0xff53; |
297 | |
326 | |
298 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
327 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
299 | |
328 | |
300 | return 1; |
329 | return 1; |
301 | } elsif ($keysym == 0xff54) { |
330 | } elsif ($keysym == 0xff54) { |
302 | $self->new_tab; |
331 | $self->new_tab; |
|
|
332 | |
|
|
333 | return 1; |
|
|
334 | } |
|
|
335 | } |
|
|
336 | elsif ($event->{state} & urxvt::ControlMask) { |
|
|
337 | if ($keysym == 0xff51 || $keysym == 0xff53) { |
|
|
338 | my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; |
|
|
339 | my $idx2 = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} }; |
|
|
340 | |
|
|
341 | ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) = |
|
|
342 | ($self->{tabs}[$idx2], $self->{tabs}[$idx1]); |
|
|
343 | |
|
|
344 | $self->make_current ($self->{tabs}[$idx2]); |
303 | |
345 | |
304 | return 1; |
346 | return 1; |
305 | } |
347 | } |
306 | } |
348 | } |
307 | |
349 | |