aboutsummaryrefslogtreecommitdiff
path: root/.config/urxvt/ext/vtwheel
blob: 919d08c248b14fc888f97334fe1f02e43058c63f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl

=head1 NAME

vtwheel - emulate scroll wheel for secondary screen

=head1 DESCRIPTION

Emulate scroll wheel on secondary screen by simulating key presses.

=cut

use strict;
use warnings;

my $scroll_lines = 3;
my $key_scroll_up = 111;
my $key_scroll_down = 116;

sub simulate_keypress {
    my ($self, $keycode) = @_;

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

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

    # Don't change scrolling on primary screen
    !$self->current_screen and return ();

    if ($event->{button} eq "4") {
        $self->simulate_keypress($key_scroll_up);
        return 1;
    } elsif ($event->{button} eq "5") {
        $self->simulate_keypress($key_scroll_down);
        return 1;
    }

    return ();
}