ocarina: Track the window's maximized state

I need to do some hacky things if the maximization changes.  First, I
need to track the old (w, h) values and restore them in the preferences
since the configure-event will resize the window before the maximize
signal is given.  Next, I need to ignore the next configure event since
it'll overwrite the preferences with the size of the window when it was
maximized.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-11 10:45:37 -04:00
parent 5c618de4df
commit ca35bfd46f
1 changed files with 44 additions and 7 deletions

View File

@ -12,6 +12,8 @@
#include <ocarina/shortcut.h>
*/
static GtkWidget *win;
static int old_w, old_h;
static bool ignore_configure_event = false;
static void resize(int w, int h)
{
@ -26,21 +28,49 @@ static void destroy(GtkWidget *widget, GdkEvent *event, gpointer data)
static void configure(GtkWidget *widget, GdkEvent *event, gpointer data)
{
int w, h;
int x = libsaria::prefs::get("ocarina.window.w");
int y = libsaria::prefs::get("ocarina.window.h");
int old_w = libsaria::prefs::get("ocarina.window.w");
int old_h = libsaria::prefs::get("ocarina.window.h");
if (ignore_configure_event == true) {
ignore_configure_event = false;
return;
}
gtk_window_get_size(GTK_WINDOW(win), &w, &h);
if ( (w == x) && (h == y) )
if ( (w == old_w) && (h == old_h) )
return;
if (w != x)
if (w != old_w)
libsaria::prefs::set("ocarina.window.w", w);
if (h != y)
if (h != old_h)
libsaria::prefs::set("ocarina.window.h", h);
println("New (w,h): (%d, %d)", w, h);
gtk_window_resize(GTK_WINDOW(win), w, h);
}
static void window_state(GtkWidget *widget, GdkEvent *event, gpointer data)
{
bool maxed = false;
bool maximized = libsaria::prefs::get("ocarina.window.maximized");
GdkWindowState state = gdk_window_get_state(GTK_WIDGET(win)->window);
if (state & GDK_WINDOW_STATE_MAXIMIZED)
maxed = true;
if (maxed == maximized)
return;
println("Maximization changed to: %d", maxed);
libsaria::prefs::set("ocarina.window.maximized", maxed);
ignore_configure_event = true;
if ( (maximized == false) && (maxed == true) ) {
println("Restoring old (w,h): (%d, %d)", old_w, old_h);
libsaria::prefs::set("ocarina.window.w", old_w);
libsaria::prefs::set("ocarina.window.h", old_h);
}
}
/*
void window_resize(int w, int h)
{
@ -77,11 +107,18 @@ namespace ocarina
g_signal_connect(win, "destroy", G_CALLBACK(destroy), NULL);
g_signal_connect(win, "configure-event", G_CALLBACK(configure), NULL);
g_signal_connect(win, "window-state-event", G_CALLBACK(window_state), NULL);
set_title("Ocarina " + vers_str());
set_icon(full_path("images/ocarina.png"));
resize(libsaria::prefs::init("ocarina.window.w", 800),
libsaria::prefs::init("ocarina.window.h", 600));
old_w = libsaria::prefs::init("ocarina.window.w", 800);
old_h = libsaria::prefs::init("ocarina.window.h", 600);
resize(old_w, old_h);
if (libsaria::prefs::init("ocarina.window.maximized", false) == true)
gtk_window_maximize(GTK_WINDOW(win));
gtk_widget_show(win);
}