summaryrefslogtreecommitdiffstats
path: root/scripts/resize_split.pl
blob: 17444192b73c7b5e6cf77965940ceed0c9069c6f (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
58
59
60
61
62
use Irssi;
use strict;
use vars qw/$VERSION %IRSSI/;
$VERSION = 1.0;
%IRSSI = (
   authors     => 'David Leadbeater',
   contact     => 'dgl@dgl.cx',
   name        => 'resize_split',
   description => 'Resizes a split window when it is made active (see comments in script for details)',
   license     => 'GNU GPLv2 or later',
   url         => 'http://irssi.dgl.cx/',
);

# This script is for if you have a split window for status (or anything else)
# it makes it bigger when it's active.
# (The way I have Irssi setup is with a split status window along the top,
# created with /window show 1 in a channel window).
 
# For example you do a command that outputs a large amount of text into
# the status window such as /help or /motd (depending on what you put in
# your status window). Then simply hit alt+up and the status window resizes
# to give you more room to read the output, when you go back to another window
# the status window will automatically go back to its previous size.

# BUGS (mostly due to lack of Irssi API for split windows).
# As far as I can see there is no easy way to find out where in a split a
# window is displayed, so if more than one window is sticky inside a split
# and you set that window in the setting below this script will have problems.
# Also if you have more than 2 split windows things won't work as expected.

# Setting: resize_windows
# A space seperated list of windows that you want to be resized when you
# change to them.
# If it contains something that's not a (permanently displayed) split window
# then windows will probably end up with incorrect sizes.
Irssi::settings_add_str("misc", "resize_windows", "1");

Irssi::signal_add("window changed", \&winchg);

sub winchg {
   my($newwin, $oldwin) = @_;
   if(is_resized($oldwin->{refnum})) {
      my $height = $oldwin->{height} - $newwin->{height};
      return if $height < 0; # Work around bug in Irssi, minus numbers here
                             # do weird things (i.e. grow without error
                             # checking)
      $oldwin->command("window shrink $height");
   }
   
   if(is_resized($newwin->{refnum})) {
      my $height = $oldwin->{height} - $newwin->{height};
      return if $height < 0; # same problem as above..
      $newwin->command("window grow $height");
   }
}

sub is_resized {
   for my $refnum(split ' ', Irssi::settings_get_str("resize_windows")) {
      return 1 if $refnum == $_[0];
   }
}