+my $current;
+my $pid;
+my $pipeline;
+
+&reread_directory ();
+
+print STDERR "read ", 0+@files, " files\n" if $verbose;
+if (@files == 0) {
+ warn "techtalk-pse: no files found, continuing anyway ...\n"
+}
+
+my $w = Gtk2::Window->new ();
+my $vbox = Gtk2::VBox->new ();
+my $webkit = Gtk2::WebKit::WebView->new ();
+my $vte = Gnome2::Vte::Terminal->new ();
+my $notebook = Gtk2::Notebook->new ();
+my $splash = make_splash_page ();
+my $emptylabel = Gtk2::Label->new ();
+
+my $webkitscroll = Gtk2::ScrolledWindow->new ();
+$webkitscroll->add ($webkit);
+$webkitscroll->set_policy('automatic', 'automatic');
+
+my $webkitpage = $notebook->append_page ($webkitscroll);
+my $shpage = $notebook->append_page ($emptylabel);
+my $vtepage = $notebook->append_page ($vte);
+my $splashpage = $notebook->append_page ($splash);
+
+my ($bbox, $bquit, $breload, $bnext, $bback, $brestart) = make_button_bar ();
+
+$vbox->pack_start($bbox, 0, 0, 0);
+$vbox->pack_start($notebook, 1, 1, 0);
+
+$notebook->set_show_tabs(0);
+$notebook->set_show_border(0);
+
+# Default font size is almost certainly too small
+# for audience to see.
+# XXX we should make font size configurable via
+# @ARGV.
+# XXX any way we can scale WebKit programmatically
+# to set base size which CSS is relative to ?
+# NB careful setting it too big, because it will
+# force a min size on the terminal. Scaling 1.3
+# is biggest we can do while fitting 1024x768
+my $font = $vte->get_font;
+$font->set_size($font->get_size * 1.3);
+
+# When an external command exits, automatically
+# go to the next slide
+$vte->signal_connect (
+ 'child-exited' => sub {
+ if ($pid) {
+ $pid = 0;
+ &switch_slide("NEXT");
+ }
+ });
+
+# Exit if the window is closed
+$w->signal_connect (
+ destroy => sub {
+ Gtk2->main_quit;
+ return FALSE;
+ });
+
+# Handle left/right arrows, page up/down & home/end
+# as slide navigation commands. But not when there
+# is a shell running
+$w->signal_connect (
+ 'key-press-event' => sub {
+ my $src = shift;
+ my $ev = shift;
+
+ # If a shell is running, don't trap keys
+ if ($pid) {
+ return 0;
+ }
+
+ if ($ev->keyval == $Gtk2::Gdk::Keysyms{Right} ||
+ $ev->keyval == $Gtk2::Gdk::Keysyms{Page_Down}) {
+ &switch_slide("NEXT");
+ return 1;
+ } elsif ($ev->keyval == $Gtk2::Gdk::Keysyms{Left} ||
+ $ev->keyval == $Gtk2::Gdk::Keysyms{Page_Up}) {
+ &switch_slide("PREV");
+ return 1;
+ } elsif ($ev->keyval == $Gtk2::Gdk::Keysyms{Home}) {
+ &switch_slide("FIRST");
+ return 1;
+ } elsif ($ev->keyval == $Gtk2::Gdk::Keysyms{End}) {
+ &switch_slide("LAST");
+ return 1;
+ } elsif ($ev->keyval == $Gtk2::Gdk::Keysyms{q} ||
+ $ev->keyval == $Gtk2::Gdk::Keysyms{Escape}) {
+ Gtk2->main_quit;
+ return 1;
+ }
+ return 0;
+ });
+
+
+$w->add ($vbox);
+
+# This allows us to resize the window in window_in_corner().
+$w->set_geometry_hints ($w, { min_width => 100 }, qw(min-size));
+
+$w->show_all ();
+
+window_fullscreen ();
+
+&update_slide();
+
+Gtk2->main();
+
+exit 0;
+