diff --git a/data/io.elementary.terminal.gschema.xml b/data/io.elementary.terminal.gschema.xml index 64205fc134..af65e147de 100644 --- a/data/io.elementary.terminal.gschema.xml +++ b/data/io.elementary.terminal.gschema.xml @@ -17,15 +17,20 @@ - - (-1, -1) - Most recent window size - Most recent window size (width, height) - - - "Normal" - The saved state of the window. - The saved state of the window. + + 700 + Most recent window height + Most recent window height + + + 1024 + Most recent window width + Most recent window width + + + false + Whether window is maximized + Whether the main application window is maximized or not [] diff --git a/src/Application.vala b/src/Application.vala index 19cf91150a..99d07a21cf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -288,6 +288,10 @@ public class Terminal.Application : Gtk.Application { window.add_tab_with_working_directory (working_directory, null, new_tab); } + //TODO In Gtk4 we can just bind the settings to first window properties + // instead of this function + restore_saved_state (window, is_first_window); + if (options.lookup ("minimized", "b", out minimized) && minimized) { window.iconify (); } else { @@ -296,6 +300,28 @@ public class Terminal.Application : Gtk.Application { return 0; } + private void restore_saved_state (Gtk.Window window, bool is_first_window) { + window.resize ( + Application.saved_state.get_int ("window-width"), + Application.saved_state.get_int ("window-height") + ); + + if (Application.saved_state.get_boolean ("is-maximized")) { + window.maximize (); + } + + if (is_first_window) { + window.size_allocate.connect ((alloc) => { + if (!window.is_maximized) { + Application.saved_state.set_int ("window-width", alloc.width); + Application.saved_state.set_int ("window-height", alloc.height); + } + + Application.saved_state.set_boolean ("is-maximized", window.is_maximized); + }); + } + } + protected override void dbus_unregister (DBusConnection connection, string path) { if (dbus_id != 0) { connection.unregister_object (dbus_id); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3460bb37a8..ad94cd0580 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -48,7 +48,6 @@ namespace Terminal { } private Gtk.EventControllerKey key_controller; - private uint timer_window_state_change = 0; private uint focus_timeout = 0; private const int NORMAL = 0; @@ -232,7 +231,6 @@ namespace Terminal { set_size_request (app.minimum_width, app.minimum_height); - restore_saved_state (); show_all (); if (recreate_tabs) { @@ -470,28 +468,6 @@ namespace Terminal { return false; } - private void restore_saved_state () { - var rect = Gdk.Rectangle (); - Terminal.Application.saved_state.get ("window-size", "(ii)", out rect.width, out rect.height); - - default_width = rect.width; - default_height = rect.height; - - if (default_width == -1 || default_height == -1) { - var geometry = get_display ().get_primary_monitor ().get_geometry (); - - default_width = geometry.width * 2 / 3; - default_height = geometry.height * 3 / 4; - } - - var window_state = Terminal.Application.saved_state.get_enum ("window-state"); - if (window_state == MainWindow.MAXIMIZED) { - maximize (); - } else if (window_state == MainWindow.FULLSCREEN) { - is_fullscreen = true; - } - } - private void on_tab_added (Hdy.TabPage tab, int pos) { var term = get_term_widget (tab); term.main_window = this; @@ -604,37 +580,6 @@ namespace Terminal { return appinfo; } - protected override bool configure_event (Gdk.EventConfigure event) { - // triggered when the size, position or stacking of the window has changed - // it is delayed 400ms to prevent spamming gsettings - if (timer_window_state_change > 0) { - GLib.Source.remove (timer_window_state_change); - } - - timer_window_state_change = GLib.Timeout.add (400, () => { - timer_window_state_change = 0; - if (get_window () == null) - return false; - - /* Check for fullscreen first: https://github.com/elementary/terminal/issues/377 */ - if ((get_window ().get_state () & Gdk.WindowState.FULLSCREEN) != 0) { - Terminal.Application.saved_state.set_enum ("window-state", MainWindow.FULLSCREEN); - } else if (is_maximized) { - Terminal.Application.saved_state.set_enum ("window-state", MainWindow.MAXIMIZED); - } else { - Terminal.Application.saved_state.set_enum ("window-state", MainWindow.NORMAL); - - var rect = Gdk.Rectangle (); - get_size (out rect.width, out rect.height); - Terminal.Application.saved_state.set ("window-size", "(ii)", rect.width, rect.height); - } - - return false; - }); - - return base.configure_event (event); - } - private void open_tabs () { string[] tabs = {}; double[] zooms = {};