Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

Try to save window position #178

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions data/gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@
<summary>Warn on no network connection</summary>
<description>Whether or not Ephemeral should warn when there is no network available connection</description>
</key>
<key name="window-maximized" type="b">
<default>false</default>
<summary>Maximized</summary>
<description>Whether the last-used window is maximized</description>
</key>
<key name="window-position" type="(ii)">
<default>(-1, -1)</default>
<summary>Window position</summary>
<description>Most recent window position (x, y) of the last-used window</description>
</key>
<key name="window-size" type="(ii)">
<default>(-1, -1)</default>
<summary>Window size</summary>
<description>Most recent window size (width, height) of the last-used window</description>
</key>
<key name="zoom" type="d">
<default>1.0</default>
<summary>Zoom level</summary>
Expand Down
48 changes: 45 additions & 3 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Ephemeral.MainWindow : Gtk.Window {
private BrowserButton browser_button;
private Gtk.Button erase_button;
private uint overlay_timeout_id = 0;
private uint configure_id;

public MainWindow (Gtk.Application application, string? _uri = null) {
Object (
Expand All @@ -50,9 +51,6 @@ public class Ephemeral.MainWindow : Gtk.Window {
}

construct {
default_height = 800;
default_width = 1280;

var header = new Gtk.HeaderBar ();
header.show_close_button = true;
header.has_subtitle = false;
Expand Down Expand Up @@ -322,6 +320,22 @@ public class Ephemeral.MainWindow : Gtk.Window {
set_titlebar (header);
add (grid);

int window_x, window_y;
var rect = Gtk.Allocation ();

Application.settings.get ("window-position", "(ii)", out window_x, out window_y);
Application.settings.get ("window-size", "(ii)", out rect.width, out rect.height);

if (window_x != -1 || window_y != -1) {
move (window_x, window_y);
}

set_allocation (rect);

if (Application.settings.get_boolean ("window-maximized")) {
maximize ();
}

show_all ();

if (uri != null && uri != "") {
Expand Down Expand Up @@ -724,6 +738,34 @@ public class Ephemeral.MainWindow : Gtk.Window {
add_accel_group (accel_group);
}

public override bool configure_event (Gdk.EventConfigure event) {
if (configure_id != 0) {
GLib.Source.remove (configure_id);
}

configure_id = Timeout.add (100, () => {
configure_id = 0;

if (is_maximized) {
Application.settings.set_boolean ("window-maximized", true);
} else {
Application.settings.set_boolean ("window-maximized", false);

Gdk.Rectangle rect;
get_allocation (out rect);
Application.settings.set ("window-size", "(ii)", rect.width, rect.height);

int root_x, root_y;
get_position (out root_x, out root_y);
Application.settings.set ("window-position", "(ii)", root_x, root_y);
}

return false;
});

return base.configure_event (event);
}

private void update_progress () {
title = web_view.title;
back_button.sensitive = web_view.can_go_back ();
Expand Down