From 3f0fd02c57328634821ce8da0e67c1d9d63cdbcc Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 19 Dec 2024 11:52:43 +0000 Subject: [PATCH 1/5] Apply minimum dimensions on restore --- src/MainWindow.vala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index eace3dc76e..99e50fddd9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -508,6 +508,9 @@ namespace Terminal { default_height = geometry.height * 3 / 4; } + default_width = int.max (Application.MINIMUM_WIDTH, default_width); + default_height = int.max (Application.MINIMUM_HEIGHT, default_height); + var window_state = Terminal.Application.saved_state.get_enum ("window-state"); if (window_state == MainWindow.MAXIMIZED) { maximize (); From b51147b922660be02542d8a3dc9c4e8f610d0b75 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 20 Dec 2024 11:45:31 +0000 Subject: [PATCH 2/5] Drop using monitor dimensions --- src/MainWindow.vala | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 99e50fddd9..0b51a2174b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -494,22 +494,13 @@ namespace Terminal { return false; } + // This must run before the window is realized 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; - } - - default_width = int.max (Application.MINIMUM_WIDTH, default_width); - default_height = int.max (Application.MINIMUM_HEIGHT, default_height); + default_width = int.max (Application.MINIMUM_WIDTH, rect.width); + default_height = int.max (Application.MINIMUM_HEIGHT, rect.height); var window_state = Terminal.Application.saved_state.get_enum ("window-state"); if (window_state == MainWindow.MAXIMIZED) { From 7c7595184e39f31e9fda28f8c766a3d3c99abb3d Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 20 Dec 2024 19:06:47 +0000 Subject: [PATCH 3/5] Only first window saves state --- src/Application.vala | 17 ++++++++------- src/MainWindow.vala | 52 ++++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 0fa5a9a084..1e7f3b3439 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -261,15 +261,11 @@ public class Terminal.Application : Gtk.Application { string dir = Environment.get_home_dir (); if (active_window != null) { dir = ((MainWindow)active_window).current_terminal.current_working_directory; + } else { + return; } - var new_window = new MainWindow (this, active_window == null); - new_window.present (); - new_window.set_size_request ( - active_window.width_request, - active_window.height_request - ); - + var new_window = new MainWindow (this, false); new_window.add_tab_with_working_directory (dir); }); @@ -297,11 +293,16 @@ public class Terminal.Application : Gtk.Application { unowned var options = command_line.get_options_dict (); var window = (MainWindow) active_window; var is_first_window = window == null; - bool new_window; + bool new_window = false; // Always restore tabs if creating first window, but no extra tab at this stage if (is_first_window || options.lookup ("new-window", "b", out new_window) && new_window) { window = new MainWindow (this, is_first_window); + // All windows restore the window state from settings so matches first window, + // but only the first window saves its window state + if (is_first_window) { + window.save_window_state (); + } } // If a specified working directory is not requested, use the current working directory from the commandline diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0b51a2174b..ea94bd9091 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -605,35 +605,39 @@ 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); - } + public void save_window_state () { + // Another method used for Gtk4 but keep existing one for now + configure_event.connect (() => { + // 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; + timer_window_state_change = GLib.Timeout.add (400, () => { + timer_window_state_change = 0; + if (get_window () == null) { + return Source.REMOVE; + } - /* 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); + /* 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); + } - 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 Source.REMOVE; + }); - return false; + return Gdk.EVENT_PROPAGATE; }); - - return base.configure_event (event); } private void open_tabs () { From 22d7e7491896e583670fd7c35985e937a21f38ce Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 6 Feb 2025 12:28:19 +0000 Subject: [PATCH 4/5] Set size request from settings before realize; restore to minimum after --- src/Application.vala | 2 +- src/MainWindow.vala | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 1e7f3b3439..98f90d9732 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -298,7 +298,7 @@ public class Terminal.Application : Gtk.Application { // Always restore tabs if creating first window, but no extra tab at this stage if (is_first_window || options.lookup ("new-window", "b", out new_window) && new_window) { window = new MainWindow (this, is_first_window); - // All windows restore the window state from settings so matches first window, + // All windows restore the window state from settings so matches first window, // but only the first window saves its window state if (is_first_window) { window.save_window_state (); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index cb29e7c157..864f7f0d72 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -247,15 +247,18 @@ namespace Terminal { Application.settings.changed["font"].connect (update_font); set_size_request (Application.MINIMUM_WIDTH, Application.MINIMUM_HEIGHT); - - restore_saved_state (); - show_all (); - + restore_saved_state (); // Restores saved window size and state if (recreate_tabs) { open_tabs (); } delete_event.connect (on_delete_event); + realize.connect (() => { + // Reset the size request to allow user to resize the window smaller than initial size + set_size_request (Application.MINIMUM_WIDTH, Application.MINIMUM_HEIGHT); + }); + + show_all (); } public void add_tab_with_working_directory ( @@ -503,9 +506,9 @@ 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 = int.max (Application.MINIMUM_WIDTH, rect.width); - default_height = int.max (Application.MINIMUM_HEIGHT, rect.height); + var initial_width = int.max (Application.MINIMUM_WIDTH, rect.width); + var initial_height = int.max (Application.MINIMUM_HEIGHT, rect.height); + set_size_request (initial_width, initial_height); var window_state = Terminal.Application.saved_state.get_enum ("window-state"); if (window_state == MainWindow.MAXIMIZED) { From 20984fec5e050b5ffc2676864bfb48aa4ec0e31b Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 6 Feb 2025 17:11:42 +0000 Subject: [PATCH 5/5] Ensure zoom_overlay hidden on startup --- src/MainWindow.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 864f7f0d72..203777ebbb 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -256,6 +256,7 @@ namespace Terminal { realize.connect (() => { // Reset the size request to allow user to resize the window smaller than initial size set_size_request (Application.MINIMUM_WIDTH, Application.MINIMUM_HEIGHT); + zoom_overlay.hide_zoom_level (); }); show_all ();