[gthumb] slideshow: start on the same monitor of the window



commit 5a3395b7018efe7f7deefd0555aa67f1e09b87b9
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jan 3 19:37:40 2017 +0100

    slideshow: start on the same monitor of the window

 extensions/slideshow/actions.c |   17 +++++++---
 gthumb/gtk-utils.c             |   66 ++++++++++++++++++++++++++++++++++++++++
 gthumb/gtk-utils.h             |    3 ++
 3 files changed, 81 insertions(+), 5 deletions(-)
---
diff --git a/extensions/slideshow/actions.c b/extensions/slideshow/actions.c
index bd89921..573a9c9 100644
--- a/extensions/slideshow/actions.c
+++ b/extensions/slideshow/actions.c
@@ -45,7 +45,6 @@ gth_browser_activate_slideshow (GSimpleAction *action,
        GthFileData  *location;
        char         *transition_id;
        GList        *transitions = NULL;
-       GdkScreen    *screen;
 
        items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view 
(browser)));
        if ((items == NULL) || (items->next == NULL))
@@ -129,10 +128,18 @@ gth_browser_activate_slideshow (GSimpleAction *action,
        }
        gth_slideshow_set_transitions (GTH_SLIDESHOW (slideshow), transitions);
 
-       screen = gtk_widget_get_screen (slideshow);
-       gtk_window_set_default_size (GTK_WINDOW (slideshow), gdk_screen_get_width (screen), 
gdk_screen_get_height (screen));
-       gtk_window_fullscreen (GTK_WINDOW (slideshow));
-       gtk_window_present (GTK_WINDOW (slideshow));
+       {
+               GdkRectangle  monitor_geometry;
+               int           monitor_num;
+
+               if (_gtk_window_get_monitor_info (GTK_WINDOW (browser), &monitor_geometry, &monitor_num)) {
+                       gtk_window_set_default_size (GTK_WINDOW (slideshow), monitor_geometry.width, 
monitor_geometry.height);
+                       gtk_window_fullscreen_on_monitor (GTK_WINDOW (slideshow), gtk_window_get_screen 
(GTK_WINDOW (browser)), monitor_num);
+               }
+               else
+                       gtk_window_fullscreen (GTK_WINDOW (slideshow));
+               gtk_window_present (GTK_WINDOW (slideshow));
+       }
 
        _g_object_list_unref (transitions);
        g_object_unref (settings);
diff --git a/gthumb/gtk-utils.c b/gthumb/gtk-utils.c
index bb5abe9..d99e907 100644
--- a/gthumb/gtk-utils.c
+++ b/gthumb/gtk-utils.c
@@ -1150,6 +1150,72 @@ _gtk_window_get_is_maximized (GtkWindow *window)
 }
 
 
+gboolean
+_gtk_window_get_monitor_info (GtkWindow           *window,
+                             GdkRectangle *geometry,
+                             int          *number)
+{
+#if GTK_CHECK_VERSION(3, 22, 0)
+
+       GdkWindow  *win;
+       GdkMonitor *monitor;
+
+       win = gtk_widget_get_window (GTK_WIDGET (window));
+       if (win == NULL)
+               return FALSE;
+
+       monitor = gdk_display_get_monitor_at_window (gdk_window_get_display (win), win);
+       if (monitor == NULL)
+               return FALSE;
+
+       if (geometry != NULL)
+               gdk_monitor_get_geometry (monitor, geometry);
+
+       if (number != NULL) {
+               GdkDisplay *display;
+               int         monitor_num;
+               int         i;
+
+               display = gdk_monitor_get_display (monitor);
+               monitor_num = 0;
+               for (i = 0; /* void */; i++) {
+                       GdkMonitor *m = gdk_display_get_monitor (display, i);
+                       if (m == monitor) {
+                               monitor_num = i;
+                               break;
+                       }
+                       if (m == NULL)
+                               break;
+               }
+               *number = monitor_num;
+       }
+
+#else
+
+       GdkWindow *win;
+       GdkScreen *screen;
+       int        monitor_num;
+
+       win = gtk_widget_get_window (GTK_WIDGET (window));
+       if (win == NULL)
+               return FALSE;
+
+       screen = gdk_window_get_screen (win);
+       if (screen == NULL)
+               return FALSE;
+
+       monitor_num = gdk_screen_get_monitor_at_window (screen, win);
+       if (number != NULL)
+               *number = monitor_num;
+
+       if (geometry != NULL)
+               gdk_screen_get_monitor_geometry (screen, monitor_num, geometry);
+#endif
+
+       return TRUE;
+}
+
+
 GdkDevice *
 _gtk_widget_get_client_pointer (GtkWidget *widget)
 {
diff --git a/gthumb/gtk-utils.h b/gthumb/gtk-utils.h
index b316a9f..4ddc0ce 100644
--- a/gthumb/gtk-utils.h
+++ b/gthumb/gtk-utils.h
@@ -150,6 +150,9 @@ void                _gtk_window_add_accelerator_for_action     (GtkWindow           
*window,
 void           _gtk_window_add_accelerators_from_menu     (GtkWindow           *window,
                                                            GMenuModel          *menu);
 gboolean       _gtk_window_get_is_maximized               (GtkWindow           *window);
+gboolean        _gtk_window_get_monitor_info               (GtkWindow          *window,
+                                                           GdkRectangle        *geometry,
+                                                           int                 *number);
 GdkDevice *     _gtk_widget_get_client_pointer            (GtkWidget           *widget);
 void            _gtk_list_box_add_separator               (GtkListBox          *list_box);
 gboolean        _gtk_settings_get_dialogs_use_header       (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]