Work around windows inability to properly position tall windows
This commit is contained in:
parent
53f1915cb0
commit
8e745ef9d8
@ -39,6 +39,8 @@
|
||||
|
||||
|
||||
#define PREFS_REMEMBER_SIZE "window/remember_size"
|
||||
#define PREFS_X "window/x"
|
||||
#define PREFS_Y "window/y"
|
||||
#define PREFS_WIDTH "window/width"
|
||||
#define PREFS_HEIGHT "window/height"
|
||||
#define PREFS_MAXIMIZED "window/maximized"
|
||||
@ -47,6 +49,9 @@
|
||||
#define PREFS_SHOW_STATUSBAR "window/show_statusbar"
|
||||
#define PREFS_TOOLBAR_STYLE "window/toolbar_style"
|
||||
|
||||
#define DEFAULT_X -1000000 // an impossible window position
|
||||
#define DEFAULT_Y -1000000 // an impossible window position
|
||||
|
||||
#define TOOLBAR_STYLE_ACTION_ID "ToolbarStyle"
|
||||
|
||||
static char *default_geometry = NULL;
|
||||
@ -405,6 +410,48 @@ moo_window_class_init (MooWindowClass *klass)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
// Workaround for maximized vertically state bug: in that case the window size is
|
||||
// exactly the vertical size of the monitor (minus task bar), and when the window
|
||||
// is shown, it gets shown below the top edge, so the bottom piece of the window
|
||||
// is covered by the task bar. To work that around, we save and restore the window
|
||||
// position as well.
|
||||
// Note, this is only a partial workaround, consequent windows still will not be
|
||||
// positioned correctly.
|
||||
static void
|
||||
move_first_window (MooWindow *window)
|
||||
{
|
||||
GList *l;
|
||||
GList *toplevels;
|
||||
gboolean first;
|
||||
int x, y;
|
||||
|
||||
x = moo_prefs_get_int (setting (window, PREFS_X));
|
||||
y = moo_prefs_get_int (setting (window, PREFS_Y));
|
||||
|
||||
if (x == DEFAULT_X || y == DEFAULT_Y)
|
||||
return;
|
||||
|
||||
// Do this only for the first window
|
||||
first = TRUE;
|
||||
toplevels = gtk_window_list_toplevels ();
|
||||
for (l = toplevels; l != NULL; l = l->next)
|
||||
{
|
||||
if (window != l->data && MOO_IS_WINDOW (l->data))
|
||||
{
|
||||
first = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free (toplevels);
|
||||
toplevels = NULL;
|
||||
|
||||
if (first)
|
||||
gtk_window_move (GTK_WINDOW (window), x, y);
|
||||
}
|
||||
#endif // __WIN32__
|
||||
|
||||
|
||||
static GObject *
|
||||
moo_window_constructor (GType type,
|
||||
guint n_props,
|
||||
@ -467,6 +514,10 @@ moo_window_constructor (GType type,
|
||||
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
|
||||
|
||||
#ifdef __WIN32__
|
||||
move_first_window (window);
|
||||
#endif // __WIN32__
|
||||
|
||||
if (moo_prefs_get_bool (setting (window, PREFS_MAXIMIZED)))
|
||||
gtk_window_maximize (GTK_WINDOW (window));
|
||||
}
|
||||
@ -745,6 +796,8 @@ moo_window_key_press_event (GtkWidget *widget,
|
||||
return GTK_WIDGET_CLASS (moo_window_parent_class)->key_press_event (widget, event);
|
||||
else
|
||||
return activate_global_accel (window, event) ||
|
||||
/* Call propagate_key_event() and activate_key() in inverse order
|
||||
* from that used by Gtk, so that the focused widget gets it first. */
|
||||
gtk_window_propagate_key_event (GTK_WINDOW (widget), event) ||
|
||||
gtk_window_activate_key (GTK_WINDOW (widget), event) ||
|
||||
/* GtkWindowClass would call two guys above again and then chain up
|
||||
@ -780,6 +833,20 @@ save_size (MooWindow *window)
|
||||
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
|
||||
moo_prefs_set_int (setting (window, PREFS_WIDTH), width);
|
||||
moo_prefs_set_int (setting (window, PREFS_HEIGHT), height);
|
||||
|
||||
#ifdef __WIN32__
|
||||
// see move_first_window()
|
||||
{
|
||||
int x, y;
|
||||
gtk_window_get_position (GTK_WINDOW (window), &x, &y);
|
||||
// It refuses to restore a window snapped to the left,
|
||||
// move it one pixel to the right.
|
||||
if (x == 0 && y == 0)
|
||||
x = 1;
|
||||
moo_prefs_set_int (setting (window, PREFS_X), x);
|
||||
moo_prefs_set_int (setting (window, PREFS_Y), y);
|
||||
}
|
||||
#endif // __WIN32__
|
||||
}
|
||||
}
|
||||
|
||||
@ -1247,6 +1314,8 @@ init_prefs (MooWindow *window)
|
||||
moo_prefs_create_key (setting (window, PREFS_MAXIMIZED), MOO_PREFS_STATE, G_TYPE_BOOLEAN, FALSE);
|
||||
moo_prefs_create_key (setting (window, PREFS_WIDTH), MOO_PREFS_STATE, G_TYPE_INT, 800);
|
||||
moo_prefs_create_key (setting (window, PREFS_HEIGHT), MOO_PREFS_STATE, G_TYPE_INT, 600);
|
||||
moo_prefs_create_key (setting (window, PREFS_X), MOO_PREFS_STATE, G_TYPE_INT, DEFAULT_X);
|
||||
moo_prefs_create_key (setting (window, PREFS_Y), MOO_PREFS_STATE, G_TYPE_INT, DEFAULT_Y);
|
||||
}
|
||||
|
||||
static GtkToolbarStyle
|
||||
|
Loading…
x
Reference in New Issue
Block a user