From add4cb71c33f4fdb5af5bcae1a561595175ef3ef Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Thu, 26 May 2011 15:12:35 +0200 Subject: [PATCH 1/7] New user commands to rename and move tabs --- tabbedex | 61 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 15 deletions(-) mode change 100644 => 100755 tabbedex diff --git a/tabbedex b/tabbedex old mode 100644 new mode 100755 index 0d9badf..2b35f38 --- a/tabbedex +++ b/tabbedex @@ -68,6 +68,12 @@ ## 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 +## sub update_autohide { @@ -498,25 +504,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; } } @@ -556,6 +549,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. @@ -580,6 +582,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. From 48c13db1a72fb465db83f87b6d2e7e4400c5a3a6 Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Thu, 26 May 2011 15:21:42 +0200 Subject: [PATCH 2/7] Let the user disable the default keybindings --- tabbedex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tabbedex b/tabbedex index 2b35f38..54d5356 100755 --- a/tabbedex +++ b/tabbedex @@ -74,6 +74,9 @@ ## 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. +## sub update_autohide { @@ -368,6 +371,8 @@ sub on_init { ($self->x_resource ('title') or 'true') !~ /^(?:false|0|no)/i; $self->{autohide} = ($self->x_resource ('autohide') or 'false') !~ /^(?:false|0|no)/i; + $self->{no_default_keys} = + ($self->x_resource ('no-tabbedex-keys') or 'false') !~ /^(?:false|0|no)/i; (); } @@ -492,6 +497,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) { From 4fde846b35901eaed14cc4c0a985940e0c542d6f Mon Sep 17 00:00:00 2001 From: Mark Pustjens Date: Tue, 6 Dec 2011 10:35:54 +0100 Subject: [PATCH 3/7] Resources are read respecting the -name parameter. --- tabbedex | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tabbedex b/tabbedex index 54d5356..2aa42ae 100755 --- a/tabbedex +++ b/tabbedex @@ -253,6 +253,12 @@ sub copy_properties { } +sub my_resource { + my $self = shift; + $self->x_resource ("tabbed.$_[0]"); +} + + sub make_current { my ($self, $tab) = @_; @@ -328,17 +334,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; @@ -352,7 +357,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; @@ -366,13 +371,13 @@ 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->x_resource ('no-tabbedex-keys') or 'false') !~ /^(?:false|0|no)/i; + ($self->my_resource ('no-tabbedex-keys') or 'false') !~ /^(?:false|0|no)/i; (); } From 2d5e581ee661faf503601c224a6d2c2c58d2f982 Mon Sep 17 00:00:00 2001 From: Mark Pustjens Date: Tue, 6 Dec 2011 10:37:12 +0100 Subject: [PATCH 4/7] Resources are now read from the tabbedex class. This break compatibility with older version. --- tabbedex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabbedex b/tabbedex index 2aa42ae..e73590b 100755 --- a/tabbedex +++ b/tabbedex @@ -255,7 +255,7 @@ sub copy_properties { sub my_resource { my $self = shift; - $self->x_resource ("tabbed.$_[0]"); + $self->x_resource ("tabbedex.$_[0]"); } From f662f403b7aedcb318721a691f8d1b26e105b332 Mon Sep 17 00:00:00 2001 From: Mark Pustjens Date: Tue, 6 Dec 2011 10:44:23 +0100 Subject: [PATCH 5/7] Added option to create a new tab when the last tab is closed. --- tabbedex | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tabbedex b/tabbedex index e73590b..6e874df 100755 --- a/tabbedex +++ b/tabbedex @@ -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 -## +## (mail4stb/AT/gmail.com), Steven Merrill +## and Mark Pustjens +## ## ## The following has been added: ## @@ -77,6 +78,11 @@ ## 12. Ability to disable the default keybindings using the ## no-tabbedex-keys resource. ## +## Added by Mark Pustjens +## +## 13. Ability to prevent the last tab from closing. +## Use the following in your ~/.Xdefaults to enable: +## URXvt.tabbed.noexit: yes sub update_autohide { @@ -378,6 +384,8 @@ sub on_init { ($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->{no_exit} = + ($self->my_resource ('no-exit') or 'false') !~ /^(?:false|0|no)/i; (); } @@ -460,6 +468,11 @@ sub tab_start { sub tab_destroy { my ($self, $tab) = @_; + if ($self->{no_exit} && $#{ $self->{tabs} } == 0) { + $self->new_tab; + $self->make_current ($self->{tabs}[-1]); + } + $self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ]; $self->update_autohide (); From cb0ab49254e98571ce859587adf5680b6dcc4689 Mon Sep 17 00:00:00 2001 From: Mark Pustjens Date: Fri, 9 Dec 2011 12:42:56 +0100 Subject: [PATCH 6/7] Renamed no-exit to reopen-on-close. --- tabbedex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tabbedex b/tabbedex index 6e874df..920155c 100755 --- a/tabbedex +++ b/tabbedex @@ -384,8 +384,8 @@ sub on_init { ($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->{no_exit} = - ($self->my_resource ('no-exit') or 'false') !~ /^(?:false|0|no)/i; + $self->{reopen_on_close} = + ($self->my_resource ('reopen-on-close') or 'false') !~ /^(?:false|0|no)/i; (); } @@ -468,7 +468,7 @@ sub tab_start { sub tab_destroy { my ($self, $tab) = @_; - if ($self->{no_exit} && $#{ $self->{tabs} } == 0) { + if ($self->{reopen_on_close} && $#{ $self->{tabs} } == 0) { $self->new_tab; $self->make_current ($self->{tabs}[-1]); } From f30f6889c21f86764405acd85c851bcd446fb5c5 Mon Sep 17 00:00:00 2001 From: Mark Pustjens Date: Fri, 9 Dec 2011 13:17:59 +0100 Subject: [PATCH 7/7] Added a blacklist resource to prevent perl extensions from loading in spawned tabs. Needed when using kuake in combination with tabbedex. --- tabbedex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tabbedex b/tabbedex index 920155c..5ac04ee 100755 --- a/tabbedex +++ b/tabbedex @@ -193,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::; @@ -387,6 +387,11 @@ sub on_init { $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); + + (); }