[PATCH 1/2] Window save functionality

Dirk Hohndel dirk at hohndel.org
Thu Feb 28 15:43:42 PST 2013


I have now pushed out a modified version of this. I decided against
storing the window position - I think that should be up to the window
manager. It is, however, quite convenient to be able to have Subsurface
remember its size and so I have added that part.

I stayed with the integer values as I need those for another change I am
working on - and two integers seems harmless to me.

/D

subsurface at henrik.synth.no writes:

> From: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
>
> Attached is a second attempt at the window save functionality. It
> adds simple checks for a recollection of a large screen from a
> previous session and either sets geometry to 70% (arbitrary choice)
> of currency screen dims, starting at (0,0),  or to the remembered dims.
>
> I did consider opting for a "maximise" if previous screen too
> large for current, but figured some people might really hate that
> (but I might be wrong?).
>
> I have not (yet) looked at replacing the <>..set_conf_int interface
> with reuse of the string equivalent suggested by Dirk.  I'm not
> sure I'll get to that on V3.0 timescales.  If anyone else can - I'm
> fine with that.
>
> That means for full support this would need the previous contribution
> from Henrik (OSX), plus same for Windows (don't think I saw anything
> on that front).
>
> I realise that this doesn't address all concerns flagged previously,
> but the "big screen last time checks" seemed to me to have the
> greatest impact on the user.  Happy to re-visit the behind the
> scenes stuff for 3.1, or for someone else to add string parsing stuff
> for 3.0.
>
> Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
> Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
> ---
>  gtk-gui.c | 38 ++++++++++++++++++++++++++++++++++++++
>  linux.c   | 14 ++++++++++++++
>  macos.c   | 12 ++++++++++++
>  pref.h    |  2 ++
>  windows.c | 10 ++++++++++
>  5 files changed, 76 insertions(+)
>
> diff --git a/gtk-gui.c b/gtk-gui.c
> index cd9f757..f759b8f 100644
> --- a/gtk-gui.c
> +++ b/gtk-gui.c
> @@ -315,6 +315,38 @@ static void file_open(GtkWidget *w, gpointer data)
>  	gtk_widget_destroy(dialog);
>  }
>  
> +void save_window_geometry(void)
> +{
> +	/* GDK_GRAVITY_NORTH_WEST assumed ( it is the default ) */
> +	int window_origin_x, window_origin_y, window_width, window_height;
> +	gtk_window_get_position(GTK_WINDOW (main_window), &window_origin_x, &window_origin_y);
> +	gtk_window_get_size(GTK_WINDOW (main_window), &window_width, &window_height);
> +
> +	subsurface_set_conf_int("window_origin_x", window_origin_x);
> +	subsurface_set_conf_int("window_origin_y", window_origin_y);
> +	subsurface_set_conf_int("window_width", window_width);
> +	subsurface_set_conf_int("window_height", window_height);
> +}
> +
> +void restore_window_geometry(void)
> +{
> +	int window_origin_x, window_origin_y, window_width, window_height;
> +
> +	window_origin_x = subsurface_get_conf_int("window_origin_x");
> +	window_origin_y = subsurface_get_conf_int("window_origin_y");
> +	window_height = subsurface_get_conf_int("window_height");
> +	window_width = subsurface_get_conf_int("window_width");
> +
> +	window_origin_x == -1 ? window_origin_x = 0 : window_origin_x;
> +	window_origin_y == -1 ? window_origin_y = 0 : window_origin_y;
> +	window_height == -1 ? window_height = 300 : window_height;
> +	window_width == -1 ? window_width = 700 : window_width;
> +
> +	gtk_window_move (GTK_WINDOW (main_window), window_origin_x, window_origin_y);
> +	gtk_window_resize (GTK_WINDOW (main_window), window_width, window_height);
> +
> +}
> +
>  gboolean on_delete(GtkWidget* w, gpointer data)
>  {
>  	/* Make sure to flush any modified dive data */
> @@ -325,6 +357,7 @@ gboolean on_delete(GtkWidget* w, gpointer data)
>  		quit = ask_save_changes();
>  
>  	if (quit){
> +		save_window_geometry();
>  		return FALSE; /* go ahead, kill the program, we're good now */
>  	} else {
>  		return TRUE; /* We are not leaving */
> @@ -347,6 +380,7 @@ static void quit(GtkWidget *w, gpointer data)
>  		quit = ask_save_changes();
>  
>  	if (quit){
> +		save_window_geometry();
>  		dive_list_destroy();
>  		gtk_main_quit();
>  	}
> @@ -1253,6 +1287,7 @@ static void edit_dc_nicknames(GtkWidget *w, gpointer data)
>  		GTK_STOCK_APPLY,
>  		GTK_RESPONSE_APPLY,
>  		NULL);
> +
>  	gtk_widget_set_size_request(dialog, 700, 400);
>  
>  	scroll = gtk_scrolled_window_new(NULL, NULL);
> @@ -1622,6 +1657,7 @@ void init_ui(int *argcp, char ***argvp)
>  	g_signal_connect (G_OBJECT (win), "key_press_event", G_CALLBACK (on_key_press), dive_list);
>  
>  	gtk_widget_set_app_paintable(win, TRUE);
> +	restore_window_geometry();
>  	gtk_widget_show_all(win);
>  
>  	return;
> @@ -1632,6 +1668,8 @@ void run_ui(void)
>  	gtk_main();
>  }
>  
> +
> +
>  void exit_ui(void)
>  {
>  	subsurface_close_conf();
> diff --git a/linux.c b/linux.c
> index bf5c21d..4add7bb 100644
> --- a/linux.c
> +++ b/linux.c
> @@ -38,6 +38,11 @@ void subsurface_set_conf_bool(char *name, int value)
>  	gconf_client_set_bool(gconf, gconf_name(name), value > 0, NULL);
>  }
>  
> +void subsurface_set_conf_int(char *name, int value)
> +{
> +	gconf_client_set_int(gconf, gconf_name(name), value , NULL);
> +}
> +
>  const void *subsurface_get_conf(char *name)
>  {
>  	return gconf_client_get_string(gconf, gconf_name(name), NULL);
> @@ -56,6 +61,15 @@ int subsurface_get_conf_bool(char *name)
>  	return ret;
>  }
>  
> +int subsurface_get_conf_int(char *name)
> +{
> +	int val = gconf_client_get_int(gconf, gconf_name(name), NULL);
> +	if(!val)
> +		return -1;
> +
> +	return val;
> +}
> +
>  void subsurface_flush_conf(void)
>  {
>  	/* this is a no-op */
> diff --git a/macos.c b/macos.c
> index 2e549f9..792b165 100644
> --- a/macos.c
> +++ b/macos.c
> @@ -44,6 +44,11 @@ void subsurface_set_conf_bool(char *name, int value)
>  		value ? kCFBooleanTrue : kCFBooleanFalse, SUBSURFACE_PREFERENCES);
>  }
>  
> +void subsurface_set_conf_int(char *name, int value)
> +{
> +	/* CF pref stuff here? */
> +}
> +
>  const void *subsurface_get_conf(char *name)
>  {
>  	CFPropertyListRef strpref;
> @@ -64,6 +69,13 @@ int subsurface_get_conf_bool(char *name)
>  	return boolpref;
>  }
>  
> +int subsurface_get_conf_int(char *name)
> +{
> +
> +	return -1; /* CF pref stuff here? */
> +
> +}
> +
>  void subsurface_flush_conf(void)
>  {
>  	int ok = CFPreferencesAppSynchronize(SUBSURFACE_PREFERENCES);
> diff --git a/pref.h b/pref.h
> index 7dd0e5a..c4287aa 100644
> --- a/pref.h
> +++ b/pref.h
> @@ -44,9 +44,11 @@ extern struct preferences prefs, default_prefs;
>  extern void subsurface_open_conf(void);
>  extern void subsurface_set_conf(char *name, const char *value);
>  extern void subsurface_set_conf_bool(char *name, gboolean value);
> +extern void subsurface_set_conf_int(char *name, int value);
>  extern void subsurface_unset_conf(char *name);
>  extern const void *subsurface_get_conf(char *name);
>  extern int subsurface_get_conf_bool(char *name);
> +extern int subsurface_get_conf_int(char *name);
>  extern void subsurface_flush_conf(void);
>  extern void subsurface_close_conf(void);
>  
> diff --git a/windows.c b/windows.c
> index 3db08de..948b1f7 100644
> --- a/windows.c
> +++ b/windows.c
> @@ -84,6 +84,11 @@ void subsurface_set_conf_bool(char *name, int value)
>  	free(wname);
>  }
>  
> +void subsurface_set_conf_int(char *name, int value)
> +{
> +	/* call to set registry key to value here? */
> +}
> +
>  const void *subsurface_get_conf(char *name)
>  {
>  	const int csize = 64;
> @@ -127,6 +132,11 @@ int subsurface_get_conf_bool(char *name)
>  	return get_from_registry(hkey, name);
>  }
>  
> +int subsurface_get_conf_int(char *name)
> +{
> +	return -1; /* windows registry call here? */
> +}
> +
>  void subsurface_flush_conf(void)
>  {
>  	/* this is a no-op */
> -- 
> 1.8.1.3
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface


More information about the subsurface mailing list