gui/window: Store window position
And restore it when restarting Ocarina. Implements #88: Remember window position Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
fa96def899
commit
1d3438932e
25
gui/window.c
25
gui/window.c
|
@ -7,9 +7,13 @@
|
|||
|
||||
static const gchar *SETTINGS_WIDTH = "gui.window.width";
|
||||
static const gchar *SETTINGS_HEIGHT = "gui.window.height";
|
||||
static const gchar *SETTINGS_X = "gui.window.x";
|
||||
static const gchar *SETTINGS_Y = "gui.window.y";
|
||||
|
||||
static int saved_width = 0;
|
||||
static int saved_height = 0;
|
||||
static int saved_x = 0;
|
||||
static int saved_y = 0;
|
||||
|
||||
|
||||
gboolean __window_configure(GtkWindow *window, GdkEventConfigure *event,
|
||||
|
@ -17,6 +21,8 @@ gboolean __window_configure(GtkWindow *window, GdkEventConfigure *event,
|
|||
{
|
||||
int width = settings_get(SETTINGS_WIDTH);
|
||||
int height = settings_get(SETTINGS_HEIGHT);
|
||||
int x = settings_get(SETTINGS_X);
|
||||
int y = settings_get(SETTINGS_Y);
|
||||
|
||||
if (event->width != width) {
|
||||
saved_width = width;
|
||||
|
@ -28,6 +34,16 @@ gboolean __window_configure(GtkWindow *window, GdkEventConfigure *event,
|
|||
settings_set(SETTINGS_HEIGHT, event->height);
|
||||
}
|
||||
|
||||
if (event->x != x) {
|
||||
saved_x = x;
|
||||
settings_set(SETTINGS_X, event->x);
|
||||
}
|
||||
|
||||
if (event->y != y) {
|
||||
saved_y = y;
|
||||
settings_set(SETTINGS_Y, event->y);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -38,6 +54,8 @@ gboolean __window_state(GtkWindow *window, GdkEventWindowState *event,
|
|||
event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
|
||||
settings_set(SETTINGS_WIDTH, saved_width);
|
||||
settings_set(SETTINGS_HEIGHT, saved_height);
|
||||
settings_set(SETTINGS_X, saved_x);
|
||||
settings_set(SETTINGS_Y, saved_y);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
@ -53,8 +71,13 @@ void gui_window_init(const gchar *icon)
|
|||
|
||||
saved_width = settings_get(SETTINGS_WIDTH);
|
||||
saved_height = settings_get(SETTINGS_HEIGHT);
|
||||
if (saved_width > 0 && saved_height > 0)
|
||||
saved_x = settings_get(SETTINGS_X);
|
||||
saved_y = settings_get(SETTINGS_Y);
|
||||
|
||||
if (saved_width > 0 || saved_height > 0)
|
||||
gtk_window_resize(gui_window(), saved_width, saved_height);
|
||||
if (saved_x > 0 || saved_y > 0)
|
||||
gtk_window_move(gui_window(), saved_x, saved_y);
|
||||
|
||||
g_free(title);
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
<property name="title" translatable="yes">Ocarina 6.1.3</property>
|
||||
<property name="default_width">1024</property>
|
||||
<property name="default_height">615</property>
|
||||
<property name="gravity">static</property>
|
||||
<signal name="configure-event" handler="__window_configure" swapped="no"/>
|
||||
<signal name="window-state-event" handler="__window_state" swapped="no"/>
|
||||
<child>
|
||||
|
|
|
@ -12,19 +12,27 @@ static void test_window()
|
|||
|
||||
g_assert_false(settings_has("gui.window.width"));
|
||||
g_assert_false(settings_has("gui.window.height"));
|
||||
g_assert_false(settings_has("gui.window.x"));
|
||||
g_assert_false(settings_has("gui.window.y"));
|
||||
g_assert_cmpstr(gtk_window_get_title(window), ==, "Ocarina " CONFIG_VERSION);
|
||||
|
||||
gui_test_main_loop();
|
||||
g_assert_true(settings_has("gui.window.width"));
|
||||
g_assert_true(settings_has("gui.window.height"));
|
||||
g_assert_true(settings_has("gui.window.x"));
|
||||
g_assert_true(settings_has("gui.window.y"));
|
||||
|
||||
settings_set("gui.window.width", 800);
|
||||
settings_set("gui.window.height", 600);
|
||||
settings_set("gui.window.x", 42);
|
||||
settings_set("gui.window.y", 42);
|
||||
gui_window_init("share/ocarina/ocarina.png");
|
||||
|
||||
gui_test_main_loop();
|
||||
g_assert_cmpuint(settings_get("gui.window.width"), ==, 800);
|
||||
g_assert_cmpuint(settings_get("gui.window.height"), ==, 600);
|
||||
g_assert_cmpuint(settings_get("gui.window.x"), ==, 42);
|
||||
g_assert_cmpuint(settings_get("gui.window.y"), ==, 42);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue