Use newer API for full screen presentation
authorThomas White <taw@physics.org>
Mon, 4 Dec 2017 21:22:22 +0000 (22:22 +0100)
committerThomas White <taw@physics.org>
Mon, 4 Dec 2017 21:23:29 +0000 (22:23 +0100)
src/slideshow.c
src/slideshow.h
src/testcard.c

index 86b2426..cbb41bd 100644 (file)
@@ -135,13 +135,25 @@ static gboolean ss_realize_sig(GtkWidget *w, SCSlideshow *ss)
                                                      GDK_BLANK_CURSOR);
        gdk_window_set_cursor(GDK_WINDOW(win), ss->blank_cursor);
 
-       gtk_window_parse_geometry(GTK_WINDOW(w), ss->geom);
        slideshow_rerender(ss);
 
        return FALSE;
 }
 
 
+static void ss_size_sig(GtkWidget *widget, GdkRectangle *rect, SCSlideshow *ss)
+{
+       int w;
+
+       w = rect->height * ss->p->slide_width/ss->p->slide_height;
+       if ( w > rect->width ) w = rect->width;
+       ss->slide_width = w;
+       ss->slide_height = rect->height;
+
+       slideshow_rerender(ss);
+}
+
+
 void sc_slideshow_set_slide(SCSlideshow *ss, SCBlock *ns)
 {
        ss->cur_slide = ns;
@@ -153,10 +165,7 @@ SCSlideshow *sc_slideshow_new(struct presentation *p)
 {
        GdkDisplay *display;
        int n_monitors;
-       int i;
        SCSlideshow *ss;
-       double slide_width = 1024.0; /* Logical slide size */
-       double slide_height = 768.0; /* FIXME: Should come from slide */
 
        ss = g_object_new(SC_TYPE_SLIDESHOW, NULL);
        if ( ss == NULL ) return NULL;
@@ -180,6 +189,8 @@ SCSlideshow *sc_slideshow_new(struct presentation *p)
                         G_CALLBACK(ss_destroy_sig), ss);
        g_signal_connect(G_OBJECT(ss), "realize",
                         G_CALLBACK(ss_realize_sig), ss);
+       g_signal_connect(G_OBJECT(ss), "size-allocate",
+                        G_CALLBACK(ss_size_sig), ss);
 
        g_signal_connect(G_OBJECT(ss->drawingarea), "draw",
                         G_CALLBACK(ss_draw_sig), ss);
@@ -188,26 +199,25 @@ SCSlideshow *sc_slideshow_new(struct presentation *p)
 
        display = gdk_display_get_default();
        n_monitors = gdk_display_get_n_monitors(display);
-       for ( i=0; i<n_monitors; i++ ) {
-
-               GdkMonitor *monitor;
-               GdkRectangle rect;
-               int w;
-
-               monitor = gdk_display_get_monitor(display, i);
-               gdk_monitor_get_geometry(monitor,&rect);
-               snprintf(ss->geom, 255, "%ix%i+%i+%i",
-                        rect.width, rect.height, rect.x, rect.y);
 
-               w = rect.height * slide_width/slide_height;
-               if ( w > rect.width ) w = rect.width;
-               ss->slide_width = w;
-               ss->slide_height = rect.height;
+       GdkMonitor *mon_ss;
+       if ( n_monitors == 1 ) {
+               mon_ss = gdk_display_get_primary_monitor(display);
+               printf("Single monitor mode\n");
+               ss->single_monitor = 1;
+       } else {
+               mon_ss = gdk_display_get_monitor(display, 1);
+               printf("Dual monitor mode\n");
+               ss->single_monitor = 0;
+       }
 
-       } /* FIXME: Sensible (configurable) choice of monitor */
+       /* Workaround because gtk_window_fullscreen_on_monitor doesn't work */
+       GdkRectangle rect;
+       gdk_monitor_get_geometry(mon_ss, &rect);
+       gtk_window_move(GTK_WINDOW(ss), rect.x, rect.y);
+       gtk_window_fullscreen(GTK_WINDOW(ss));
 
        ss->linked = 1;
-       gtk_window_fullscreen(GTK_WINDOW(ss));
        gtk_widget_show_all(GTK_WIDGET(ss));
 
        if ( ss->inhibit != NULL ) do_inhibit(ss->inhibit, 1);
index 2ffc577..665134d 100644 (file)
@@ -54,13 +54,13 @@ struct _scslideshow
        GtkWidget           *drawingarea;
        GdkCursor           *blank_cursor;
        int                  blank;
-       char                 geom[256];
        int                  slide_width;
        int                  slide_height;
        struct inhibit_sys  *inhibit;
        int                  linked;
        cairo_surface_t     *surface;
        struct frame        *top;
+       int                  single_monitor;
 };
 
 
index f2c1d70..4ddb611 100644 (file)
@@ -214,17 +214,22 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct testcard *tc)
 }
 
 
-static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
-                              struct testcard *tc)
+static void size_sig(GtkWidget *widget, GdkRectangle *rect, struct testcard *ss)
 {
-       if ( !event->is_modifier ) gtk_widget_destroy(tc->window);
-       return FALSE;
+       int w;
+
+       w = rect->height * ss->p->slide_width/ss->p->slide_height;
+       if ( w > rect->width ) w = rect->width;
+       ss->slide_width = w;
+       ss->slide_height = rect->height;
 }
 
 
-static gboolean realize_sig(GtkWidget *w, struct testcard *tc)
+
+static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
+                              struct testcard *tc)
 {
-       gtk_window_parse_geometry(GTK_WINDOW(w), tc->geom);
+       if ( !event->is_modifier ) gtk_widget_destroy(tc->window);
        return FALSE;
 }
 
@@ -233,10 +238,7 @@ void show_testcard(struct presentation *p)
 {
        GdkDisplay *display;
        int n_monitors;
-       int i;
        struct testcard *tc;
-       double slide_width = 1024.0; /* Logical slide size */
-       double slide_height = 768.0; /* FIXME: Should come from slide */
 
        tc = calloc(1, sizeof(struct testcard));
        if ( tc == NULL ) return;
@@ -259,8 +261,8 @@ void show_testcard(struct presentation *p)
                         G_CALLBACK(key_press_sig), tc);
        g_signal_connect(G_OBJECT(tc->window), "destroy",
                         G_CALLBACK(destroy_sig), tc);
-       g_signal_connect(G_OBJECT(tc->window), "realize",
-                        G_CALLBACK(realize_sig), tc);
+       g_signal_connect(G_OBJECT(tc->window), "size-allocate",
+                        G_CALLBACK(size_sig), tc);
        g_signal_connect(G_OBJECT(tc->drawingarea), "draw",
                         G_CALLBACK(draw_sig), tc);
 
@@ -268,25 +270,22 @@ void show_testcard(struct presentation *p)
 
        display = gdk_display_get_default();
        n_monitors = gdk_display_get_n_monitors(display);
-       for ( i=0; i<n_monitors; i++ ) {
-
-               GdkMonitor *monitor;
-               GdkRectangle rect;
-               int w;
-
-               monitor = gdk_display_get_monitor(display, i);
-               gdk_monitor_get_geometry(monitor,&rect);
-               snprintf(tc->geom, 255, "%ix%i+%i+%i",
-                        rect.width, rect.height, rect.x, rect.y);
 
-               w = rect.height * slide_width/slide_height;
-               if ( w > rect.width ) w = rect.width;
-               tc->slide_width = w;
-               tc->slide_height = rect.height;
-
-       } /* FIXME: Sensible (configurable) choice of monitor */
+       GdkMonitor *mon_ss;
+       if ( n_monitors == 1 ) {
+               mon_ss = gdk_display_get_primary_monitor(display);
+               printf("Single monitor mode\n");
+       } else {
+               mon_ss = gdk_display_get_monitor(display, 1);
+               printf("Dual monitor mode\n");
+       }
 
+       /* Workaround because gtk_window_fullscreen_on_monitor doesn't work */
+       GdkRectangle rect;
+       gdk_monitor_get_geometry(mon_ss, &rect);
+       gtk_window_move(GTK_WINDOW(tc->window), rect.x, rect.y);
        gtk_window_fullscreen(GTK_WINDOW(tc->window));
+
        gtk_widget_show_all(GTK_WIDGET(tc->window));
 
        if ( tc->inhibit != NULL ) do_inhibit(tc->inhibit, 1);