16

I have started working with rxvt-unicode (aka urxvt) but found an issue with mouse-wheel scrolling, as compared to gnome-terminal and konsole. The mouse wheel works fine for going through the scrollback buffer, but it doesn't work for automatic scrolling in less/most or vim (though in vim, setting mouse=a makes it work, but in a very different way, which I don't have to do with gnome-terminal/konsole).

Is there a way to make urxvt behave like gnome-terminal and konsole when in less and vim where the mouse wheel Just Works?

  • A similar question has been on serverfault for a while, but hasn't received a positive answer: serverfault.com/questions/10308/… – nidi Jan 15 '10 at 14:34
  • 1
    Thanks, this wasn't annoying me until you pointed it out! – Kyle Smith May 18 '11 at 15:02
8

Old question, but: while this is not possible in urxvt, I made some changes that will add an option (secondaryWheel) to do exactly that, and make it behave like VTE-based terminals.

What this new option does, is pretty simple: when using the mouse wheel, if you’re on secondary screen(*) then no scrolling will occur, and instead 3 “fake” keystrokes will be sent to the running application. So, a wheel up will have the same result as pressing the Up key three times, and wheel down will do the same as pressing 3 times the Down key.

(*) not sure whether this is the “official” term or not, but at least that’s how it’s called in urxvt.

Easy enough, but that does the trick: now when running man, less or any other application that uses the secondary screen, you can use the mouse wheel to move around (or whatever said application would do, if you pressed the Up/Down keys).

It should be noted that I'm not sure this is actually how things are done in VTE-based terminals - I never checked - but this does the job, so it works for me.

A little more info, and links to the code & PKGBUILD for Arch Linux can be found there: http://mywaytoarch.tumblr.com/post/14455320734/scrolling-mouse-wheel-improvments-vte-like-in-urxvt

Hopefully this can be helpful to some!

  • 1
    Any updates on the patch? Has it been suggested for inclusion? – blueyed Dec 20 '14 at 5:42
1

I wrote this for a very similar question, see https://superuser.com/a/1356948/900060

Paste this in $HOME/.urxvt/ext/vtwheel (create the file if it doesn't exist):

#! perl

# Implements a scrollwheel just like in good old vt100's mices

sub simulate_keypress {
    my ($self, $type) = @_; #type: 0:up, 1:down

    my $keycode_up = 111;
    my $keycode_down = 116;

    my $numlines = 3;

    my $keycode = 0;
    if ($type eq 0) {
        $keycode = $keycode_up;
    } elsif ($type eq 1) {
        $keycode = $keycode_down;
    } else {
        return;
    }

    for (my $i = 0 ; $i ne $numlines ; $i++) {
        $self->key_press(0,$keycode);
        $self->key_release(0,$keycode);
    }
}

sub on_button_release {
    my ($self, $event) = @_;

    #my $res_ss = $self->resource("secondaryScroll");
    #warn("ressource ss is <$res_ss>");

    !$self->current_screen and return ();

    #warn("foo, event: <$event->{button}>\n");
    if ($event->{button} eq "4") { # scroll up
        $self->simulate_keypress(0);
        return 1;
    } elsif ($event->{button} eq "5") { # scroll down
        $self->simulate_keypress(1);
        return 1;
    }

    return ();
}

Then add URxvt.perl-ext-common:vtewheel to your .Xresources (or .Xdefaults) and run xrdb .Xresources

Source: https://aur.archlinux.org/cgit/aur.git/tree/vtwheel?h=urxvt-vtwheel

0

Nice question! Some useful post I'll cite Linux Question - "less" command output-I cannot scroll through it! and Archlinux Forum - Use Mouse Wheel in man/less.

Seems like less are just listening to keyboard events and does not have support for mouse. The enchantment request for mouse support is open Ref # 272.

The real solution is to use another terminal or pager(Vimpager).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.