Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initial window size on Wayland #829

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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
Expand Down
64 changes: 31 additions & 33 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +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, 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) {
Expand Down Expand Up @@ -611,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 () {
Expand Down
Loading