1
0
mirror of https://github.com/gryf/tabbedalt.git synced 2026-04-26 16:41:27 +02:00

Compare commits

...

8 Commits

Author SHA1 Message Date
gryf 57f5423dc4 Added more memory optimizations 2026-04-24 19:54:29 +02:00
gryf b811ca58f6 Removed redundant sections 2026-04-21 18:44:08 +02:00
gryf 2cede3b996 Fix memory leaks caused by not freed resources from X properites 2026-04-21 16:35:27 +02:00
gryf 2ba623a811 Fix wrong shortcut in README 2026-04-21 16:28:46 +02:00
gryf 8da342b9b0 Fix an issue with confirmation to close terminal.
Sometimes, it happens that closing terminal with mouse/keyboard
confirmation dialog appears (no matter if it was graphical or the one
build on top of urxvt overlay).

The culprit was with lines origin from `ps` command, which wasn't
correctly split, but, what is more important, wasn't properly trimmed.
This commit fixing the issue by removing whitespace from both ends of
the string and splitting using space character rather, than regexp, and
second, be sure to chop off all the whitespace characters before
splitting line and after splitting process name and its arguments.
2024-12-10 19:02:41 +01:00
gryf a9eb5cee5d Added ability to disable tab activity indicator. 2024-06-10 10:42:27 +02:00
gryf 7e76d39402 Fix overlay placement depending on the line length 2023-10-28 17:18:32 +02:00
gryf 697a698add Added urxvt overlay based dialog for closing window 2023-10-28 17:08:32 +02:00
2 changed files with 156 additions and 70 deletions
+23 -41
View File
@@ -121,6 +121,10 @@ You can change those values but bear in mind, that first group should have
timeout in seconds set higher, than middle one. You can also change symbols for
those groups.
Tab activity can be disabled by setting::
URxvt.tabbedalt.disable-activity: true
Flickering
~~~~~~~~~~
@@ -179,7 +183,7 @@ several keysyms mapped to the actions:
* ``Shift-Up``: ``rename_tab`` - for tab title renaming
* ``Shift-Left``: ``prev_tab`` - for jumping to previous tab
* ``Shift-Right``: ``next_tab`` - for jumping to next tab
* ``Shift-Left``: ``move_tab_left`` - for moving tab to the left
* ``Control-Left``: ``move_tab_left`` - for moving tab to the left
* ``Control-Right``: ``move_tab_right`` - for moving tab to the right
* ``Control-1..0``: ``jump_to_tab`` - for quickly jumping into first tenth tabs
@@ -196,9 +200,11 @@ It might be wise to define own shortcuts before disabling default keys.
``tab-command``, for example::
URxvt.keysym.Control-t: tabbedalt:new_tab:htop:htop
URxvt.keysym.Control-Shift-R: tabbedalt:new_tab:root:sudo su -
where pressing control+t it will run new tab with title ``htop`` and command
``htop``.
``htop``, while pressing control+shift+r will create tab with ``root``
title and run ``sudo su -`` inside.
Both title and command may be omitted. If so, default title ``shell`` will
be used in absence of title, and default shell will be run on missing
@@ -255,14 +261,24 @@ Confirm closing window
When working with tabs, sometimes user accidentally could close the window, and
loose all the applications run on the tabs. There might be multiple tabs open,
or just one with running process on it (i.e. some editor), where closing window
by accident could result in data loss. To prevent this, there are couple of
resources to be set. First one, disabled by default is::
by accident could result in data loss. To prevent this, there are two
additional resources that can be set. First one, disabled by default is::
URxvt.tabbedalt.confirm-quit: false
When set to ``true`` it will execute a message program defined in
``confirm-program`` resource. It might be whatever X program, which can accept
text as an argument, and can provide dialog which:
When set to ``true`` it will either execute a message program or will display
an urxvt overlay with the dialog directly on current tab. Note that overlay
dialog will expect the user to either press:
- ``y`` or ``enter`` key to close the window
- ``n`` or ``escape`` key to deny closing it
Second one is to provide X dialog program::
URxvt.tabbedalt.confirm-program:
It might be whatever X program, which can accept text as an argument, and can
provide dialog which:
- have two buttons (i.e. yes/no, ok/cancel) where first will exit dialog with 0
exit code and the latter will exit with whatever other number,
@@ -282,40 +298,6 @@ or `kdialog`_::
or… any other dialog programs which fulfill the above criteria.
Note, that ``confirm-program`` resource have no default value and you'll need
to configure it alongside with the ``confirm-quit``, otherwise ``confirm-quit``
will have no effect.
Creating specific commands/shells
---------------------------------
Let's assume, that one want to add three kind of custom shells:
* simple one (default shell in the system),
* midnight commander,
* root (namely - su command)
A way to do this is to associate keystroke for it in ``.Xdefaults`` using
urxvts ``keysym`` option, and the actions described above::
URxvt.keysym.Control-Shift-N: tabbedalt:new_tab:shell
URxvt.keysym.Control-Shift-R: tabbedalt:new_tab:root:su -
URxvt.keysym.Control-Shift-M: tabbedalt:new_tab:mc:mc
Resource values are colon separated values, which are in order:
* **plugin name:command**, which in this case of creating new tab will be
``tabbedalt:new_tab``.
* **title of the tab**, it could be anything but the colon.
* **optional command**. If omitted, default shell will be launched.
Renaming tabs
-------------
On runtime, tabs can be renamed using (by default) ``Shift+Up`` - now you can
type name for the tab. ``Return`` accept change, ``ESC`` cancels it. This
feature was taken from `stepb`_ tabbedx repository.
.. _urxvt-unicode: http://software.schmorp.de/pkg/rxvt-unicode.html
.. _activity indicator: http://mina86.com/2009/05/16/tabbed-urxvt-extension/
.. _stepb: http://github.com/stepb/urxvt-tabbedex
+120 -16
View File
@@ -152,6 +152,26 @@
# 2023-10-24 21:14:56
# - Added confirmation when closing window when there is more than one tab or
# there is a process still running.
#
# 2023-10-28 16:30:32
# - Added overlay based dialog to confirm closing urxvt window
#
# 2024-06-10 10:34:47
# - Added option for disabling activity marks and colors
#
# 2024-12-10 18:30:22
# - Fix an issue with requesting closing terminal, which appear to be a
# single instance
#
# 2026-04-21 16:29:49
# - Fix small but constant memory consumption, which over time eventually will
# cause urxvt to consume huge amount of memory
#
# 2026-04-21 18:34:16
# - Make some more optimization on memory usage - remove data from destroyed
# tab and disable its hooks
# - update tab property notifications, don't update it too often, clean up X
# properties variables after use, update only changed X properties
use Scalar::Util;
@@ -225,6 +245,7 @@ package urxvt::ext::tabbedalt::main;
sub tab_activity_mark ($$) {
my ($self, $tab) = @_;
return ' ' unless defined $tab->{lastActivity};
return ' ' if $self->{disable_activity};
return ' ' if $tab == $self->{cur};
if (defined $self->{timeouts}) {
my $diff = int urxvt::NOW - $tab->{lastActivity};
@@ -255,14 +276,16 @@ sub refresh {
my ($self) = @_;
my $tabs_no = (@{$self->{tabs}});
my $old_tabheight = $self->{tabheight} // 0;
if ($self->{autohide} && $tabs_no == 1 &&
! $self->{cur}->{is_being_renamed}) {
$self->{tabheight} = 0;
$self->configure;
$self->copy_properties;
return;
} else {
$self->{tabheight} = $self->{_tabheight};
}
if ($old_tabheight != $self->{tabheight}) {
$self->configure;
$self->copy_properties;
}
@@ -272,6 +295,8 @@ sub refresh {
my $text = " " x $ncol;
my $rend = [($self->{rs_tabbar}) x $ncol];
undef $self->{tabofs};
my ($ofs, $idx, @ofs) = (0, 0);
if ($self->{new_button}) {
@@ -303,6 +328,7 @@ sub refresh {
if ($tab == $self->{cur}) {
@$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab}) x $len;
} else {
if (!$self->{disable_activity}) {
if ($act eq "*") {
@$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab_act}) x $len;
} elsif ($act eq $self->{timeouts}[0][1]) {
@@ -311,6 +337,7 @@ sub refresh {
@$rend[$ofs .. $ofs + $len - 1] = ($self->{rs_tab_acs}) x $len;
}
}
}
# sub with make current will activate events with mouse buttons
push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ];
@@ -409,6 +436,9 @@ sub copy_properties {
if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
$self->{current_properties}{$atom} = [$type, $format, $items];
undef $type;
undef $format;
undef $items;
}
# pass 2, delete all extraneous properties
@@ -563,6 +593,7 @@ sub init {
$self->{stop_flickering} = $self->x_resource_boolean('stop-flickering');
$self->{confirm_quit} = $self->x_resource_boolean('confirm-quit');
$self->{confirm_program} = $self->x_resource('confirm-program');
$self->{disable_activity} = $self->x_resource_boolean('disable-activity');
my $timeouts = $self->x_resource ("tabbar-timeouts");
$timeouts = '16:.:8:::4:+' unless defined $timeouts;
@@ -588,6 +619,23 @@ sub init {
}
sub dialog_key_press {
# react only on certain keys:
# n and ESC - this case will delete the overlay
# y and Enter - in this case, all tabs will be destroyed
my ($tab, $event, $keysym, $str) = @_;
if ($keysym == 0xff0d || $keysym == 0xff8d || $keysym == 0x79) { # enter/y
$tab->disable('key_press');
$_->destroy for @{ $tab->{main}->{tabs} };
} elsif ($keysym == 0xff1b || $keysym == 0x6e) { # escape/n
delete $tab->{overlay};
$tab->disable('key_press');
$tab->{main}->refresh;
}
return 1;
}
_on start => sub {
my ($self) = @_;
@@ -626,18 +674,19 @@ _on configure_notify => sub {
_on wm_delete_window => sub {
my ($self) = @_;
if ($self->{confirm_quit} and $self->{confirm_program}) {
if ($self->{confirm_quit}) {
my $tab_count = @{ $self->{tabs} };
my $subp_count = 0;
my @subprocesses = split(/\n/, `ps --ppid $$ -o pid=,cmd=`);
my %process_to_skip = ( "bash"=>1, "zsh"=>1, "ps"=>1, "fish"=>1, "sh"=>1 );
foreach my $line (@subprocesses) {
chomp $line;
my @split_line = split(/ /, $line);
$line =~ s/^\s+|\s+$//g;
my @split_line = split(" ", $line);
my $pid = @split_line[0];
my $proc_name = @split_line[1];
chomp $proc_name;
my @line = split(" ", @split_line[1]);
my $proc_name = @line[0];
$proc_name =~ s/^\s+|\s+$//g;
if (!exists $process_to_skip{$proc_name}) {
$subp_count = $subp_count + 1;
} else {
@@ -647,21 +696,19 @@ _on wm_delete_window => sub {
if ($tab_count > 1 or $subp_count > 0) {
my $msg = "";
my $qst = "Are you sure you want to close urxvt?";
$msg = "There are $tab_count tabs opened" if ($tab_count > 1);
if ($subp_count > 0) {
if (! $msg) {
$msg = "There is $subp_count active processes running.";
$msg = "$msg Are you sure you want to close urxvt?";
} else {
$msg = "$msg and there is $subp_count active processes running.";
$msg = "$msg Are you sure you want to close urxvt?";
}
}else{
$msg = "$msg. Are you sure you want to close urxvt?";
}
`$self->{confirm_program} '$msg'`;
if ($self->{confirm_program}) {
`$self->{confirm_program} '$msg $qst'`;
if ($? == 0) {
$self->{is_being_destroyed} = 1;
@@ -669,6 +716,23 @@ _on wm_delete_window => sub {
$self->{timer}->stop();
$_->destroy for @{ $self->{tabs} };
}
} else {
my $marginc = 0;
$qst = "$qst (y/n)";
if ((length $msg) > (length $qst)) {
$marginc = int(($self->ncol - length $msg)/2);
} elsif ((length $msg) <= (length $qst)) {
$marginc = int(($self->ncol - length $qst)/2);
}
my $marginr = int(($self->nrow - 4)/2);
my $tab = $self->{cur};
$tab->{overlay} = $tab->overlay_simple($marginc, $marginr,
"$msg\n$qst");
# action for removing all tabs will be decided in following
# method.
$tab->enable(key_press => \&dialog_key_press);
}
} else {
$_->destroy for @{ $self->{tabs} };
}
@@ -697,6 +761,18 @@ sub tab_start {
sub tab_destroy {
my ($self, $tab) = @_;
# Disable hooks and remove data from tab
$tab->disable('line_update', 'key_press', 'property_notify', 'action', 'start', 'destroy');
delete $tab->{lastActivity};
delete $tab->{is_being_renamed};
delete $tab->{old_name};
delete $tab->{new_name};
delete $tab->{overlay};
delete $tab->{main};
delete $tab->{parent};
delete $tab->{'tabbedalt_main'};
delete $tab->{name};
$self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ];
if (@{ $self->{tabs} }) {
@@ -728,8 +804,37 @@ sub command {
sub tab_property_notify {
my ($self, $tab, $event) = @_;
$self->copy_properties
if $event->{window} == $tab->parent;
return () unless $event->{window} == $tab->parent;
return () unless $tab == $self->{cur};
# skip if called too often (within 0.1s)
my $now = urxvt::NOW;
my $last = $self->{last_property_update} // 0;
if ($now - $last < 0.1) {
return ();
}
$self->{last_property_update} = $now;
# update only the changed property instead of all properties
my $atom = $event->{atom};
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
# fix up size hints
if ($atom == $wm_normal_hints) {
my (@hints) = unpack "l!*", $items;
$hints[$_] += $self->{tabheight} for (4, 6, 16);
$items = pack "l!*", @hints;
}
$self->XChangeProperty ($self->parent, $atom, $type, $format, $items);
$self->{current_properties}{$atom} = [$type, $format, $items];
# free memory from X properties
undef $type;
undef $format;
undef $items;
()
}
@@ -881,7 +986,6 @@ sub start_rename_tab {
1
}
sub _rename_tab_key_press {
my ($tab, $event, $keysym, $str) = @_;