From: Iain Patterson Date: Thu, 27 Aug 2009 10:51:01 +0000 (+0100) Subject: Proper urxvt resizing. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=212a9a6fa92630c7ff33a97cbe29cf602b73fdff;p=profile.git Proper urxvt resizing. Use Perl extension to dynamically change fontsets. Note that because we can't put variables into the URxvt.perl-lib resource we assume that urxvt is run from the home directory and can thus find .urxvt in there. --- diff --git a/.Xdefaults b/.Xdefaults index 0f74741..2ceb3c9 100644 --- a/.Xdefaults +++ b/.Xdefaults @@ -40,8 +40,10 @@ urxvt.scrollstyle: next urxvt.secondaryscroll: True urxvt.answerbackString: urxvt ! Change font size. -urxvt.keysym.M-minus: command:\033]50;xft:DejaVu Sans Mono:pixelsize=10:aspect=0.9,xft:AR PL UMing HK\007 -urxvt.keysym.M-equal: command:\033]50;xft:DejaVu Sans Mono:pixelsize=12:aspect=0.9,xft:AR PL UMing HK\007 +urxvt.perl-lib: .urxvt +urxvt.perl-ext: font +urxvt.keysym.M-minus: perl:font:smaller +urxvt.keysym.M-equal: perl:font:bigger ! transparency !rxvt*inheritPixmap: True diff --git a/.urxvt/font b/.urxvt/font new file mode 100644 index 0000000..1796a45 --- /dev/null +++ b/.urxvt/font @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# Perl extension to resize the terminal. +sub on_user_command { + my ($self, $cmd) = @_; + + # Get existing fontset, something like: + # xft:DejaVu Sans Mono:pixelsize=12:aspect=0.9,xft:AR PL Uming HK + my $fontset = $self->{term}->resource("font"); + my @fonts = split /,/, $fontset; + my @new = (); + + # Split into individual font definitions. + foreach my $font (@fonts) { + if ($font =~ /:pixelsize=(\d+)/) { + my $size = $1; + my $adjusted = $size; + + # Rewrite the font definition to be resized. + if ($cmd =~ /:bigger/) { $adjusted++ } + elsif ($cmd =~ /:smaller/) { $adjusted-- } + + $font =~ s/:pixelsize=$size/:pixelsize=$adjusted/; + } + + push @new, $font; + } + + # Set the new fontset. Just putting the resource doesn't work so + # use an escape sequence. + $fontset = join(",", @new); + $self->{term}->cmd_parse("\033]50;$fontset\007"); +}