mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Richard Cohen's 'replace-deprecated-gdk-screen-width-height' into master.
This commit is contained in:
commit
68ece42440
@ -52,8 +52,6 @@ option (WITH_OFX "compile with ofx support (needs LibOFX)" ON)
|
|||||||
option (WITH_PYTHON "enable python plugin and bindings" OFF)
|
option (WITH_PYTHON "enable python plugin and bindings" OFF)
|
||||||
option (ENABLE_BINRELOC "compile with binary relocation support" ON)
|
option (ENABLE_BINRELOC "compile with binary relocation support" ON)
|
||||||
option (DISABLE_NLS "do not use Native Language Support" OFF)
|
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.
|
# 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)
|
set(HAVE_OSX_KEYCHAIN 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WARN_DEPRECATED_GLIB)
|
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GLIB_MIN_MATCH ${GLIB_MIN_VERSION})
|
||||||
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GLIB_MIN_MATCH ${GLIB_MIN_VERSION})
|
set(GLIB_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
|
||||||
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
|
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" GTK_MIN_MATCH ${GTK_MIN_VERSION})
|
||||||
GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_${GLIB_API}
|
set(GTK_API ${CMAKE_MATCH_1}_${CMAKE_MATCH_2})
|
||||||
GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_${GLIB_API})
|
target_compile_definitions(PkgConfig::GTK3 INTERFACE
|
||||||
else()
|
GDK_VERSION_MIN_REQUIRED=GDK_VERSION_${GTK_API}
|
||||||
target_compile_definitions(PkgConfig::GLIB2 INTERFACE
|
GDK_VERSION_MAX_ALLOWED=GDK_VERSION_${GTK_API})
|
||||||
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()
|
|
||||||
|
|
||||||
add_definitions (-DHAVE_CONFIG_H)
|
add_definitions (-DHAVE_CONFIG_H)
|
||||||
|
|
||||||
|
@ -536,6 +536,106 @@ cleanup:
|
|||||||
g_free(page_group);
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else if (pos)
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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
|
/** Restore all the pages in a given window. This function restores
|
||||||
* all the window specific attributes, then calls a helper function
|
* all the window specific attributes, then calls a helper function
|
||||||
@ -550,17 +650,15 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
|
|||||||
{
|
{
|
||||||
GncMainWindowPrivate *priv;
|
GncMainWindowPrivate *priv;
|
||||||
GAction *action;
|
GAction *action;
|
||||||
gint *pos, *geom, *order;
|
gint *order;
|
||||||
gsize length;
|
gsize length;
|
||||||
gboolean max;
|
|
||||||
gchar *window_group;
|
|
||||||
gsize page_start, page_count, i;
|
gsize page_start, page_count, i;
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
|
|
||||||
/* Setup */
|
/* Setup */
|
||||||
ENTER("window %p, data %p (key file %p, window %d)",
|
ENTER("window %p, data %p (key file %p, window %d)",
|
||||||
window, data, data->key_file, data->window_num);
|
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
|
/* 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
|
* but no pages. An example to get in such a situation can be found
|
||||||
@ -619,83 +717,10 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
|
|||||||
window = gnc_main_window_new();
|
window = gnc_main_window_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
|
||||||
|
|
||||||
/* Get the window coordinates, etc. */
|
/* Get the window coordinates, etc. */
|
||||||
geom = g_key_file_get_integer_list(data->key_file, window_group,
|
set_window_geometry(window, data, 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,
|
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to add the accelerator keys
|
// need to add the accelerator keys
|
||||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
||||||
@ -980,7 +1005,7 @@ gnc_main_window_save_window (GncMainWindow *window, GncMainWindowSaveData *data)
|
|||||||
gint *pos = priv->pos;
|
gint *pos = priv->pos;
|
||||||
g_key_file_set_integer_list(data->key_file, window_group,
|
g_key_file_set_integer_list(data->key_file, window_group,
|
||||||
WINDOW_POSITION, &pos[0], 2);
|
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
|
else
|
||||||
g_key_file_set_integer_list(data->key_file, window_group,
|
g_key_file_set_integer_list(data->key_file, window_group,
|
||||||
@ -989,7 +1014,7 @@ gnc_main_window_save_window (GncMainWindow *window, GncMainWindowSaveData *data)
|
|||||||
WINDOW_GEOMETRY, &coords[2], 2);
|
WINDOW_GEOMETRY, &coords[2], 2);
|
||||||
g_key_file_set_boolean(data->key_file, window_group,
|
g_key_file_set_boolean(data->key_file, window_group,
|
||||||
WINDOW_MAXIMIZED, maximized);
|
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],
|
coords[2], coords[3],
|
||||||
maximized ? "maximized" : "not maximized");
|
maximized ? "maximized" : "not maximized");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user