Save paned positions and main window size to config file
authorHugo Villeneuve <hugo@hugovil.com>
Wed, 2 Oct 2013 02:02:17 +0000 (22:02 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 10 Oct 2013 01:07:21 +0000 (21:07 -0400)
src/emugtk.c

index f84ab0b..91efb28 100644 (file)
@@ -43,6 +43,7 @@
 #include "regwin.h"
 #include "pgmwin.h"
 #include "memwin.h"
+#include "app-config.h"
 
 #define BUTTONS_BORDER 2
 
@@ -50,6 +51,8 @@ static int running;
 static int running_function_tag;
 static GtkWidget *mainwin;
 
+extern struct app_config_t *cfg;
+
 /* Signal DestroyEvent */
 static void
 WindowDestroyEvent(GtkWidget *widget, gpointer data)
@@ -247,6 +250,31 @@ AddMenu(void)
        return menu_bar;
 }
 
+static void
+mainwin_configure_event(GtkWindow *window, GdkEvent *event, gpointer data)
+{
+       //event->configure.x;
+       //event->configure.y;
+       cfg->win_width = event->configure.width;
+       cfg->win_height = event->configure.height;
+}
+
+static void
+hpaned_notify_event(GtkWindow *window, GdkEvent *event, gpointer data)
+{
+       GtkWidget *hpaned = data;
+
+       cfg->hpane_pos = gtk_paned_get_position(GTK_PANED(hpaned));
+}
+
+static void
+vpaned_notify_event(GtkWindow *window, GdkEvent *event, gpointer data)
+{
+       GtkWidget *vpaned = data;
+
+       cfg->vpane_pos = gtk_paned_get_position(GTK_PANED(vpaned));
+}
+
 static void
 emugtk_window_init(void)
 {
@@ -259,12 +287,17 @@ emugtk_window_init(void)
 
        mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(mainwin), PACKAGE);
+       gtk_window_set_default_size(GTK_WINDOW(mainwin),
+                                   cfg->win_width, cfg->win_height);
        gtk_container_set_border_width(GTK_CONTAINER(mainwin), 0);
 
        /* Window DESTROY event. */
        g_signal_connect(mainwin, "destroy",
                         G_CALLBACK(WindowDestroyEvent), NULL);
 
+       g_signal_connect(G_OBJECT(mainwin), "configure-event",
+                        G_CALLBACK(mainwin_configure_event), NULL);
+
        /*
         * main_vbox contains the menu bar and body_vbox (for all remaining
         * items).
@@ -287,9 +320,15 @@ emugtk_window_init(void)
         *   Bottom: memory window
         */
        vpaned = gtk_vpaned_new();
+       gtk_paned_set_position(GTK_PANED(vpaned), cfg->vpane_pos);
+       g_signal_connect(G_OBJECT(vpaned), "notify::position",
+                        G_CALLBACK(vpaned_notify_event), vpaned);
 
        /* hpaned will contain registers and disassembly windows. */
        hpaned = gtk_hpaned_new();
+       gtk_paned_set_position(GTK_PANED(hpaned), cfg->hpane_pos);
+       g_signal_connect(G_OBJECT(hpaned), "notify::position",
+                        G_CALLBACK(hpaned_notify_event), hpaned);
 
        /* 8051 registers frame. */
        scrollwin = regwin_init();
@@ -353,6 +392,8 @@ main(int argc, char **argv)
 
        ParseCommandLineOptions(argc, argv);
 
+       app_config_load();
+
        cpu8051_init();
 
        running = 0;
@@ -372,5 +413,7 @@ main(int argc, char **argv)
        printf("End of program.\n");
 #endif
 
+       app_config_save();
+
        return EXIT_SUCCESS;
 }