1use Irssi;
2use strict;
3use vars qw/$VERSION %IRSSI/;
4$VERSION = 1.0;
5%IRSSI = (
6   authors     => 'David Leadbeater',
7   contact     => 'dgl@dgl.cx',
8   name        => 'resize_split',
9   description => 'Resizes a split window when it is made active (see comments in script for details)',
10   license     => 'GNU GPLv2 or later',
11   url         => 'http://irssi.dgl.cx/',
12);
13
14# This script is for if you have a split window for status (or anything else)
15# it makes it bigger when it's active.
16# (The way I have Irssi setup is with a split status window along the top,
17# created with /window show 1 in a channel window).
18
19# For example you do a command that outputs a large amount of text into
20# the status window such as /help or /motd (depending on what you put in
21# your status window). Then simply hit alt+up and the status window resizes
22# to give you more room to read the output, when you go back to another window
23# the status window will automatically go back to its previous size.
24
25# BUGS (mostly due to lack of Irssi API for split windows).
26# As far as I can see there is no easy way to find out where in a split a
27# window is displayed, so if more than one window is sticky inside a split
28# and you set that window in the setting below this script will have problems.
29# Also if you have more than 2 split windows things won't work as expected.
30
31# Setting: resize_windows
32# A space seperated list of windows that you want to be resized when you
33# change to them.
34# If it contains something that's not a (permanently displayed) split window
35# then windows will probably end up with incorrect sizes.
36Irssi::settings_add_str("misc", "resize_windows", "1");
37
38Irssi::signal_add("window changed", \&winchg);
39
40sub winchg {
41   my($newwin, $oldwin) = @_;
42   if(is_resized($oldwin->{refnum})) {
43      my $height = $oldwin->{height} - $newwin->{height};
44      return if $height < 0; # Work around bug in Irssi, minus numbers here
45                             # do weird things (i.e. grow without error
46                             # checking)
47      $oldwin->command("window shrink $height");
48   }
49
50   if(is_resized($newwin->{refnum})) {
51      my $height = $oldwin->{height} - $newwin->{height};
52      return if $height < 0; # same problem as above..
53      $newwin->command("window grow $height");
54   }
55}
56
57sub is_resized {
58   for my $refnum(split ' ', Irssi::settings_get_str("resize_windows")) {
59      return 1 if $refnum == $_[0];
60   }
61}
62
63