$ diff -u monk.pl.orig monk.pl --- monk.pl.orig 2008-01-27 12:04:05.921317488 -0500 +++ monk.pl 2008-01-27 12:03:44.446582144 -0500 @@ -44,15 +44,18 @@ $y > $portrait[1] ? $portrait[1] : $y + 2); } - # all these values are the same as default, except the first. these - # values are just for testing. the eventual plan is to adjust them - # so the viewport is centered, but even with static values it - # doesn't work. - my $ha = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); - my $va = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1); - - $sw->set_hadjustment($ha); - $sw->set_vadjustment($va); + # + # After the widgets are create and know their size, scroll to the + # middle of the image. Notice the halfway point is actually + # (upper-pagesize)/2, not upper/2 --- otherwise you'll attempt to + # scroll out of bounds. + # + $sw->signal_connect_after (realize => sub { + my $va = $_[0]->get_vadjustment; + $va->set_value (($va->upper - $va->page_size) / 2); + my $ha = $_[0]->get_hadjustment; + $ha->set_value (($ha->upper - $ha->page_size) / 2); + }); $mw->set_title("$file ${x}x${y}"); $mw->show_all();