summaryrefslogtreecommitdiffstats
path: root/autochangie
blob: 0d49f3593167ed9d9bc8890e9fb09bb00c7b353c (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
45
46
47
48
49
50
51
52
53
54
55
56
57
#! perl
# To dynamically change font size of your current font. 
# Bind a key like --> URxvt.keysym.M-3: perl:changefont:toggle
#
# Define font size range like 
# URxvt.frange: 10,13
# Your current font size is automatically added to it

sub on_start {
    my ($term) = @_;
    $term->{'sizearr'} = [];
    my @tmp = split /,/, $term->x_resource ("frange") || qw(13);
    my $font = $term->resource('font');
    my $xsize = (split(/-/,(split(/:/, $font))[1]))[1];
    push @tmp, $xsize;
    $term->{'origindex'} = $#tmp;
    $term->{'sizearr'} = \@tmp;
}

sub on_user_command {
     my ($term, $cmd) = @_;
     if ($cmd eq 'changie:toggle-down') {
        toggle($term,-1);
     }
     else {
        toggle($term,+1);
     }
     ()
}
 
sub toggle {
   my ($self,$inc) = @_;
   my $index = $self->{'origindex'};
   my $font = $self->resource('font');
   my @tmp = @{$self->{'sizearr'}};
   $index = $index + (1 * $inc);
   $index %= @tmp;
   $font =~ s/(?<=-)[0-9]+(?=:)/$tmp[$index]/;
   $self->overlay_simple (0, -1, "Size set to $tmp[$index]");
   $self->cmd_parse("\033]710;$font\007");
   $self->{'origindex'} = $index;
   ()
}

sub on_map_notifyxxx {
    my ($term) = @_;
    my $autochange = $term->x_resource ("autotoggle") || 1;
    if ($autochange == 1){
        my $str = `tail -2 /tmp/xmonad.log | grep Xye | awk -F ' . ' '{ print $3 }'`;
        if ($str =~ m{/([0-9]):.*/.*<([0-9]).*>}) {
            if ($1 < $3) {
                toggle($term,+1);
            }
        }
    }
    ()
}