Code

tpdfview: Added simple presentation mode.
authorSebastian Harl <sh@tokkee.org>
Fri, 30 Dec 2011 23:31:20 +0000 (00:31 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 30 Dec 2011 23:31:20 +0000 (00:31 +0100)
This mode is enabled by using the '-P' command line switch. If enabled, a
second window will be created to display two "slave" GtkTPDFV widgets side by
side (using a paned widget). One will display the same content as the main
window while the other displays the next slide.

src/tpdfview.c

index 9ae1b792ff4ab6ece44103765d78282d61bf9d44..4d0cec8d09f56ded20459f926c7fd58821725195 100644 (file)
@@ -213,6 +213,8 @@ main(int argc, char **argv)
 
        char win_title[1024];
 
+       _Bool presentation_mode = 0;
+
        GdkColor bg_color;
 
        char *filename;
@@ -220,12 +222,16 @@ main(int argc, char **argv)
        gtk_init(&argc, &argv);
 
        while (42) {
-               int opt = getopt(argc, argv, "hV");
+               int opt = getopt(argc, argv, "PhV");
 
                if (-1 == opt)
                        break;
 
                switch (opt) {
+                       case 'P':
+                               presentation_mode = 1;
+                               break;
+
                        case 'h':
                                exit_usage(argv[0], 0);
                                break;
@@ -266,13 +272,68 @@ main(int argc, char **argv)
        if (! ctl)
                return 1;
 
+       /* TODO: use resource file */
+       gdk_color_parse("#000000", &bg_color);
+
+       if (presentation_mode) {
+               GtkWidget *pres_win;
+               GtkWidget *paned;
+               GtkWidget *tpdfv1, *tpdfv2;
+
+               tpdfv1 = gtk_tpdfv_new(filename);
+               if (! tpdfv1)
+                       return 1;
+
+               if (! tpdfv_ctl_add_slave(ctl, GTK_TPDFV(tpdfv1),
+                                       /* factor = */ 1, /* offset = */ 0))
+                       return 1;
+
+               tpdfv2 = gtk_tpdfv_new(filename);
+               if (! tpdfv2)
+                       return 1;
+
+               if (! tpdfv_ctl_add_slave(ctl, GTK_TPDFV(tpdfv2),
+                                       /* factor = */ 1, /* offset = */ 1))
+                       return 1;
+
+               paned = gtk_hpaned_new();
+               if (! paned)
+                       return 1;
+
+               gtk_paned_pack1(GTK_PANED(paned), tpdfv1, TRUE, TRUE);
+               gtk_paned_pack2(GTK_PANED(paned), tpdfv2, TRUE, TRUE);
+
+               gtk_tpdfv_zoom_fit(tpdfv1);
+               gtk_tpdfv_zoom_fit(tpdfv2);
+
+               pres_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+               if (! pres_win)
+                       return 1;
+
+               gtk_window_set_title(GTK_WINDOW(pres_win), win_title);
+
+               gtk_container_add(GTK_CONTAINER(pres_win), paned);
+
+               gtk_widget_modify_bg(tpdfv1, GTK_STATE_NORMAL, &bg_color);
+               gtk_widget_modify_bg(tpdfv2, GTK_STATE_NORMAL, &bg_color);
+
+               g_signal_connect(G_OBJECT(pres_win), "destroy",
+                               G_CALLBACK(on_destroy), NULL);
+               g_signal_connect(G_OBJECT(pres_win), "key-press-event",
+                               G_CALLBACK(key_press), ctl);
+
+               gtk_widget_modify_bg(pres_win, GTK_STATE_NORMAL, &bg_color);
+               gtk_widget_modify_bg(tpdfv1, GTK_STATE_NORMAL, &bg_color);
+               gtk_widget_modify_bg(tpdfv2, GTK_STATE_NORMAL, &bg_color);
+
+               gtk_widget_show_all(pres_win);
+       }
+
        g_signal_connect(G_OBJECT(win), "destroy",
                        G_CALLBACK(on_destroy), NULL);
        g_signal_connect(G_OBJECT(win), "key-press-event",
                        G_CALLBACK(key_press), ctl);
 
-       /* TODO: use resource file */
-       gdk_color_parse("#000000", &bg_color);
        gtk_widget_modify_bg(tpdfv, GTK_STATE_NORMAL, &bg_color);
 
        gtk_widget_show_all(win);