gnucash master: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Thu Mar 16 13:28:57 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/68ece424 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f8262404 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e6a072e9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f38526c0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b46d81e5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/252b1694 (commit)
	from  https://github.com/Gnucash/gnucash/commit/ef0c9deb (commit)



commit 68ece42440f69e2a086b22adb306fb7b99467ec9
Merge: ef0c9deb7f f826240488
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Mar 16 10:01:39 2023 -0700

    Merge Richard Cohen's 'replace-deprecated-gdk-screen-width-height' into master.


commit f826240488d3d2e4dd92645d1331e5fb4fe00e7b
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Mon Mar 13 10:20:19 2023 +0000

    Always enable deprecation warnings for glib & gtk
    
    - Remove WARN_DEPRECATED_GLIB/GTK

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3e18e2cea..3c8b935490 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,8 +52,6 @@ option (WITH_OFX "compile with ofx support (needs LibOFX)" ON)
 option (WITH_PYTHON "enable python plugin and bindings" OFF)
 option (ENABLE_BINRELOC "compile with binary relocation support" ON)
 option (DISABLE_NLS "do not use Native Language Support" OFF)
-option (WARN_DEPRECATED_GLIB "warn about deprecated glib functions" OFF)
-option (WARN_DEPRECATED_GTK "warn about deprecated gtk, gdk or gdk-pixbuf functions" OFF)
 # ############################################################
 
 # These are also settable from the command line in a similar way.
@@ -775,29 +773,17 @@ set(PLATFORM_OSX 1)
 set(HAVE_OSX_KEYCHAIN 1)
 endif()
 
-if(WARN_DEPRECATED_GLIB)
-  string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GLIB_MIN_MATCH ${GLIB_MIN_VERSION})
-  set(GLIB_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
+string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GLIB_MIN_MATCH ${GLIB_MIN_VERSION})
+set(GLIB_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
+target_compile_definitions(PkgConfig::GLIB2 INTERFACE
+  GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_${GLIB_API}
+  GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_${GLIB_API})
 
-  target_compile_definitions(PkgConfig::GLIB2 INTERFACE
-      GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_${GLIB_API}
-      GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_${GLIB_API})
-else()
-  target_compile_definitions(PkgConfig::GLIB2 INTERFACE
-      GLIB_DISABLE_DEPRECATION_WARNINGS)
-endif()
-
-if (WARN_DEPRECATED_GTK)
-  string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GTK_MIN_MATCH ${GTK_MIN_VERSION})
-  set(GTK_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
-
-  target_compile_definitions(PkgConfig::GTK3 INTERFACE
-      GDK_VERSION_MIN_REQUIRED=GDK_VERSION_${GTK_API}
-      GDK_VERSION_MAX_ALLOWED=GDK_VERSION_${GTK_API})
-else()
-  target_compile_definitions(PkgConfig::GTK3 INTERFACE
-      GDK_DISABLE_DEPRECATION_WARNINGS)
-endif()
+string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GTK_MIN_MATCH ${GTK_MIN_VERSION})
+set(GTK_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
+target_compile_definitions(PkgConfig::GTK3 INTERFACE
+    GDK_VERSION_MIN_REQUIRED=GDK_VERSION_${GTK_API}
+    GDK_VERSION_MAX_ALLOWED=GDK_VERSION_${GTK_API})
 
 add_definitions (-DHAVE_CONFIG_H)
 

commit e6a072e906ee2cd5e97d296b91a24cc4c75f0840
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Mon Mar 13 12:29:52 2023 +0000

    Replace deprecated gdk_screen_width/height

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index e9a5391b88..839598d552 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -536,11 +536,32 @@ cleanup:
     g_free(page_group);
 }
 
