Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 90 additions & 29 deletions tabbedex
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
##
## Tabbed plugin for rxvt-unicode
## Modified by Michal Nazarewicz (mina86/AT/mina86.com), StephenB
## (mail4stb/AT/gmail.com) and Steven Merrill
## <steven dot merrill at gmail.com>
## (mail4stb/AT/gmail.com), Steven Merrill
## <steven dot merrill at gmail.com> and Mark Pustjens
## <pustjens@dds.nl>
##
## The following has been added:
##
Expand Down Expand Up @@ -68,6 +69,20 @@
## to other extension packages if the mouse was not over the urxvt
## window.
##
## Added by Thomas Jost:
##
## 11. Add several user commands: tabbedex:rename_tab,
## tabbedex:move_tab_(left|right).
## e.g. (see 9.) URxvt.keysym.C-S-Left: perl:tabbex:move_tab_left
##
## 12. Ability to disable the default keybindings using the
## no-tabbedex-keys resource.
##
## Added by Mark Pustjens <pustjens@dds.nl>
##
## 13. Ability to prevent the last tab from closing.
## Use the following in your ~/.Xdefaults to enable:
## URXvt.tabbed.noexit: yes


sub update_autohide {
Expand Down Expand Up @@ -178,7 +193,7 @@ sub new_tab {
if defined $value;
}

$term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . ",-tabbedex");
$term->resource (perl_ext_2 => $term->resource ("perl_ext_2") . $self->{perl_ext_blacklist});
};

push @urxvt::TERM_EXT, urxvt::ext::tabbedex::tab::;
Expand Down Expand Up @@ -244,6 +259,12 @@ sub copy_properties {
}


sub my_resource {
my $self = shift;
$self->x_resource ("tabbedex.$_[0]");
}


