/** Read in a single geometry key value pair from the recent file. * * @param name the geom_name of the window * @param key the subkey of this pair (e.g. "x") * @param value the new value (e.g. "123") */ static void window_geom_recent_read_pair(const char *name, const char *key, const char *value) { window_geometry_t geom; /* find window geometry maybe already in hashtable */ if(!window_geom_load(name, &geom)) { /* not in table, init geom with "basic" values */ geom.key = NULL; /* Will be set in window_geom_save() */ geom.set_pos = FALSE; geom.x = -1; geom.y = -1; geom.set_size = FALSE; geom.width = -1; geom.height = -1; geom.set_maximized = FALSE;/* this is valid in GTK2 only */ geom.maximized = FALSE; /* this is valid in GTK2 only */ } if (strcmp(key, "x") == 0) { geom.x = (gint)strtol(value, NULL, 10); geom.set_pos = TRUE; } else if (strcmp(key, "y") == 0) { geom.y = (gint)strtol(value, NULL, 10); geom.set_pos = TRUE; } else if (strcmp(key, "width") == 0) { geom.width = (gint)strtol(value, NULL, 10); geom.set_size = TRUE; } else if (strcmp(key, "height") == 0) { geom.height = (gint)strtol(value, NULL, 10); geom.set_size = TRUE; } else if (strcmp(key, "maximized") == 0) { if (g_ascii_strcasecmp(value, "true") == 0) { geom.maximized = TRUE; } else { geom.maximized = FALSE; } geom.set_maximized = TRUE; } else { /* * Silently ignore the bogus key. We shouldn't abort here, * as this could be due to a corrupt recent file. * * XXX - should we print a message about this? */ return; } /* save / replace geometry in hashtable */ window_geom_save(name, &geom); }
/* Present the created window on the screen. */ void window_present(GtkWidget *win) { window_geometry_t geom; const gchar *name; /* present this window */ gtk_window_present(GTK_WINDOW(win)); /* do we have a previously saved size and position of this window? */ name = g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY); if(name) { if(window_geom_load(name, &geom)) { /* XXX - use prefs to select which values to set? */ geom.set_pos = TRUE; geom.set_size = TRUE; geom.set_maximized = TRUE; window_set_geometry(win, &geom); } } }
/* Same as window_new(), but will keep it's geometry values (size, position, ...). * Be sure to use window_present() and window_destroy() appropriately! */ GtkWidget * window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name) { window_geometry_t geom; GtkWidget *win = window_new(type, title); g_object_set_data(G_OBJECT(win), WINDOW_GEOM_KEY, (gpointer)g_strdup(geom_name)); /* do we have a previously saved size and position of this window? */ if(geom_name) { /* It's a good idea to set the position and size of the window already here, * as it's still invisible and won't "flicker the screen" while initially resizing. */ if(window_geom_load(geom_name, &geom)) { /* XXX - use prefs to select which values to set? */ geom.set_pos = TRUE; geom.set_size = TRUE; geom.set_maximized = FALSE; /* don't maximize until window is shown */ window_set_geometry(win, &geom); } } return win; }