+static bool
+intersects_some_monitor(const GdkRectangle& rect)
+{
+    auto display = gdk_display_get_default();
+    if (!display)
+        return false;
+
+    int n = gdk_display_get_n_monitors(display);
+    for (int i = 0; i < n; ++i)
+    {
+        auto monitor = gdk_display_get_monitor(display, i);
+        GdkRectangle monitor_geometry;
+        gdk_monitor_get_geometry(monitor, &monitor_geometry);
+        DEBUG("Monitor %d: position (%d,%d), size %dx%d\n", i,
+                        monitor_geometry.x, monitor_geometry.y,
+                        monitor_geometry.width, monitor_geometry.height);
+        if (gdk_rectangle_intersect(&rect, &monitor_geometry, nullptr))
+            return true;
+    }
+
+    return false;
+}
+
 static void
 set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *window_group)
 {
-    auto priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
-
     gsize length;
     GError *error = nullptr;
     gint *geom = g_key_file_get_integer_list(data->key_file, window_group,
@@ -579,21 +600,24 @@ set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *w
         g_warning("invalid number of values for group %s key %s",
                   window_group, WINDOW_POSITION);
     }
-    /* Prevent restoring coordinates if this would move the window off-screen */
-    else if ((pos[0] + (geom ? geom[0] : 0) < 0) ||
-             (pos[0] > gdk_screen_width()) ||
-             (pos[1] + (geom ? geom[1] : 0) < 0) ||
-             (pos[1] > gdk_screen_height()))
+    else if (pos)
     {
-        DEBUG("position (%d,%d), size %dx%d is offscreen; will not move",
-                pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
-    }
-    else
-    {
-        gtk_window_move(GTK_WINDOW(window), pos[0], pos[1]);
-        priv->pos[0] = pos[0];
-        priv->pos[1] = pos[1];
-        DEBUG("window (%p) position (%d,%d)", window, pos[0], pos[1]);
+        // Prevent restoring coordinates if this would move the window off-screen
+        // If missing geom, use height=width=1 to make the intersection check work
+        GdkRectangle geometry{pos[0], pos[1], geom ? geom[0] : 1, geom ? geom[1] : 1};
+        if (intersects_some_monitor(geometry))
+        {
+            gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
+            auto priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+            priv->pos[0] = geometry.x;
+            priv->pos[1] = geometry.y;
+            DEBUG("window (%p) position (%d,%d)", window, geometry.x, geometry.y);
+        }
+        else
+        {
+            DEBUG("position (%d,%d), size %dx%d is offscreen; will not move",
+                  geometry.x, geometry.y, geometry.width, geometry.height);
+        }
     }
     g_free(geom);
     g_free(pos);

commit f38526c0914cf439189ae24cf41dcb434513697f
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Mon Mar 13 12:29:45 2023 +0000

    Remove some unnecessary null checks before g_free

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index f95fa1dfde..e9a5391b88 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -595,14 +595,8 @@ set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *w
         priv->pos[1] = pos[1];
         DEBUG("window (%p) position (%d,%d)", window, pos[0], pos[1]);
     }
-    if (geom)
-    {
-        g_free(geom);
-    }
-    if (pos)
-    {
-        g_free(pos);
-    }
+    g_free(geom);
+    g_free(pos);
 
     gboolean max = g_key_file_get_boolean(data->key_file, window_group,
                                  WINDOW_MAXIMIZED, &error);

commit b46d81e5e028227d0fb9f8001b4786a45db6b180
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Mon Mar 13 12:26:45 2023 +0000

    Correct some DEBUG messages

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index b163944b2b..f95fa1dfde 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -585,7 +585,7 @@ set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *w
              (pos[1] + (geom ? geom[1] : 0) < 0) ||
              (pos[1] > gdk_screen_height()))
     {
-        DEBUG("position %dx%d, size%dx%d is offscreen; will not move",
+        DEBUG("position (%d,%d), size %dx%d is offscreen; will not move",
                 pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
     }
     else
@@ -987,7 +987,7 @@ gnc_main_window_save_window (GncMainWindow *window, GncMainWindowSaveData *data)
         gint *pos = priv->pos;
         g_key_file_set_integer_list(data->key_file, window_group,
                                     WINDOW_POSITION, &pos[0], 2);
-        DEBUG("window minimized (%p) position %dx%d", window, pos[0], pos[1]);
+        DEBUG("window minimized (%p) position (%d,%d)", window, pos[0], pos[1]);
     }
     else
         g_key_file_set_integer_list(data->key_file, window_group,
@@ -996,7 +996,7 @@ gnc_main_window_save_window (GncMainWindow *window, GncMainWindowSaveData *data)
                                 WINDOW_GEOMETRY, &coords[2], 2);
     g_key_file_set_boolean(data->key_file, window_group,
                            WINDOW_MAXIMIZED, maximized);
-    DEBUG("window (%p) position %dx%d, size %dx%d, %s", window,  coords[0], coords[1],
+    DEBUG("window (%p) position (%d,%d), size %dx%d, %s", window,  coords[0], coords[1],
           coords[2], coords[3],
           maximized ? "maximized" : "not maximized");
 

commit 252b1694144a4b3a932e26faeae385342660b0a6
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Mon Mar 13 10:34:09 2023 +0000

    Refactor: Extract method set_window_geometry()

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index 7a940bac72..b163944b2b 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -536,6 +536,88 @@ cleanup:
     g_free(page_group);
 }
 
+static void
+set_window_geometry(GncMainWindow *window, GncMainWindowSaveData *data, gchar *window_group)
+{
+    auto priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+
+    gsize length;
+    GError *error = nullptr;
+    gint *geom = g_key_file_get_integer_list(data->key_file, window_group,
+                                       WINDOW_GEOMETRY, &length, &error);
+    if (error)
+    {
+        g_warning("error reading group %s key %s: %s",
+                  window_group, WINDOW_GEOMETRY, error->message);
+        g_error_free(error);
+        error = nullptr;
+    }
+    else if (length != 2)
+    {
+        g_warning("invalid number of values for group %s key %s",
+                  window_group, WINDOW_GEOMETRY);
+    }
+    else
+    {
+        gtk_window_resize(GTK_WINDOW(window), geom[0], geom[1]);
+        DEBUG("window (%p) size %dx%d", window, geom[0], geom[1]);
+    }
+
+    /* keep the geometry for a test whether the windows position
+       is offscreen */
+    gint *pos = g_key_file_get_integer_list(data->key_file, window_group,
+                                      WINDOW_POSITION, &length, &error);
+    if (error)
+    {
+        g_warning("error reading group %s key %s: %s",
+                  window_group, WINDOW_POSITION, error->message);
+        g_error_free(error);
+        error = nullptr;
+    }
+    else if (length != 2)
+    {
+        g_warning("invalid number of values for group %s key %s",
+                  window_group, WINDOW_POSITION);
+    }
+    /* Prevent restoring coordinates if this would move the window off-screen */
+    else if ((pos[0] + (geom ? geom[0] : 0) < 0) ||
+             (pos[0] > gdk_screen_width()) ||
+             (pos[1] + (geom ? geom[1] : 0) < 0) ||
+             (pos[1] > gdk_screen_height()))
+    {
+        DEBUG("position %dx%d, size%dx%d is offscreen; will not move",
+                pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
+    }
+    else
+    {
+        gtk_window_move(GTK_WINDOW(window), pos[0], pos[1]);
+        priv->pos[0] = pos[0];
+        priv->pos[1] = pos[1];
+        DEBUG("window (%p) position (%d,%d)", window, pos[0], pos[1]);
+    }
+    if (geom)
+    {
+        g_free(geom);
+    }
+    if (pos)
+    {
+        g_free(pos);
+    }
+
+    gboolean max = g_key_file_get_boolean(data->key_file, window_group,
+                                 WINDOW_MAXIMIZED, &error);
+    if (error)
+    {
+        g_warning("error reading group %s key %s: %s",
+                  window_group, WINDOW_MAXIMIZED, error->message);
+        g_error_free(error);
+        error = nullptr;
+    }
+    else if (max)
+    {
+        gtk_window_maximize(GTK_WINDOW(window));
+    }
+}
 
 /** Restore all the pages in a given window.  This function restores
  *  all the window specific attributes, then calls a helper function
@@ -550,17 +632,15 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
 {
     GncMainWindowPrivate *priv;
     GAction *action;
-    gint *pos, *geom, *order;
+    gint *order;
     gsize length;
-    gboolean max;
-    gchar *window_group;
     gsize page_start, page_count, i;
     GError *error = nullptr;
 
     /* Setup */
     ENTER("window %p, data %p (key file %p, window %d)",
           window, data, data->key_file, data->window_num);
-    window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
+    gchar *window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
 
     /* Deal with the uncommon case that the state file defines a window
      * but no pages. An example to get in such a situation can be found
@@ -619,83 +699,10 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
         window = gnc_main_window_new();
     }
 
-    priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
-
     /* Get the window coordinates, etc. */
-    geom = g_key_file_get_integer_list(data->key_file, window_group,
-                                       WINDOW_GEOMETRY, &length, &error);
-    if (error)
-    {
-        g_warning("error reading group %s key %s: %s",
-                  window_group, WINDOW_GEOMETRY, error->message);
-        g_error_free(error);
-        error = nullptr;
-    }
-    else if (length != 2)
-    {
-        g_warning("invalid number of values for group %s key %s",
-                  window_group, WINDOW_GEOMETRY);
-    }
-    else
-    {
-        gtk_window_resize(GTK_WINDOW(window), geom[0], geom[1]);
-        DEBUG("window (%p) size %dx%d", window, geom[0], geom[1]);
-    }
-    /* keep the geometry for a test whether the windows position
-       is offscreen */
-
-    pos = g_key_file_get_integer_list(data->key_file, window_group,
-                                      WINDOW_POSITION, &length, &error);
-    if (error)
-    {
-        g_warning("error reading group %s key %s: %s",
-                  window_group, WINDOW_POSITION, error->message);
-        g_error_free(error);
-        error = nullptr;
-    }
-    else if (length != 2)
-    {
-        g_warning("invalid number of values for group %s key %s",
-                  window_group, WINDOW_POSITION);
-    }
-    /* Prevent restoring coordinates if this would move the window off-screen */
-    else if ((pos[0] + (geom ? geom[0] : 0) < 0) ||
-             (pos[0] > gdk_screen_width()) ||
-             (pos[1] + (geom ? geom[1] : 0) < 0) ||
-             (pos[1] > gdk_screen_height()))
-    {
-        DEBUG("position %dx%d, size%dx%d is offscreen; will not move",
-                pos[0], pos[1], geom ? geom[0] : 0, geom ? geom[1] : 0);
-    }
-    else
-    {
-        gtk_window_move(GTK_WINDOW(window), pos[0], pos[1]);
-        priv->pos[0] = pos[0];
-        priv->pos[1] = pos[1];
-        DEBUG("window (%p) position %dx%d", window, pos[0], pos[1]);
-    }
-    if (geom)
-    {
-        g_free(geom);
-    }
-    if (pos)
-    {
-        g_free(pos);
-    }
+    set_window_geometry(window, data, window_group);
 
-    max = g_key_file_get_boolean(data->key_file, window_group,
-                                 WINDOW_MAXIMIZED, &error);
-    if (error)
-    {
-        g_warning("error reading group %s key %s: %s",
-                  window_group, WINDOW_MAXIMIZED, error->message);
-        g_error_free(error);
-        error = nullptr;
-    }
-    else if (max)
-    {
-        gtk_window_maximize(GTK_WINDOW(window));
-    }
+    priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
 
     // need to add the accelerator keys
     gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);



Summary of changes:
 CMakeLists.txt                          |  34 ++----
 gnucash/gnome-utils/gnc-main-window.cpp | 187 ++++++++++++++++++--------------
 2 files changed, 116 insertions(+), 105 deletions(-)



More information about the gnucash-changes mailing list