Skip to content

Commit df563cc

Browse files
committed
Center window on first save. Avoid the size of window too small when demaximizing (in the first execution).
1 parent 4de3f69 commit df563cc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

appshell/browser/root_window_gtk.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void SaveWindowState(GtkWindow* window) {
7878
gint width = DEFAULT_WINDOW_WIDTH;
7979
gint height = DEFAULT_WINDOW_HEIGHT;
8080

81+
// Try to center the window.
82+
GdkScreen* screen = gdk_screen_get_default();
83+
if (screen) {
84+
left = (gdk_screen_get_width(screen) - DEFAULT_WINDOW_WIDTH) / 2 ;
85+
top = (gdk_screen_get_height(screen) - DEFAULT_WINDOW_HEIGHT) / 2 ;
86+
}
87+
8188
GKeyFile* key_file = g_key_file_new();
8289
GError* err = NULL;
8390
gchar* filePath = NULL;
@@ -182,17 +189,16 @@ void LoadWindowState(GtkWindow* window) {
182189
height = DEFAULT_WINDOW_HEIGHT;
183190
maximized = TRUE;
184191
}
185-
186-
gtk_window_move(GTK_WINDOW(window), left, top);
187-
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
188-
189-
if (maximized)
190-
MaximizeWindow(window);
191-
192192
} else {
193193
any_error = true;
194194
}
195195

196+
gtk_window_move(GTK_WINDOW(window), left, top);
197+
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
198+
199+
if (maximized)
200+
MaximizeWindow(window);
201+
196202
if (err || any_error) {
197203

198204
// The failure could be because the file may not have been present,

0 commit comments

Comments
 (0)