Add window save/restore
Amit Chaudhuri
amit.k.chaudhuri at gmail.com
Sun Feb 3 00:15:11 PST 2013
Hi.
This patch adds window save/restore functionality. Window position and
dimensions are stored and recalled using the same gconf_client style of
calls used elsewhere in subsurface.
For Linux I have made the necessary changes to linux.c, but on windows and
OSX I provide function stubs to invite others to complete. Anyone?
Regards,
Amit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130203/19ba1a63/attachment-0001.html>
-------------- next part --------------
diff --git a/gtk-gui.c b/gtk-gui.c
index e009f5a..4d6f211 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -311,6 +311,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 */
@@ -321,6 +353,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 */
@@ -343,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();
}
@@ -1249,6 +1283,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);
@@ -1618,6 +1653,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;
@@ -1628,6 +1664,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 f78a7c6..0248214 100644
--- a/macos.c
+++ b/macos.c
@@ -43,6 +43,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;
@@ -63,6 +68,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/satellite.h b/satellite.h
index 0e9e228..2cf6f15 100644
--- a/satellite.h
+++ b/satellite.h
@@ -2,27 +2,31 @@
static const GdkPixdata satellite_pixbuf = {
0x47646b50, /* Pixbuf magic: 'GdkP' */
- 24 + 445, /* header length + pixel_data length */
+ 24 + 576, /* header length + pixel_data length */
0x2010002, /* pixdata_type */
44, /* rowstride */
11, /* width */
15, /* height */
/* pixel_data: */
- "\204\0\0\0\0\6\0\0\0\27\0\0\0\243\0\0\0\240\0\0\0\253\0\0\0\215\0\0\0"
- "\22\202\0\0\0\0\2\0\0\0(\0\0\0\23\202\0\0\0\0\11\0\0\0\4\0\0\0.\0\0\0"
- ")\0\0\0,\0\0\0\256\0\0\0\14\0\0\0\0\0\0\0""0\0\0\0\241\202\0\0\0\0\12"
- "\0\0\0\12\0\0\0u\0\0\0\221\0\0\0n\0\0\0A\0\0\0r\0\0\0\0\0\0\0\"\0\0\0"
- "\376\0\0\0<\204\0\0\0\0\10\0\0\0\254\0\0\0\2\0\0\0\245\0\0\0\0\0\0\0"
- "\2\0\0\0\357\0\0\0\337\0\0\0\23\203\0\0\0\0\3\0\0\0[\0\0\0\17\0\0\0\232"
- "\202\0\0\0\0\4\0\0\0\257\0\0\0\377\0\0\0\321\0\0\0\36\204\0\0\0\0\1\0"
- "\0\0\24\202\0\0\0\0\6\0\0\0""7\0\0\0\376\0\0\0\377\0\0\0\362\0\0\0y\0"
- "\0\0\23\206\0\0\0\0\2\0\0\0g\0\0\0\374\202\0\0\0\377\4\0\0\0\373\0\0"
- "\0\301\0\0\0{\0\0\0,\204\0\0\0\0\12\0\0\0\35\0\0\0o\0\0\0\206\0\0\0\200"
- "\0\0\0d\0\0\0""3\0\0\0\4\0\0\0\0\0\0\0-\0\0\0\7\211\0\0\0\0\3\0\0\0\243"
- "\0\0\0\307\0\0\0P\207\0\0\0\0\5\0\0\0\5\0\0\0\360\0\0\0\377\0\0\0\372"
- "\0\0\0\33\206\0\0\0\0\1\0\0\0@\203\0\0\0\377\1\0\0\0\201\206\0\0\0\0"
- "\1\0\0\0\215\203\0\0\0\377\2\0\0\0\352\0\0\0\10\205\0\0\0\0\1\0\0\0\331"
- "\204\0\0\0\377\1\0\0\0_\205\0\0\0\0",
+ "R\226\226\226\0\223\223\223\2\226\226\226\1...\0""5551\36\36\36\253\33"
+ "\33\33\243\34\34\34\251\35\35\35\243+++5\0\0\0\0""555\0""999,@@@%111"
+ "\0///\17""444*,,,O***O'''Q\35\35\35\241///,\26\26\26\0\40\40\40N\33\33"
+ "\33\222jjj\5>>>\0AAA\40\"\"\"u\33\33\33\221&&&r$$$]\35\35\35\214\31\31"
+ "\31\0\36\36\36=\12\12\12\347###T\0\0\0\0\377\377\377\0\7\7\7\0---\26"
+ "\33\33\33\235+++=\34\34\34\251...\0///#\10\10\10\345\13\13\13\330..."
+ "0\31\31\31\0OOO\0""999\12(((d,,,=\36\36\36\237RRR\0bbb\10\17\17\17\265"
+ "\1\1\1\377\14\14\14\312+++:\374\374\374\1\0\0\0\0\377\377\377\0===\23"
+ "333+\254\254\254\0\0\0\0\0\"\"\"Y\5\5\5\366\0\0\0\377\10\10\10\344\25"
+ "\25\25\201)))+___\6\0\0\0\0\367\367\367\0\0\0\0\0GGG\0\\\\\\\10\33\33"
+ "\33\201\6\6\6\357\202\1\1\1\377\4\7\7\7\352\20\20\20\265\40\40\40rFF"
+ "F0\202\0\0\0\0\16GGG\0WWW\5$$$<\26\26\26}\11\11\11\223\14\14\14\222\24"
+ "\24\24}\37\37\37SHHH#\1\1\1\0""7779999!\31\31\31\0\353\353\353\0\206"
+ "\0\0\0\0\6\211\211\211\5\22\22\22\250\16\16\16\311\40\40\40_XXX\6SSS"
+ "\0\205\0\0\0\0\6""444%\11\11\11\334\0\0\0\377\7\7\7\354***7\36\36\36"
+ "\0\205\0\0\0\0\7\37\37\37`\3\3\3\370\0\0\0\377\1\1\1\377\25\25\25\215"
+ "\377\377\377\0jjj\0\204\0\0\0\0\2\23\23\23\252\1\1\1\377\202\0\0\0\377"
+ "\3\11\11\11\334555$...\0\204\0\0\0\0\1\13\13\13\347\203\0\0\0\377\4\3"
+ "\3\3\376\35\35\35i\0\0\0\0\331\331\331\0\203\0\0\0\0",
};
diff --git a/satellite.png b/satellite.png
index f019538..123a8d5 100644
Binary files a/satellite.png and b/satellite.png differ
diff --git a/windows.c b/windows.c
index 9087c9e..2807c21 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 */
More information about the subsurface
mailing list