From d742d7b391fb1e28e784161368689b05af791b71 Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Tue, 12 Feb 2013 13:03:23 +0100 Subject: Remember window size This commit has gone through a few iterations and I trimmed it down to what I consider the "conservative minimum" - so this only stores window size, not window position. And in my mind that's the more relevant part, anyway. Have your window manager position the window at a "smart" spot on your screen... Signed-off-by: Amit Chaudhuri Signed-off-by: Henrik Brautaset Aronsen Signed-off-by: Dirk Hohndel --- gtk-gui.c | 26 ++++++++++++++++++++++++++ linux.c | 14 ++++++++++++++ macos.c | 12 ++++++++++++ pref.h | 2 ++ windows.c | 10 ++++++++++ 5 files changed, 64 insertions(+) diff --git a/gtk-gui.c b/gtk-gui.c index adff9e068..58a4d386f 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -319,6 +319,29 @@ 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_width, window_height; + gtk_window_get_size(GTK_WINDOW (main_window), &window_width, &window_height); + subsurface_set_conf_int("window_width", window_width); + subsurface_set_conf_int("window_height", window_height); +} + +void restore_window_geometry(void) +{ + int window_width, window_height; + + window_height = subsurface_get_conf_int("window_height"); + window_width = subsurface_get_conf_int("window_width"); + + window_height == -1 ? window_height = 300 : window_height; + window_width == -1 ? window_width = 700 : window_width; + + 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 */ @@ -329,6 +352,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 */ @@ -352,6 +376,7 @@ static void quit(GtkWidget *w, gpointer data) quit = ask_save_changes(); if (quit){ + save_window_geometry(); dive_list_destroy(); gtk_main_quit(); } @@ -1647,6 +1672,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; diff --git a/linux.c b/linux.c index bf5c21d94..4add7bb01 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 cdfce4c67..af72a69e3 100644 --- a/macos.c +++ b/macos.c @@ -45,6 +45,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; @@ -65,6 +70,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 7dd0e5af4..c4287aa3b 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 3db08deab..948b1f701 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 */ -- cgit v1.2.3-70-g09d2