/********************************************************************\ * gnc_restore_window_size * * restores the position and size of the given window, if these * * these parameters have been saved earlier. Does nothing if no * * saved values are found. * * * * Args: group - the preferences group to look in for saved coords * * window - the window for which the coords are to be * * restored * * Returns: nothing * \*******************************************************************/ void gnc_restore_window_size(const char *group, GtkWindow *window) { gint wpos[2], wsize[2]; GVariant *geometry; ENTER(""); g_return_if_fail(group != NULL); g_return_if_fail(window != NULL); if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY)) return; geometry = gnc_prefs_get_value (group, GNC_PREF_LAST_GEOMETRY); if (g_variant_is_of_type (geometry, (const GVariantType *) "(iiii)") ) { gint screen_width; gint screen_height; #if GTK_CHECK_VERSION(3,22,0) GdkWindow *win = gdk_screen_get_root_window (gtk_window_get_screen (window)); GdkMonitor *mon = gdk_display_get_monitor_at_window (gtk_widget_get_display (GTK_WIDGET(window)), win); GdkRectangle monitor_size; gdk_monitor_get_geometry (mon, &monitor_size); screen_width = monitor_size.width; screen_height = monitor_size.height; #else screen_width = gdk_screen_width(); //default screen screen_height = gdk_screen_height(); //default screen #endif g_variant_get (geometry, "(iiii)", &wpos[0], &wpos[1], &wsize[0], &wsize[1]); DEBUG("geometry from preferences - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d", wpos[0], wpos[1], wsize[0], wsize[1]); /* (-1, -1) means no geometry was saved (default preferences value) */ if ((wpos[0] != -1) && (wpos[1] != -1)) { /* Keep the window on screen if possible */ if (screen_width != 0) wpos[0] = wpos[0] % screen_width; if (screen_height != 0) wpos[1] = wpos[1] % screen_height; DEBUG("geometry after screen adaption - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d", wpos[0], wpos[1], wsize[0], wsize[1]); gtk_window_move(window, wpos[0], wpos[1]); } /* Don't attempt to restore invalid sizes */ if ((wsize[0] > 0) && (wsize[1] > 0)) gtk_window_resize(window, wsize[0], wsize[1]); } g_variant_unref (geometry); LEAVE(""); }
gint64 gnc_prefs_get_int64 (const gchar *group, const gchar *pref_name) { gint64 result = 0; GVariant *var = gnc_prefs_get_value(group, pref_name); result = g_variant_get_int64 (var); g_variant_unref (var); return result; }
void gnc_prefs_get_coords (const gchar *group, const gchar *pref_name, gdouble *x, gdouble *y) { GVariant *coords = gnc_prefs_get_value (group, pref_name); *x = 0; *y = 0; if (g_variant_is_of_type (coords, (const GVariantType *) "(dd)") ) g_variant_get (coords, "(dd)", x, y); g_variant_unref (coords); }
/********************************************************************\ * gnc_restore_window_size * * restores the position and size of the given window, if these * * these parameters have been saved earlier. Does nothing if no * * saved values are found. * * * * Args: group - the preferences group to look in for saved coords * * window - the window for which the coords are to be * * restored * * Returns: nothing * \*******************************************************************/ void gnc_restore_window_size(const char *group, GtkWindow *window) { gint wpos[2], wsize[2]; GVariant *geometry; ENTER(""); g_return_if_fail(group != NULL); g_return_if_fail(window != NULL); if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY)) return; geometry = gnc_prefs_get_value (group, GNC_PREF_LAST_GEOMETRY); if (g_variant_is_of_type (geometry, (const GVariantType *) "(iiii)") ) { gint screen_width = gdk_screen_width(); gint screen_height = gdk_screen_height(); g_variant_get (geometry, "(iiii)", &wpos[0], &wpos[1], &wsize[0], &wsize[1]); DEBUG("geometry from preferences - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d", wpos[0], wpos[1], wsize[0], wsize[1]); /* (-1, -1) means no geometry was saved (default preferences value) */ if ((wpos[0] != -1) && (wpos[1] != -1)) { /* Keep the window on screen if possible */ if (screen_width != 0) wpos[0] = wpos[0] % screen_width; if (screen_height != 0) wpos[1] = wpos[1] % screen_height; DEBUG("geometry after screen adaption - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d", wpos[0], wpos[1], wsize[0], wsize[1]); gtk_window_move(window, wpos[0], wpos[1]); } /* Don't attempt to restore invalid sizes */ if ((wsize[0] > 0) && (wsize[1] > 0)) gtk_window_resize(window, wsize[0], wsize[1]); } g_variant_unref (geometry); LEAVE(""); }