From 8cdade160641f448d422ca24fca8615036e819c3 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 5 Sep 2024 18:25:10 +0100 Subject: [PATCH 1/5] Do not override deprecated configure event --- src/MainWindow.vala | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ee433deb08..8da8845706 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -604,37 +604,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 = {}; From 052ebfe1a8231bdd9823bb03245cc9f757ab603b Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 5 Sep 2024 19:01:27 +0100 Subject: [PATCH 2/5] Use separate window dimension settings; update with size allocate --- data/io.elementary.terminal.gschema.xml | 13 +++++++++---- src/MainWindow.vala | 20 +++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/data/io.elementary.terminal.gschema.xml b/data/io.elementary.terminal.gschema.xml index 64205fc134..6cf81265bb 100644 --- a/data/io.elementary.terminal.gschema.xml +++ b/data/io.elementary.terminal.gschema.xml @@ -17,10 +17,15 @@ - - (-1, -1) - Most recent window size - Most recent window size (width, height) + + 700 + Most recent window height + Most recent window height + + + 1024 + Most recent window width + Most recent window width "Normal" diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 8da8845706..aa22db5cfe 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -471,18 +471,16 @@ namespace Terminal { } 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 (); + //TODO In Gtk4 we can just bind the settings to the default width and default height + resize ( + Application.saved_state.get_int ("window-width"), + Application.saved_state.get_int ("window-height") + ); - default_width = geometry.width * 2 / 3; - default_height = geometry.height * 3 / 4; - } + size_allocate.connect ((alloc) => { + Application.saved_state.set_int ("window-width", alloc.width); + Application.saved_state.set_int ("window-height", alloc.height); + }); var window_state = Terminal.Application.saved_state.get_enum ("window-state"); if (window_state == MainWindow.MAXIMIZED) { From 10c00e6508adfa41525f06d5de423b16fd0da798 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 5 Sep 2024 19:33:46 +0100 Subject: [PATCH 3/5] Use "is-maximized" setting --- data/io.elementary.terminal.gschema.xml | 8 +++---- src/MainWindow.vala | 28 ++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/data/io.elementary.terminal.gschema.xml b/data/io.elementary.terminal.gschema.xml index 6cf81265bb..af65e147de 100644 --- a/data/io.elementary.terminal.gschema.xml +++ b/data/io.elementary.terminal.gschema.xml @@ -27,10 +27,10 @@ Most recent window width Most recent window width - - "Normal" - The saved state of the window. - The saved state of the window. + + false + Whether window is maximized + Whether the main application window is maximized or not [] diff --git a/src/MainWindow.vala b/src/MainWindow.vala index aa22db5cfe..41bf92fd2f 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; @@ -471,23 +470,24 @@ namespace Terminal { } private void restore_saved_state () { - //TODO In Gtk4 we can just bind the settings to the default width and default height - resize ( - Application.saved_state.get_int ("window-width"), - Application.saved_state.get_int ("window-height") - ); + if (Application.saved_state.get_boolean ("is-maximized")) { + maximize (); + } else { + //TODO In Gtk4 we can just bind the settings to the default width and default height + // for the first window + resize ( + Application.saved_state.get_int ("window-width"), + Application.saved_state.get_int ("window-height") + ); + } size_allocate.connect ((alloc) => { - Application.saved_state.set_int ("window-width", alloc.width); - Application.saved_state.set_int ("window-height", alloc.height); + 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", is_maximized); }); - 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) { From 321b57bcf27e904334a13628eb9e711f0fec210c Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 5 Sep 2024 19:45:30 +0100 Subject: [PATCH 4/5] Handle restoring window dimensions in Application.command_line () --- src/Application.vala | 23 +++++++++++++++++++++++ src/MainWindow.vala | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 19cf91150a..58cda1ecb1 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,25 @@ public class Terminal.Application : Gtk.Application { return 0; } + private void restore_saved_state (Gtk.Window window, bool is_first_window) { + if (Application.saved_state.get_boolean ("is-maximized")) { + window.maximize (); + } else { + window.resize ( + Application.saved_state.get_int ("window-width"), + Application.saved_state.get_int ("window-height") + ); + } + + if (is_first_window) { + window.size_allocate.connect ((alloc) => { + 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 41bf92fd2f..81e181ab73 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -231,7 +231,6 @@ namespace Terminal { set_size_request (app.minimum_width, app.minimum_height); - restore_saved_state (); show_all (); if (recreate_tabs) { @@ -469,27 +468,6 @@ namespace Terminal { return false; } - private void restore_saved_state () { - if (Application.saved_state.get_boolean ("is-maximized")) { - maximize (); - } else { - //TODO In Gtk4 we can just bind the settings to the default width and default height - // for the first window - resize ( - Application.saved_state.get_int ("window-width"), - Application.saved_state.get_int ("window-height") - ); - } - - size_allocate.connect ((alloc) => { - 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", is_maximized); - }); - - - } - private void on_tab_added (Hdy.TabPage tab, int pos) { var term = get_term_widget (tab); term.main_window = this; From 9002f34f43f533e98e8f5d491cd85cbbc6c5d8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 5 Sep 2024 14:24:04 -0700 Subject: [PATCH 5/5] Fix restoring window size when maximized --- src/Application.vala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 58cda1ecb1..99d07a21cf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -301,19 +301,22 @@ public class Terminal.Application : Gtk.Application { } 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 (); - } else { - window.resize ( - Application.saved_state.get_int ("window-width"), - Application.saved_state.get_int ("window-height") - ); } if (is_first_window) { window.size_allocate.connect ((alloc) => { - Application.saved_state.set_int ("window-width", alloc.width); - Application.saved_state.set_int ("window-height", alloc.height); + 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); }); }