sub make_current {
my ($self, $tab) = @_;

Expand Down Expand Up @@ -319,17 +340,16 @@ sub on_init {
$self->{resource} = [map $self->resource ("+$_"), 0 .. urxvt::NUM_RESOURCES - 1];

$self->resource (int_bwidth => 0);
$self->resource (name => "URxvt.tabbed");
$self->resource (pty_fd => -1);

$self->option ($urxvt::OPTION{scrollBar}, 0);

my $fg = $self->x_resource ("tabbar-fg");
my $bg = $self->x_resource ("tabbar-bg");
my $tabfg = $self->x_resource ("tab-fg");
my $tabbg = $self->x_resource ("tab-bg");
my $titfg = $self->x_resource ("title-fg");
my $titbg = $self->x_resource ("title-bg");
my $fg = $self->my_resource ("tabbar-fg");
my $bg = $self->my_resource ("tabbar-bg");
my $tabfg = $self->my_resource ("tab-fg");
my $tabbg = $self->my_resource ("tab-bg");
my $titfg = $self->my_resource ("title-fg");
my $titbg = $self->my_resource ("title-bg");

defined $fg or $fg = 3;
defined $bg or $bg = 0;
Expand All @@ -343,7 +363,7 @@ sub on_init {
$self->{rs_title} = urxvt::SET_COLOR (urxvt::DEFAULT_RSTYLE, $titfg + 2, $titbg + 2);


my $timeouts = $self->x_resource ("tabbar-timeouts");
my $timeouts = $self->my_resource ("tabbar-timeouts");
$timeouts = '16:.:8:::4:+' unless defined $timeouts;
if ($timeouts ne '') {
my @timeouts;
Expand All @@ -357,11 +377,20 @@ sub on_init {
}

$self->{new_button} =
($self->x_resource ('new-button') or 'false') !~ /^(?:false|0|no)/i;
($self->my_resource ('new-button') or 'false') !~ /^(?:false|0|no)/i;
$self->{tab_title} =
($self->x_resource ('title') or 'true') !~ /^(?:false|0|no)/i;
($self->my_resource ('title') or 'true') !~ /^(?:false|0|no)/i;
$self->{autohide} =
($self->x_resource ('autohide') or 'false') !~ /^(?:false|0|no)/i;
($self->my_resource ('autohide') or 'false') !~ /^(?:false|0|no)/i;
$self->{no_default_keys} =
($self->my_resource ('no-tabbedex-keys') or 'false') !~ /^(?:false|0|no)/i;
$self->{reopen_on_close} =
($self->my_resource ('reopen-on-close') or 'false') !~ /^(?:false|0|no)/i;

my @blacklist = split(',', $self->my_resource ('perl-ext-blacklist'));
unshift @blacklist, ",-tabbedex";
$self->{perl_ext_blacklist} = join (",-", @blacklist);


();
}
Expand Down Expand Up @@ -444,6 +473,11 @@ sub tab_start {
sub tab_destroy {
my ($self, $tab) = @_;

if ($self->{reopen_on_close} && $#{ $self->{tabs} } == 0) {
$self->new_tab;
$self->make_current ($self->{tabs}[-1]);
}

$self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ];
$self->update_autohide ();

Expand Down Expand Up @@ -486,6 +520,8 @@ sub tab_key_press {
return 1;
}

return () if ($self->{no_default_keys});

if ($event->{state} & urxvt::ShiftMask) {
if ($keysym == 0xff51 || $keysym == 0xff53) {
if (@{ $self->{tabs} } > 1) {
Expand All @@ -498,25 +534,12 @@ sub tab_key_press {
return 1;

} elsif ($keysym == 0xff52) {
$tab->{is_inputting_name} = 1;
$tab->{old_name} = $tab->{name} ? $tab->{name} : "";
$tab->{new_name} = "";
$tab->{name} = "█";
$self->update_autohide (1);
$self->refresh;
$self->rename_tab($tab);
return 1;
}
} elsif ($event->{state} & urxvt::ControlMask) {
if ($keysym == 0xff51 || $keysym == 0xff53) {
if (@{ $self->{tabs} } > 1) {
my $idx1 = 0;
++$idx1 while $self->{tabs}[$idx1] != $tab;
my $idx2 = ($idx1 + $keysym - 0xff52) % @{ $self->{tabs} };

($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
$self->make_current ($self->{tabs}[$idx2]);
}
$self->move_tab($tab, $keysym - 0xff52);
return 1;
}
}
Expand Down Expand Up @@ -556,6 +579,15 @@ sub tab_user_command {
elsif ($cmd eq 'tabbedex:prev_tab') {
$self->change_tab($tab, -1);
}
elsif ($cmd eq 'tabbedex:move_tab_left') {
$self->move_tab($tab, -1);
}
elsif ($cmd eq 'tabbedex:move_tab_right') {
$self->move_tab($tab, 1);
}
elsif ($cmd eq 'tabbedex:rename_tab') {
$self->rename_tab($tab);
}
else {
# Proxy the user command through to the tab's term, while taking care not
# to get caught in an infinite loop.
Expand All @@ -580,6 +612,35 @@ sub change_tab {
();
}

sub move_tab {
my ($self, $tab, $direction) = @_;

if (@{ $self->{tabs} } > 1) {
my $idx1 = 0;
++$idx1 while $self->{tabs}[$idx1] != $tab;
my $idx2 = ($idx1 + $direction) % @{ $self->{tabs} };

($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
($self->{tabs}[$idx2], $self->{tabs}[$idx1]);
$self->make_current ($self->{tabs}[$idx2]);
}

();
}

sub rename_tab {
my ($self, $tab) = @_;

$tab->{is_inputting_name} = 1;
$tab->{old_name} = $tab->{name} ? $tab->{name} : "";
$tab->{new_name} = "";
$tab->{name} = "█";
$self->update_autohide (1);
$self->refresh;

();
}

package urxvt::ext::tabbedex::tab;

# helper extension implementing the subwindows of a tabbed terminal.
Expand Down