From 012b015f821dfaa5202e3e6141c8b9552f2c5b5f Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 5 Aug 2016 18:31:17 -0700 Subject: [PATCH] gtk: save games list window size and position --- xwords4/linux/gamesdb.h | 1 + xwords4/linux/gtkmain.c | 34 ++++++++++++++++++++++++++++++++++ xwords4/linux/main.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/xwords4/linux/gamesdb.h b/xwords4/linux/gamesdb.h index a821b1355..d395fa30a 100644 --- a/xwords4/linux/gamesdb.h +++ b/xwords4/linux/gamesdb.h @@ -66,6 +66,7 @@ void deleteGame( sqlite3* pDb, sqlite3_int64 rowid ); #define KEY_LDEVID "LDEVID" #define KEY_SMSPHONE "SMSPHONE" #define KEY_SMSPORT "SMSPORT" +#define KEY_WIN_LOC "WIN_LOC" void db_store( sqlite3* dbp, const gchar* key, const gchar* value ); XP_Bool db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen ); diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index bbaf5359d..85fc6b98e 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -418,6 +418,13 @@ handle_destroy( GtkWidget* XP_UNUSED(widget), gpointer data ) // freeGlobals( globals ); } g_slist_free( apg->globalsList ); + + gchar buf[64]; + sprintf( buf, "%d:%d:%d:%d", apg->lastConfigure.x, + apg->lastConfigure.y, apg->lastConfigure.width, + apg->lastConfigure.height ); + db_store( apg->params->pDb, KEY_WIN_LOC, buf ); + gtk_main_quit(); } @@ -428,6 +435,16 @@ handle_quit_button( GtkWidget* XP_UNUSED(widget), gpointer data ) handle_destroy( NULL, apg ); } +static gboolean +window_configured( GtkWidget* XP_UNUSED(widget), + GdkEventConfigure* event, GtkAppGlobals* apg ) +{ + /* XP_LOGF( "%s(x=%d, y=%d, width=%d, height=%d)", __func__, */ + /* event->x, event->y, event->width, event->height ); */ + apg->lastConfigure = *event; + return FALSE; +} + static GtkWidget* addButton( gchar* label, GtkWidget* parent, GCallback proc, void* closure ) { @@ -462,6 +479,19 @@ setWindowTitle( GtkAppGlobals* apg ) gtk_window_set_title( GTK_WINDOW(window), title ); } +static void +trySetWinConfig( GtkAppGlobals* apg ) +{ + gchar buf[64]; + if ( db_fetch( apg->params->pDb, KEY_WIN_LOC, buf, sizeof(buf)) ) { + int xx, yy, width, height; + sscanf( buf, "%d:%d:%d:%d", &xx, &yy, &width, &height ); + + gtk_window_resize( GTK_WINDOW(apg->window), width, height ); + gtk_window_move (GTK_WINDOW(apg->window), xx, yy ); + } +} + static void makeGamesWindow( GtkAppGlobals* apg ) { @@ -471,9 +501,13 @@ makeGamesWindow( GtkAppGlobals* apg ) apg->window = window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); g_signal_connect( G_OBJECT(window), "destroy", G_CALLBACK(handle_destroy), apg ); + g_signal_connect( window, "configure_event", + G_CALLBACK(window_configured), apg ); setWindowTitle( apg ); + trySetWinConfig( apg ); + GtkWidget* swin = gtk_scrolled_window_new( NULL, NULL ); gtk_container_add( GTK_CONTAINER(window), swin ); gtk_widget_show( swin ); diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index 838e3cc87..1997183bf 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -249,6 +249,8 @@ typedef struct _GtkAppGlobals { GtkWidget* openButton; GtkWidget* rematchButton; GtkWidget* deleteButton; + /* save window position */ + GdkEventConfigure lastConfigure; } GtkAppGlobals; #endif