[nautilus/wip/antoniof/gtk4-preparation-popovers: 3/14] window: Drop GdkScreen parameter from ::new()




commit 7eb303d51bfed2c554c8947525c4b7f6e41a69d1
Author: António Fernandes <antoniof gnome org>
Date:   Thu Dec 16 00:05:47 2021 +0000

    window: Drop GdkScreen parameter from ::new()
    
    GdkScreen is obsolete, and gone in GTK 4. Also, most of the time it's
    just the default screen anyway.
    
    For the 2 cases where we actually want to set a display, do it
    separately using wrapers with the same signatures as the GTK 4 API.

 src/nautilus-application.c  | 21 +++++++++++----------
 src/nautilus-application.h  |  3 +--
 src/nautilus-gtk4-helpers.c | 17 +++++++++++++++++
 src/nautilus-gtk4-helpers.h |  6 ++++++
 src/nautilus-window.c       |  8 ++++----
 src/nautilus-window.h       |  2 +-
 6 files changed, 40 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 973e1b521..0240cedf6 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -66,6 +66,7 @@
 #include "nautilus-view.h"
 #include "nautilus-window-slot.h"
 #include "nautilus-window.h"
+#include "nautilus-gtk4-helpers.h"
 
 typedef struct
 {
@@ -240,8 +241,7 @@ menu_provider_init_callback (void)
 }
 
 NautilusWindow *
-nautilus_application_create_window (NautilusApplication *self,
-                                    GdkScreen           *screen)
+nautilus_application_create_window (NautilusApplication *self)
 {
     NautilusWindow *window;
     gboolean maximized;
@@ -252,7 +252,7 @@ nautilus_application_create_window (NautilusApplication *self,
     g_return_val_if_fail (NAUTILUS_IS_APPLICATION (self), NULL);
     nautilus_profile_start (NULL);
 
-    window = nautilus_window_new (screen);
+    window = nautilus_window_new ();
 
     maximized = g_settings_get_boolean
                     (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED);
@@ -369,7 +369,7 @@ real_open_location_full (NautilusApplication     *self,
     GFile *old_location = NULL;
     char *old_uri, *new_uri;
     gboolean use_same;
-    GdkScreen *screen;
+    GdkDisplay *display;
 
     use_same = TRUE;
     /* FIXME: We are having problems on getting the current focused window with
@@ -441,12 +441,13 @@ real_open_location_full (NautilusApplication     *self,
     }
     else
     {
-        screen = active_window != NULL ?
-                 gtk_window_get_screen (GTK_WINDOW (active_window)) :
-                 gdk_screen_get_default ();
+        display = active_window != NULL ?
+                  gtk_root_get_display (GTK_ROOT (active_window)) :
+                  gdk_display_get_default ();
 
-        target_window = nautilus_application_create_window (self, screen);
+        target_window = nautilus_application_create_window (self);
         /* Whatever the caller says, the slot won't be the same */
+        gtk_window_set_display (GTK_WINDOW (target_window), display);
         target_slot = NULL;
     }
 
@@ -465,7 +466,7 @@ open_window (NautilusApplication *self,
     NautilusWindow *window;
 
     nautilus_profile_start (NULL);
-    window = nautilus_application_create_window (self, gdk_screen_get_default ());
+    window = nautilus_application_create_window (self);
 
     if (location != NULL)
     {
@@ -506,7 +507,7 @@ nautilus_application_open_location (NautilusApplication *self,
 
     if (!slot)
     {
-        window = nautilus_application_create_window (self, gdk_screen_get_default ());
+        window = nautilus_application_create_window (self);
     }
     else
     {
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index f915b0d4d..8a66acd1b 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -43,8 +43,7 @@ struct _NautilusApplicationClass {
 
 NautilusApplication * nautilus_application_new (void);
 
-NautilusWindow *     nautilus_application_create_window (NautilusApplication *application,
-                                                        GdkScreen           *screen);
+NautilusWindow *     nautilus_application_create_window (NautilusApplication *application);
 
 void nautilus_application_set_accelerator (GApplication *app,
                                           const gchar  *action_name,
diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c
index 60da7672a..a68363cb8 100644
--- a/src/nautilus-gtk4-helpers.c
+++ b/src/nautilus-gtk4-helpers.c
@@ -88,3 +88,20 @@ gtk_widget_get_first_child (GtkWidget *widget)
 
     return NULL;
 }
+
+GdkDisplay *
+gtk_root_get_display (GtkRoot *root)
+{
+    g_assert (GTK_IS_WINDOW (root));
+
+    return gdk_screen_get_display (gtk_window_get_screen (GTK_WINDOW (root)));
+}
+
+void
+gtk_window_set_display (GtkWindow  *window,
+                        GdkDisplay *display)
+{
+    g_assert (GTK_IS_WINDOW (window));
+
+    gtk_window_set_screen (window, gdk_display_get_default_screen (display));
+}
diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h
index 201183c15..dfd32a65d 100644
--- a/src/nautilus-gtk4-helpers.h
+++ b/src/nautilus-gtk4-helpers.h
@@ -26,5 +26,11 @@ void gtk_revealer_set_child        (GtkRevealer       *revealer,
 
 GtkWidget *gtk_widget_get_first_child (GtkWidget *widget);
 
+#define GTK_ROOT(root) ((GtkRoot *) GTK_WINDOW (root))
+typedef GtkWindow GtkRoot;
+GdkDisplay *gtk_root_get_display   (GtkRoot           *root);
+void        gtk_window_set_display (GtkWindow         *window,
+                                    GdkDisplay        *display);
+
 #endif
 G_END_DECLS
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index c22344882..c866925a7 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1965,8 +1965,9 @@ notebook_create_window_cb (GtkNotebook *notebook,
     }
 
     app = NAUTILUS_APPLICATION (g_application_get_default ());
-    new_window = nautilus_application_create_window
-                     (app, gtk_widget_get_screen (GTK_WIDGET (notebook)));
+    new_window = nautilus_application_create_window (app);
+    gtk_window_set_display (GTK_WINDOW (new_window),
+                            gtk_widget_get_display (GTK_WIDGET (notebook)));
 
     slot = NAUTILUS_WINDOW_SLOT (page);
     g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
@@ -2800,11 +2801,10 @@ nautilus_window_class_init (NautilusWindowClass *class)
 }
 
 NautilusWindow *
-nautilus_window_new (GdkScreen *screen)
+nautilus_window_new (void)
 {
     return g_object_new (NAUTILUS_TYPE_WINDOW,
                          "icon-name", APPLICATION_ID,
-                         "screen", screen,
                          NULL);
 }
 
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 5b9bf9133..7db42b6cf 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -57,7 +57,7 @@ typedef void (* NautilusWindowHandleExported) (NautilusWindow *window,
 #define NAUTILUS_WINDOW_DEFAULT_WIDTH          890
 #define NAUTILUS_WINDOW_DEFAULT_HEIGHT         550
 
-NautilusWindow * nautilus_window_new                  (GdkScreen         *screen);
+NautilusWindow * nautilus_window_new                  (void);
 void             nautilus_window_close                (NautilusWindow    *window);
 
 void nautilus_window_open_location_full               (NautilusWindow          *window,


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